| @@ -20,12 +20,13 @@ nearley_grammar = r""" | |||||
| ?expr: item [":" /[+*?]/] | ?expr: item [":" /[+*?]/] | ||||
| ?item: rule|string|regexp | |||||
| ?item: rule|string|regexp|null | |||||
| | "(" expansions ")" | | "(" expansions ")" | ||||
| rule: NAME | rule: NAME | ||||
| string: STRING | string: STRING | ||||
| regexp: REGEXP | regexp: REGEXP | ||||
| null: "null" | |||||
| JS: /{%.*?%}/s | JS: /{%.*?%}/s | ||||
| js: JS? | js: JS? | ||||
| @@ -83,6 +84,9 @@ class NearleyToLark(InlineTransformer): | |||||
| def regexp(self, r): | def regexp(self, r): | ||||
| return '/%s/' % r | return '/%s/' % r | ||||
| def null(self): | |||||
| return '' | |||||
| def string(self, s): | def string(self, s): | ||||
| return self._extra_rule(s) | return self._extra_rule(s) | ||||
| @@ -83,6 +83,15 @@ class TestNearley(unittest.TestCase): | |||||
| parse = d['parse'] | parse = d['parse'] | ||||
| parse(u'"') | parse(u'"') | ||||
| def test_null(self): | |||||
| grammar = r'main -> "a" | null' | |||||
| code = create_code_for_nearley_grammar(grammar, 'main', BUILTIN_PATH, './') | |||||
| d = {} | |||||
| exec (code, d) | |||||
| parse = d['parse'] | |||||
| parse('a') | |||||
| parse('') | |||||
| def test_utf8_2(self): | def test_utf8_2(self): | ||||
| fn = os.path.join(TEST_PATH, 'grammars/unicode.ne') | fn = os.path.join(TEST_PATH, 'grammars/unicode.ne') | ||||
| nearley_tool_main(fn, 'x', NEARLEY_PATH) | nearley_tool_main(fn, 'x', NEARLEY_PATH) | ||||