Skip to content

Commit 39828b0

Browse files
committed
squashed up to ea33d07
1 parent 6df4d5b commit 39828b0

21 files changed

+41356
-15975
lines changed

ocaml/boot/menhir/parser.ml

Lines changed: 40358 additions & 15773 deletions
Large diffs are not rendered by default.

ocaml/boot/menhir/parser.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ type token =
129129
| BAR
130130
| BANG
131131
| BACKQUOTE
132+
| ATAT
133+
| AT
132134
| ASSERT
133135
| AS
134136
| ANDOP of (string)

ocaml/parsing/ast_iterator.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,11 @@ let default_iterator =
814814
value_description =
815815
(fun this {pval_name; pval_type; pval_prim = _; pval_loc;
816816
pval_attributes} ->
817+
let modes, ptyp_attributes =
818+
Jane_syntax.Mode_expr.maybe_of_attrs pval_type.ptyp_attributes
819+
in
820+
Option.iter (this.modes this) modes;
821+
let pval_type = {pval_type with ptyp_attributes} in
817822
iter_loc this pval_name;
818823
this.typ this pval_type;
819824
this.location this pval_loc;
@@ -962,7 +967,7 @@ let default_iterator =
962967
this.location this a.attr_loc
963968
);
964969
attributes = (fun this l -> List.iter (this.attribute this) l);
965-
(* [ast_iterator] should not know about the structure of mode expressions *)
970+
(* CR zqian: should go into the modes and at least iterate the locations. *)
966971
modes = (fun _this _m -> ());
967972
payload =
968973
(fun this -> function

ocaml/parsing/ast_mapper.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type mapper = {
9393
Jane_syntax.Structure_item.t -> Jane_syntax.Structure_item.t;
9494
typ_jane_syntax: mapper -> Jane_syntax.Core_type.t -> Jane_syntax.Core_type.t;
9595

96+
modes : mapper -> Jane_syntax.Mode_expr.t -> Jane_syntax.Mode_expr.t;
9697
}
9798

9899
let map_fst f (x, y) = (f x, y)
@@ -925,9 +926,26 @@ let default_mapper =
925926
value_description =
926927
(fun this {pval_name; pval_type; pval_prim; pval_loc;
927928
pval_attributes} ->
929+
let modes, ptyp_attributes =
930+
Jane_syntax.Mode_expr.maybe_of_attrs pval_type.ptyp_attributes
931+
in
932+
let pval_type = { pval_type with ptyp_attributes } in
933+
let pval_type = this.typ this pval_type in
934+
let attr =
935+
match modes with
936+
| None -> None
937+
| Some modes ->
938+
let modes = this.modes this modes in
939+
Jane_syntax.Mode_expr.attr_of modes
940+
in
941+
let pval_type =
942+
match attr with
943+
| None -> pval_type
944+
| Some attr -> {pval_type with ptyp_attributes = attr :: pval_type.ptyp_attributes}
945+
in
928946
Val.mk
929947
(map_loc this pval_name)
930-
(this.typ this pval_type)
948+
pval_type
931949
~attrs:(this.attributes this pval_attributes)
932950
~loc:(this.location this pval_loc)
933951
~prim:pval_prim
@@ -1096,6 +1114,9 @@ let default_mapper =
10961114
signature_item_jane_syntax = MT.map_signature_item_jst;
10971115
structure_item_jane_syntax = M.map_structure_item_jst;
10981116
typ_jane_syntax = T.map_jst;
1117+
1118+
(* CR zqian: should go into the modes and at least map the locations. *)
1119+
modes = (fun _this m -> m);
10991120
}
11001121

11011122
let extension_of_error {kind; main; sub} =

ocaml/parsing/ast_mapper.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type mapper = {
131131
Jane_syntax.Structure_item.t -> Jane_syntax.Structure_item.t;
132132
typ_jane_syntax: mapper -> Jane_syntax.Core_type.t -> Jane_syntax.Core_type.t;
133133

134+
modes : mapper -> Jane_syntax.Mode_expr.t -> Jane_syntax.Mode_expr.t;
134135
}
135136
(** A mapper record implements one "method" per syntactic category,
136137
using an open recursion style: each method takes as its first

ocaml/parsing/jane_syntax.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ module Mode_expr = struct
452452
let const' = (const : Const.t :> _ Location.loc) in
453453
Location.mkloc [const] const'.loc
454454

455+
let concat mode0 mode1 =
456+
let txt = mode0.txt @ mode1.txt in
457+
Location.mknoloc txt
458+
455459
let feature : Feature.t = Language_extension Mode
456460

457461
let attribute_or_extension_name =

ocaml/parsing/jane_syntax.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ module Mode_expr : sig
140140
(** The mode expression containing a single mode constant. *)
141141
val singleton : Const.t -> t
142142

143+
(** Merging two mode expressions. This will be hard to define as mode
144+
expressions gets complex. Currently it's for merging legacy and new syntax
145+
*)
146+
val concat : t -> t -> t
147+
143148
(** Extract the mode attribute (if any) from a list of attributes; also
144149
returns the rest of the attributes; Raises if multiple relevant attributes
145150
are found *)

ocaml/parsing/lexer.mll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ rule token = parse
752752
{ PREFIXOP op }
753753
| ['=' '<' '>' '|' '&' '$'] symbolchar * as op
754754
{ INFIXOP0 op }
755+
| "@" { AT }
756+
| "@@" { ATAT }
755757
| ['@' '^'] symbolchar * as op
756758
{ INFIXOP1 op }
757759
| ['+' '-'] symbolchar * as op

0 commit comments

Comments
 (0)