浏览代码

Merge pull request #327 from tomyun/literal-range-escape

Fix literal range escape assertion
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Erez Shinan 5 年前
committed by GitHub
父节点
当前提交
cb608591d7
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. +1
    -1
      lark/load_grammar.py
  2. +12
    -0
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py 查看文件

@@ -389,7 +389,7 @@ class PrepareLiterals(Transformer_InPlace):
assert start.type == end.type == 'STRING'
start = start.value[1:-1]
end = end.value[1:-1]
assert len(start) == len(end) == 1, (start, end, len(start), len(end))
assert len(_fix_escaping(start)) == len(_fix_escaping(end)) == 1, (start, end, len(_fix_escaping(start)), len(_fix_escaping(end)))
regexp = '[%s-%s]' % (start, end)
return ST('pattern', [PatternRE(regexp)])



+ 12
- 0
tests/test_parser.py 查看文件

@@ -456,6 +456,18 @@ def _make_parser_test(LEXER, PARSER):
""")
g.parse('\x01\x02\xABCD')

def test_unicode_literal_range_escape(self):
g = _Lark(r"""start: A+
A: "\u0061".."\u0063"
""")
g.parse('abc')

def test_hex_literal_range_escape(self):
g = _Lark(r"""start: A+
A: "\x01".."\x03"
""")
g.parse('\x01\x02\x03')

@unittest.skipIf(PARSER == 'cyk', "Takes forever")
def test_stack_for_ebnf(self):
"""Verify that stack depth isn't an issue for EBNF grammars"""


正在加载...
取消
保存