Procházet zdrojové kódy

Fixed support for hex encoding (\xAA)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Erez Shinan před 5 roky
rodič
revize
6b2df208c2
2 změnil soubory, kde provedl 9 přidání a 3 odebrání
  1. +6
    -1
      lark/lexer.py
  2. +3
    -2
      tests/test_parser.py

+ 6
- 1
lark/lexer.py Zobrazit soubor

@@ -72,7 +72,12 @@ class Token(Str):
__slots__ = ('type', 'pos_in_stream', 'value', 'line', 'column', 'end_line', 'end_column')

def __new__(cls, type_, value, pos_in_stream=None, line=None, column=None):
self = super(Token, cls).__new__(cls, value)
try:
self = super(Token, cls).__new__(cls, value)
except UnicodeDecodeError:
value = value.decode('latin1')
self = super(Token, cls).__new__(cls, value)

self.type = type_
self.pos_in_stream = pos_in_stream
self.value = value


+ 3
- 2
tests/test_parser.py Zobrazit soubor

@@ -449,11 +449,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
g = _Lark(r"""start: A B C
A: "\x01"
B: /\x02/
C: "\xABCD"
""")
g.parse('\x01\x02')
g.parse('\x01\x02\xABCD')

@unittest.skipIf(PARSER == 'cyk', "Takes forever")
def test_stack_for_ebnf(self):


Načítá se…
Zrušit
Uložit