Pārlūkot izejas kodu

Merge pull request #1 from lark-parser/master

pull error fix form upstream commit
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
TG-Techie pirms 4 gadiem
committed by GitHub
vecāks
revīzija
e4de6fc3de
Šim parakstam datu bāzē netika atrasta zināma atslēga GPG atslēgas ID: 4AEE18F83AFDEB23
2 mainītis faili ar 14 papildinājumiem un 14 dzēšanām
  1. +13
    -13
      lark/load_grammar.py
  2. +1
    -1
      tests/test_grammar.py

+ 13
- 13
lark/load_grammar.py Parādīt failu

@@ -789,19 +789,19 @@ def _find_used_symbols(tree):
for t in x.scan_values(lambda t: t.type in ('RULE', 'TERMINAL'))}

class GrammarLoader:
ERRORS = {
'Unclosed parenthesis': ['a: (\n'],
'Umatched closing parenthesis': ['a: )\n', 'a: [)\n', 'a: (]\n'],
'Expecting rule or terminal definition (missing colon)': ['a\n', 'A\n', 'a->\n', 'A->\n', 'a A\n'],
'Illegal name for rules or terminals': ['Aa:\n'],
'Alias expects lowercase name': ['a: -> "a"\n'],
'Unexpected colon': ['a::\n', 'a: b:\n', 'a: B:\n', 'a: "a":\n'],
'Misplaced operator': ['a: b??', 'a: b(?)', 'a:+\n', 'a:?\n', 'a:*\n', 'a:|*\n'],
'Expecting option ("|") or a new rule or terminal definition': ['a:a\n()\n'],
'Terminal names cannot contain dots': ['A.B\n'],
'%import expects a name': ['%import "a"\n'],
'%ignore expects a value': ['%ignore %import\n'],
}
ERRORS = [
('Unclosed parenthesis', ['a: (\n']),
('Umatched closing parenthesis', ['a: )\n', 'a: [)\n', 'a: (]\n']),
('Expecting rule or terminal definition (missing colon)', ['a\n', 'A\n', 'a->\n', 'A->\n', 'a A\n']),
('Illegal name for rules or terminals', ['Aa:\n']),
('Alias expects lowercase name', ['a: -> "a"\n']),
('Unexpected colon', ['a::\n', 'a: b:\n', 'a: B:\n', 'a: "a":\n']),
('Misplaced operator', ['a: b??', 'a: b(?)', 'a:+\n', 'a:?\n', 'a:*\n', 'a:|*\n']),
('Expecting option ("|") or a new rule or terminal definition', ['a:a\n()\n']),
('Terminal names cannot contain dots', ['A.B\n']),
('%import expects a name', ['%import "a"\n']),
('%ignore expects a value', ['%ignore %import\n']),
]

def __init__(self, re_module):
terminals = [TerminalDef(name, PatternRE(value)) for name, value in TERMINALS.items()]


+ 1
- 1
tests/test_grammar.py Parādīt failu

@@ -12,7 +12,7 @@ class TestGrammar(TestCase):
pass

def test_errors(self):
for msg, examples in GrammarLoader.ERRORS.items():
for msg, examples in GrammarLoader.ERRORS:
for example in examples:
try:
p = Lark(example)


Notiek ielāde…
Atcelt
Saglabāt