Skip to content

Commit 0e758d2

Browse files
committed
provide a compatible layer for syntax
1 parent 58f2369 commit 0e758d2

28 files changed

+3216
-2202
lines changed

jscomp/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ COMMON_SRCS= bs_version\
226226
COMMON_CMXS= $(addprefix common/, $(addsuffix .cmx, $(COMMON_SRCS)))
227227
SYNTAX_SRCS= \
228228
bs_syntaxerr\
229+
ast_compatible\
229230
ast_utf8_string\
230231
ast_utf8_string_interp\
231232
ast_derive_constructor \

jscomp/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,25 @@ so that we don't need bootstrap compiler, everytime we deliver a new feature.
4444
## [test](./test)
4545

4646
The directory containing unit-test files, some unit tests are copied from OCaml distribution(4.02)
47+
48+
## compiler sourcetree
49+
50+
- ext
51+
- common
52+
- bsb
53+
- depends
54+
- core
55+
- bspp
56+
- outcome_printer
57+
- stubs
58+
- super_errors
59+
- syntax
60+
## tools (deprecatd code)
61+
## xwatcher (dev tools)
62+
## runtime
63+
## build_tests
64+
## bin
65+
## cmd_tests
66+
## ounit
67+
## ounit_tests
68+
## others (belt/stdlib/node bindings)

jscomp/all.depend

Lines changed: 1000 additions & 997 deletions
Large diffs are not rendered by default.

jscomp/bin/all_ounit_tests.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ bin/all_ounit_tests.ml : ./ounit_tests/ounit_union_find_tests.ml
117117
bin/all_ounit_tests.ml : ./ounit_tests/ounit_utf8_test.ml
118118
bin/all_ounit_tests.ml : ./ounit_tests/ounit_vec_test.ml
119119
bin/all_ounit_tests.ml : ./stubs/bs_hash_stubs.ml
120+
bin/all_ounit_tests.ml : ./syntax/ast_compatible.ml
121+
bin/all_ounit_tests.ml : ./syntax/ast_compatible.mli
120122
bin/all_ounit_tests.ml : ./syntax/ast_utf8_string.ml
121123
bin/all_ounit_tests.ml : ./syntax/ast_utf8_string.mli
122124
bin/all_ounit_tests.ml : ./syntax/ast_utf8_string_interp.ml

jscomp/bin/all_ounit_tests.ml

Lines changed: 173 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14295,6 +14295,171 @@ let transform loc s =
1429514295

1429614296

1429714297

