Przeglądaj źródła

Support hex escape (\xhh) in string literal

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Kyungdahm Yun 5 lat temu
rodzic
commit
70d724732d
2 zmienionych plików z 7 dodań i 2 usunięć
  1. +1
    -1
      lark/load_grammar.py
  2. +6
    -1
      tests/test_parser.py

+ 1
- 1
lark/load_grammar.py Wyświetl plik

@@ -346,7 +346,7 @@ def _fix_escaping(s):
n2 = next(i)
if n2 == '\\':
w += '\\\\'
elif n2 not in 'unftr':
elif n2 not in 'uxnftr':
w += '\\'
w += n2
w = w.replace('\\"', '"').replace("'", "\\'")


+ 6
- 1
tests/test_parser.py Wyświetl plik

@@ -448,6 +448,12 @@ def _make_parser_test(LEXER, PARSER):
""")
g.parse(u'\xa3\u0101\u00a3\u0203\n')

def test_hex_escape(self):
g = _Lark(r"""start: A B
A: "\x01"
B: /\x02/
""")
g.parse('\x01\x02')

@unittest.skipIf(PARSER == 'cyk', "Takes forever")
def test_stack_for_ebnf(self):
@@ -1363,4 +1369,3 @@ for _LEXER in ('dynamic', 'dynamic_complete'):

if __name__ == '__main__':
unittest.main()


Ładowanie…
Anuluj
Zapisz