Browse Source

BUGFIX: Fixed common.ESCAPED_STRING (Issue #309)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Erez Shinan 6 years ago
parent
commit
d2f55fe3ba
2 changed files with 30 additions and 12 deletions
  1. +4
    -3
      lark/grammars/common.lark
  2. +26
    -9
      tests/test_parser.py

+ 4
- 3
lark/grammars/common.lark View File

@@ -20,9 +20,10 @@ SIGNED_NUMBER: ["+"|"-"] NUMBER
//
// Strings
//
//STRING: /"(\\\"|\\\\|[^"\n])*?"i?/
STRING_INNER: ("\\\""|/[^"]/)
ESCAPED_STRING: "\"" STRING_INNER* "\""
_STRING_INNER: /.*?/
_STRING_ESC_INNER: _STRING_INNER /(?<!\\)(\\\\)*?/

ESCAPED_STRING : "\"" _STRING_ESC_INNER "\""


//


+ 26
- 9
tests/test_parser.py View File

@@ -741,15 +741,6 @@ def _make_parser_test(LEXER, PARSER):
""")
x = g.parse(r'\a')

def test_special_chars(self):
g = _Lark(r"""start: "\n"
""")
x = g.parse('\n')

g = _Lark(r"""start: /\n/
""")
x = g.parse('\n')


def test_backslash2(self):
g = _Lark(r"""start: "\"" "-"
@@ -760,6 +751,18 @@ def _make_parser_test(LEXER, PARSER):
""")
x = g.parse('/-')



def test_special_chars(self):
g = _Lark(r"""start: "\n"
""")
x = g.parse('\n')

g = _Lark(r"""start: /\n/
""")
x = g.parse('\n')


# def test_token_recurse(self):
# g = _Lark("""start: A
# A: B
@@ -1322,6 +1325,20 @@ def _make_parser_test(LEXER, PARSER):
self.assertEqual(p.parse("cbbbb").children, [None, 'c', 'b', 'b', 'b', 'b', None, None])


def test_escaped_string(self):
"Tests common.ESCAPED_STRING"
grammar = r"""
start: ESCAPED_STRING+

%import common (WS_INLINE, ESCAPED_STRING)
%ignore WS_INLINE
"""

parser = _Lark(grammar)
parser.parse(r'"\\" "b" "c"')

parser.parse(r'"That" "And a \"b"')


_NAME = "Test" + PARSER.capitalize() + LEXER.capitalize()
_TestParser.__name__ = _NAME


Loading…
Cancel
Save