14298+
end
14299+
module Ast_compatible : sig
14300+
#1 "ast_compatible.mli"
14301+
(* Copyright (C) 2018 Authors of BuckleScript
14302+
*
14303+
* This program is free software: you can redistribute it and/or modify
14304+
* it under the terms of the GNU Lesser General Public License as published by
14305+
* the Free Software Foundation, either version 3 of the License, or
14306+
* (at your option) any later version.
14307+
*
14308+
* In addition to the permissions granted to you by the LGPL, you may combine
14309+
* or link a "work that uses the Library" with a publicly distributed version
14310+
* of this file to produce a combined library or application, then distribute
14311+
* that combined work under the terms of your choosing, with no requirement
14312+
* to comply with the obligations normally placed on you by section 4 of the
14313+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14314+
* should you choose to use a later version).
14315+
*
14316+
* This program is distributed in the hope that it will be useful,
14317+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14318+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14319+
* GNU Lesser General Public License for more details.
14320+
*
14321+
* You should have received a copy of the GNU Lesser General Public License
14322+
* along with this program; if not, write to the Free Software
14323+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
14324+
14325+
14326+
type loc = Location.t
14327+
type attrs = Parsetree.attribute list
14328+
open Parsetree
14329+
14330+
14331+
val const_exp_string:
14332+
?loc:Location.t ->
14333+
?attrs:attrs ->
14334+
?delimiter:string ->
14335+
string ->
14336+
expression
14337+
14338+
val const_exp_int:
14339+
?loc:Location.t ->
14340+
?attrs:attrs ->
14341+
int ->
14342+
expression
14343+
14344+
val const_exp_int_list_as_array:
14345+
int list ->
14346+
expression
14347+
14348+
val apply_simple:
14349+
?loc:Location.t ->
14350+
?attrs:attrs ->
14351+
expression ->
14352+
expression list ->
14353+
expression
14354+
14355+
14356+
val apply_labels:
14357+
?loc:Location.t ->
14358+
?attrs:attrs ->
14359+
expression ->
14360+
(string * expression) list ->
14361+
(* [(label,e)] [label] is strictly interpreted as label *)
14362+
expression
14363+
14364+
val fun_ :
14365+
?loc:Location.t ->
14366+
?attrs:attrs ->
14367+
pattern ->
14368+
expression ->
14369+
expression
14370+
end = struct
14371+
#1 "ast_compatible.ml"
14372+
(* Copyright (C) 2018 Authors of BuckleScript
14373+
*
14374+
* This program is free software: you can redistribute it and/or modify
14375+
* it under the terms of the GNU Lesser General Public License as published by
14376+
* the Free Software Foundation, either version 3 of the License, or
14377+
* (at your option) any later version.
14378+
*
14379+
* In addition to the permissions granted to you by the LGPL, you may combine
14380+
* or link a "work that uses the Library" with a publicly distributed version
14381+
* of this file to produce a combined library or application, then distribute
14382+
* that combined work under the terms of your choosing, with no requirement
14383+
* to comply with the obligations normally placed on you by section 4 of the
14384+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14385+
* should you choose to use a later version).
14386+
*
14387+
* This program is distributed in the hope that it will be useful,
14388+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14389+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14390+
* GNU Lesser General Public License for more details.
14391+
*
14392+
* You should have received a copy of the GNU Lesser General Public License
14393+
* along with this program; if not, write to the Free Software
14394+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
14395+
14396+
type loc = Location.t
14397+
type attrs = Parsetree.attribute list
14398+
open Parsetree
14399+
let default_loc = Location.none
14400+
14401+
14402+
14403+
let const_exp_string
14404+
?(loc = default_loc)
14405+
?(attrs = [])
14406+
?delimiter
14407+
(s : string) : expression =
14408+
{
14409+
pexp_loc = loc;
14410+
pexp_attributes = attrs;
14411+
pexp_desc = Pexp_constant(Const_string(s,delimiter))
14412+
}
14413+
14414+
14415+
let const_exp_int
14416+
?(loc = default_loc)
14417+
?(attrs = [])
14418+
(s : int) : expression =
14419+
{
14420+
pexp_loc = loc;
14421+
pexp_attributes = attrs;
14422+
pexp_desc = Pexp_constant(Const_int s)
14423+
}
14424+
14425+
14426+
let const_exp_int_list_as_array xs =
14427+
Ast_helper.Exp.array
14428+
(Ext_list.map (fun x -> const_exp_int x ) xs)
14429+
14430+
let apply_simple
14431+
?(loc = default_loc)
14432+
?(attrs = [])
14433+
fn args : expression =
14434+
{ pexp_loc = loc;
14435+
pexp_attributes = attrs;
14436+
pexp_desc =
14437+
Pexp_apply(
14438+
fn,
14439+
(Ext_list.map (fun x -> "",x) args) ) }
14440+
14441+
let apply_labels
14442+
?(loc = default_loc)
14443+
?(attrs = [])
14444+
fn args : expression =
14445+
{ pexp_loc = loc;
14446+
pexp_attributes = attrs;
14447+
pexp_desc =
14448+
Pexp_apply(
14449+
fn,
14450+
args ) }
14451+
14452+
let fun_
14453+
?(loc = default_loc)
14454+
?(attrs = [])
14455+
pat
14456+
exp =
14457+
{
14458+
pexp_loc = loc;
14459+
pexp_attributes = attrs;
14460+
pexp_desc = Pexp_fun("",None, pat, exp)
14461+
}
14462+
1429814463
end
1429914464
module Bs_loc : sig
1430014465
#1 "bs_loc.mli"
@@ -14845,10 +15010,10 @@ let concat_exp
1484515010
(a : Parsetree.expression)
1484615011
(b : Parsetree.expression) : Parsetree.expression =
1484715012
let loc = Bs_loc.merge a.pexp_loc b.pexp_loc in
14848-
Exp.apply ~loc
15013+
Ast_compatible.apply_simple ~loc
1484915014
(Exp.ident { txt =concat_ident; loc})
14850-
["",a ;
14851-
"",b]
15015+
[a ;
15016+
b]
1485215017

1485315018
let border = String.length "{j|"
1485415019

@@ -14859,19 +15024,17 @@ let aux loc (segment : segment) =
1485915024
begin match kind with
1486015025
| String ->
1486115026
let loc = update border start finish loc in
14862-
Exp.constant
14863-
~loc
14864-
(Const_string (content, escaped))
15027+
Ast_compatible.const_exp_string
15028+
content ?delimiter:escaped ~loc
1486515029
| Var (soffset, foffset) ->
1486615030
let loc = {
1486715031
loc with
1486815032
loc_start = update_position (soffset + border) start loc.loc_start ;
1486915033
loc_end = update_position (foffset + border) finish loc.loc_start
1487015034
} in
14871-
Exp.apply ~loc
15035+
Ast_compatible.apply_simple ~loc
1487215036
(Exp.ident ~loc {loc ; txt = to_string_ident })
1487315037
[
14874-
"",
1487515038
Exp.ident ~loc {loc ; txt = Lident content}
1487615039
]
1487715040
end
@@ -14896,8 +15059,8 @@ let transform_interp loc s =
1489615059
let rev_segments = cxt.segments in
1489715060
match rev_segments with
1489815061
| [] ->
14899-
Exp.constant ~loc
14900-
(Const_string ("", Some Literals.escaped_j_delimiter))
15062+
Ast_compatible.const_exp_string ~loc
15063+
"" ~delimiter:Literals.escaped_j_delimiter
1490115064
| [ segment] ->
1490215065
aux loc segment
1490315066
| a::rest ->

0 commit comments

Comments
 (0)