Commit 4f49a2af authored by Kim Nguyễn's avatar Kim Nguyễn

Remove the a workaround the AST for patterns that was used to

correctly handle insantiated types in regular expressions.
parent bcf40231
......@@ -117,7 +117,6 @@ and ppat' =
| Regexp of regexp
| Concat of ppat * ppat
| Merge of ppat * ppat
| Group of ppat
and regexp =
| Epsilon
......
......@@ -131,10 +131,6 @@ let let_in e1 p e2 = Match (e1, [p,e2])
let seq e1 e2 = let_in e1 pat_nil e2
let concat e1 e2 = apply_op2_noloc "@" e1 e2
let opt_to_list = function None -> [] | Some l -> l
let clean_pvar x =
match x.[0] with
| '(' -> String.sub x 2 (String.length x - 2)
| _ -> x
EXTEND Gram
GLOBAL: top_phrases prog expr pat regexp keyword;
......@@ -154,7 +150,7 @@ EXTEND Gram
| (_,p,e1) = let_binding; "in"; e2 = expr LEVEL "top"->
[ mk _loc (EvalStatement (exp _loc (let_in e1 p e2))) ]
| "type"; x = located_ident;
args = OPT [ "("; l = LIST1 [ v = PVAR -> U.mk (clean_pvar v) ] SEP ","; ")" -> l ];
args = OPT [ "("; l = LIST1 [ v = PVAR -> U.mk v ] SEP ","; ")" -> l ];
"="; t = pat ->
[ mk _loc (TypeDecl (x, opt_to_list args ,t)) ]
| "using"; name = IDENT; "="; cu = [ x = IDENT -> x | x = STRING2 -> x ] ->
......@@ -552,7 +548,7 @@ EXTEND Gram
| _ -> e
in
match unseq x, unseq y with
| (Elem x | Arg (Elem x)), (Elem y | Arg (Elem y)) ->
| Elem x , Elem y ->
let res = if op = "&" then And (x, y) else Diff (x, y) in
Elem (mk _loc res)
| _ -> error _loc ( op ^ " not allowed in regular expression")
......@@ -583,7 +579,7 @@ EXTEND Gram
| [ "("; x = LIST1 regexp SEP ","; ")" ->
(match x with
| [ Elem x ] -> Arg (Elem x)
| [ x ] -> x
| [ x ] -> x
| _ ->
let x =
List.map
......@@ -610,11 +606,7 @@ EXTEND Gram
re_seq (Elem (mknoloc (Internal (Types.char c)))) accu)
(seq_of_string s)
Epsilon ]
| [ e = pat LEVEL "basic" ->
match e.descr with
Group p -> Arg (Elem p)
| _ -> Elem e
]
| [ e = pat LEVEL "basic" -> Elem e ]
];
schema_ref: [
......@@ -639,10 +631,7 @@ EXTEND Gram
mk _loc (PatVar (List.map ident ids, opt_to_list args)) ]
| "basic" [
x = PVAR ->
let nx = clean_pvar x in
let res = mk _loc (Internal (Types.var (Var.mk (ident_aux nx)))) in
if x == nx then res else
mk _loc (Group (res))
mk _loc (Internal (Types.var (Var.mk (ident_aux x))))
| ids = LIST1 ident_or_keyword SEP "." ->
mk _loc (PatVar (List.map ident ids, []))
| "{"; r = record_spec; "}" -> r
......@@ -675,7 +664,7 @@ EXTEND Gram
| i = char ; "--"; j = char ->
mk _loc (Internal (Types.char (Chars.char_class i j)))
| "`"; c = tag_type -> c
| "("; l = LIST1 pat SEP ","; ")" -> mk _loc (Group (multi_prod _loc l))
| "("; l = LIST1 pat SEP ","; ")" -> multi_prod _loc l
| "["; r = [ r = regexp -> r | -> Epsilon ];
q = [ ";"; q = pat -> Some q | -> None ];
"]" ->
......
......@@ -393,7 +393,6 @@ module IType = struct
| Regexp r -> rexp (derecurs_regexp env (clean_re r))
| Concat (p1,p2) -> mk_concat (derecurs env p1) (derecurs env p2)
| Merge (p1,p2) -> mk_merge (derecurs env p1) (derecurs env p2)
| Group p -> derecurs env p
and derecurs_regexp env = function
| Epsilon -> mk_epsilon
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment