summaryrefslogtreecommitdiff
path: root/autochomp/tests/compare/nibble_exp.nb
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2021-04-21 10:19:00 +0100
committerGreg Brown <gmb60@cam.ac.uk>2021-04-21 10:19:00 +0100
commit449695dcf87d26b0d06a51ca27bbc8214338f954 (patch)
tree32edf289a1d8287149f160a9b54cecb339be321c /autochomp/tests/compare/nibble_exp.nb
parentbb3c8d1455f7a102a0c0abffd757ccace94f77d5 (diff)
Add some comparison tests for Autochomp.
Diffstat (limited to 'autochomp/tests/compare/nibble_exp.nb')
-rw-r--r--autochomp/tests/compare/nibble_exp.nb44
1 files changed, 44 insertions, 0 deletions
diff --git a/autochomp/tests/compare/nibble_exp.nb b/autochomp/tests/compare/nibble_exp.nb
new file mode 100644
index 0000000..6e6d8b5
--- /dev/null
+++ b/autochomp/tests/compare/nibble_exp.nb
@@ -0,0 +1,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; \ No newline at end of file