/[svn]/parser/parser.ml
ViewVC logotype

Diff of /parser/parser.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 224 by abate, Tue Jul 10 17:16:14 2007 UTC revision 225 by abate, Tue Jul 10 17:16:34 2007 UTC
# Line 1  Line 1 
1  open Location  open Location
2  open Ast  open Ast
3    open Ident
4    
5  (*  (*
6  let ()  = Grammar.error_verbose := true  let ()  = Grammar.error_verbose := true
# Line 87  Line 88 
88      [ "match"; e = SELF; "with"; b = branches -> mk loc (Match (e,b))      [ "match"; e = SELF; "with"; b = branches -> mk loc (Match (e,b))
89      | "try"; e = SELF; "with"; b = branches ->      | "try"; e = SELF; "with"; b = branches ->
90          let default =          let default =
91            (mk noloc (Capture "x"),            (mk noloc (Capture (ident "x")),
92             mk noloc (Op ("raise",[mk noloc (Var "x")]))) in             mk noloc (Op ("raise",[mk noloc (Var (ident "x"))]))) in
93          mk loc (Try (e,b@[default]))          mk loc (Try (e,b@[default]))
94      | "map"; e = SELF; "with"; b = branches -> mk loc (Map (e,b))      | "map"; e = SELF; "with"; b = branches -> mk loc (Map (e,b))
95      | "transform"; e = SELF; "with"; b = branches ->      | "transform"; e = SELF; "with"; b = branches ->
96          let default = mk noloc (Capture "x"), cst_nil in          let default = mk noloc (Capture (ident "x")), cst_nil in
97          mk loc (Op ("flatten", [mk loc (Map (e,b@[default]))]))          mk loc (Op ("flatten", [mk loc (Map (e,b@[default]))]))
98      | "fun"; (f,a,b) = fun_decl ->      | "fun"; (f,a,b) = fun_decl ->
99          mk loc (Abstraction { fun_name = f; fun_iface = a; fun_body = b })          mk loc (Abstraction { fun_name = f; fun_iface = a; fun_body = b })
# Line 113  Line 114 
114          let tag = mk loc (Internal (Types.atom (Atoms.any))) in          let tag = mk loc (Internal (Types.atom (Atoms.any))) in
115          let att = mk loc (Internal Types.Record.any) in          let att = mk loc (Internal Types.Record.any) in
116          let any = mk loc (Internal (Types.any)) in          let any = mk loc (Internal (Types.any)) in
117          let re = Star(Alt(SeqCapture("x",Elem p), Elem any)) in          let re = Star(Alt(SeqCapture(ident "x",Elem p), Elem any)) in
118          let ct = mk loc (Regexp (re,any)) in          let ct = mk loc (Regexp (re,any)) in
119          let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in          let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
120          let b = (p,  mk loc (Var "x")) in          let b = (p,  mk loc (Var (ident "x"))) in
121          mk loc (Op ("flatten", [mk loc (Map (e,[b]))]))          mk loc (Op ("flatten", [mk loc (Map (e,[b]))]))
122      ]      ]
123      |      |
# Line 161  Line 162 
162      | "{"; r = [ expr_record_spec | -> mk loc (RecordLitt []) ]; "}" -> r      | "{"; r = [ expr_record_spec | -> mk loc (RecordLitt []) ]; "}" -> r
163      | s = STRING2 ->      | s = STRING2 ->
164          tuple loc (char_list loc s @ [cst_nil])          tuple loc (char_list loc s @ [cst_nil])
165      | a = LIDENT -> mk loc (Var a)      | a = LIDENT -> mk loc (Var (ident a))
166      ]      ]
167    
168    ];    ];
# Line 190  Line 191 
191   fun_decl: [   fun_decl: [
192  (* need an hack to do this, because both productions would  (* need an hack to do this, because both productions would
193     match   [ OPT LIDENT; "("; pat ] .... *)     match   [ OPT LIDENT; "("; pat ] .... *)
194     [ f = OPT LIDENT; "("; p1 = pat LEVEL "no_arrow";     [ f = OPT [ x = LIDENT -> ident x]; "("; p1 = pat LEVEL "no_arrow";
195      res = [ "->"; p2 = pat;      res = [ "->"; p2 = pat;
196              a = [ ";"; a = LIST0 arrow SEP ";" -> a | -> [] ];              a = [ ";"; a = LIST0 arrow SEP ";" -> a | -> [] ];
197              ")"; b = branches -> `Classic (p2,a,b)              ")"; b = branches -> `Classic (p2,a,b)
# Line 228  Line 229 
229    regexp: [    regexp: [
230      [ x = regexp; "|"; y = regexp -> Alt (x,y) ]      [ x = regexp; "|"; y = regexp -> Alt (x,y) ]
231    | [ x = regexp; y = regexp -> Seq (x,y) ]    | [ x = regexp; y = regexp -> Seq (x,y) ]
232    | [ a = LIDENT; "::"; x = regexp -> SeqCapture (a,x) ]    | [ a = LIDENT; "::"; x = regexp -> SeqCapture (ident a,x) ]
233    | [ x = regexp; "*" -> Star x    | [ x = regexp; "*" -> Star x
234      | x = regexp; "*?" -> WeakStar x      | x = regexp; "*?" -> WeakStar x
235      | x = regexp; "+" -> Seq (x, Star x)      | x = regexp; "+" -> Seq (x, Star x)
# Line 236  Line 237 
237      | x = regexp; "?" ->  Alt (x, Epsilon)      | x = regexp; "?" ->  Alt (x, Epsilon)
238      | x = regexp; "??" -> Alt (Epsilon, x) ]      | x = regexp; "??" -> Alt (Epsilon, x) ]
239    | [ "("; x = regexp; ")" -> x    | [ "("; x = regexp; ")" -> x
240      | "("; a = LIDENT; ":="; c = const; ")" -> Elem (mk loc (Constant (a,c)))      | "("; a = LIDENT; ":="; c = const; ")" ->
241            Elem (mk loc (Constant ((ident a,c))))
242      | UIDENT "PCDATA" -> string_regexp      | UIDENT "PCDATA" -> string_regexp
243      | i = STRING1; "--"; j = STRING1 ->      | i = STRING1; "--"; j = STRING1 ->
244          let i = Chars.mk_char (parse_char loc i)          let i = Chars.mk_char (parse_char loc i)
# Line 267  Line 269 
269        [ "{"; r = record_spec; "}" -> mk loc (Record (true,r))        [ "{"; r = record_spec; "}" -> mk loc (Record (true,r))
270        | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))        | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
271        | LIDENT "_" -> mk loc (Internal Types.any)        | LIDENT "_" -> mk loc (Internal Types.any)
272        | a = LIDENT -> mk loc (Capture a)        | a = LIDENT -> mk loc (Capture (ident a))
273        | "("; a = LIDENT; ":="; c = const; ")" -> mk loc (Constant (a,c))        | "("; a = LIDENT; ":="; c = const; ")" ->
274              mk loc (Constant (ident a,c))
275        | a = UIDENT -> mk loc (PatVar a)        | a = UIDENT -> mk loc (PatVar a)
276        | i = INT ; "--"; j = INT ->        | i = INT ; "--"; j = INT ->
277            let i =  Intervals.mk i            let i =  Intervals.mk i

Legend:
Removed from v.224  
changed lines
  Added in v.225

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5