Sfoglia il codice sorgente

Added template tests

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.6
MegaIng1 4 anni fa
parent
commit
732a835b53
1 ha cambiato i file con 14 aggiunte e 0 eliminazioni
  1. +14
    -0
      tests/test_parser.py

+ 14
- 0
tests/test_parser.py Vedi File

@@ -810,6 +810,20 @@ def _make_parser_test(LEXER, PARSER):
x = g.parse('Hello HelloWorld')
self.assertSequenceEqual(x.children, ['HelloWorld'])

def test_templates(self):
g = _Lark(r"""
start: number_list "\n" number_dict
sep{item, delim}: item (delim item)*
number_list: "[" sep{NUMBER, ","} "]"
number_dict: "{" sep{(NUMBER ":" NUMBER), ";"} "}" // Just to test this
NUMBER: /\d+/
%ignore " "
""")
x = g.parse("[1, 2, 3, 4] {1:2, 3:4, 5:6}")
print(x)
x = g.parse("[1] {1:2}")
print(x)

def test_token_collision_WS(self):
g = _Lark(r"""start: "Hello" NAME
NAME: /\w/+


Caricamento…
Annulla
Salva