parser.ml 17.1 KB
Newer Older
1 2
open Location
open Ast
3
open Ident
4
open Printf
5

6
(*
7
let ()  = Grammar.error_verbose := true
8
*)
9

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

13 14
let gram    = Grammar.gcreate (Wlexer.lexer Wlexer.token Wlexer.latin1_engine)

15 16 17 18
let true_atom = Atoms.mk_ascii "true"
let false_atom = Atoms.mk_ascii "false"
let true_type = Types.atom (Atoms.atom true_atom)
let false_type = Types.atom (Atoms.atom false_atom)
19

20
let parse_ident = U.mk_latin1
21

22
let id_dummy = ident (U.mk "$$$")
23

24
let label = parse_ident
25
let ident s = ident (parse_ident s)
26

27
let prog    = Grammar.Entry.create gram "prog"
28
let top_phrases   = Grammar.Entry.create gram "toplevel phrases"
29 30 31 32 33
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"
let const   = Grammar.Entry.create gram "scalar constant"
		
34 35
let exp pos e = LocatedExpr (loc_of_pos pos,e)

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

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


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

64

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

70 71
let include_stack = ref []

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

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

85
let dot_RE = Pcre.regexp "\\."
86

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

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

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

98 99
  uident: [ [ x = UIDENT -> parse_ident x ] ];

100
  phrase: [
101 102 103 104
    [ (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"->
105
        [ mk loc (EvalStatement (exp loc (Match (e1,[p,e2])))) ]
106
    | "type"; x = uident; "="; t = pat -> [ mk loc (TypeDecl (x,t)) ]
107
    | "type"; x = LIDENT -> error loc "Type identifiers must be capitalized"
108
    | "schema"; name = UIDENT; "="; uri = STRING2 ->
109
	protect_op "schema";
110
        let schema_doc = Schema_xml.pxp_tree_of uri in
111 112
        let schema = Schema_parser.parse_schema schema_doc in
        [ mk loc (SchemaDecl (name, schema))]
113 114 115 116 117
    | (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)) ]
118
    | "debug"; d = debug_directive -> [ mk loc (Debug d) ]
119 120
    | DIRECTIVE "#quit" -> [ mk loc (Directive `Quit) ]
    | DIRECTIVE "#env" -> [ mk loc (Directive `Env) ]
121
    | DIRECTIVE "#reinit_ns" -> [ mk loc (Directive `Reinit_ns) ]
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 137
	  protect_exn
	    (fun () ->
	       let chan = open_in s in
138 139 140 141 142
	       protect_exn
		 (fun () ->
		    let input = Stream.of_channel chan in
		    Grammar.Entry.parse prog input)
		 (fun () -> close_in chan))
143 144 145
	    (fun () ->
	       Location.pop_source ();
	       include_stack := List.tl !include_stack)
146
	)
147
    ] | 
148
    [ e = expr -> [ mk loc (EvalStatement e) ]
149 150 151 152 153
    ]
  ];

  debug_directive: [
    [ LIDENT "filter"; t = pat; p = pat -> `Filter(t,p)
154
    | LIDENT "accept"; p = pat -> `Accept p
155
    | LIDENT "compile"; t = pat; p = LIST1 pat -> `Compile (t,p)
156
    | LIDENT "sample"; t = pat -> `Sample t
157
    | LIDENT "subtype"; t1 = pat; t2 = pat -> `Subtype (t1,t2)
158
    ]
159
  ];
160

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

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

218
    | 
219
    [ e1 = expr; op = ["+" | "-" | "@" ]; e2 = expr -> 
220
	exp loc (Op (op,[e1;e2]))
221
    | e = expr; "\\"; l = [LIDENT | UIDENT | keyword ] -> 
222
	exp loc (RemoveField (e, label l)) 
223 224
    ]
    |
225
    [ e1 = expr; op = ["*"]; e2 = expr -> exp loc (Op (op,[e1;e2]))  
226 227 228 229 230
    | 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
231
	let re = Star(Alt(SeqCapture(id_dummy,Elem p), Elem any)) in
232 233
	let ct = mk loc (Regexp (re,any)) in
        let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
234
	let b = (p,  Var id_dummy) in
235
	exp loc (Transform (e,[b]))
236
    ]
237
    |
238
    [ e = expr;  "."; l = [LIDENT | UIDENT | keyword ] -> 
239
	exp loc (Dot (e, label l)) 
240
    ]  
241
 
242
    |
243 244
    [ op = [ LIDENT "flatten"
	   | LIDENT "load_xml"
245
	   | LIDENT "load_file" | LIDENT "load_file_utf8"
246
           | LIDENT "getenv"
247
	   | LIDENT "load_html"
248
	   | LIDENT "print_xml" | LIDENT "print_xml_utf8"
249
	   | LIDENT "print"
250
	   | LIDENT "int_of"
251
	   | LIDENT "string_of"
252
	   | LIDENT "atom_of"
253
	   | LIDENT "raise"
254
	   ]; 
255
      e = expr -> exp loc (Op (op,[e]))
256
    | op = [ LIDENT "dump_to_file" | LIDENT "dump_to_file_utf8" ];
257 258 259 260
      e1 = expr LEVEL "no_appl"; e2 = expr -> exp loc (Op (op, [e1;e2])) 
    | e1 = SELF; LIDENT "div"; e2 = expr -> exp loc (Op ("/", [e1;e2]))
    | e1 = SELF; LIDENT "mod"; e2 = expr -> exp loc (Op ("mod", [e1;e2]))
    | e1 = SELF; e2 = expr -> exp loc (Apply (e1,e2))
261 262
    ]

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

  ];
