Skip to content

Commit

Permalink
handle toplevel primitives with multiple arguments
Browse files Browse the repository at this point in the history
Fix #18
  • Loading branch information
Jeremie Dimino committed Apr 17, 2014
1 parent 1d4c549 commit 9c66aad
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions camlp4/Camlp4/Camlp4Ast.partial.ml
Expand Up @@ -238,7 +238,7 @@
(* sg ; sg *)
| SgSem of loc and sig_item and sig_item
(* # s or # s e *)
| SgDir of loc and string and expr
| SgDir of loc and string and list expr
(* exception t *)
| SgExc of loc and ctyp
(* external s : t = s ... s *)
Expand Down Expand Up @@ -327,7 +327,7 @@
(* st ; st *)
| StSem of loc and str_item and str_item
(* # s or # s e *)
| StDir of loc and string and expr
| StDir of loc and string and list expr
(* exception t or exception t = i *)
| StExc of loc and ctyp and meta_option(*FIXME*) ident
(* e *)
Expand Down
7 changes: 3 additions & 4 deletions camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
Expand Up @@ -1308,10 +1308,9 @@ value varify_constructors var_names =
value sig_item ast = sig_item ast [];
value str_item ast = str_item ast [];
value directive =
value directive_arg =
fun
[ <:expr<>> -> Pdir_none
| ExStr _ s -> Pdir_string s
[ ExStr _ s -> Pdir_string s
| ExInt _ i -> Pdir_int (int_of_string i)
| <:expr< True >> -> Pdir_bool True
| <:expr< False >> -> Pdir_bool False
Expand All @@ -1320,7 +1319,7 @@ value varify_constructors var_names =
value phrase =
fun
[ StDir _ d dp -> Ptop_dir d (directive dp)
[ StDir _ d args -> Ptop_dir d (List.map directive_arg args)
| si -> Ptop_def (str_item si) ]
;
Expand Down
4 changes: 2 additions & 2 deletions camlp4/Camlp4Bin.ml
Expand Up @@ -142,12 +142,12 @@ value process dyn_loader name pa pr clean fold_filters getdir =

value gind =
fun
[ <:sig_item@loc< # $n$ $str:s$ >> -> Some (loc, n, s)
[ Ast.SgDir loc n [ Ast.ExStr _ s ] -> Some (loc, n, s)
| _ -> None ];

value gimd =
fun
[ <:str_item@loc< # $n$ $str:s$ >> -> Some (loc, n, s)
[ Ast.StDir loc n [ Ast.ExStr _ s ] -> Some (loc, n, s)
| _ -> None ];

value process_intf dyn_loader name =
Expand Down
6 changes: 3 additions & 3 deletions camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
Expand Up @@ -145,7 +145,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
DELETE_RULE Gram meth_list: meth_decl; opt_dot_dot END;
DELETE_RULE Gram expr: "let"; opt_rec; binding; "in"; SELF END;
DELETE_RULE Gram expr: "let"; "module"; a_UIDENT; module_binding0; "in"; SELF END;
DELETE_RULE Gram expr: "let"; "open"; "!"; module_longident; "in"; SELF END;
DELETE_RULE Gram expr: "let"; "open"; "!"; module_longident; "in"; SELF END;
DELETE_RULE Gram expr: "let"; "open"; module_longident; "in"; SELF END;
DELETE_RULE Gram expr: "fun"; "["; LIST0 match_case0 SEP "|"; "]" END;
DELETE_RULE Gram expr: "if"; SELF; "then"; SELF; "else"; SELF END;
Expand Down Expand Up @@ -711,8 +711,8 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
] ]
;
top_phrase:
[ [ "#"; n = a_LIDENT; dp = opt_expr; ";;" ->
Some <:str_item< # $n$ $dp$ >>
[ [ "#"; n = a_LIDENT; args = LIST0 expr; ";;" ->
Some (Ast.StDir _loc n args)
| l = LIST1 str_item; ";;" -> Some (Ast.stSem_of_list l)
| `EOI -> None
] ]
Expand Down
20 changes: 10 additions & 10 deletions camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
Expand Up @@ -1699,8 +1699,8 @@ New syntax:\
] ]
;
interf:
[ [ "#"; n = a_LIDENT; dp = opt_expr; semi ->
([ <:sig_item< # $n$ $dp$ >> ], stopped_at _loc)
[ [ "#"; n = a_LIDENT; args = LIST0 expr; semi ->
([ Ast.SgDir _loc n args ], stopped_at _loc)
| si = sig_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped)
| `EOI -> ([], None) ] ]
;
Expand All @@ -1713,8 +1713,8 @@ New syntax:\
] ]
;
implem:
[ [ "#"; n = a_LIDENT; dp = opt_expr; semi ->
([ <:str_item< # $n$ $dp$ >> ], stopped_at _loc)
[ [ "#"; n = a_LIDENT; args = LIST0 expr; semi ->
([ Ast.StDir _loc n args ], stopped_at _loc)
| si = str_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped)
| `EOI -> ([], None)
] ]
Expand All @@ -1733,15 +1733,15 @@ New syntax:\
] ]
;
use_file:
[ [ "#"; n = a_LIDENT; dp = opt_expr; semi ->
([ <:str_item< # $n$ $dp$ >> ], stopped_at _loc)
[ [ "#"; n = a_LIDENT; args = LIST0 expr; semi ->
([ Ast.StDir _loc n args ], stopped_at _loc)
| si = str_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped)
| `EOI -> ([], None)
] ]
;
phrase:
[ [ "#"; n = a_LIDENT; dp = opt_expr; semi ->
<:str_item< # $n$ $dp$ >>
[ [ "#"; n = a_LIDENT; args = LIST0 expr; semi ->
Ast.StDir _loc n args
| st = str_item; semi -> st
] ]
;
Expand Down Expand Up @@ -1852,7 +1852,7 @@ New syntax:\
] ]
;
str_item_quot:
[ [ "#"; n = a_LIDENT; dp = opt_expr -> <:str_item< # $n$ $dp$ >>
[ [ "#"; n = a_LIDENT; args = LIST0 expr -> Ast.StDir _loc n args
| st1 = str_item; semi; st2 = SELF ->
match st2 with
[ <:str_item<>> -> st1
Expand All @@ -1861,7 +1861,7 @@ New syntax:\
| -> <:str_item<>> ] ]
;
sig_item_quot:
[ [ "#"; n = a_LIDENT; dp = opt_expr -> <:sig_item< # $n$ $dp$ >>
[ [ "#"; n = a_LIDENT; args = LIST0 expr -> Ast.SgDir _loc n args
| sg1 = sig_item; semi; sg2 = SELF ->
match sg2 with
[ <:sig_item<>> -> sg1
Expand Down
4 changes: 2 additions & 2 deletions camlp4/Camlp4Top/Top.ml
Expand Up @@ -79,9 +79,9 @@ value use_file token_stream =
in
if stopped_at_directive <> None then
match pl with
[ [ <:str_item< #load $str:s$ >> ] ->
[ [ Ast.StDir _ "load" [ Ast.ExStr _ s ] ] ->
do { Topdirs.dir_load Format.std_formatter s; loop () }
| [ <:str_item< #directory $str:s$ >> ] ->
| [ Ast.StDir _ "directory" [ Ast.ExStr _ s ] ] ->
do { Topdirs.dir_directory s; loop () }
| _ -> (pl, False) ]
else (pl, True)
Expand Down
20 changes: 12 additions & 8 deletions camlp4/boot/Camlp4Ast.ml
Expand Up @@ -2431,7 +2431,7 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(Ast.IdUid _loc "SgDir")))
(meta_loc _loc x0))
(meta_string _loc x1))
(meta_expr _loc x2)
(meta_list meta_expr _loc x2)
| Ast.SgSem x0 x1 x2 ->
Ast.ExApp _loc
(Ast.ExApp _loc
Expand Down Expand Up @@ -2570,7 +2570,7 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(Ast.IdUid _loc "StDir")))
(meta_loc _loc x0))
(meta_string _loc x1))
(meta_expr _loc x2)
(meta_list meta_expr _loc x2)
| Ast.StSem x0 x1 x2 ->
Ast.ExApp _loc
(Ast.ExApp _loc
Expand Down Expand Up @@ -4636,7 +4636,7 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(Ast.IdUid _loc "SgDir")))
(meta_loc _loc x0))
(meta_string _loc x1))
(meta_expr _loc x2)
(meta_list meta_expr _loc x2)
| Ast.SgSem x0 x1 x2 ->
Ast.PaApp _loc
(Ast.PaApp _loc
Expand Down Expand Up @@ -4775,7 +4775,7 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(Ast.IdUid _loc "StDir")))
(meta_loc _loc x0))
(meta_string _loc x1))
(meta_expr _loc x2)
(meta_list meta_expr _loc x2)
| Ast.StSem x0 x1 x2 ->
Ast.PaApp _loc
(Ast.PaApp _loc
Expand Down Expand Up @@ -4939,7 +4939,8 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
| StDir _x _x_i1 _x_i2 ->
let _x = o#loc _x in
let _x_i1 = o#string _x_i1 in
let _x_i2 = o#expr _x_i2 in StDir _x _x_i1 _x_i2
let _x_i2 = o#list (fun o -> o#expr) _x_i2
in StDir _x _x_i1 _x_i2
| StExc _x _x_i1 _x_i2 ->
let _x = o#loc _x in
let _x_i1 = o#ctyp _x_i1 in
Expand Down Expand Up @@ -4996,7 +4997,8 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
| SgDir _x _x_i1 _x_i2 ->
let _x = o#loc _x in
let _x_i1 = o#string _x_i1 in
let _x_i2 = o#expr _x_i2 in SgDir _x _x_i1 _x_i2
let _x_i2 = o#list (fun o -> o#expr) _x_i2
in SgDir _x _x_i1 _x_i2
| SgExc _x _x_i1 ->
let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in SgExc _x _x_i1
| SgExt _x _x_i1 _x_i2 _x_i3 ->
Expand Down Expand Up @@ -5854,7 +5856,8 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
let o = o#str_item _x_i1 in let o = o#str_item _x_i2 in o
| StDir _x _x_i1 _x_i2 ->
let o = o#loc _x in
let o = o#string _x_i1 in let o = o#expr _x_i2 in o
let o = o#string _x_i1 in
let o = o#list (fun o -> o#expr) _x_i2 in o
| StExc _x _x_i1 _x_i2 ->
let o = o#loc _x in
let o = o#ctyp _x_i1 in
Expand Down Expand Up @@ -5895,7 +5898,8 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
let o = o#sig_item _x_i1 in let o = o#sig_item _x_i2 in o
| SgDir _x _x_i1 _x_i2 ->
let o = o#loc _x in
let o = o#string _x_i1 in let o = o#expr _x_i2 in o
let o = o#string _x_i1 in
let o = o#list (fun o -> o#expr) _x_i2 in o
| SgExc _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o
| SgExt _x _x_i1 _x_i2 _x_i3 ->
let o = o#loc _x in
Expand Down
2 changes: 1 addition & 1 deletion camlp4/config/Camlp4_config.ml
Expand Up @@ -32,7 +32,7 @@ let verbose = ref false;;
let antiquotations = ref false;;
let quotations = ref true;;
let inter_phrases = ref None;;
let camlp4_ast_impl_magic_number = "Camlp42006M003";;
let camlp4_ast_impl_magic_number = "Camlp42006M004";;
let camlp4_ast_intf_magic_number = "Camlp42006N003";;
let ocaml_ast_intf_magic_number = Camlp4_import.ast_intf_magic_number;;
let ocaml_ast_impl_magic_number = Camlp4_import.ast_impl_magic_number;;
Expand Down

0 comments on commit 9c66aad

Please sign in to comment.