parser.ml 17 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 "load_html"
247
	   | LIDENT "print_xml" | LIDENT "print_xml_utf8"
248
	   | LIDENT "print"
249
	   | LIDENT "int_of"
250
	   | LIDENT "string_of"
251
	   | LIDENT "atom_of"
252
	   | LIDENT "raise"
253
	   ]; 
254
      e = expr -> exp loc (Op (op,[e]))
255
    | op = [ LIDENT "dump_to_file" | LIDENT "dump_to_file_utf8" ];
256 257 258 259
      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))
260 261
    ]

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

  ];
293

294
  tag: [ [ a = [ LIDENT | UIDENT | keyword ] -> 
295
	     Const_atom (parse_ident a) ] ];
296 297 298

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

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

  
325
  let_binding: [
326 327 328 329
    [ "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
330
        let e = exp loc (Abstraction abst) in
331
        (true,p,e)
332 333
    | "let"; p = pat; "="; e = expr -> (false,p,e)
    | "let"; p = pat; ":"; t = pat; "="; e = expr -> (false,p, Forget (e,t))
334 335 336
    ] 
  ];

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

367
 arrow: [
368
    [ t1 = pat LEVEL "no_arrow"; "->"; t2 = pat -> (t1,t2)]
369 370 371
  ];

  branches: [
372
    [ OPT "|"; l = LIST1 branch SEP "|" -> l ]
373 374 375
  ];

  branch: [
376
    [ p = pat LEVEL "no_arrow"; "->"; e = expr -> (p,e) ]
377 378 379 380
  ];

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

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

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

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


  attrib_spec:
522 523 524 525 526 527 528
    [ [ 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)) 
529 530 531 532
      | "("; t = pat; ")" -> t 
      | "{"; r = record_spec; "}" -> mk loc (Record (true,r))
      | "{|"; r = record_spec; "|}" -> mk loc (Record (false,r))
      ] ];
533 534 535

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

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

554
let pat = Grammar.Entry.parse pat
555 556
and expr = Grammar.Entry.parse expr
and prog = Grammar.Entry.parse prog
557 558
and top_phrases = Grammar.Entry.parse top_phrases

559 560 561 562 563 564 565 566 567 568 569 570
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 ()