| 1 |
import py |
| 2 |
from rpython.rlib.parsing.tree import Nonterminal, Symbol, RPythonVisitor |
| 3 |
from rpython.rlib.parsing.parsing import PackratParser, Symbol, ParseError, Rule |
| 4 |
from rpython.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function |
| 5 |
from rpython.rlib.parsing.test.test_parse import EvaluateVisitor |
| 6 |
|
| 7 |
from sets import Set |
| 8 |
|
| 9 |
def test_simple(): |
| 10 |
regexs, rules, transformer = parse_ebnf(""" |
| 11 |
IGNORE: " "; |
| 12 |
DECIMAL: "0|[1-9][0-9]*"; |
| 13 |
additive: multitive "+" additive | multitive; |
| 14 |
multitive: primary "*" multitive | primary; #nonsense! |
| 15 |
# the following too! |
| 16 |
primary: "(" additive ")" | DECIMAL; |
| 17 |
""") |
| 18 |
class MyEvalVisitor(EvaluateVisitor): |
| 19 |
def visit_primary(self, node): |
| 20 |
if len(node.children) == 3: |
| 21 |
return node.children[1].visit(self) |
| 22 |
return int(node.children[0].additional_info) |
| 23 |
parse = make_parse_function(regexs, rules) |
| 24 |
tree = parse("0 + 10 + 999") |
| 25 |
assert tree.visit(MyEvalVisitor()) == 10 + 999 |
| 26 |
tree = parse("22 * 12 + 44)") |
| 27 |
r = tree.visit(MyEvalVisitor()) |
| 28 |
assert r == 22 * 12 + 44 |
| 29 |
tree = parse("2*(3+5*2*(2+61))") |
| 30 |
assert tree.visit(MyEvalVisitor()) == 2 * (3 + 5 * 2 * (2 + 61)) |
| 31 |
tree = parse("12 + 4 * 5)") |
| 32 |
|
| 33 |
def test_long_inline_quotes(): |
| 34 |
regexs, rules, transformer = parse_ebnf(""" |
| 35 |
DECIMAL: "0|[1-9][0-9]*"; |
| 36 |
IGNORE: " "; |
| 37 |
additive: multitive "+!" additive | multitive; |
| 38 |
multitive: primary "*!" multitive | primary; #nonsense! |
| 39 |
primary: "(" additive ")" | DECIMAL; |
| 40 |
""") |
| 41 |
class MyEvalVisitor(EvaluateVisitor): |
| 42 |
def visit_primary(self, node): |
| 43 |
if len(node.children) == 3: |
| 44 |
return node.children[1].visit(self) |
| 45 |
return int(node.children[0].additional_info) |
| 46 |
parse = make_parse_function(regexs, rules) |
| 47 |
tree = parse("0 +! 10 +! 999") |
| 48 |
assert tree.visit(MyEvalVisitor()) == 10 + 999 |
| 49 |
|
| 50 |
def test_toast(): |
| 51 |
regexs, rules, ToAST = parse_ebnf(""" |
| 52 |
DECIMAL: "0|[1-9][0-9]*"; |
| 53 |
IGNORE: " "; |
| 54 |
additive: multitive ["+!"] additive | <multitive>; |
| 55 |
multitive: primary ["*!"] multitive | <primary>; #nonsense! |
| 56 |
primary: "(" <additive> ")" | <DECIMAL>; |
| 57 |
""") |
| 58 |
parse = make_parse_function(regexs, rules) |
| 59 |
tree = parse("(0 +! 10) *! (999 +! 10) +! 1") |
| 60 |
tree = tree.visit(ToAST())[0] |
| 61 |
assert len(tree.children) == 2 |
| 62 |
assert tree.children[0].children[0].symbol == "additive" |
| 63 |
assert tree.children[1].symbol == "DECIMAL" |
| 64 |
|
| 65 |
def test_eof(): |
| 66 |
grammar = """ |
| 67 |
DECIMAL: "0|[1-9][0-9]*"; |
| 68 |
IGNORE: " "; |
| 69 |
expr: additive0_9 EOF; |
| 70 |
additive0_9: multitive "+!" additive0_9 | multitive; |
| 71 |
multitive: primary "*!" multitive | primary; #nonsense! |
| 72 |
primary: "(" additive0_9 ")" | DECIMAL; |
| 73 |
""" |
| 74 |
regexs, rules, ToAST = parse_ebnf(grammar) |
| 75 |
class MyEvalVisitor(EvaluateVisitor): |
| 76 |
def visit_primary(self, node): |
| 77 |
if len(node.children) == 3: |
| 78 |
return node.children[1].visit(self) |
| 79 |
return int(node.children[0].additional_info) |
| 80 |
def visit_expr(self, node): |
| 81 |
return node.children[0].visit(self) |
| 82 |
visit_additive0_9 = EvaluateVisitor.visit_additive |
| 83 |
parse = make_parse_function(regexs, rules, eof=True) |
| 84 |
tree = parse("0 +! 10 +! 999") |
| 85 |
assert tree.visit(MyEvalVisitor()) == 10 + 999 |
| 86 |
py.test.raises(ParseError, parse, "0 +! 10 +! 999 0000") |
| 87 |
grammar += "some garbage here" |
| 88 |
py.test.raises(ParseError, parse_ebnf, grammar) |
| 89 |
|
| 90 |
|
| 91 |
def test_prolog(): |
| 92 |
regexs, rules, ToAST = parse_ebnf(""" |
| 93 |
ATOM: "[a-z]([a-zA-Z0-9]|_)*"; |
| 94 |
VAR: "[A-Z]([a-zA-Z0-9]|_)*|_"; |
| 95 |
NUMBER: "0|[1-9][0-9]*"; |
| 96 |
IGNORE: "[ \\n\\t]"; |
| 97 |
file: fact file | fact; |
| 98 |
fact: complexterm "." | complexterm ":-" compoundexpr "."; |
| 99 |
compoundexpr: complexterm "," compoundexpr | complexterm ";" compoundexpr | complexterm; |
| 100 |
complexterm: ATOM "(" exprlist ")" | ATOM; |
| 101 |
exprlist: expr "," exprlist | expr; |
| 102 |
expr: complexterm | ATOM | NUMBER | VAR; |
| 103 |
""") |
| 104 |
parse = make_parse_function(regexs, rules) |
| 105 |
tree = parse("prefix(\n\tlonger(and_nested(term(X))), Xya, _, X0, _).") |
| 106 |
assert tree.children[0].children[0].children[2].children[0].getsourcepos().lineno == 1 |
| 107 |
assert tree is not None |
| 108 |
tree = parse(""" |
| 109 |
foo(X, Y) :- bar(Y, X), bar(Y, X) ; foobar(X, Y, 1234, atom).""") |
| 110 |
assert tree is not None |
| 111 |
|
| 112 |
def test_toast_bigger(): |
| 113 |
regexs, rules, ToAST = parse_ebnf(""" |
| 114 |
BOOLCONST: "TRUE|FALSE"; |
| 115 |
IDENTIFIER: "[a-zA-Z_][a-zA-Z0-9_]*"; |
| 116 |
NUMBER: "0|[1-9][0-9]*"; |
| 117 |
IGNORE: " "; |
| 118 |
# expression |
| 119 |
expr: <intexpr> | <boolexpr>; |
| 120 |
intexpr: multitive "+" intexpr | multitive "-" intexpr | <multitive>; |
| 121 |
multitive: primary "*" unaryexpr | primary "/" unaryexpr | |
| 122 |
primary "%" unaryexpr | <unaryexpr>; |
| 123 |
unaryexpr: "+" unaryexpr | "-" unaryexpr | <primary>; |
| 124 |
primary: "(" <intexpr> ")" | <NUMBER> | <IDENTIFIER>; |
| 125 |
boolexpr: <BOOLCONST>; #strange thing |
| 126 |
""") |
| 127 |
parse = make_parse_function(regexs, rules) |
| 128 |
tree = parse("x * floor + 1") |
| 129 |
tree = ToAST().transform(tree) |
| 130 |
assert tree.children[2].symbol == "NUMBER" |
| 131 |
|
| 132 |
def test_parser_repr_is_evalable(): |
| 133 |
regexs, rules, ToAST = parse_ebnf(""" |
| 134 |
BOOLCONST: "TRUE|FALSE"; |
| 135 |
IDENTIFIER: "[a-zA-Z_][a-zA-Z0-9_]*"; |
| 136 |
NUMBER: "0|[1-9][0-9]*"; |
| 137 |
IGNORE: " "; |
| 138 |
# expression |
| 139 |
expr: <intexpr> | <boolexpr>; |
| 140 |
intexpr: multitive "+" intexpr | multitive "-" intexpr | <multitive>; |
| 141 |
multitive: primary "*" unaryexpr | primary "/" unaryexpr | |
| 142 |
primary "%" unaryexpr | <unaryexpr>; |
| 143 |
unaryexpr: "+" unaryexpr | "-" unaryexpr | <primary>; |
| 144 |
primary: "(" <intexpr> ")" | <NUMBER> | <IDENTIFIER>; |
| 145 |
boolexpr: <BOOLCONST>; #strange thing |
| 146 |
|
| 147 |
""") |
| 148 |
parser = PackratParser(rules, rules[0].nonterminal) |
| 149 |
s = repr(parser) |
| 150 |
print s |
| 151 |
newparser = eval(s) |
| 152 |
assert repr(newparser) == s |
| 153 |
|
| 154 |
def test_lexer_end_string_corner_case(): |
| 155 |
regexs, rules, ToAST = parse_ebnf(""" |
| 156 |
NUMBER: "[0-9]*(\.[0-9]+)?"; |
| 157 |
ATOM: "\."; |
| 158 |
IGNORE: " "; |
| 159 |
expr: NUMBER ATOM EOF; |
| 160 |
""") |
| 161 |
parse = make_parse_function(regexs, rules, eof=True) |
| 162 |
t = parse("2.") |
| 163 |
assert t.children[0].additional_info == "2" |
| 164 |
assert t.children[1].additional_info == "." |
| 165 |
|
| 166 |
def test_escape_quotes(): |
| 167 |
regexs, rules, ToAST = parse_ebnf(""" |
| 168 |
QUOTE: "a\\""; |
| 169 |
IGNORE: " "; |
| 170 |
expr: QUOTE "\\"" EOF;""") |
| 171 |
parse = make_parse_function(regexs, rules, eof=True) |
| 172 |
t = parse('a" "') |
| 173 |
assert t.children[0].additional_info == 'a"' |
| 174 |
assert t.children[1].additional_info == '"' |
| 175 |
|
| 176 |
def test_leftrecursion(): |
| 177 |
regexs, rules, ToAST = parse_ebnf(""" |
| 178 |
A: "a"; |
| 179 |
B: "b"; |
| 180 |
IGNORE: " |\n"; |
| 181 |
expr1: A | expr2 A; |
| 182 |
expr2: expr1 B; |
| 183 |
""") |
| 184 |
py.test.raises(AssertionError, make_parse_function, regexs, rules, True) |
| 185 |
|
| 186 |
def test_jsonparse(): |
| 187 |
source = """ |
| 188 |
STRING: "\\"[^\\\\"]*\\""; |
| 189 |
NUMBER: "\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][\+\-]?[0-9]+)?"; |
| 190 |
IGNORE: " |\n"; |
| 191 |
value: <STRING> | <NUMBER> | <object> | <array> | <"null"> | |
| 192 |
<"true"> | <"false">; |
| 193 |
object: ["{"] (entry [","])* entry ["}"]; |
| 194 |
array: ["["] (value [","])* value ["]"]; |
| 195 |
entry: STRING [":"] value; |
| 196 |
""" |
| 197 |
regexs, rules, ToAST = parse_ebnf(source) |
| 198 |
parse = make_parse_function(regexs, rules, eof=True) |
| 199 |
t = parse(""" |
| 200 |
{ |
| 201 |
"type": "SCRIPT", |
| 202 |
"0": { |
| 203 |
"type": "SEMICOLON", |
| 204 |
"end": "5", |
| 205 |
"expression": { |
| 206 |
"type": "ASSIGN", |
| 207 |
"0": { |
| 208 |
"type": "IDENTIFIER", |
| 209 |
"assignOp": "null", |
| 210 |
"end": "1", |
| 211 |
"lineno": "1", |
| 212 |
"start": "0", |
| 213 |
"tokenizer": "[object Object]", |
| 214 |
"value": "x" |
| 215 |
} , |
| 216 |
"1": { |
| 217 |
"type": "NUMBER", |
| 218 |
"end": "5", |
| 219 |
"lineno": "1", |
| 220 |
"start": "4", |
| 221 |
"tokenizer": "[object Object]", |
| 222 |
"value": "1" |
| 223 |
} , |
| 224 |
"end": "5", |
| 225 |
"length": "2", |
| 226 |
"lineno": "1", |
| 227 |
"start": "0", |
| 228 |
"tokenizer": "[object Object]", |
| 229 |
"value": "=" |
| 230 |
} , |
| 231 |
"lineno": "1", |
| 232 |
"start": "0", |
| 233 |
"tokenizer": "[object Object]", |
| 234 |
"value": "x" |
| 235 |
} , |
| 236 |
"funDecls": "", |
| 237 |
"length": "1", |
| 238 |
"lineno": "1", |
| 239 |
"tokenizer": "[object Object]", |
| 240 |
"varDecls": "" |
| 241 |
}""") |
| 242 |
t = ToAST().transform(t) |
| 243 |
t = parse('{"a": "5", "b": [1, null, 3, true, {"f": "g", "h": 6}]}') |
| 244 |
print "".join(list(t.dot())) |
| 245 |
t = ToAST().transform(t) |
| 246 |
print "\n".join(list(t.dot())) |
| 247 |
|
| 248 |
def test_starparse(): |
| 249 |
regexs, rules, ToAST = parse_ebnf(""" |
| 250 |
QUOTED_STRING: "'[^\\']*'"; |
| 251 |
IGNORE: " |\n"; |
| 252 |
list: ["["] (QUOTED_STRING [","])* QUOTED_STRING ["]"]; |
| 253 |
""") |
| 254 |
parse = make_parse_function(regexs, rules, eof=True) |
| 255 |
t = parse("""['a', 'b', 'c']""") |
| 256 |
t = ToAST().transform(t) |
| 257 |
assert t.symbol == "list" |
| 258 |
assert len(t.children) == 3 |
| 259 |
assert [c.symbol for c in t.children] == ["QUOTED_STRING"] * 3 |
| 260 |
t = parse("['a']") |
| 261 |
t = ToAST().transform(t) |
| 262 |
assert t.symbol == "list" |
| 263 |
assert len(t.children) == 1 |
| 264 |
assert [c.symbol for c in t.children] == ["QUOTED_STRING"] * 1 |
| 265 |
|
| 266 |
def test_double_star(): |
| 267 |
regexs, rules, ToAST = parse_ebnf(""" |
| 268 |
IGNORE: " |\n"; |
| 269 |
start: "a"* "b"* "c"; |
| 270 |
""") |
| 271 |
parse = make_parse_function(regexs, rules, eof=True) |
| 272 |
for s in ["a a a b b c", "a b b c", "a a c", "b b c", "c"]: |
| 273 |
t = parse(s) |
| 274 |
t = ToAST().transform(t) |
| 275 |
assert [c.additional_info for c in t.children] == s.split() |
| 276 |
|
| 277 |
def test_transform_star(): |
| 278 |
|
| 279 |
regexs, rules, ToAST = parse_ebnf(""" |
| 280 |
IGNORE: " "; |
| 281 |
ATOM: "[\+a-zA-Z_][a-zA-Z0-9_]*"; |
| 282 |
|
| 283 |
sexpr: ATOM | list; |
| 284 |
list: "(" sexpr* ")"; |
| 285 |
""") |
| 286 |
parse = make_parse_function(regexs, rules) |
| 287 |
tree = parse("()") |
| 288 |
list_expr = tree.visit(ToAST())[0].children[0] |
| 289 |
assert list_expr.symbol == 'list' |
| 290 |
|
| 291 |
assert len(list_expr.children) == 2 |
| 292 |
assert list_expr.children[0].additional_info == '(' |
| 293 |
assert list_expr.children[1].additional_info == ')' |
| 294 |
tree = parse("(a b c)") |
| 295 |
list_expr = ToAST().transform(tree) |
| 296 |
|
| 297 |
|
| 298 |
def test_quoting(): |
| 299 |
regexs, rules, ToAST = parse_ebnf(""" |
| 300 |
ATOM: "[a-z]*"; |
| 301 |
IGNORE: " "; |
| 302 |
list: ATOM "\n" ATOM; |
| 303 |
""") |
| 304 |
parse = make_parse_function(regexs, rules, eof=True) |
| 305 |
t = parse("""abc |
| 306 |
abd""") |
| 307 |
assert len(t.children) == 3 |
| 308 |
assert t.children[1].additional_info == "\n" |
| 309 |
|
| 310 |
def test_check_for_missing_names(): |
| 311 |
regexs, rules, ToAST = parse_ebnf(""" |
| 312 |
IGNORE: " "; |
| 313 |
DECIMAL: "0|[1-9][0-9]*"; |
| 314 |
additive: multitive "+" additive | multitive; |
| 315 |
multitive: primary "*" multitive | primari; # observe the typo |
| 316 |
# the following too! |
| 317 |
primary: "(" additive ")" | DECIMAL; |
| 318 |
""") |
| 319 |
excinfo = py.test.raises(ValueError, make_parse_function, regexs, rules) |
| 320 |
assert "primari" in str(excinfo.value) |
| 321 |
|
| 322 |
def test_starred_star(): |
| 323 |
regexs, rules, ToAST = parse_ebnf(""" |
| 324 |
IGNORE: " "; |
| 325 |
start: ("b"* "a")* EOF; |
| 326 |
""") |
| 327 |
parse = make_parse_function(regexs, rules, eof=True) |
| 328 |
for s in ["b b b b a b b a", "b a b a", "a a", ""]: |
| 329 |
t = parse(s) |
| 330 |
t = ToAST().transform(t) |
| 331 |
assert [c.additional_info for c in t.children] == (s + " EOF").split() |
| 332 |
|
| 333 |
def test_transform_greater_than(): |
| 334 |
regexs, rules, ToAST = parse_ebnf(""" |
| 335 |
IGNORE: " "; |
| 336 |
x: ["a"] >b< "c"; |
| 337 |
b: "A" "A"; |
| 338 |
""") |
| 339 |
parse = make_parse_function(regexs, rules) |
| 340 |
t = parse("a A A c") |
| 341 |
t = ToAST().transform(t) |
| 342 |
assert len(t.children) == 3 |
| 343 |
assert t.children[0].additional_info == "A" |
| 344 |
assert t.children[1].additional_info == "A" |
| 345 |
assert t.children[2].additional_info == "c" |
| 346 |
|
| 347 |
def test_plus(): |
| 348 |
regexs, rules, ToAST = parse_ebnf(""" |
| 349 |
IGNORE: " "; |
| 350 |
x: "A"+ "B"; |
| 351 |
""") |
| 352 |
parse = make_parse_function(regexs, rules) |
| 353 |
t = parse("A A B") |
| 354 |
t = ToAST().transform(t) |
| 355 |
assert len(t.children) == 3 |
| 356 |
assert t.children[0].additional_info == "A" |
| 357 |
assert t.children[1].additional_info == "A" |
| 358 |
assert t.children[2].additional_info == "B" |
| 359 |
py.test.raises(ParseError, parse, "B") |
| 360 |
|
| 361 |
def test_questionmark(): |
| 362 |
regexs, rules, ToAST = parse_ebnf(""" |
| 363 |
IGNORE: " "; |
| 364 |
x: ["A"] ("B" ["C"] "D")? "E"; |
| 365 |
""") |
| 366 |
parse = make_parse_function(regexs, rules) |
| 367 |
t = parse("A B C D E") |
| 368 |
py.test.raises(ParseError, parse, "A B C D B C D E") |
| 369 |
t = ToAST().transform(t) |
| 370 |
assert len(t.children) == 3 |
| 371 |
assert t.children[0].additional_info == "B" |
| 372 |
assert t.children[1].additional_info == "D" |
| 373 |
assert t.children[2].additional_info == "E" |
| 374 |
t = parse("A E") |
| 375 |
t = ToAST().transform(t) |
| 376 |
assert len(t.children) == 1 |
| 377 |
assert t.children[0].additional_info == "E" |
| 378 |
|
| 379 |
def test_grouping_only_parens(): |
| 380 |
regexs, rules, ToAST = parse_ebnf(""" |
| 381 |
IGNORE: " "; |
| 382 |
x: ["m"] ("a" "b") "c" | <y>; |
| 383 |
y: ["n"] "a" "b" "c"; |
| 384 |
""") |
| 385 |
parse = make_parse_function(regexs, rules) |
| 386 |
t0 = ToAST().transform(parse("m a b c")) |
| 387 |
t1 = ToAST().transform(parse("n a b c")) |
| 388 |
assert len(t0.children) == len(t1.children) |
| 389 |
|
| 390 |
def test_mix_star_and_questionmark(): |
| 391 |
regexs, rules, ToAST = parse_ebnf(""" |
| 392 |
IGNORE: " "; |
| 393 |
y: x "END"; |
| 394 |
x: "B" ("A" "B")* "A"?; |
| 395 |
""") |
| 396 |
parse = make_parse_function(regexs, rules) |
| 397 |
t = ToAST().transform(parse("B A B END")) |
| 398 |
assert len(t.children[0].children) == 3 |
| 399 |
|
| 400 |
def test_nest_star_and_questionmark(): |
| 401 |
regexs, rules, ToAST = parse_ebnf(""" |
| 402 |
IGNORE: " "; |
| 403 |
y: x "END"; |
| 404 |
x: "B" ("A" "B"?)*; |
| 405 |
""") |
| 406 |
parse = make_parse_function(regexs, rules) |
| 407 |
t = ToAST().transform(parse("B A B A B END")) |
| 408 |
t = ToAST().transform(parse("B A A A END")) |
| 409 |
|
| 410 |
def test_clash_literal_nonterminal(): |
| 411 |
regexs, rules, ToAST = parse_ebnf(""" |
| 412 |
IGNORE: " "; |
| 413 |
y: x "END"; |
| 414 |
x: "y"; |
| 415 |
a: "x"; |
| 416 |
""") |
| 417 |
parse = make_parse_function(regexs, rules) |
| 418 |
py.test.raises(ParseError, parse, "x END") |
| 419 |
parse("y END") |
| 420 |
|
| 421 |
def test_example1(): |
| 422 |
regexs, rules, ToAST = parse_ebnf(""" |
| 423 |
IGNORE: " "; |
| 424 |
n: "a" "b" "c" m; |
| 425 |
m: "(" <n> ")" | "d"; |
| 426 |
""") |
| 427 |
parse = make_parse_function(regexs, rules) |
| 428 |
t = parse("a b c (a b c d)") |
| 429 |
t = ToAST().transform(t) |
| 430 |
|
| 431 |
def test_example2(): |
| 432 |
regexs, rules, ToAST = parse_ebnf(""" |
| 433 |
IGNORE: " "; |
| 434 |
DECIMAL: "0|[1-9][0-9]*"; |
| 435 |
list: DECIMAL >list< | DECIMAL; |
| 436 |
""") |
| 437 |
parse = make_parse_function(regexs, rules) |
| 438 |
t = parse("1 2 3 4 5") |
| 439 |
t = ToAST().transform(t) |
| 440 |
|
| 441 |
def test_bug(): |
| 442 |
|
| 443 |
|
| 444 |
py.test.skip("fix me somehow") |
| 445 |
regexs, rules, ToAST = parse_ebnf(""" |
| 446 |
IGNORE: " "; |
| 447 |
DECIMAL: "0|[1-9][0-9]*"; |
| 448 |
list: DECIMAL >list< | <DECIMAL>; |
| 449 |
""") |
| 450 |
parse = make_parse_function(regexs, rules) |
| 451 |
t = parse("1 2 3 4 5") |
| 452 |
t = ToAST().transform(t) |
| 453 |
|
| 454 |
def test_empty_production(): |
| 455 |
|
| 456 |
|
| 457 |
regexs, rules, ToAST = parse_ebnf(""" |
| 458 |
IGNORE: " "; |
| 459 |
DECIMAL: "0|[1-9][0-9]*"; |
| 460 |
file: <stuff> EOF; |
| 461 |
stuff: "a" >stuff< "a" | "y" | >empty<; |
| 462 |
empty: ; |
| 463 |
""") |
| 464 |
parse = make_parse_function(regexs, rules, eof=True) |
| 465 |
t = parse(" ") |
| 466 |
t = ToAST().transform(t) |
| 467 |
assert isinstance(t, Nonterminal) |
| 468 |
assert len(t.children) == 0 |
| 469 |
t = parse(" a a a a a a ") |
| 470 |
t = ToAST().transform(t) |
| 471 |
assert len(t.children) == 6 |
| 472 |
excinfo = py.test.raises(ParseError, parse, "a") |
| 473 |
|
| 474 |
def test_zero_repetition_production(): |
| 475 |
grammar = """ |
| 476 |
IGNORE: " "; |
| 477 |
foo: "A"?; |
| 478 |
""" |
| 479 |
excinfo = py.test.raises(ValueError, parse_ebnf, grammar) |
| 480 |
assert "foo" in str(excinfo.value) |