Skip to content

Commit 676a4c5

Browse files
authored
Vendor the parser. (#285)
Vendor the sources of the ReScript parser.
1 parent 21d484f commit 676a4c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+22886
-4
lines changed

analysis/src/ProcessCmt.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1276,10 +1276,8 @@ let rec resolvePath ~env ~path ~package =
12761276
| Some file ->
12771277
resolvePath ~env:(QueryEnv.fromFile file) ~path:fullPath ~package))
12781278

1279-
let tupleOfLexing {Lexing.pos_lnum; pos_cnum; pos_bol} =
1280-
(pos_lnum - 1, pos_cnum - pos_bol)
1281-
1282-
let locationIsBefore {Location.loc_start} pos = tupleOfLexing loc_start <= pos
1279+
let locationIsBefore {Location.loc_start} pos =
1280+
Utils.tupleOfLexing loc_start <= pos
12831281

12841282
let findInScope pos name iter stamps =
12851283
(* Log.log("Find " ++ name ++ " with " ++ string_of_int(Hashtbl.length(stamps)) ++ " stamps"); *)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6+
(* *)
7+
(* Copyright 1996 Institut National de Recherche en Informatique et *)
8+
(* en Automatique. *)
9+
(* *)
10+
(* All rights reserved. This file is distributed under the terms of *)
11+
(* the GNU Lesser General Public License version 2.1, with the *)
12+
(* special exception on linking described in the file LICENSE. *)
13+
(* *)
14+
(**************************************************************************)
15+
16+
(* Entry points in the parser *)
17+
18+
(* Skip tokens to the end of the phrase *)
19+
20+
let rec skip_phrase lexbuf =
21+
try
22+
match Lexer.token lexbuf with
23+
Parser.SEMISEMI | Parser.EOF -> ()
24+
| _ -> skip_phrase lexbuf
25+
with
26+
| Lexer.Error (Lexer.Unterminated_comment _, _)
27+
| Lexer.Error (Lexer.Unterminated_string, _)
28+
| Lexer.Error (Lexer.Unterminated_string_in_comment _, _)
29+
| Lexer.Error (Lexer.Illegal_character _, _) -> skip_phrase lexbuf
30+
;;
31+
32+
let maybe_skip_phrase lexbuf =
33+
if Parsing.is_current_lookahead Parser.SEMISEMI
34+
|| Parsing.is_current_lookahead Parser.EOF
35+
then ()
36+
else skip_phrase lexbuf
37+
38+
let wrap parsing_fun lexbuf =
39+
try
40+
Docstrings.init ();
41+
Lexer.init ();
42+
let ast = parsing_fun Lexer.token lexbuf in
43+
Parsing.clear_parser();
44+
Docstrings.warn_bad_docstrings ();
45+
ast
46+
with
47+
| Lexer.Error(Lexer.Illegal_character _, _) as err
48+
when !Location.input_name = "//toplevel//"->
49+
skip_phrase lexbuf;
50+
raise err
51+
| Syntaxerr.Error _ as err
52+
when !Location.input_name = "//toplevel//" ->
53+
maybe_skip_phrase lexbuf;
54+
raise err
55+
| Parsing.Parse_error | Syntaxerr.Escape_error ->
56+
let loc = Location.curr lexbuf in
57+
if !Location.input_name = "//toplevel//"
58+
then maybe_skip_phrase lexbuf;
59+
raise(Syntaxerr.Error(Syntaxerr.Other loc))
60+
61+
let implementation = wrap Parser.implementation
62+
and interface = wrap Parser.interface
63+
and toplevel_phrase = wrap Parser.toplevel_phrase
64+
and use_file = wrap Parser.use_file
65+
and core_type = wrap Parser.parse_core_type
66+
and expression = wrap Parser.parse_expression
67+
and pattern = wrap Parser.parse_pattern
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6+
(* *)
7+
(* Copyright 1996 Institut National de Recherche en Informatique et *)
8+
(* en Automatique. *)
9+
(* *)
10+
(* All rights reserved. This file is distributed under the terms of *)
11+
(* the GNU Lesser General Public License version 2.1, with the *)
12+
(* special exception on linking described in the file LICENSE. *)
13+
(* *)
14+
(**************************************************************************)
15+
16+
(** Entry points in the parser *)
17+
18+
val implementation : Lexing.lexbuf -> Parsetree.structure
19+
val interface : Lexing.lexbuf -> Parsetree.signature
20+
val toplevel_phrase : Lexing.lexbuf -> Parsetree.toplevel_phrase
21+
val use_file : Lexing.lexbuf -> Parsetree.toplevel_phrase list
22+
val core_type : Lexing.lexbuf -> Parsetree.core_type
23+
val expression : Lexing.lexbuf -> Parsetree.expression
24+
val pattern : Lexing.lexbuf -> Parsetree.pattern

0 commit comments

Comments
 (0)