Browse Source

Bugfix for Scanless Earley. Thanks Ken!

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
5946e78ed2
2 changed files with 9 additions and 1 deletions
  1. +1
    -1
      lark/load_grammar.py
  2. +8
    -0
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py View File

@@ -313,7 +313,7 @@ class PrepareLiterals(InlineTransformer):
class SplitLiterals(InlineTransformer):
def pattern(self, p):
if isinstance(p, PatternStr) and len(p.value)>1:
return T('expansion', [T('pattern', [PatternStr(ch)]) for ch in p.value])
return T('expansion', [T('pattern', [PatternStr(ch, flags=p.flags)]) for ch in p.value])
return T('pattern', [p])

class TokenTreeToPattern(Transformer):


+ 8
- 0
tests/test_parser.py View File

@@ -568,6 +568,14 @@ def _make_parser_test(LEXER, PARSER):
tree = l.parse('AB,a')
self.assertEqual(tree.children, ['AB'])

def test_token_flags3(self):
l = _Lark("""!start: ABC+
ABC: "abc"i
"""
)
tree = l.parse('aBcAbC')
self.assertEqual(tree.children, ['aBc', 'AbC'])

def test_token_flags2(self):
g = """!start: ("a"i | /a/ /b/?)+
"""


Loading…
Cancel
Save