Permalink
Browse files

Allow keywords and capitalized longidents as toplevel directives.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14617 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
alainfrisch committed Apr 17, 2014
1 parent 26a8bc2 commit cd5e18a8a3ce8c1987f83b8e41a526046a471b49
Showing with 20 additions and 9 deletions.
  1. +15 −7 parsing/parser.mly
  2. +1 −0 parsing/parsetree.mli
  3. +3 −2 parsing/pprintast.ml
  4. +1 −0 parsing/printast.ml
View
@@ -520,9 +520,9 @@ use_file_tail:
| SEMISEMI seq_expr post_item_attributes use_file_tail
{ Ptop_def[mkstrexp $2 $3] :: $4 }
| SEMISEMI structure_item use_file_tail { Ptop_def[$2] :: $3 }
- | SEMISEMI toplevel_directive use_file_tail { $2 :: $3 }
+ | SEMISEMI toplevel_directive SEMISEMI use_file_tail { $2 :: $4 }
| structure_item use_file_tail { Ptop_def[$1] :: $2 }
- | toplevel_directive use_file_tail { $1 :: $2 }
+ | toplevel_directive SEMISEMI use_file_tail { $1 :: $3 }
;
parse_core_type:
core_type EOF { $1 }
@@ -1944,8 +1944,13 @@ toplevel_directive_arg:
| STRING { Pdir_string (fst $1) }
| INT { Pdir_int $1 }
| val_longident { Pdir_ident $1 }
- | FALSE { Pdir_bool false }
- | TRUE { Pdir_bool true }
+ | mod_longident { Pdir_ident $1 }
+ | keyword {
+ match $1 with
+ | "true" -> Pdir_bool true
+ | "false" -> Pdir_bool false
+ | s -> Pdir_keyword s
+ }
toplevel_directive_args:
| /*empty*/ { [] }
| toplevel_directive_arg toplevel_directive_args { $1 :: $2 }
@@ -2005,9 +2010,7 @@ additive:
/* Attributes and extensions */
-single_attr_id:
- LIDENT { $1 }
- | UIDENT { $1 }
+keyword:
| AND { "and" }
| AS { "as" }
| ASSERT { "assert" }
@@ -2058,6 +2061,11 @@ single_attr_id:
| WITH { "with" }
/* mod/land/lor/lxor/lsl/lsr/asr are not supported for now */
;
+single_attr_id:
+ LIDENT { $1 }
+ | UIDENT { $1 }
+ | keyword { $1 }
+;
attr_id:
single_attr_id { mkloc $1 (symbol_rloc()) }
View
@@ -767,3 +767,4 @@ and directive_argument =
| Pdir_int of int
| Pdir_ident of Longident.t
| Pdir_bool of bool
+ | Pdir_keyword of string
View
@@ -1222,11 +1222,12 @@ class printer ()= object(self:'self)
pp f "~%s:%a" lbl self#simple_expr e
method directive_argument f x =
- (match x with
+ match x with
| Pdir_string (s) -> pp f "@ %S" s
| Pdir_int (i) -> pp f "@ %d" i
| Pdir_ident (li) -> pp f "@ %a" self#longident li
- | Pdir_bool (b) -> pp f "@ %s" (string_of_bool b))
+ | Pdir_bool (b) -> pp f "@ %s" (string_of_bool b)
+ | Pdir_keyword s -> pp f "@ %s" s
method toplevel_phrase f x =
match x with
View
@@ -846,6 +846,7 @@ and directive_argument i ppf x =
| Pdir_int (i) -> line i ppf "Pdir_int %d\n" i;
| Pdir_ident (li) -> line i ppf "Pdir_ident %a\n" fmt_longident li;
| Pdir_bool (b) -> line i ppf "Pdir_bool %s\n" (string_of_bool b);
+ | Pdir_keyword s -> line i ppf "Pdir_keyword %s\n" s;
;;
let interface ppf x = list 0 signature_item ppf x;;

0 comments on commit cd5e18a

Please sign in to comment.