Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for the let%foo syntax as structure item.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14600 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
commit 984814d6a1b4e8fa3051b02d01f47719b869b36f 1 parent 546c22b
@alainfrisch alainfrisch authored
Showing with 12 additions and 5 deletions.
  1. +5 −0 experimental/frisch/extension_points.txt
  2. +7 −5 parsing/parser.mly
View
5 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
View
12 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
Please sign in to comment.
Something went wrong with that request. Please try again.