diff options
-rw-r--r-- | experimental/frisch/extension_points.txt | 5 | ||||
-rw-r--r-- | parsing/parser.mly | 12 |
2 files changed, 12 insertions, 5 deletions
diff --git a/experimental/frisch/extension_points.txt b/experimental/frisch/extension_points.txt index b0961f7a0..830577843 100644 --- a/experimental/frisch/extension_points.txt +++ b/experimental/frisch/extension_points.txt @@ -122,6 +122,7 @@ As other structure item, signature item, class field or class type field, attributes can be attached to a [%%id s] extension node. + === Alternative syntax for attributes and extensions on specific kinds of nodes All expression constructions starting with a keyword (EXPR = KW REST) support an @@ -165,6 +166,10 @@ begin[@foo] ... end ==== (begin ... end)[@foo] match%foo e with ... ==== [%foo match e with ...] +The let-binding form of structure items also supports this form: + +let%foo x = ... ==== [%%foo let x = ...] + === Quoted strings Quoted strings gives a different syntax to write string literals in diff --git a/parsing/parser.mly b/parsing/parser.mly index eddec83ac..384ea37ae 100644 --- a/parsing/parser.mly +++ b/parsing/parser.mly @@ -67,6 +67,7 @@ let ghexp d = Exp.mk ~loc:(symbol_gloc ()) d let ghpat d = Pat.mk ~loc:(symbol_gloc ()) d let ghtyp d = Typ.mk ~loc:(symbol_gloc ()) d let ghloc d = { txt = d; loc = symbol_gloc () } +let ghstr d = Str.mk ~loc:(symbol_gloc()) d let ghunit () = ghexp (Pexp_construct (mknoloc (Lident "()"), None)) @@ -620,11 +621,12 @@ structure_item: let exp = wrap_exp_attrs exp $2 in mkstr(Pstr_eval (exp, attrs)) | l -> - begin match $2 with - | None, [] -> mkstr(Pstr_value($3, List.rev l)) - | Some _, _ -> not_expecting 2 "extension" - | None, _ :: _ -> not_expecting 2 "attribute" - end + let str = mkstr(Pstr_value($3, List.rev l)) in + let (ext, attrs) = $2 in + if attrs <> [] then not_expecting 2 "attribute"; + match ext with + | None -> str + | Some id -> ghstr (Pstr_extension((id, PStr [str]), [])) } | EXTERNAL val_ident COLON core_type EQUAL primitive_declaration post_item_attributes |