Procházet zdrojové kódy

Add test for custom indenter

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.1
Chanic Panic před 3 roky
rodič
revize
13abf7ca3a
1 změnil soubory, kde provedl 23 přidání a 0 odebrání
  1. +23
    -0
      tests/test_parser.py

+ 23
- 0
tests/test_parser.py Zobrazit soubor

@@ -37,6 +37,7 @@ from lark.tree import Tree
from lark.visitors import Transformer, Transformer_InPlace, v_args
from lark.grammar import Rule
from lark.lexer import TerminalDef, Lexer, TraditionalLexer
from lark.indenter import Indenter

logger.setLevel(logging.INFO)

@@ -1876,6 +1877,28 @@ def _make_parser_test(LEXER, PARSER):
tree = parser.parse(test_file)
self.assertEqual(tree.children, [Token('B', 'A')])

@unittest.skipIf(LEXER=='dynamic', "%declare/postlex doesn't work with dynamic")
def test_postlex_indenter(self):
class CustomIndenter(Indenter):
NL_type = 'NEWLINE'
OPEN_PAREN_types = []
CLOSE_PAREN_types = []
INDENT_type = 'INDENT'
DEDENT_type = 'DEDENT'
tab_len = 8

grammar = r"""
start: "a" NEWLINE INDENT "b" NEWLINE DEDENT

NEWLINE: ( /\r?\n */ )+

%ignore " "+
%declare INDENT DEDENT
"""

parser = _Lark(grammar, postlex=CustomIndenter())
parser.parse("a\n b\n")

def test_import_custom_sources(self):
custom_loader = FromPackageLoader('tests', ('grammars', ))



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