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

Contents of /parser/parser.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 623 - (hide annotations)
Tue Jul 10 17:48:50 2007 UTC (5 years, 11 months ago) by abate
File size: 17438 byte(s)
[r2003-07-24 15:11:47 by cvscast] Experiment with encoded references

Original author: cvscast
Date: 2003-07-24 15:12:14+00:00
1 abate 4 open Location
2     open Ast
3 abate 225 open Ident
4 abate 501 open Printf
5 abate 4
6 abate 161 (*
7 abate 151 let () = Grammar.error_verbose := true
8 abate 161 *)
9 abate 81
10 abate 529 exception Error of string
11     let error (i,j) s = Location.raise_loc i j (Error s)
12 abate 469
13 abate 81 let gram = Grammar.gcreate (Wlexer.lexer Wlexer.token Wlexer.latin1_engine)
14    
15 abate 421 let true_atom = Atoms.mk_ascii "true"
16     let false_atom = Atoms.mk_ascii "false"
17     let true_type = Types.atom (Atoms.atom true_atom)
18     let false_type = Types.atom (Atoms.atom false_atom)
19 abate 81
20 abate 529 let parse_ident = U.mk_latin1
21 abate 374
22 abate 375 let id_dummy = ident (U.mk "$$$")
23 abate 529
24 abate 549 let label = parse_ident
25 abate 375 let ident s = ident (parse_ident s)
26 abate 374
27 abate 38 let prog = Grammar.Entry.create gram "prog"
28 abate 431 let top_phrases = Grammar.Entry.create gram "toplevel phrases"
29 abate 38 let expr = Grammar.Entry.create gram "expression"
30     let pat = Grammar.Entry.create gram "type/pattern expression"
31     let regexp = Grammar.Entry.create gram "type/pattern regexp"
32     let const = Grammar.Entry.create gram "scalar constant"
33    
34 abate 316 let exp pos e = LocatedExpr (loc_of_pos pos,e)
35    
36 abate 38 let rec multi_prod loc = function
37     | [ x ] -> x
38     | x :: l -> mk loc (Prod (x, multi_prod loc l))
39     | [] -> assert false
40    
41 abate 316 let rec tuple = function
42 abate 38 | [ x ] -> x
43 abate 316 | x :: l -> Pair (x, tuple l)
44 abate 38 | [] -> assert false
45 abate 89
46     let tuple_queue =
47 abate 316 List.fold_right (fun x q -> Pair (x, q))
48 abate 89
49 abate 233
50 abate 249 let char = mknoloc (Internal (Types.char Chars.any))
51 abate 66 let string_regexp = Star (Elem char)
52 abate 38
53 abate 529 let cst_nil = Cst (Const_internal (Types.Atom Sequence.nil_atom))
54 abate 623 let pat_nil = mknoloc (Internal (Sequence.nil_type))
55 abate 38
56 abate 525 let seq_of_string s =
57 abate 326 let s = Encodings.Utf8.mk s in
58     let rec aux i j =
59 abate 525 if Encodings.Utf8.equal_index i j then []
60     else let (c,i) = Encodings.Utf8.next s i in c :: (aux i j)
61 abate 326 in
62 abate 525 aux (Encodings.Utf8.start_index s) (Encodings.Utf8.end_index s)
63 abate 326
64 abate 233
65 abate 81 let parse_char loc s =
66 abate 525 match seq_of_string s with
67     | [ c ] -> c
68 abate 310 | _ -> error loc "Character litteral must have length 1"
69 abate 81
70 abate 249 let include_stack = ref []
71    
72 abate 448 let protect_exn f g =
73     try let x = f () in g (); x
74     with e -> g (); raise e
75    
76 abate 470 let is_fun_decl =
77     Grammar.Entry.of_parser gram "[is_fun_decl]"
78     (fun strm ->
79     match Stream.npeek 3 strm with
80     | [ ("", "fun"); ("LIDENT", _); ("", "(") ]
81     | [ ("LIDENT", _) ; ("", "(") ; _ ] -> ()
82     | _ -> raise Stream.Failure
83     )
84    
85 abate 501 let dot_RE = Pcre.regexp "\\."
86 abate 470
87 abate 38 EXTEND
88 abate 431 GLOBAL: top_phrases prog expr pat regexp const;
89 abate 4
90 abate 431 top_phrases: [
91 abate 446 [ l = LIST0 phrase; ";;" -> List.flatten l ]
92 abate 431 ];
93    
94 abate 10 prog: [
95 abate 431 [ l = LIST0 [ p = phrase ; OPT ";;" -> p ]; EOI -> List.flatten l ]
96 abate 10 ];
97    
98 abate 529 uident: [ [ x = UIDENT -> parse_ident x ] ];
99    
100 abate 13 phrase: [
101 abate 431 [ (f,p,e) = let_binding ->
102     if f then [ mk loc (FunDecl e) ] else
103     [ mk loc (LetDecl (p,e)) ]
104     | (_,p,e1) = let_binding; "in"; e2 = expr LEVEL "top"->
105 abate 316 [ mk loc (EvalStatement (exp loc (Match (e1,[p,e2])))) ]
106 abate 529 | "type"; x = uident; "="; t = pat -> [ mk loc (TypeDecl (x,t)) ]
107 abate 431 | "type"; x = LIDENT -> error loc "Type identifiers must be capitalized"
108 abate 501 | "schema"; name = UIDENT; "="; uri = STRING2 ->
109 abate 522 protect_op "schema";
110 abate 525 let schema_doc = Schema_xml.pxp_tree_of uri in
111 abate 501 let schema = Schema_parser.parse_schema schema_doc in
112     [ mk loc (SchemaDecl (name, schema))]
113 abate 530 | (name,ns) = namespace_binding ->
114     [ mk loc (Namespace (name, ns)) ]
115     | (name,ns) = namespace_binding; "in"; e2 = expr LEVEL "top" ->
116     let e = exp loc (NamespaceIn (name, ns, e2)) in
117     [ mk loc (EvalStatement (exp loc e)) ]
118 abate 431 | "debug"; d = debug_directive -> [ mk loc (Debug d) ]
119 abate 446 | DIRECTIVE "#quit" -> [ mk loc (Directive `Quit) ]
120     | DIRECTIVE "#env" -> [ mk loc (Directive `Env) ]
121 abate 553 | DIRECTIVE "#reinit_ns" -> [ mk loc (Directive `Reinit_ns) ]
122 abate 431 | "include"; s = STRING2 ->
123 abate 471 let s =
124     if Filename.is_relative s
125     then Filename.concat (Location.current_dir ()) s
126     else s in
127 abate 249 protect_op "File inclusion";
128     (* avoid looping; should issue an error ? *)
129 abate 471 (* it is possible to have looping with x/../x/../x/.. ....
130     Need to canonicalize filename *)
131 abate 249 if List.mem s !include_stack then []
132     else (
133     include_stack := s :: !include_stack;
134     Location.push_source (`File s);
135 abate 448 protect_exn
136     (fun () ->
137     let chan = open_in s in
138 abate 471 protect_exn
139     (fun () ->
140     let input = Stream.of_channel chan in
141     Grammar.Entry.parse prog input)
142     (fun () -> close_in chan))
143 abate 448 (fun () ->
144     Location.pop_source ();
145     include_stack := List.tl !include_stack)
146 abate 249 )
147 abate 66 ] |
148 abate 249 [ e = expr -> [ mk loc (EvalStatement e) ]
149 abate 43 ]
150 abate 13 ];
151    
152 abate 43 debug_directive: [
153     [ LIDENT "filter"; t = pat; p = pat -> `Filter(t,p)
154 abate 75 | LIDENT "accept"; p = pat -> `Accept p
155 abate 43 | LIDENT "compile"; t = pat; p = LIST1 pat -> `Compile (t,p)
156 abate 407 | LIDENT "sample"; t = pat -> `Sample t
157 abate 224 | LIDENT "subtype"; t1 = pat; t2 = pat -> `Subtype (t1,t2)
158 abate 43 ]
159     ];
160    
161 abate 332 keyword: [
162     [ a =
163     [ "map" | "match" | "with" | "try" | "xtransform"
164     | "if" | "then" | "else"
165     | "transform" | "fun" | "in"
166 abate 431 | "let" | "type" | "debug" | "include"
167 abate 623 | "and" | "validate" | "schema" | "namespace" | "ref"
168 abate 332 ]
169     -> a
170     ]
171     ];
172    
173 abate 4 expr: [
174     "top" RIGHTA
175 abate 421 [ "match"; e = SELF; "with"; b = branches ->
176     exp loc (Match (e,b))
177 abate 64 | "try"; e = SELF; "with"; b = branches ->
178 abate 425 exp loc (Try (e,b))
179 abate 421 | "map"; e = SELF; "with"; b = branches ->
180     exp loc (Map (e,b))
181     | "xtransform"; e = SELF; "with"; b = branches ->
182     exp loc (Xtrans (e,b))
183 abate 237 | "if"; e = SELF; "then"; e1 = SELF; "else"; e2 = SELF ->
184 abate 421 let p1 = mk loc (Internal true_type)
185     and p2 = mk loc (Internal false_type) in
186 abate 316 exp loc (Match (e, [p1,e1; p2,e2]))
187 abate 17 | "transform"; e = SELF; "with"; b = branches ->
188 abate 421 exp loc (Transform (e,b))
189 abate 501 | "validate"; e = SELF; "with"; schema = UIDENT; "#";
190     typ = [ UIDENT | LIDENT | keyword ] ->
191     exp loc (Validate (e, schema, typ))
192 abate 48 | "fun"; (f,a,b) = fun_decl ->
193 abate 316 exp loc (Abstraction { fun_name = f; fun_iface = a; fun_body = b })
194 abate 431 | (_,p,e1) = let_binding; "in"; e2 = expr LEVEL "top"->
195 abate 316 exp loc (Match (e1,[p,e2]))
196 abate 530 | (name,ns) = namespace_binding; "in"; e2 = expr LEVEL "top" ->
197     exp loc (NamespaceIn (name, ns, e2))
198 abate 54 | e = expr; ":"; p = pat ->
199 abate 316 exp loc (Forget (e,p))
200 abate 623 | e1 = expr; ";"; e2 = expr ->
201     exp loc (Match (e1, [pat_nil,e2]))
202     | "ref"; p = pat; e = expr ->
203     exp loc (Ref (e,p))
204 abate 4 ]
205 abate 623 |
206     [ e1 = expr; ":="; e2 = expr ->
207     exp loc (Apply (Dot (e1, U.mk "set"), e2))
208     ]
209 abate 15 |
210 abate 237 [ e1 = expr; op = ["=" | "<=" | "<<" | ">>" | ">=" ]; e2 = expr ->
211     let op = match op with
212     | "<<" -> "<"
213     | ">>" -> ">"
214     | s -> s in
215 abate 316 exp loc (Op (op,[e1;e2]))
216 abate 237 ]
217    
218     |
219 abate 242 [ e1 = expr; op = ["+" | "-" | "@" ]; e2 = expr ->
220 abate 316 exp loc (Op (op,[e1;e2]))
221 abate 339 | e = expr; "\\"; l = [LIDENT | UIDENT | keyword ] ->
222 abate 374 exp loc (RemoveField (e, label l))
223 abate 51 ]
224 abate 16 |
225 abate 316 [ e1 = expr; op = ["*"]; e2 = expr -> exp loc (Op (op,[e1;e2]))
226 abate 151 | e = expr; op = "/"; p = pat ->
227    
228     let tag = mk loc (Internal (Types.atom (Atoms.any))) in
229     let att = mk loc (Internal Types.Record.any) in
230     let any = mk loc (Internal (Types.any)) in
231 abate 375 let re = Star(Alt(SeqCapture(id_dummy,Elem p), Elem any)) in
232 abate 151 let ct = mk loc (Regexp (re,any)) in
233     let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
234 abate 375 let b = (p, Var id_dummy) in
235 abate 421 exp loc (Transform (e,[b]))
236 abate 51 ]
237 abate 26 |
238 abate 339 [ e = expr; "."; l = [LIDENT | UIDENT | keyword ] ->
239 abate 374 exp loc (Dot (e, label l))
240 abate 51 ]
241 abate 26
242 abate 52 |
243 abate 66 [ op = [ LIDENT "flatten"
244     | LIDENT "load_xml"
245 abate 374 | LIDENT "load_file" | LIDENT "load_file_utf8"
246 abate 188 | LIDENT "load_html"
247 abate 374 | LIDENT "print_xml" | LIDENT "print_xml_utf8"
248 abate 124 | LIDENT "print"
249 abate 66 | LIDENT "int_of"
250 abate 133 | LIDENT "string_of"
251 abate 329 | LIDENT "atom_of"
252 abate 421 | LIDENT "raise"
253 abate 66 ];
254 abate 316 e = expr -> exp loc (Op (op,[e]))
255 abate 374 | op = [ LIDENT "dump_to_file" | LIDENT "dump_to_file_utf8" ];
256 abate 316 e1 = expr LEVEL "no_appl"; e2 = expr -> exp loc (Op (op, [e1;e2]))
257     | e1 = SELF; LIDENT "div"; e2 = expr -> exp loc (Op ("/", [e1;e2]))
258     | e1 = SELF; LIDENT "mod"; e2 = expr -> exp loc (Op ("mod", [e1;e2]))
259     | e1 = SELF; e2 = expr -> exp loc (Apply (e1,e2))
260 abate 52 ]
261    
262 abate 4 | "no_appl"
263 abate 316 [ c = const -> exp loc (Cst c)
264     | "("; l = LIST1 expr SEP ","; ")" -> exp loc (tuple l)
265 abate 561 | "["; l = LIST0 seq_elem; e = OPT [ ";"; e = expr -> e ];
266     (_,loc_end) = ["]" -> loc] ->
267 abate 18 let e = match e with Some e -> e | None -> cst_nil in
268 abate 321 let l = List.fold_right
269     (fun x q ->
270     match x with
271 abate 522 | `String (loc,i,j,s) -> exp loc (String (i,j,s,q))
272 abate 561 | `Elems ((loc,_),x) -> exp (loc,loc_end) (Pair(x,q))
273 abate 321 | `Explode x -> Op ("@",[x;q])
274     ) l e
275     in
276     exp loc l
277 abate 332 | "<"; t = [ "("; e = expr; ")" -> e
278 abate 529 | a = tag -> exp loc (Cst a)
279     ];
280 abate 81 a = expr_attrib_spec; ">"; c = expr ->
281 abate 529 (* let t = Pair (cst_nil, t) in *)
282     exp loc (Xml (t, Pair (a,c)))
283 abate 549 | "{"; r = [ expr_record_spec | -> exp loc (RecordLitt []) ]; "}" -> r
284 abate 81 | s = STRING2 ->
285 abate 525 let s = U.mk s in
286 abate 522 exp loc (String (U.start_index s, U.end_index s, s, cst_nil))
287 abate 375 | a = LIDENT -> exp loc (Var (ident a))
288 abate 623 | "!"; e = expr ->
289     exp loc (Apply (Dot (e, U.mk "get"), cst_nil))
290 abate 4 ]
291    
292     ];
293 abate 18
294 abate 529 tag: [ [ a = [ LIDENT | UIDENT | keyword ] ->
295 abate 542 Const_atom (parse_ident a) ] ];
296 abate 529
297     tag_type: [
298     [ LIDENT "_" -> mk loc (Internal (Types.atom Atoms.any))
299 abate 542 | a = [ LIDENT | UIDENT | keyword ] -> mk loc (AtomT (parse_ident a))
300     | t = ANY_IN_NS -> mk loc (NsT (parse_ident t))
301 abate 529 ]
302     ];
303    
304 abate 18 seq_elem: [
305 abate 522 [ x = STRING1 ->
306 abate 525 let s = U.mk x in
307 abate 522 `String (loc, U.start_index s, U.end_index s, s)
308 abate 561 | e = expr LEVEL "no_appl" -> `Elems (loc,e)
309 abate 89 | "!"; e = expr LEVEL "no_appl" -> `Explode e
310 abate 18 ]
311     ];
312 abate 530
313     namespace_binding: [
314     [ "namespace";
315     name = [ name = [ UIDENT | LIDENT | keyword ]; "=" ->
316     parse_ident name
317     | -> U.mk "" ];
318     uri = STRING2 ->
319 abate 542 let ns = Ns.mk (parse_ident uri) in
320 abate 530 (name,ns)
321     ]
322     ];
323    
324    
325 abate 4 let_binding: [
326 abate 470 [ "let"; is_fun_decl; OPT "fun"; (f,a,b) = fun_decl ->
327     let f = match f with Some x -> x | None -> assert false in
328     let p = mk loc (Capture f) in
329     let abst = { fun_name = Some f; fun_iface = a; fun_body = b } in
330 abate 316 let e = exp loc (Abstraction abst) in
331 abate 431 (true,p,e)
332 abate 470 | "let"; p = pat; "="; e = expr -> (false,p,e)
333     | "let"; p = pat; ":"; t = pat; "="; e = expr -> (false,p, Forget (e,t))
334 abate 4 ]
335     ];
336    
337 abate 470 fun_decl_after_lparen: [
338 abate 85 (* need an hack to do this, because both productions would
339     match [ OPT LIDENT; "("; pat ] .... *)
340 abate 470 [ p1 = pat LEVEL "no_arrow";
341     res = [ "->"; p2 = pat;
342     a = [ ";"; a = LIST0 arrow SEP ";" -> a | -> [] ];
343     ")"; b = branches -> `Classic (p2,a,b)
344     | ":"; targ1 = pat;
345     args = LIST0 [ ","; arg = pat; ":"; targ = pat -> (arg,targ) ];
346     ")"; ":"; tres = pat ;
347     "="; body = expr ->
348     `Compact (targ1,args,tres,body)
349     ] ->
350     match res with
351     | `Classic (p2,a,b) -> (p1,p2)::a,b
352     | `Compact (targ1,args,tres,body) ->
353     let args = (p1,targ1) :: args in
354     let targ = multi_prod nopos (List.map snd args) in
355     let arg = multi_prod nopos (List.map fst args) in
356     let b = [arg, body] in
357     let a = [targ,tres] in
358     (a,b) ] ];
359    
360    
361     fun_decl: [
362     [ f = OPT [ x = LIDENT -> ident x]; "("; (a,b) = fun_decl_after_lparen ->
363 abate 85 (f,a,b)
364 abate 470 ]
365 abate 48 ];
366    
367 abate 85 arrow: [
368 abate 9 [ t1 = pat LEVEL "no_arrow"; "->"; t2 = pat -> (t1,t2)]
369 abate 4 ];
370    
371     branches: [
372 abate 81 [ OPT "|"; l = LIST1 branch SEP "|" -> l ]
373 abate 4 ];
374    
375     branch: [
376 abate 6 [ p = pat LEVEL "no_arrow"; "->"; e = expr -> (p,e) ]
377 abate 4 ];
378    
379    
380     regexp: [
381 abate 236 [ x = regexp; "|"; y = regexp ->
382     match (x,y) with
383     | Elem x, Elem y -> Elem (mk loc (Or (x,y)))
384     | _ -> Alt (x,y)
385     ]
386 abate 4 | [ x = regexp; y = regexp -> Seq (x,y) ]
387 abate 375 | [ a = LIDENT; "::"; x = regexp -> SeqCapture (ident a,x) ]
388 abate 4 | [ x = regexp; "*" -> Star x
389     | x = regexp; "*?" -> WeakStar x
390     | x = regexp; "+" -> Seq (x, Star x)
391     | x = regexp; "+?" -> Seq (x, WeakStar x)
392 abate 71 | x = regexp; "?" -> Alt (x, Epsilon)
393 abate 4 | x = regexp; "??" -> Alt (Epsilon, x) ]
394     | [ "("; x = regexp; ")" -> x
395 abate 225 | "("; a = LIDENT; ":="; c = const; ")" ->
396 abate 375 Elem (mk loc (Constant ((ident a,c))))
397 abate 66 | UIDENT "PCDATA" -> string_regexp
398 abate 81 | i = STRING1; "--"; j = STRING1 ->
399 abate 310 let i = Chars.mk_int (parse_char loc i)
400     and j = Chars.mk_int (parse_char loc j) in
401 abate 66 Elem (mk loc (Internal (Types.char (Chars.char_class i j))))
402 abate 81 | s = STRING1 ->
403 abate 18 List.fold_right
404 abate 525 (fun c accu ->
405 abate 310 let c = Chars.mk_int c in
406 abate 18 let c = Chars.atom c in
407 abate 525 Seq (Elem (mknoloc (Internal (Types.char c))), accu))
408     (seq_of_string s)
409 abate 66 Epsilon
410 abate 4 | e = pat LEVEL "simple" -> Elem e
411     ]
412     ];
413    
414     pat: [
415 abate 332 [ x = pat; LIDENT "where";
416 abate 529 b = LIST1 [ a = uident; "="; y = pat -> (a,y)
417 abate 338 | LIDENT -> error loc "Type/pattern identifiers must be capitalized"
418     ] SEP "and"
419 abate 4 -> mk loc (Recurs (x,b)) ]
420     | RIGHTA [ x = pat; "->"; y = pat -> mk loc (Arrow (x,y)) ]
421 abate 6 | "no_arrow" [ x = pat; "|"; y = pat -> mk loc (Or (x,y)) ]
422 abate 121 | "simple" [ x = pat; "&"; y = pat -> mk loc (And (x,y))
423 abate 99 | x = pat; "\\"; y = pat -> mk loc (Diff (x,y)) ]
424 abate 4 |
425 abate 159 [ "{"; r = record_spec; "}" -> mk loc (Record (true,r))
426     | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
427 abate 623 | "ref"; p = pat ->
428     let get_fun = mk loc (Arrow (pat_nil, p))
429     and set_fun = mk loc (Arrow (p, pat_nil)) in
430     let fields = [ label "get", get_fun; label "set", set_fun ] in
431     mk loc (Record (false, fields))
432 abate 4 | LIDENT "_" -> mk loc (Internal Types.any)
433 abate 375 | a = LIDENT -> mk loc (Capture (ident a))
434 abate 225 | "("; a = LIDENT; ":="; c = const; ")" ->
435 abate 375 mk loc (Constant (ident a,c))
436 abate 501 | schema = UIDENT; "#"; typ = [ UIDENT | LIDENT | keyword ];
437     k = OPT [ "as"; k = [ "element" | "type" | "attribute" ] -> k ] ->
438     let kind =
439     match k with
440     | None -> `Any
441     | Some "element" -> `Element
442     | Some "type" -> `Type
443     | Some "attribute" -> `Attribute
444     | _ -> assert false
445     in
446     mk loc (SchemaVar (kind, schema, typ))
447 abate 529 | a = uident -> mk loc (PatVar a)
448 abate 4 | i = INT ; "--"; j = INT ->
449 abate 222 let i = Intervals.mk i
450     and j = Intervals.mk j in
451 abate 52 mk loc (Internal (Types.interval (Intervals.bounded i j)))
452     | i = INT ->
453 abate 222 let i = Intervals.mk i in
454 abate 52 mk loc (Internal (Types.interval (Intervals.atom i)))
455 abate 81 | "*"; "--"; j = INT ->
456 abate 222 let j = Intervals.mk j in
457 abate 52 mk loc (Internal (Types.interval (Intervals.left j)))
458 abate 81 | i = INT; "--"; "*" ->
459 abate 222 let i = Intervals.mk i in
460 abate 52 mk loc (Internal (Types.interval (Intervals.right i)))
461 abate 19 | i = char ->
462     mk loc (Internal (Types.char (Chars.char_class i i)))
463 abate 13 | i = char ; "--"; j = char ->
464 abate 18 mk loc (Internal (Types.char (Chars.char_class i j)))
465 abate 529 | "`"; c = tag_type -> c
466     | c = const ->
467     (match c with
468 abate 542 | Const_atom l -> mk loc (AtomT l)
469     | Const_internal c -> mk loc (Internal (Types.constant c))
470 abate 529 )
471 abate 4 | "("; l = LIST1 pat SEP ","; ")" -> multi_prod loc l
472     | "["; r = [ r = regexp -> r | -> Epsilon ];
473     q = [ ";"; q = pat -> q
474 abate 623 | -> pat_nil ];
475 abate 4 "]" -> mk loc (Regexp (r,q))
476 abate 332 | "<"; t =
477 abate 529 [ x = tag_type -> x
478     | "("; t = pat; ")" -> t ];
479 abate 81 a = attrib_spec; ">"; c = pat ->
480 abate 529 (* let t = mk loc (Prod (mk loc (Internal Sequence.nil_type), t)) in *)
481 abate 110 mk loc (XmlT (t, multi_prod loc [a;c]))
482 abate 81 | s = STRING2 ->
483 abate 525 let s =
484     List.map
485     (fun c ->
486     mknoloc (Internal
487     (Types.char
488     (Chars.atom
489     (Chars.mk_int c)))))
490     (seq_of_string s) in
491     let s = s @ [mknoloc (Internal (Sequence.nil_type))] in
492 abate 63 multi_prod loc s
493 abate 4 ]
494    
495     ];
496    
497     record_spec:
498 abate 339 [ [ r = LIST0 [ l = [LIDENT | UIDENT | keyword ]; "=";
499 abate 81 o = [ "?" -> true | -> false];
500 abate 229 x = pat ->
501     let x = if o then mk loc (Optional x) else x in
502 abate 374 (label l, x)
503 abate 4 ] SEP ";" ->
504 abate 549 r
505 abate 4 ] ];
506    
507 abate 13 char:
508     [
509 abate 310 [ c = STRING1 -> Chars.mk_int (parse_char loc c) ]
510 abate 13 ];
511    
512    
513 abate 4 const:
514     [
515 abate 529 [ i = INT -> Const_internal (Types.Integer (Intervals.mk i))
516     | "`"; a = tag -> a
517     | c = char -> Const_internal (Types.Char c) ]
518 abate 4 ];
519    
520    
521     attrib_spec:
522 abate 561 [ [ r = LIST0 [ l = [LIDENT | UIDENT | keyword ]; "=";
523     o = [ "?" -> true | -> false];
524     x = pat; OPT ";" ->
525     let x = if o then mk loc (Optional x) else x in
526     (label l, x)
527     ] ->
528     mk loc (Record (true,r))
529 abate 252 | "("; t = pat; ")" -> t
530     | "{"; r = record_spec; "}" -> mk loc (Record (true,r))
531     | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
532     ] ];
533 abate 4
534     expr_record_spec:
535     [ [ r = LIST1
536 abate 339 [ l = [LIDENT | UIDENT | keyword ]; "="; x = expr ->
537 abate 374 (label l,x) ]
538 abate 561 SEP ";" ->
539 abate 549 exp loc (RecordLitt r)
540 abate 4 ] ];
541 abate 561
542 abate 4 expr_attrib_spec:
543 abate 561 [ [ r = LIST1
544     [ l = [LIDENT | UIDENT | keyword ]; "="; x = expr LEVEL "no_appl"; OPT ";" ->
545     (label l,x) ] ->
546     exp loc (RecordLitt r)
547     ]
548 abate 4 | [ e = expr LEVEL "no_appl" -> e
549 abate 549 | -> exp loc (RecordLitt [])
550 abate 4 ]
551     ];
552     END
553    
554 abate 10 let pat = Grammar.Entry.parse pat
555 abate 81 and expr = Grammar.Entry.parse expr
556     and prog = Grammar.Entry.parse prog
557 abate 431 and top_phrases = Grammar.Entry.parse top_phrases
558 abate 10
559 abate 495 let sync () =
560     match !Wlexer.lexbuf with
561     | None -> ()
562     | Some lb ->
563     let rec aux () =
564     match !Wlexer.last_tok with
565     | ("",";;") | ("EOI","") -> ()
566     | _ ->
567     Wlexer.last_tok := Wlexer.token Wlexer.latin1_engine lb;
568     aux ()
569     in
570     aux ()

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