296

297
  tag: [ [ a = [ LIDENT | UIDENT | keyword ] -> 
298
	     Const_atom (parse_ident a) ] ];
299 300 301

  tag_type: [
    [ LIDENT "_" ->  mk loc (Internal (Types.atom Atoms.any))
302 303
    | a = [ LIDENT | UIDENT | keyword ] -> mk loc (AtomT (parse_ident a))
    | t = ANY_IN_NS -> mk loc (NsT (parse_ident t)) 
304 305 306
    ]
  ];

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

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

340
 fun_decl_after_lparen: [
341 342
(* need an hack to do this, because both productions would
   match   [ OPT LIDENT; "("; pat ] .... *)
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
   [ 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: [
   [ f = OPT [ x = LIDENT -> ident x]; "("; (a,b) = fun_decl_after_lparen ->
366
	    (f,a,b)
367
   ]
368 369
 ];

370
 arrow: [
371
    [ t1 = pat LEVEL "no_arrow"; "->"; t2 = pat -> (t1,t2)]
372 373 374
  ];

  branches: [
375
    [ OPT "|"; l = LIST1 branch SEP "|" -> l ]
376 377 378
  ];

  branch: [
379
    [ p = pat LEVEL "no_arrow"; "->"; e = expr -> (p,e) ]
380 381 382 383
  ];

	  
  regexp: [ 
384 385 386 387 388
    [ x = regexp; "|"; y = regexp -> 
	match (x,y) with
	  | Elem x, Elem y -> Elem (mk loc (Or (x,y)))
	  | _ -> Alt (x,y) 
    ]
389
  | [ x = regexp; y = regexp -> Seq (x,y) ]
390
  | [ a = LIDENT; "::"; x = regexp -> SeqCapture (ident a,x) ]
391 392 393 394
  | [ x = regexp; "*" -> Star x
    | x = regexp; "*?" -> WeakStar x
    | x = regexp; "+" -> Seq (x, Star x)
    | x = regexp; "+?" -> Seq (x, WeakStar x)
395
    | x = regexp; "?" ->  Alt (x, Epsilon)
396 397
    | x = regexp; "??" -> Alt (Epsilon, x) ]
  | [ "("; x = regexp; ")" -> x
398
    | "("; a = LIDENT; ":="; c = const; ")" -> 
399
	Elem (mk loc (Constant ((ident a,c))))
400
    | UIDENT "PCDATA" -> string_regexp
401
    | i = STRING1; "--"; j = STRING1 ->
402 403
	let i = Chars.mk_int (parse_char loc i)
	and j = Chars.mk_int (parse_char loc j) in
404
        Elem (mk loc (Internal (Types.char (Chars.char_class i j))))
405
    |  s = STRING1 ->
406
	List.fold_right
407
	  (fun c accu -> 
408
	     let c = Chars.mk_int c in
409
	     let c = Chars.atom c in
410 411
	     Seq (Elem (mknoloc (Internal (Types.char c))), accu))
	  (seq_of_string s)
412
	  Epsilon 
413 414 415 416 417
    | e = pat LEVEL "simple" -> Elem e
    ]
  ];

  pat: [ 
418
      [ x = pat; LIDENT "where"; 
419
        b = LIST1 [ a = uident; "="; y = pat -> (a,y)
420 421
		  | LIDENT -> error loc "Type/pattern identifiers must be capitalized"
		  ] SEP "and"
422 423
            -> mk loc (Recurs (x,b)) ]
    | RIGHTA [ x = pat; "->"; y = pat -> mk loc (Arrow (x,y)) ]
424
    | "no_arrow" [ x = pat; "|"; y = pat -> mk loc (Or (x,y)) ] 
425
    | "simple" [ x = pat; "&"; y = pat -> mk loc (And (x,y)) 
426
	       | x = pat; "\\"; y = pat -> mk loc (Diff (x,y)) ]
427
    | 
428 429
      [ "{"; r = record_spec; "}" -> mk loc (Record (true,r))
      | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
430 431 432 433 434
      | "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))
435
      | LIDENT "_" -> mk loc (Internal Types.any)
436
      | a = LIDENT -> mk loc (Capture (ident a))
437
      | "("; a = LIDENT; ":="; c = const; ")" -> 
438
	  mk loc (Constant (ident a,c))
439 440 441 442 443 444 445 446 447 448 449
      | schema = UIDENT; "#"; typ = [ UIDENT | LIDENT | keyword ];
        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))
450
      | a = uident -> mk loc (PatVar a)
451
      | i = INT ; "--"; j = INT -> 
452 453
          let i =  Intervals.mk i 
	  and j =  Intervals.mk j in
454 455
          mk loc (Internal (Types.interval (Intervals.bounded i j)))
      | i = INT -> 
456
          let i =  Intervals.mk i  in
457
          mk loc (Internal (Types.interval (Intervals.atom i)))
458
      | "*"; "--"; j = INT ->
459
	  let j =  Intervals.mk j in
460
          mk loc (Internal (Types.interval (Intervals.left j)))
461
      | i = INT; "--"; "*" ->
462
	  let i = Intervals.mk i in
463
          mk loc (Internal (Types.interval (Intervals.right i)))
464 465
      | i = char ->
          mk loc (Internal (Types.char (Chars.char_class i i)))
466
      | i = char ; "--"; j = char ->
467
          mk loc (Internal (Types.char (Chars.char_class i j)))
468 469 470
      | "`"; c = tag_type -> c
      | c = const -> 
	  (match c with
471 472
	     | Const_atom l -> mk loc (AtomT l)
	     | Const_internal c -> mk loc (Internal (Types.constant c))
473
	  )
474 475 476
      | "("; l = LIST1 pat SEP ","; ")" -> multi_prod loc l
      | "["; r = [ r = regexp -> r | -> Epsilon ];
             q = [ ";"; q = pat -> q 
477
                 | -> pat_nil ]; 
478
             "]" -> mk loc (Regexp (r,q))
479
      | "<"; t =
480 481
            [ x = tag_type -> x
            | "("; t = pat; ")" -> t ];
482
	a = attrib_spec; ">"; c = pat ->
483
(*	  let t = mk loc (Prod (mk loc (Internal Sequence.nil_type), t)) in *)
484
          mk loc (XmlT (t, multi_prod loc [a;c]))
485
      | s = STRING2 ->
486 487 488 489 490 491 492 493 494
	  let s = 
	    List.map 
	      (fun c -> 
		 mknoloc (Internal
			     (Types.char
				(Chars.atom
				   (Chars.mk_int c))))) 
	      (seq_of_string s) in
	  let s = s @ [mknoloc (Internal (Sequence.nil_type))] in
495
	  multi_prod loc s
496 497 498 499 500
      ]
    
  ];

  record_spec:
