summaryrefslogtreecommitdiff
path: root/autochomp/tests/compare/nibble_exp.nb
blob: 6e6d8b55bcdb7ed7b4a335f3c09661a627bc40ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
let opt(x) = _ | x;
let plus(x) = [plus](x . opt(plus));
let star(x) = [star](opt(x . star));

let Pattern_Whitespace = "\n"|" ";

let XID_Start =
    "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
    "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
    "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
    "y" | "z" |
    "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
    "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
    "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
    "Y" | "Z" ;
let XID_Continue =
    XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

let literal_char = XID_Continue;

let ws = star(Pattern_Whitespace);
let must_ws = plus(Pattern_Whitespace);

let punctuated(x, p) = [rec](x . opt(p . ws . rec));
let list(x) = "(" . ws . [rec](x . opt("," . ws . opt(rec))) . ")";

let epsilon = "_";
let ident = XID_Start . star(XID_Continue);
let literal = "\"" . plus(literal_char) . "\"";
let parens(expr) = "(" . ws . expr . ")";
let fix(expr) = "[" . ws . ident . ws . "]" . ws . parens(expr);

let term(expr) =
      epsilon . ws
    | literal . ws
    | parens(expr) . ws
    | fix(expr) . ws
    | ident . ws . opt(list(expr) . ws)
    ;

let cat(expr) = punctuated(term(expr), ".");
let alt(expr) = punctuated(cat(expr), "|");
let expr = [expr](alt(expr));
match expr;