Skip to content

Commit 4033ff5

Browse files
authored
Merge pull request #827 from bloomberg/bs_pp_standalone
bspp standalone
2 parents bf21812 + f160448 commit 4033ff5

21 files changed

+20973
-613
lines changed

jscomp/Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,27 @@ js_fold.ml:js_fold.mlp j.ml
4444
./bin/bsppx.exe: ./bin/config_bsppx.mli ./bin/config_bsppx.ml ./bin/bsppx.mli ./bin/bsppx.ml
4545
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin $^ -o $@
4646

47+
./bin/bspp.exe: ./bin/config_bspp.mli ./bin/config_bspp.ml ./bin/bspp.mli ./bin/bspp.ml
48+
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin $^ -o $@
49+
4750
./bin/bsdep.exe: ./bin/config_bsdep.mli ./bin/config_bsdep.ml ./bin/bsdep.mli ./bin/bsdep.ml
4851
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin $^ -o $@
4952

5053
snapshot: ./bin/bspack.exe snapshotcmj
5154
$(MAKE) snapshotml
5255

56+
57+
# TODO
58+
# enhace for Parser module, we only care about Parser.token
59+
# files including Parsetree/Parser should be shaked
5360
snapshotml:./bin/bspack.exe ./bin/compiler.mllib
5461
@echo "Snapshot ml"
5562
$< -bs-mllib bin/compiler.mllib -o bin/compiler.ml
5663
$< -bs-log-mllib bin/bsppx.mllib -prelude-str 'module Config = Config_bsppx' -bs-exclude-I config -I ../ocaml/utils/ -I ../ocaml/parsing/ -I common -I ext -I syntax -bs-main bsppx_main.ml -o bin/bsppx.ml
5764
$< -bs-log-mllib bin/whole_compiler.mllib -prelude-str 'module Config = Config_whole_compiler' -bs-exclude-I config -o bin/whole_compiler.ml -bs-main js_main.ml -I ../ocaml/utils/ -I ../ocaml/parsing/ -I ../ocaml/typing/ -I ../ocaml/bytecomp/ -I ../ocaml/driver/ -I ext -I syntax -I depends -I common
5865
$< -bs-log-mllib bin/bsdep.mllib -prelude-str 'module Config = Config_bsdep' -bs-exclude-I config -I ../ocaml/utils/ -I ../ocaml/parsing/ -I ../ocaml/driver -I common -I ext -I syntax -I depends -bs-main bsdep_main.ml -o bin/bsdep.ml
66+
$< -bs-log-mllib bin/bspp.mllib -prelude-str 'module Config = Config_bspp' -bs-exclude-I config -I ../ocaml/utils/ -I ../ocaml/parsing/ -I common -I ext -I syntax -I depends -bs-main bspp_main.ml -o bin/bspp.ml
67+
5968

6069
snapshotcmj:
6170
@echo "Collecting cmj files"
@@ -97,12 +106,13 @@ libs:
97106
cd others && $(MAKE) all
98107
@echo "Making others finished"
99108

100-
releasebuild:./bin/bspack.exe
109+
releasebuild:
101110
@echo "Make release compiler"
102111
$(NATIVE) -g -inline 1000 -linkall -w -a -I +compiler-libs -I bin ocamlcommon.cmxa bin/compiler.mli bin/compiler.ml -o bin/bsc.exe
103112
@echo "Make release ppx"
104113
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin bin/config_bsppx.mli bin/config_bsppx.ml bin/bsppx.mli bin/bsppx.ml -o bin/bsppx.exe
105114
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin bin/config_bsdep.mli bin/config_bsdep.ml bin/bsdep.mli bin/bsdep.ml -o bin/bsdep.exe
115+
$(NATIVE) -g -inline 1000 -linkall -w -a -I bin bin/config_bspp.mli bin/config_bspp.ml bin/bspp.mli bin/bspp.ml -o bin/bspp.exe
106116

107117
release:snapshot
108118
$(MAKE) releasebuild
@@ -119,6 +129,7 @@ dist-world:
119129
$(MAKE) bin/bspack.exe
120130
$(MAKE) bin/bsppx.exe
121131
$(MAKE) bin/bsdep.exe
132+
$(MAKE) bin/bspp.exe
122133
$(MAKE) libs
123134

124135

@@ -138,7 +149,7 @@ DEST_BIN=../bin
138149
install:
139150
@echo "copy exe"
140151
mkdir -p $(DEST_BIN) $(DEST)
141-
cp ./bin/bsc.exe ./bin/bsppx.exe ./bin/bspack.exe ./bin/bsdep.exe $(DEST_BIN)
152+
cp ./bin/bsc.exe ./bin/bsppx.exe ./bin/bspack.exe ./bin/bsdep.exe ./bin/bsdep.exe $(DEST_BIN)
142153
@echo "copy stdlib"
143154
cp ./runtime/*.cmt* ./runtime/*.cmj* ./stdlib/*.cm* ./others/*.ml ./others/*.mli ./others/*.cm* \
144155
./runtime/js.ml ./runtime/js.cmi ./runtime/js_unsafe.cmi ./runtime/js_null.ml ./runtime/js_null.cmi \

jscomp/bin/bsdep.ml

+115-88
Original file line numberDiff line numberDiff line change
@@ -18272,6 +18272,8 @@ val iter_directive_built_in_value :
1827218272
(** semantic version predicate *)
1827318273
val semver : Location.t -> string -> string -> bool
1827418274

18275+
val filter_directive_from_lexbuf : Lexing.lexbuf -> (int * int) list
18276+
1827518277
end = struct
1827618278
#1 "lexer.ml"
1827718279
# 15 "parsing/lexer.mll"
@@ -21006,6 +21008,94 @@ and __ocaml_lex_skip_sharp_bang_rec lexbuf __ocaml_lex_state =
2100621008

2100721009
and docstring = Docstrings.docstring
2100821010

21011+
let interpret_directive lexbuf cont look_ahead =
21012+
let if_then_else = !if_then_else in
21013+
begin match token_with_comments lexbuf, if_then_else with
21014+
| IF, Dir_out ->
21015+
let rec skip_from_if_false () =
21016+
let token = token_with_comments lexbuf in
21017+
if token = EOF then
21018+
raise (Error (Unterminated_if, Location.curr lexbuf)) else
21019+
if token = SHARP && at_bol lexbuf then
21020+
begin
21021+
let token = token_with_comments lexbuf in
21022+
match token with
21023+
| END ->
21024+
begin
21025+
update_if_then_else Dir_out;
21026+
cont lexbuf
21027+
end
21028+
| ELSE ->
21029+
begin
21030+
update_if_then_else Dir_if_false;
21031+
cont lexbuf
21032+
end
21033+
| IF ->
21034+
raise (Error (Unexpected_directive, Location.curr lexbuf))
21035+
| _ ->
21036+
if is_elif token &&
21037+
directive_parse token_with_comments lexbuf then
21038+
begin
21039+
update_if_then_else Dir_if_true;
21040+
cont lexbuf
21041+
end
21042+
else skip_from_if_false ()
21043+
end
21044+
else skip_from_if_false () in
21045+
if directive_parse token_with_comments lexbuf then
21046+
begin
21047+
update_if_then_else Dir_if_true (* Next state: ELSE *);
21048+
cont lexbuf
21049+
end
21050+
else
21051+
skip_from_if_false ()
21052+
| IF, (Dir_if_false | Dir_if_true)->
21053+
raise (Error(Unexpected_directive, Location.curr lexbuf))
21054+
| LIDENT "elif", (Dir_if_false | Dir_out)
21055+
-> (* when the predicate is false, it will continue eating `elif` *)
21056+
raise (Error(Unexpected_directive, Location.curr lexbuf))
21057+
| (LIDENT "elif" | ELSE as token), Dir_if_true ->
21058+
(* looking for #end, however, it can not see #if anymore *)
21059+
let rec skip_from_if_true else_seen =
21060+
let token = token_with_comments lexbuf in
21061+
if token = EOF then
21062+
raise (Error (Unterminated_else, Location.curr lexbuf)) else
21063+
if token = SHARP && at_bol lexbuf then
21064+
begin
21065+
let token = token_with_comments lexbuf in
21066+
match token with
21067+
| END ->
21068+
begin
21069+
update_if_then_else Dir_out;
21070+
cont lexbuf
21071+
end
21072+
| IF ->
21073+
raise (Error (Unexpected_directive, Location.curr lexbuf))
21074+
| ELSE ->
21075+
if else_seen then
21076+
raise (Error (Unexpected_directive, Location.curr lexbuf))
21077+
else
21078+
skip_from_if_true true
21079+
| _ ->
21080+
if else_seen && is_elif token then
21081+
raise (Error (Unexpected_directive, Location.curr lexbuf))
21082+
else
21083+
skip_from_if_true else_seen
21084+
end
21085+
else skip_from_if_true else_seen in
21086+
skip_from_if_true (token = ELSE)
21087+
| ELSE, Dir_if_false
21088+
| ELSE, Dir_out ->
21089+
raise (Error(Unexpected_directive, Location.curr lexbuf))
21090+
| END, (Dir_if_false | Dir_if_true ) ->
21091+
update_if_then_else Dir_out;
21092+
cont lexbuf
21093+
| END, Dir_out ->
21094+
raise (Error(Unexpected_directive, Location.curr lexbuf))
21095+
| token, (Dir_if_true | Dir_if_false | Dir_out) ->
21096+
look_ahead token
21097+
end
21098+
2100921099
let token lexbuf =
2101021100
let post_pos = lexeme_end_p lexbuf in
2101121101
let attach lines docs pre_pos =
@@ -21052,93 +21142,10 @@ and __ocaml_lex_skip_sharp_bang_rec lexbuf __ocaml_lex_state =
2105221142
| BlankLine -> BlankLine
2105321143
in
2105421144
loop lines' docs lexbuf
21055-
| SHARP when at_bol lexbuf ->
21056-
let if_then_else = !if_then_else in
21057-
begin match token_with_comments lexbuf, if_then_else with
21058-
| IF, Dir_out ->
21059-
let rec skip_from_if_false () : Parser.token =
21060-
let token = token_with_comments lexbuf in
21061-
if token = EOF then
21062-
raise (Error (Unterminated_if, Location.curr lexbuf)) else
21063-
if token = SHARP && at_bol lexbuf then
21064-
begin
21065-
let token = token_with_comments lexbuf in
21066-
match token with
21067-
| END ->
21068-
begin
21069-
update_if_then_else Dir_out;
21070-
loop lines docs lexbuf
21071-
end
21072-
| ELSE ->
21073-
begin
21074-
update_if_then_else Dir_if_false;
21075-
loop lines docs lexbuf
21076-
end
21077-
| IF ->
21078-
raise (Error (Unexpected_directive, Location.curr lexbuf))
21079-
| _ ->
21080-
if is_elif token &&
21081-
directive_parse token_with_comments lexbuf then
21082-
begin
21083-
update_if_then_else Dir_if_true;
21084-
loop lines docs lexbuf
21085-
end
21086-
else skip_from_if_false ()
21087-
end
21088-
else skip_from_if_false () in
21089-
if directive_parse token_with_comments lexbuf then
21090-
begin
21091-
update_if_then_else Dir_if_true (* Next state: ELSE *);
21092-
loop lines docs lexbuf
21093-
end
21094-
else
21095-
skip_from_if_false ()
21096-
| IF, (Dir_if_false | Dir_if_true)->
21097-
raise (Error(Unexpected_directive, Location.curr lexbuf))
21098-
| LIDENT "elif", (Dir_if_false | Dir_out)
21099-
-> (* when the predicate is false, it will continue eating `elif` *)
21100-
raise (Error(Unexpected_directive, Location.curr lexbuf))
21101-
| (LIDENT "elif" | ELSE as token), Dir_if_true ->
21102-
(* looking for #end, however, it can not see #if anymore *)
21103-
let rec skip_from_if_true else_seen =
21104-
let token = token_with_comments lexbuf in
21105-
if token = EOF then
21106-
raise (Error (Unterminated_else, Location.curr lexbuf)) else
21107-
if token = SHARP && at_bol lexbuf then
21108-
begin
21109-
let token = token_with_comments lexbuf in
21110-
match token with
21111-
| END ->
21112-
begin
21113-
update_if_then_else Dir_out;
21114-
loop lines docs lexbuf
21115-
end
21116-
| IF ->
21117-
raise (Error (Unexpected_directive, Location.curr lexbuf))
21118-
| ELSE ->
21119-
if else_seen then
21120-
raise (Error (Unexpected_directive, Location.curr lexbuf))
21121-
else
21122-
skip_from_if_true true
21123-
| _ ->
21124-
if else_seen && is_elif token then
21125-
raise (Error (Unexpected_directive, Location.curr lexbuf))
21126-
else
21127-
skip_from_if_true else_seen
21128-
end
21129-
else skip_from_if_true else_seen in
21130-
skip_from_if_true (token = ELSE)
21131-
| ELSE, Dir_if_false
21132-
| ELSE, Dir_out ->
21133-
raise (Error(Unexpected_directive, Location.curr lexbuf))
21134-
| END, (Dir_if_false | Dir_if_true ) ->
21135-
update_if_then_else Dir_out;
21136-
loop lines docs lexbuf
21137-
| END, Dir_out ->
21138-
raise (Error(Unexpected_directive, Location.curr lexbuf))
21139-
| token, (Dir_if_true | Dir_if_false | Dir_out) ->
21140-
sharp_look_ahead := Some token; SHARP
21141-
end
21145+
| SHARP when at_bol lexbuf ->
21146+
interpret_directive lexbuf
21147+
(fun lexbuf -> loop lines docs lexbuf)
21148+
(fun token -> sharp_look_ahead := Some token; SHARP)
2114221149
| DOCSTRING doc ->
2114321150
add_docstring_comment doc;
2114421151
let docs' =
@@ -21174,12 +21181,32 @@ and __ocaml_lex_skip_sharp_bang_rec lexbuf __ocaml_lex_state =
2117421181
| None -> ()
2117521182
| Some (init, _preprocess) -> init ()
2117621183

21184+
let rec filter_directive pos acc lexbuf : (int * int ) list =
21185+
match token_with_comments lexbuf with
21186+
| SHARP when at_bol lexbuf ->
21187+
(* ^[start_pos]#if ... #then^[end_pos] *)
21188+
let start_pos = Lexing.lexeme_start lexbuf in
21189+
interpret_directive lexbuf
21190+
(fun lexbuf ->
21191+
filter_directive
21192+
(Lexing.lexeme_end lexbuf)
21193+
((pos, start_pos) :: acc)
21194+
lexbuf
21195+
21196+
)
21197+
(fun _token -> filter_directive pos acc lexbuf )
21198+
| EOF -> (pos, Lexing.lexeme_end lexbuf) :: acc
21199+
| _ -> filter_directive pos acc lexbuf
21200+
21201+
let filter_directive_from_lexbuf lexbuf =
21202+
List.rev (filter_directive 0 [] lexbuf )
21203+
2117721204
let set_preprocessor init preprocess =
2117821205
escaped_newlines := true;
2117921206
preprocessor := Some (init, preprocess)
2118021207

2118121208

21182-
# 2907 "parsing/lexer.ml"
21209+
# 2932 "parsing/lexer.ml"
2118321210

2118421211
end
2118521212
module Bs_conditional_initial : sig

0 commit comments

Comments
 (0)