501
    [ [ r = LIST0 [ l = [LIDENT | UIDENT | keyword ]; "=";
502
                  o = [ "?" -> true | -> false]; 
503 504
                  x = pat -> 
		    let x = if o then mk loc (Optional x) else x in
505
		    (label l, x)
506
                ] SEP ";" ->
507
	  r
508 509
      ] ];
  
510 511
  char:
    [ 
512
      [ c = STRING1 -> Chars.mk_int (parse_char loc c) ]
513 514 515
    ];
     

516 517
  const:
    [ 
518 519 520
      [ i = INT -> Const_internal (Types.Integer (Intervals.mk i))
      | "`"; a = tag -> a
      | c = char -> Const_internal (Types.Char c) ]
521 522 523 524
    ];


  attrib_spec:
525 526 527 528 529 530 531
    [ [ r = LIST0 [ l = [LIDENT | UIDENT | keyword ]; "=";
                  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)) 
532 533 534 535
      | "("; t = pat; ")" -> t 
      | "{"; r = record_spec; "}" -> mk loc (Record (true,r))
      | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
      ] ];
536 537 538

  expr_record_spec:
    [ [ r = LIST1
539
	      [ l = [LIDENT | UIDENT | keyword ]; "="; x = expr LEVEL "no_appl" -> 
540
		  (label l,x) ] 
541
	       SEP ";"  ->
542
	  exp loc (RecordLitt r)
543
      ] ];
544

545
  expr_attrib_spec:
546 547 548 549 550
    [ [ r = LIST1
	      [ l = [LIDENT | UIDENT | keyword ]; "="; x = expr LEVEL "no_appl"; OPT ";" -> 
		  (label l,x) ] ->
	  exp loc (RecordLitt r)
      ]
551
    | [ e = expr LEVEL "no_appl" -> e 
552
      | -> exp loc (RecordLitt []) 
553 554 555 556
      ] 
    ];
END

557
let pat = Grammar.Entry.parse pat
558 559
and expr = Grammar.Entry.parse expr
and prog = Grammar.Entry.parse prog
560 561
and top_phrases = Grammar.Entry.parse top_phrases

562 563 564 565 566 567 568 569 570 571 572 573
let sync () = 
  match !Wlexer.lexbuf with
    | None -> ()
    | Some lb ->
	let rec aux () =
	  match !Wlexer.last_tok with
	    | ("",";;") | ("EOI","") -> ()
	    | _ -> 
		Wlexer.last_tok := Wlexer.token Wlexer.latin1_engine lb; 
		aux ()
	in
	aux ()