~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2009-02-22 08:49:13 UTC
  • mfrom: (12.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090222084913-3i0uw2bhd0lgw0ok
* Uploading to unstable
* debian/control: bump dh-ocaml to (>= 0.4) to avoid buggy ocamlinit.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
module Id = struct
22
22
  value name = "Camlp4OCamlRevisedParser";
23
 
  value version = "$Id: Camlp4OCamlRevisedParser.ml,v 1.2.2.31 2007/12/18 09:02:19 ertai Exp $";
 
23
  value version = Sys.ocaml_version;
24
24
end;
25
25
 
26
26
module Make (Syntax : Sig.Camlp4Syntax) = struct
115
115
  Gram.Entry.clear expr_eoi;
116
116
  Gram.Entry.clear expr_quot;
117
117
  Gram.Entry.clear field_expr;
 
118
  Gram.Entry.clear field_expr_list;
118
119
  Gram.Entry.clear fun_binding;
119
120
  Gram.Entry.clear fun_def;
120
121
  Gram.Entry.clear ident;
125
126
  Gram.Entry.clear ipatt_tcon;
126
127
  Gram.Entry.clear label;
127
128
  Gram.Entry.clear label_declaration;
 
129
  Gram.Entry.clear label_declaration_list;
 
130
  Gram.Entry.clear label_expr_list;
128
131
  Gram.Entry.clear label_expr;
129
132
  Gram.Entry.clear label_ipatt;
 
133
  Gram.Entry.clear label_ipatt_list;
130
134
  Gram.Entry.clear label_longident;
131
135
  Gram.Entry.clear label_patt;
 
136
  Gram.Entry.clear label_patt_list;
132
137
  Gram.Entry.clear labeled_ipatt;
133
138
  Gram.Entry.clear let_binding;
134
139
  Gram.Entry.clear meth_list;
 
140
  Gram.Entry.clear meth_decl;
135
141
  Gram.Entry.clear module_binding;
136
142
  Gram.Entry.clear module_binding0;
137
143
  Gram.Entry.clear module_binding_quot;
420
426
      comma_ctyp comma_expr comma_ipatt comma_patt comma_type_parameter
421
427
      constrain constructor_arg_list constructor_declaration
422
428
      constructor_declarations ctyp ctyp_quot cvalue_binding direction_flag
423
 
      dummy eq_expr expr expr_eoi expr_quot field_expr fun_binding
 
429
      dummy eq_expr expr expr_eoi expr_quot field_expr field_expr_list fun_binding
424
430
      fun_def ident ident_quot implem interf ipatt ipatt_tcon label
425
 
      label_declaration label_expr label_ipatt label_longident label_patt
426
 
      labeled_ipatt let_binding meth_list module_binding module_binding0
 
431
      label_declaration label_declaration_list label_expr label_expr_list
 
432
      label_ipatt label_ipatt_list label_longident label_patt label_patt_list
 
433
      labeled_ipatt let_binding meth_list meth_decl module_binding module_binding0
427
434
      module_binding_quot module_declaration module_expr module_expr_quot
428
435
      module_longident module_longident_with_app module_rec_declaration
429
436
      module_type module_type_quot more_ctyp name_tags opt_as_lident
692
699
            mk_list <:expr< [] >>
693
700
        | "[|"; "|]" -> <:expr< [| $<:expr<>>$ |] >>
694
701
        | "[|"; el = sem_expr; "|]" -> <:expr< [| $el$ |] >>
695
 
        | "{"; el = label_expr; "}" -> <:expr< { $el$ } >>
696
 
        | "{"; "("; e = SELF; ")"; "with"; el = label_expr; "}" ->
 
702
        | "{"; el = label_expr_list; "}" -> <:expr< { $el$ } >>
 
703
        | "{"; "("; e = SELF; ")"; "with"; el = label_expr_list; "}" ->
697
704
            <:expr< { ($e$) with $el$ } >>
698
705
        | "{<"; ">}" -> <:expr< {<>} >>
699
 
        | "{<"; fel = field_expr; ">}" -> <:expr< {< $fel$ >} >>
 
706
        | "{<"; fel = field_expr_list; ">}" -> <:expr< {< $fel$ >} >>
700
707
        | "("; ")" -> <:expr< () >>
701
708
        | "("; e = SELF; ":"; t = ctyp; ")" -> <:expr< ($e$ : $t$) >>
702
709
        | "("; e = SELF; ","; el = comma_expr; ")" -> <:expr< ( $e$, $el$ ) >>
703
710
        | "("; e = SELF; ";"; seq = sequence; ")" -> mksequence _loc <:expr< $e$; $seq$ >>
 
711
        | "("; e = SELF; ";"; ")" -> mksequence _loc e
704
712
        | "("; e = SELF; ":"; t = ctyp; ":>"; t2 = ctyp; ")" ->
705
713
            <:expr< ($e$ : $t$ :> $t2$ ) >>
706
714
        | "("; e = SELF; ":>"; t = ctyp; ")" -> <:expr< ($e$ :> $t$) >>
727
735
    comma_expr:
728
736
      [ [ e1 = SELF; ","; e2 = SELF -> <:expr< $e1$, $e2$ >>
729
737
        | `ANTIQUOT ("list" as n) s -> <:expr< $anti:mk_anti ~c:"expr," n s$ >>
730
 
        | e = expr -> e ] ]
 
738
        | e = expr LEVEL "top" -> e ] ]
731
739
    ;
732
740
    dummy:
733
741
      [ [ -> () ] ]
797
805
        | p = patt -> p
798
806
      ] ]
799
807
    ;
 
808
    label_expr_list:
 
809
      [ [ b1 = label_expr; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >>
 
810
        | b1 = label_expr; ";"            -> b1
 
811
        | b1 = label_expr                 -> b1
 
812
      ] ];
800
813
    label_expr:
801
 
      [ [ b1 = SELF; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >>
802
 
        | `ANTIQUOT ("rec_binding" as n) s ->
 
814
      [ [ `ANTIQUOT ("rec_binding" as n) s ->
803
815
            <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >>
804
816
        | `ANTIQUOT (""|"anti" as n) s ->
805
817
            <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >>
825
837
      | ".." NONA
826
838
        [ p1 = SELF; ".."; p2 = SELF -> <:patt< $p1$ .. $p2$ >> ]
827
839
      | "apply" LEFTA
828
 
        [ p1 = SELF; p2 = SELF -> <:patt< $p1$ $p2$ >> ]
 
840
        [ p1 = SELF; p2 = SELF -> <:patt< $p1$ $p2$ >>
 
841
        | "lazy"; p = SELF -> <:patt< lazy $p$ >>  ]
829
842
      | "simple"
830
843
        [ `ANTIQUOT (""|"pat"|"anti" as n) s ->
831
844
            <:patt< $anti:mk_anti ~c:"patt" n s$ >>
851
864
            mk_list <:patt< [] >>
852
865
        | "[|"; "|]" -> <:patt< [| $<:patt<>>$ |] >>
853
866
        | "[|"; pl = sem_patt; "|]" -> <:patt< [| $pl$ |] >>
854
 
        | "{"; pl = label_patt; "}" -> <:patt< { $pl$ } >>
 
867
        | "{"; pl = label_patt_list; "}" -> <:patt< { $pl$ } >>
855
868
        | "("; ")" -> <:patt< () >>
856
869
        | "("; p = SELF; ")" -> p
857
870
        | "("; p = SELF; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >>
894
907
        | p = patt -> fun acc -> <:patt< [ $p$ :: $acc$ ] >>
895
908
      ] ]
896
909
    ;
 
910
    label_patt_list:
 
911
      [ [ p1 = label_patt; ";"; p2 = SELF -> <:patt< $p1$ ; $p2$ >>
 
912
        | p1 = label_patt; ";"            -> p1
 
913
        | p1 = label_patt                 -> p1
 
914
      ] ];
897
915
    label_patt:
898
 
      [ LEFTA
899
 
        [ p1 = SELF; ";"; p2 = SELF -> <:patt< $p1$; $p2$ >>
900
 
        | `ANTIQUOT (""|"pat"|"anti" as n) s ->
 
916
      [ [ `ANTIQUOT (""|"pat"|"anti" as n) s ->
901
917
            <:patt< $anti:mk_anti ~c:"patt" n s$ >>
902
918
        | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag
903
919
        | `ANTIQUOT ("list" as n) s ->
906
922
      ] ]
907
923
    ;
908
924
    ipatt:
909
 
      [ [ "{"; pl = label_ipatt; "}" -> <:patt< { $pl$ } >>
 
925
      [ [ "{"; pl = label_ipatt_list; "}" -> <:patt< { $pl$ } >>
910
926
        | `ANTIQUOT (""|"pat"|"anti" as n) s ->
911
927
            <:patt< $anti:mk_anti ~c:"patt" n s$ >>
912
928
        | `ANTIQUOT ("tup" as n) s ->
929
945
        | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt," n s$ >>
930
946
        | p = ipatt -> p ] ]
931
947
    ;
 
948
    label_ipatt_list:
 
949
      [ [ p1 = label_ipatt; ";"; p2 = SELF -> <:patt< $p1$ ; $p2$ >>
 
950
        | p1 = label_ipatt; ";"            -> p1
 
951
        | p1 = label_ipatt                 -> p1
 
952
      ] ];
932
953
    label_ipatt:
933
 
      [ LEFTA
934
 
        [ p1 = SELF; ";"; p2 = SELF -> <:patt< $p1$; $p2$ >>
935
 
        | `ANTIQUOT (""|"pat"|"anti" as n) s ->
 
954
      [ [ `ANTIQUOT (""|"pat"|"anti" as n) s ->
936
955
            <:patt< $anti:mk_anti ~c:"patt" n s$ >>
937
956
        | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt;" n s$ >>
938
957
        | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag
1035
1054
            <:ctyp< [ < $rfl$ ] >>
1036
1055
        | "[<"; rfl = row_field; ">"; ntl = name_tags; "]" ->
1037
1056
            <:ctyp< [ < $rfl$ > $ntl$ ] >>
1038
 
        | "{"; t = label_declaration; OPT ";"; "}" -> <:ctyp< { $t$ } >>
 
1057
        | "{"; t = label_declaration_list; "}" -> <:ctyp< { $t$ } >>
1039
1058
        | "#"; i = class_longident -> <:ctyp< # $i$ >>
1040
 
        | "<"; ml = opt_meth_list; v = opt_dot_dot; ">" ->
1041
 
            <:ctyp< < $ml$ $..:v$ > >>
 
1059
        | "<"; t = opt_meth_list; ">" -> t
1042
1060
      ] ]
1043
1061
    ;
1044
1062
    star_ctyp:
1082
1100
        | t = ctyp -> t
1083
1101
      ] ]
1084
1102
    ;
 
1103
    label_declaration_list:
 
1104
      [ [ t1 = label_declaration; ";"; t2 = SELF -> <:ctyp< $t1$; $t2$ >>
 
1105
        | t1 = label_declaration; ";"            -> t1
 
1106
        | t1 = label_declaration                 -> t1
 
1107
      ] ]
 
1108
    ;
1085
1109
    label_declaration:
1086
 
      [ LEFTA
1087
 
        [ t1 = SELF; ";"; t2 = SELF -> <:ctyp< $t1$; $t2$ >>
1088
 
        | `ANTIQUOT (""|"typ" as n) s ->
 
1110
      [ [ `ANTIQUOT (""|"typ" as n) s ->
1089
1111
            <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >>
1090
1112
        | `ANTIQUOT ("list" as n) s ->
1091
1113
            <:ctyp< $anti:mk_anti ~c:"ctyp;" n s$ >>
1355
1377
        | ci = class_info_for_class_type; "="; ct = class_type -> <:class_type< $ci$ = $ct$ >>
1356
1378
      ] ]
1357
1379
    ;
 
1380
    field_expr_list:
 
1381
      [ [ b1 = field_expr; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >>
 
1382
        | b1 = field_expr; ";"            -> b1
 
1383
        | b1 = field_expr                 -> b1
 
1384
      ] ];
1358
1385
    field_expr:
1359
 
      [ LEFTA
1360
 
        [ b1 = SELF; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >>
1361
 
        | `ANTIQUOT (""|"bi"|"anti" as n) s ->
 
1386
      [ [ `ANTIQUOT (""|"bi"|"anti" as n) s ->
1362
1387
            <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >>
1363
1388
        | `ANTIQUOT ("list" as n) s ->
1364
1389
            <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >>
1365
 
        | l = label; "="; e = expr LEVEL "top" -> <:rec_binding< $lid:l$ = $e$ >> ] ]
 
1390
        | l = label; "="; e = expr -> <:rec_binding< $lid:l$ = $e$ >> ] ]
1366
1391
    ;
1367
1392
    meth_list:
1368
 
      [ LEFTA
1369
 
        [ ml1 = SELF; ";"; ml2 = SELF        -> <:ctyp< $ml1$; $ml2$ >>
1370
 
        | `ANTIQUOT (""|"typ" as n) s        -> <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >>
 
1393
      [ [ m = meth_decl; ";"; (ml, v) = SELF  -> (<:ctyp< $m$; $ml$ >>, v)
 
1394
        | m = meth_decl; ";"; v = opt_dot_dot -> (m, v)
 
1395
        | m = meth_decl; v = opt_dot_dot      -> (m, v)
 
1396
      ] ]
 
1397
    ;
 
1398
    meth_decl:
 
1399
      [ [ `ANTIQUOT (""|"typ" as n) s        -> <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >>
1371
1400
        | `ANTIQUOT ("list" as n) s          -> <:ctyp< $anti:mk_anti ~c:"ctyp;" n s$ >>
1372
1401
        | `QUOTATION x                       -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag
1373
1402
        | lab = a_LIDENT; ":"; t = poly_type -> <:ctyp< $lid:lab$ : $t$ >> ] ]
1374
1403
    ;
1375
1404
    opt_meth_list:
1376
 
      [ [ ml = meth_list; OPT ";" -> ml
1377
 
        | -> <:ctyp<>>
 
1405
      [ [ (ml, v) = meth_list -> <:ctyp< < $ml$ $..:v$ > >>
 
1406
        | v = opt_dot_dot     -> <:ctyp< < $..:v$ > >>
1378
1407
      ] ]
1379
1408
    ;
1380
1409
    poly_type:
1613
1642
    ;
1614
1643
    ctyp_quot:
1615
1644
      [ [ x = more_ctyp; ","; y = comma_ctyp -> <:ctyp< $x$, $y$ >>
1616
 
        | x = more_ctyp; ";"; y = label_declaration -> <:ctyp< $x$; $y$ >>
 
1645
        | x = more_ctyp; ";"; y = label_declaration_list -> <:ctyp< $x$; $y$ >>
1617
1646
        | x = more_ctyp; "|"; y = constructor_declarations -> <:ctyp< $x$ | $y$ >>
1618
1647
        | x = more_ctyp; "of"; y = constructor_arg_list -> <:ctyp< $x$ of $y$ >>
1619
1648
        | x = more_ctyp; "of"; y = constructor_arg_list; "|"; z = constructor_declarations ->
1622
1651
        | x = more_ctyp; "of"; "&"; y = amp_ctyp; "|"; z = row_field ->
1623
1652
            <:ctyp< $ <:ctyp< $x$ of & $y$ >> $ | $z$ >>
1624
1653
        | x = more_ctyp; ":"; y = more_ctyp -> <:ctyp< $x$ : $y$ >>
1625
 
        | x = more_ctyp; ":"; y = more_ctyp; ";"; z = label_declaration ->
 
1654
        | x = more_ctyp; ":"; y = more_ctyp; ";"; z = label_declaration_list ->
1626
1655
            <:ctyp< $ <:ctyp< $x$ : $y$ >> $ ; $z$ >>
1627
1656
        | x = more_ctyp; "*"; y = star_ctyp -> <:ctyp< $x$ * $y$ >>
1628
1657
        | x = more_ctyp; "&"; y = amp_ctyp -> <:ctyp< $x$ & $y$ >>
1670
1699
      ] ]
1671
1700
    ;
1672
1701
    rec_binding_quot:
1673
 
      [ [ x = label_expr -> x
 
1702
      [ [ x = label_expr_list -> x
1674
1703
        | -> <:rec_binding<>> ] ]
1675
1704
    ;
1676
1705
    module_binding_quot: