Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jan 30, 2023
1 parent 1d3b668 commit ca81685
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 3 additions & 4 deletions compiler/lib/js_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ let utf8_s = Stdlib.Utf8_string.of_string_exn
%token<Stdlib.Utf8_string.t * string> T_IDENTIFIER
%token<Stdlib.Utf8_string.t * int> T_STRING
%token<Stdlib.Utf8_string.t * string> T_REGEXP
%token<Stdlib.Utf8_string.t> T_TEMPLATE_PART
%token<string> T_ENCAPSED_STRING
(*-----------------------------------------*)
(* Keyword tokens *)
Expand Down Expand Up @@ -674,7 +673,6 @@ call_expr(x):
{ ECallTemplate(e, t,p $symbolstartpos) }
| e=call_expr(x) a=access i=method_name
{ EDot (e,a,i) }
| T_ASYNC arguments { CoverCallExpressionAndAsyncArrowHead (early_error (pi $startpos($1))) }

new_expr(x):
| e=member_expr(x) { e }
Expand Down Expand Up @@ -943,15 +941,16 @@ primary_no_stmt: T_ERROR TComment { assert false }
(* used for entities, parameters, labels, etc. *)
id:
| T_IDENTIFIER { fst $1 }
| ident_semi_keyword { utf8_s (Js_token.to_string $1) }
| ident_semi_keyword { utf8_s (Js_token.to_string $1) }

ident:
| id { var (p $symbolstartpos) $1 }
| id { var (p $symbolstartpos) $1 }

(* add here keywords which are not considered reserved by ECMA *)
ident_semi_keyword:
(* TODO: would like to add T_IMPORT here, but cause conflicts *)
(* can have AS and ASYNC here but need to restrict arrow_function then *)
| T_ASYNC
| T_FROM
| T_GET { T_GET }
| T_META { T_META }
Expand Down
2 changes: 0 additions & 2 deletions compiler/lib/js_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type t =
| T_NUMBER of (number_type * string)
| T_BIGINT of (bigint_type * string)
| T_STRING of (Utf8_string.t * int)
| T_TEMPLATE_PART of (Utf8_string.t * bool)
| T_IDENTIFIER of (Utf8_string.t * string)
| T_REGEXP of (Utf8_string.t * string)
(* /pattern/flags *)
Expand Down Expand Up @@ -300,7 +299,6 @@ let to_string = function
| T_EXP -> "**"
| T_EOF -> ""
| T_BIGINT (_, raw) -> raw
| T_TEMPLATE_PART (Utf8 s, _) -> s
| T_LPAREN_ARROW -> "("
| T_BACKQUOTE -> "`"
| T_DOLLARCURLY -> "${"
Expand Down
1 change: 0 additions & 1 deletion compiler/lib/js_token.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type t =
| T_NUMBER of (number_type * string)
| T_BIGINT of (bigint_type * string)
| T_STRING of (Utf8_string.t * int)
| T_TEMPLATE_PART of (Utf8_string.t * bool)
| T_IDENTIFIER of (Utf8_string.t * string)
| T_REGEXP of (Utf8_string.t * string)
(* /pattern/flags *)
Expand Down
15 changes: 15 additions & 0 deletions compiler/tests-compiler/js_parser_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,18 @@ Event.prototype.initEvent = function _Event_initEvent(type, bubbles, cancelable)
4: 4:this, 8:., 9:bubbles (identifier), 17:=, 19:bubbles (identifier), 0:; (virtual),
5: 4:this, 8:., 9:cancelable (identifier), 20:=, 22:cancelable (identifier), 0:; (virtual),
6: 0:}, 0:; (virtual), |}]

let%expect_test _ =
parse_print_token
~extra:true
{|
var y = { async: 35}

var y = async x => x
var y = async => async
|};
[%expect
{|
2: 0:var, 4:y (identifier), 6:=, 8:{, 10:async, 15::, 17:35, 19:}, 0:; (virtual),
4: 0:var, 4:y (identifier), 6:=, 8:async, 14:x (identifier), 16:=>, 19:x (identifier), 0:; (virtual),
5: 0:var, 4:y (identifier), 6:=, 8:async, 14:=>, 17:async, 0:; (virtual), |}]

0 comments on commit ca81685

Please sign in to comment.