Allow keywords and capitalized longidents as toplevel directives.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14617 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2014-04-17 09:23:22 +00:00
parent 26a8bc20a7
commit cd5e18a8a3
4 changed files with 20 additions and 9 deletions

View File

@ -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 File

@ -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 File

@ -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 File

@ -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;;