diff src/lacweb.grm @ 170:a158f8c5aa55

Parsing basic patterns
author Adam Chlipala <adamc@hcoop.net>
date Tue, 29 Jul 2008 16:38:15 -0400
parents adc4e42e3adc
children 8221b95cc24c
line wrap: on
line diff
--- a/src/lacweb.grm	Tue Jul 29 16:02:02 2008 -0400
+++ b/src/lacweb.grm	Tue Jul 29 16:38:15 2008 -0400
@@ -51,6 +51,7 @@
  | FN | PLUSPLUS | MINUSMINUS | DOLLAR | TWIDDLE
  | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN
  | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT
+ | CASE
 
  | XML_BEGIN of string | XML_END
  | NOTAGS of string 
@@ -99,6 +100,11 @@
  | tag of string * exp
  | tagHead of string * exp
 
+ | branch of pat * exp
+ | branchs of (pat * exp) list
+ | pat of pat
+ | pterm of pat
+
  | attrs of (con * exp) list
  | attr of con * exp
  | attrv of exp
@@ -310,6 +316,7 @@
 
        | LPAREN eexp RPAREN DCOLON cexp (EAnnot (eexp, cexp), s (LPARENleft, cexpright))
        | eexp MINUSMINUS cexp           (ECut (eexp, cexp), s (eexpleft, cexpright))
+       | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
 
 eterm  : LPAREN eexp RPAREN             (#1 eexp, s (LPARENleft, RPARENright))
 
@@ -330,6 +337,19 @@
                                                (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
                                          s (XML_BEGINleft, XML_ENDright))
 
+branch : pat DARROW eexp                (pat, eexp)
+
+branchs:                                ([])
+       | BAR branch branchs             (branch :: branchs)
+
+pat    : pterm                          (pterm)
+       | cpath pterm                    (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
+
+pterm  : SYMBOL                         (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
+       | cpath                          (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
+       | UNDER                          (PWild, s (UNDERleft, UNDERright))
+       | LPAREN pat RPAREN              (pat)
+
 rexp   :                                ([])
        | ident EQ eexp                  ([(ident, eexp)])
        | ident EQ eexp COMMA rexp       ((ident, eexp) :: rexp)