parser.ml 17.2 KB
Newer Older
1
2
#load "pa_extend.cmo";;

3
4
open Location
open Ast
5
open Ident
6
open Printf
7

8
(*
9
let ()  = Grammar.error_verbose := true
10
*)
11

12
13
exception Error of string
let error (i,j) s = Location.raise_loc i j (Error s)
14

15
let gram    = Grammar.gcreate Ulexer.lex
16

17
18
let true_atom = Atoms.V.mk_ascii "true"
let false_atom = Atoms.V.mk_ascii "false"
19
20
let true_type = Types.atom (Atoms.atom true_atom)
let false_type = Types.atom (Atoms.atom false_atom)
21

22
let parse_ident = U.mk
23

24
let id_dummy = ident (U.mk "$$$")
25

26
let label = parse_ident
27
let ident s = ident (parse_ident s)
28

29
let prog    = Grammar.Entry.create gram "prog"
30
let top_phrases   = Grammar.Entry.create gram "toplevel phrases"
31
32
33
34
let expr    = Grammar.Entry.create gram "expression"
let pat     = Grammar.Entry.create gram "type/pattern expression"
let regexp  = Grammar.Entry.create gram "type/pattern regexp"
		
35
36
let exp pos e = LocatedExpr (loc_of_pos pos,e)

37
38
39
40
41
let rec multi_prod loc = function
  | [ x ] -> x
  | x :: l -> mk loc (Prod (x, multi_prod loc l))
  | [] -> assert false
      
42
let rec tuple = function
43
  | [ x ] -> x
44
  | x :: l -> Pair (x, tuple l)
45
  | [] -> assert false
46
47

let tuple_queue = 
48
  List.fold_right (fun x q -> Pair (x, q))
49
50


51
let char = mknoloc (Internal (Types.char Chars.any))
52
let string_regexp = Star (Elem char)
53
	       
54
let cst_nil =  Atom (U.mk "nil")
55
let pat_nil = mknoloc (Internal (Sequence.nil_type))
56
		 
57
let seq_of_string s =
58
59
  let s = Encodings.Utf8.mk s in
  let rec aux i j =
60
61
    if Encodings.Utf8.equal_index i j then []
    else let (c,i) = Encodings.Utf8.next s i in c :: (aux i j)
62
  in
63
  aux (Encodings.Utf8.start_index s) (Encodings.Utf8.end_index s)
64

65

66
let parse_char loc s =
67
68
  match seq_of_string s with
    | [ c ] -> c
69
    | _ -> error loc "Character litteral must have length 1"
70

71
72
let include_stack = ref []

73
74
75
76
let protect_exn f g =
  try let x = f () in g (); x
  with e -> g (); raise e

77
78
79
80
let is_fun_decl =
   Grammar.Entry.of_parser gram "[is_fun_decl]"
     (fun strm ->
       match Stream.npeek 3 strm with
81
82
	 | [ ("", "fun"); ("IDENT", _); ("", "(") ]
	 | [ ("IDENT", _) ; ("", "(") ; _ ] -> ()
83
84
85
	 | _ -> raise Stream.Failure
     )

86
EXTEND
87
  GLOBAL: top_phrases prog expr pat regexp;
88
89

  top_phrases: [
90
    [ l = LIST0 phrase; ";;" -> List.flatten l  ]
91
  ];
92
93

  prog: [
94
    [ l = LIST0 [ p = phrase ; OPT ";;" -> p ]; EOI -> List.flatten l ]
95
96
97
  ];

  phrase: [
98
99
100
101
    [ (f,p,e) = let_binding -> 
	if f then [ mk loc (FunDecl e) ] else
	  [ mk loc (LetDecl (p,e)) ]
    | (_,p,e1) = let_binding; "in"; e2 = expr LEVEL "top"->
102
        [ mk loc (EvalStatement (exp loc (Match (e1,[p,e2])))) ]
103
    | "type"; x = IDENT; "="; t = pat -> [ mk loc (TypeDecl (ident x,t)) ]
104
    | "schema"; name = IDENT; "="; uri = STRING2 ->
105
	protect_op "schema";
106
        let schema_doc = Schema_xml.pxp_tree_of uri in
107
108
        let schema = Schema_parser.parse_schema schema_doc in
        [ mk loc (SchemaDecl (name, schema))]
109
110
111
112
113
    | (name,ns) = namespace_binding ->
	[ mk loc (Namespace (name, ns)) ]
    | (name,ns) = namespace_binding; "in"; e2 = expr LEVEL "top" ->
	let e = exp loc (NamespaceIn (name, ns, e2)) in
        [ mk loc (EvalStatement (exp loc e)) ]
114
    | "debug"; d = debug_directive -> [ mk loc (Debug d) ]
115
116
117
    | DIRECTIVE "#utf8" -> Ulexer.enc := Ulexing.Utf8; [ ]
    | DIRECTIVE "#latin1" -> Ulexer.enc := Ulexing.Latin1; [ ]
    | DIRECTIVE "#ascii" -> Ulexer.enc := Ulexing.Ascii; [ ]
118
119
    | DIRECTIVE "#quit" -> [ mk loc (Directive `Quit) ]
    | DIRECTIVE "#env" -> [ mk loc (Directive `Env) ]
120
    | DIRECTIVE "#reinit_ns" -> [ mk loc (Directive `Reinit_ns) ]
121
    | DIRECTIVE "#help" -> [ mk loc (Directive `Help) ]
122
    | "include"; s = STRING2 ->
123
124
125
126
	let s = 
	  if Filename.is_relative s 
	  then Filename.concat (Location.current_dir ()) s
	  else s in
127
128
	protect_op "File inclusion";
	(* avoid looping; should issue an error ? *)
129
130
	(* it is possible to have looping with x/../x/../x/.. ....
	   Need to canonicalize filename *)
131
132
133
134
	if List.mem s !include_stack then [] 
	else (
	  include_stack := s :: !include_stack;
	  Location.push_source (`File s);
135
136
	  let saved_enc = !Ulexer.enc in
	  Ulexer.enc := Ulexing.Latin1;
137
138
139
	  protect_exn
	    (fun () ->
	       let chan = open_in s in
140
141
142
143
144
	       protect_exn
		 (fun () ->
		    let input = Stream.of_channel chan in
		    Grammar.Entry.parse prog input)
		 (fun () -> close_in chan))
145
	    (fun () ->
146
	       Ulexer.enc := saved_enc;
147
148
	       Location.pop_source ();
	       include_stack := List.tl !include_stack)
149
	)
150
    ] | 
151
    [ e = expr -> [ mk loc (EvalStatement e) ]
152
153
154
155
    ]
  ];

  debug_directive: [
156
157
158
159
160
    [ IDENT "filter"; t = pat; p = pat -> `Filter(t,p)
    | IDENT "accept"; p = pat -> `Accept p
    | IDENT "compile"; t = pat; p = LIST1 pat -> `Compile (t,p)
    | IDENT "sample"; t = pat -> `Sample t
    | IDENT "subtype"; t1 = pat; t2 = pat -> `Subtype (t1,t2)
161
    | IDENT "explain"; t = pat; e = expr -> `Explain (t,e)
162
    ]
163
  ];
164

165
166
167
168
169
  keyword: [
    [ a = 
	[ "map" | "match" | "with" | "try" | "xtransform"
	| "if" | "then"	| "else"
	| "transform" | "fun" | "in"
170
	| "let" | "type" | "debug" | "include"
171
        | "and" | "validate" | "schema" | "namespace" | "ref"
172
173
174
175
176
	]
	-> a
    ]
  ];

177
178
  expr: [
    "top" RIGHTA
179
180
    [ "match"; e = SELF; "with"; b = branches -> 
	exp loc (Match (e,b))
181
    | "try"; e = SELF; "with"; b = branches -> 
182
	exp loc (Try (e,b))
183
184
185
186
    | "map"; e = SELF; "with"; b = branches -> 
	exp loc (Map (e,b))
    | "xtransform"; e = SELF; "with"; b = branches -> 
	exp loc (Xtrans (e,b))
187
    | "if"; e = SELF; "then"; e1 = SELF; "else"; e2 = SELF ->
188
189
	let p1 = mk loc (Internal true_type)
	and p2 = mk loc (Internal false_type) in
190
	exp loc (Match (e, [p1,e1; p2,e2]))
191
    | "transform"; e = SELF; "with"; b = branches -> 
192
	exp loc (Transform (e,b))
193
194
    | "validate"; e = SELF; "with"; schema = IDENT; "#";
      typ = [ IDENT | keyword ] ->
195
        exp loc (Validate (e, schema, typ))
196
    | "fun"; (f,a,b) = fun_decl ->
197
	exp loc (Abstraction { fun_name = f; fun_iface = a; fun_body = b })
198
    | (_,p,e1) = let_binding; "in"; e2 = expr LEVEL "top"->
199
        exp loc (Match (e1,[p,e2]))
200
201
    | (name,ns) = namespace_binding; "in"; e2 = expr LEVEL "top" ->
	exp loc (NamespaceIn (name, ns, e2))
202
    | e = expr; ":"; p = pat ->
203
	exp loc (Forget (e,p))
204
205
206
207
208
209
210
211
    | e1 = expr; ";"; e2 = expr ->
	exp loc (Match (e1, [pat_nil,e2]))
    | "ref"; p = pat; e = expr ->
	exp loc (Ref (e,p))
    ]
    |
    [ e1 = expr; ":="; e2 = expr ->
	exp loc (Apply (Dot (e1, U.mk "set"), e2))
212
    ]
213
214
215
216
217
218
    | 
    [ e1 = expr; op = ["=" | "<=" | "<<" | ">>" | ">=" ]; e2 = expr -> 
	let op = match op with
	  | "<<" -> "<"
	  | ">>" -> ">"
	  | s -> s in
219
	exp loc (Op (op,[e1;e2]))
220
221
    ]

222
    | 
223
    [ e1 = expr; op = ["+" | "-" | "@" ]; e2 = expr -> 
224
	exp loc (Op (op,[e1;e2]))
225
    | e = expr; "\\"; l = [IDENT | keyword ] -> 
226
	exp loc (RemoveField (e, label l)) 
227
228
    ]
    |
229
    [ e1 = expr; op = ["*"]; e2 = expr -> exp loc (Op (op,[e1;e2]))  
230
231
232
233
234
    | e = expr; op = "/"; p = pat ->

	let tag = mk loc (Internal (Types.atom (Atoms.any))) in
	let att = mk loc (Internal Types.Record.any) in
	let any = mk loc (Internal (Types.any)) in
235
	let re = Star(Alt(SeqCapture(id_dummy,Elem p), Elem any)) in
236
237
	let ct = mk loc (Regexp (re,any)) in
        let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
238
	let b = (p,  Var id_dummy) in
239
	exp loc (Transform (e,[b]))
240
    ]
241
    |
242
    [ e = expr;  "."; l = [IDENT | keyword ] -> 
243
	exp loc (Dot (e, label l)) 
244
    ]  
245
 
246
    |
247
248
249
250
251
252
253
254
255
256
257
    [ op = [ IDENT "flatten"
	   | IDENT "load_xml"
	   | IDENT "load_file" | IDENT "load_file_utf8"
           | IDENT "getenv"
	   | IDENT "load_html"
	   | IDENT "print_xml" | IDENT "print_xml_utf8"
	   | IDENT "print"
	   | IDENT "int_of"
	   | IDENT "string_of"
	   | IDENT "atom_of"
	   | IDENT "raise"
258
	   ]; 
259
      e = expr -> exp loc (Op (op,[e]))
260
    | op = [ IDENT "dump_to_file" | IDENT "dump_to_file_utf8" ];
261
      e1 = expr LEVEL "no_appl"; e2 = expr -> exp loc (Op (op, [e1;e2])) 
262
263
    | e1 = SELF; IDENT "div"; e2 = expr -> exp loc (Op ("/", [e1;e2]))
    | e1 = SELF; IDENT "mod"; e2 = expr -> exp loc (Op ("mod", [e1;e2]))
264
    | e1 = SELF; e2 = expr -> exp loc (Apply (e1,e2))
265
266
    ]

267
    | "no_appl" 
268
269
    [ 
      "("; l = LIST1 expr SEP ","; ")" -> exp loc (tuple l)
270
    | "[";  l = LIST0 seq_elem; e = OPT [ ";"; e = expr -> e ]; 
271
      loc_end = ["]" -> loc] ->
272
	let e = match e with Some e -> e | None -> cst_nil in
273
274
        let e = exp loc_end e in
        let (_,loc_end) = loc_end in
275
276
277
	let l = List.fold_right 
		  (fun x q ->
		     match x with
278
		       | `String (loc,i,j,s) -> exp loc (String (i,j,s,q))
279
		       | `Elems ((loc,_),x) -> exp (loc,loc_end) (Pair(x,q))
280
281
282
283
		       | `Explode x -> Op ("@",[x;q])
		  ) l e
	in
	exp loc l
284
    | "<"; t = [ "("; e = expr; ")" -> e
285
	       | a = tag -> exp loc a
286
	       ];
287
	a = expr_attrib_spec; ">"; c = expr ->
288
	  exp loc (Xml (t, Pair (a,c)))
289
    | "{"; r = [ expr_record_spec | -> exp loc (RecordLitt []) ]; "}" -> r
290
    | s = STRING2 ->
291
	let s = U.mk s in
292
	exp loc (String (U.start_index s, U.end_index s, s, cst_nil))
293
    | a = IDENT -> exp loc (Var (ident a))
294
295
    | "!"; e = expr ->
	exp loc (Apply (Dot (e, U.mk "get"), cst_nil))
296
297
298
    | i = INT -> exp loc (Integer (Intervals.V.mk i))
    | "`"; a = tag -> a
    | c = char -> exp loc (Char c)
299
300
301
    ]

  ];
302

303
  tag: [ [ a = [ IDENT | keyword ] -> exp loc (Atom (parse_ident a)) ] ];
304
305

  tag_type: [
306
    [ IDENT "_" ->  mk loc (Internal (Types.atom Atoms.any))
307
    | a = [ IDENT | keyword ] -> mk loc (Cst (Atom (parse_ident a)))
308
    | t = ANY_IN_NS -> mk loc (NsT (parse_ident t)) 
309
310
311
    ]
  ];

312
  seq_elem: [
313
    [ x = STRING1 -> 
314
	let s = U.mk x in
315
	`String (loc, U.start_index s, U.end_index s, s)
316
    | e = expr LEVEL "no_appl" -> `Elems (loc,e)
317
    | "!"; e = expr LEVEL "no_appl" -> `Explode e
318
319
    ]
  ];
320
321
322
	
  namespace_binding: [
    [ "namespace"; 
323
	name = [ name = [ IDENT | keyword ]; "=" ->
324
325
326
		   parse_ident name
	       | -> U.mk "" ];
	uri = STRING2 ->
327
	  let ns = Ns.mk (parse_ident uri) in
328
329
330
331
332
	  (name,ns)
    ]
  ];

  
333
  let_binding: [
334
335
    [ "let"; is_fun_decl; OPT "fun"; (f,a,b) = fun_decl ->
	let f = match f with Some x -> x | None -> assert false in
336
	let p = mk loc (PatVar f) in
337
	let abst = { fun_name = Some f; fun_iface = a; fun_body = b } in
338
        let e = exp loc (Abstraction abst) in
339
        (true,p,e)
340
341
    | "let"; p = pat; "="; e = expr -> (false,p,e)
    | "let"; p = pat; ":"; t = pat; "="; e = expr -> (false,p, Forget (e,t))
342
343
344
    ] 
  ];

345
 fun_decl_after_lparen: [
346
(* need an hack to do this, because both productions would
347
   match   [ OPT IDENT; "("; pat ] .... *)
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
   [ p1 = pat LEVEL "no_arrow";
     res = [ "->"; p2 = pat;
	     a = [ ";"; a = LIST0 arrow SEP ";" -> a | -> [] ];
	     ")"; b = branches -> `Classic (p2,a,b)
	   | ":"; targ1 = pat;
	     args = LIST0 [ ","; arg = pat; ":"; targ = pat -> (arg,targ) ]; 
	     ")"; ":"; tres = pat ; 
	     "="; body = expr ->
	       `Compact (targ1,args,tres,body)
	   ] ->
       match res with
	 | `Classic (p2,a,b) -> (p1,p2)::a,b
	 | `Compact (targ1,args,tres,body) ->
	     let args = (p1,targ1) :: args in
	     let targ = multi_prod nopos (List.map snd args) in
	     let arg = multi_prod nopos (List.map fst args) in
	     let b = [arg, body] in
	     let a = [targ,tres] in
	     (a,b) ] ];


 fun_decl: [
370
371
372
   [ f = OPT IDENT; "("; (a,b) = fun_decl_after_lparen ->
       let f = match f with Some x -> Some (ident x) | None -> None in
       (f,a,b)
373
   ]
374
375
 ];

376
 arrow: [
377
    [ t1 = pat LEVEL "no_arrow"; "->"; t2 = pat -> (t1,t2)]
378
379
380
  ];

  branches: [
381
    [ OPT "|"; l = LIST1 branch SEP "|" -> l ]
382
383
384
  ];

  branch: [
385
    [ p = pat LEVEL "no_arrow"; "->"; e = expr -> (p,e) ]
386
387
388
389
  ];

	  
  regexp: [ 
390
391
392
393
394
    [ x = regexp; "|"; y = regexp -> 
	match (x,y) with
	  | Elem x, Elem y -> Elem (mk loc (Or (x,y)))
	  | _ -> Alt (x,y) 
    ]
395
  | [ x = regexp; y = regexp -> Seq (x,y) ]
396
397
398
399
400
  | [ x = regexp; "&"; y = regexp ->
	match (x,y) with
	  | Elem x, Elem y -> Elem (mk loc (And (x,y)))
	  | _ -> error loc "Conjunction not allowed in regular expression"
    ]
401
  | [ a = IDENT; "::"; x = regexp -> SeqCapture (ident a,x) ]
402
403
404
405
  | [ x = regexp; "*" -> Star x
    | x = regexp; "*?" -> WeakStar x
    | x = regexp; "+" -> Seq (x, Star x)
    | x = regexp; "+?" -> Seq (x, WeakStar x)
406
    | x = regexp; "?" ->  Alt (x, Epsilon)
407
    | x = regexp; "??" -> Alt (Epsilon, x) ]
408
  | [ "("; x = LIST1 regexp SEP ","; ")" ->
409
410
411
412
413
414
415
416
417
418
419
	(match x with
	  | [ x ] -> x
	  | _ ->
	      let x = 
		List.map 
		  (function
		     | Elem x -> x
		     | _ -> error loc 
			 "Mixing regular expressions and products")
		  x in
	      Elem (multi_prod loc x))
420
421
    | "("; a = IDENT; ":="; c = expr; ")" -> 
	Elem (mk loc (Constant ((ident a,c))))
422
    | IDENT "PCDATA" -> string_regexp
423
    | i = STRING1; "--"; j = STRING1 ->
424
425
	let i = Chars.V.mk_int (parse_char loc i)
	and j = Chars.V.mk_int (parse_char loc j) in
426
        Elem (mk loc (Internal (Types.char (Chars.char_class i j))))
427
    |  s = STRING1 ->
428
	List.fold_right
429
	  (fun c accu -> 
430
	     let c = Chars.V.mk_int c in
431
	     let c = Chars.atom c in
432
433
	     Seq (Elem (mknoloc (Internal (Types.char c))), accu))
	  (seq_of_string s)
434
435
	  Epsilon ]
    | [ e = pat LEVEL "simple" -> Elem e
436
437
438
439
    ]
  ];

  pat: [ 
440
      [ x = pat; IDENT "where"; 
441
        b = LIST1 [ a = IDENT; "="; y = pat -> (ident a,y) ] SEP "and"
442
443
            -> mk loc (Recurs (x,b)) ]
    | RIGHTA [ x = pat; "->"; y = pat -> mk loc (Arrow (x,y)) ]
444
    | "no_arrow" [ x = pat; "|"; y = pat -> mk loc (Or (x,y)) ] 
445
    | "simple" [ x = pat; "&"; y = pat -> mk loc (And (x,y)) 
446
	       | x = pat; "\\"; y = pat -> mk loc (Diff (x,y)) ]
447
    | 
448
449
      [ "{"; r = record_spec; "}" -> mk loc (Record (true,r))
      | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
450
451
452
453
454
      | "ref"; p = pat ->
	  let get_fun = mk loc (Arrow (pat_nil, p)) 
	  and set_fun = mk loc (Arrow (p, pat_nil)) in
	  let fields = [ label "get", get_fun; label "set", set_fun ] in
	  mk loc (Record (false, fields))
455
      | IDENT "_" -> mk loc (Internal Types.any)
456
      | "("; a = IDENT; ":="; c = expr; ")" -> 
457
	  mk loc (Constant (ident a,c))
458
      | schema = IDENT; "#"; typ = [ IDENT | keyword ];
459
460
461
462
463
464
465
466
467
468
        k = OPT [ "as"; k = [ "element" | "type" | "attribute" ] -> k ] ->
          let kind =
            match k with
            | None -> `Any
            | Some "element" -> `Element
            | Some "type" -> `Type
            | Some "attribute" -> `Attribute
            | _ -> assert false
          in
          mk loc (SchemaVar (kind, schema, typ))
469
470
      | a = IDENT -> 
	  mk loc (PatVar (ident a))
471
      | i = INT ; "--"; j = INT -> 
472
473
          let i =  Intervals.V.mk i 
	  and j =  Intervals.V.mk j in
474
475
          mk loc (Internal (Types.interval (Intervals.bounded i j)))
      | i = INT -> 
476
          let i =  Intervals.V.mk i  in
477
          mk loc (Internal (Types.interval (Intervals.atom i)))
478
      | "*"; "--"; j = INT ->
479
	  let j =  Intervals.V.mk j in
480
          mk loc (Internal (Types.interval (Intervals.left j)))
481
      | i = INT; "--"; "*" ->
482
	  let i = Intervals.V.mk i in
483
          mk loc (Internal (Types.interval (Intervals.right i)))
484
485
      | i = char ->
          mk loc (Internal (Types.char (Chars.char_class i i)))
486
      | i = char ; "--"; j = char ->
487
          mk loc (Internal (Types.char (Chars.char_class i j)))
488
      | "`"; c = tag_type -> c
489
490
491
      | "("; l = LIST1 pat SEP ","; ")" -> multi_prod loc l
      | "["; r = [ r = regexp -> r | -> Epsilon ];
             q = [ ";"; q = pat -> q 
492
                 | -> pat_nil ]; 
493
             "]" -> mk loc (Regexp (r,q))
494
      | "<"; t =
495
496
            [ x = tag_type -> x
            | "("; t = pat; ")" -> t ];
497
	a = attrib_spec; ">"; c = pat ->
498
          mk loc (XmlT (t, multi_prod loc [a;c]))
499
      | s = STRING2 ->
500
501
502
503
504
505
	  let s = 
	    List.map 
	      (fun c -> 
		 mknoloc (Internal
			     (Types.char
				(Chars.atom
506
				   (Chars.V.mk_int c))))) 
507
508
	      (seq_of_string s) in
	  let s = s @ [mknoloc (Internal (Sequence.nil_type))] in
509
	  multi_prod loc s
510
511
512
513
514
      ]
    
  ];

  record_spec:
515
    [ [ r = LIST0 [ l = [IDENT | keyword ]; "=";
516
                  o = [ "?" -> true | -> false]; 
517
518
                  x = pat -> 
		    let x = if o then mk loc (Optional x) else x in
519
		    (label l, x)
520
                ] SEP ";" ->
521
	  r
522
523
      ] ];
  
524
525
  char:
    [ 
526
      [ c = STRING1 -> Chars.V.mk_int (parse_char loc c) ]
527
528
529
    ];
     

530
  attrib_spec:
531
    [ [ r = LIST0 [ l = [IDENT | keyword ]; "=";
532
533
534
535
536
537
                  o = [ "?" -> true | -> false]; 
                  x = pat; OPT ";" -> 
		    let x = if o then mk loc (Optional x) else x in
		    (label l, x)
                ] ->
	  mk loc (Record (true,r)) 
538
539
540
541
      | "("; t = pat; ")" -> t 
      | "{"; r = record_spec; "}" -> mk loc (Record (true,r))
      | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
      ] ];
542
543
544

  expr_record_spec:
    [ [ r = LIST1
545
	      [ l = [IDENT | keyword ]; "="; x = expr LEVEL "no_appl" -> 
546
		  (label l,x) ] 
547
	       SEP ";"  ->
548
	  exp loc (RecordLitt r)
549
      ] ];
550

551
  expr_attrib_spec:
552
    [ [ r = LIST1
553
	      [ l = [IDENT | keyword ]; "="; x = expr LEVEL "no_appl"; OPT ";" -> 
554
555
556
		  (label l,x) ] ->
	  exp loc (RecordLitt r)
      ]
557
    | [ e = expr LEVEL "no_appl" -> e 
558
      | -> exp loc (RecordLitt []) 
559
560
561
562
      ] 
    ];
END

563
let pat = Grammar.Entry.parse pat
564
565
and expr = Grammar.Entry.parse expr
and prog = Grammar.Entry.parse prog
566
567
and top_phrases = Grammar.Entry.parse top_phrases

568
let sync () = 
569
  match !Ulexer.lexbuf with
570
571
572
    | None -> ()
    | Some lb ->
	let rec aux () =
573
	  match !Ulexer.last_tok with
574
575
	    | ("",";;") | ("EOI","") -> ()
	    | _ -> 
576
		Ulexer.last_tok := fst (Ulexer.token lb); 
577
578
579
		aux ()
	in
	aux ()
580
581
582
583

let sync () =
  try sync ()
  with Ulexing.Error -> ()