@@ -1008,7 +1008,19 @@ def lex(self, lexer_state, parser_state):
1008
1008
1009
1009
__future_interface__ = 2
1010
1010
1011
- class CustomLexerOld (Lexer ):
1011
+ class CustomLexerOld1 (Lexer ):
1012
+ """
1013
+ Purpose of this custom lexer is to test the integration,
1014
+ so it uses the traditionalparser as implementation without custom lexing behaviour.
1015
+ """
1016
+ def __init__ (self , lexer_conf ):
1017
+ self .lexer = BasicLexer (copy (lexer_conf ))
1018
+ def lex (self , lexer_state , parser_state ):
1019
+ return self .lexer .lex (lexer_state , parser_state )
1020
+
1021
+ __future_interface__ = 1
1022
+
1023
+ class CustomLexerOld0 (Lexer ):
1012
1024
"""
1013
1025
Purpose of this custom lexer is to test the integration,
1014
1026
so it uses the traditionalparser as implementation without custom lexing behaviour.
@@ -1095,7 +1107,8 @@ def load(self,f):
1095
1107
def _make_parser_test (LEXER , PARSER ):
1096
1108
lexer_class_or_name = {
1097
1109
'custom_new' : CustomLexerNew ,
1098
- 'custom_old' : CustomLexerOld ,
1110
+ 'custom_old1' : CustomLexerOld1 ,
1111
+ 'custom_old0' : CustomLexerOld0 ,
1099
1112
}.get (LEXER , LEXER )
1100
1113
1101
1114
def _Lark (grammar , ** kwargs ):
@@ -1649,7 +1662,7 @@ def test_token_flags(self):
1649
1662
tree = l .parse ('AB,a' )
1650
1663
self .assertEqual (tree .children , ['AB' ])
1651
1664
1652
- @unittest .skipIf (LEXER in ('basic' , 'custom_old ' , 'custom_new' ), "Requires context sensitive terminal selection" )
1665
+ @unittest .skipIf (LEXER in ('basic' , 'custom_old0' , 'custom_old1 ' , 'custom_new' ), "Requires context sensitive terminal selection" )
1653
1666
def test_token_flags_collision (self ):
1654
1667
1655
1668
g = """!start: "a"i "a"
@@ -2408,7 +2421,7 @@ def test_meddling_unused(self):
2408
2421
parser = _Lark (grammar )
2409
2422
2410
2423
2411
- @unittest .skipIf (PARSER != 'lalr' or LEXER == 'custom_old ' , "Serialize currently only works for LALR parsers without custom lexers (though it should be easy to extend)" )
2424
+ @unittest .skipIf (PARSER != 'lalr' or LEXER == 'custom_old0 ' , "Serialize currently only works for LALR parsers without custom lexers (though it should be easy to extend)" )
2412
2425
def test_serialize (self ):
2413
2426
grammar = """
2414
2427
start: _ANY b "C"
@@ -2454,7 +2467,7 @@ def test_lexer_detect_newline_tokens(self):
2454
2467
self .assertEqual (a .line , 1 )
2455
2468
self .assertEqual (b .line , 2 )
2456
2469
2457
- @unittest .skipIf (PARSER == 'cyk' or LEXER == 'custom_old ' , "match_examples() not supported for CYK/old custom lexer" )
2470
+ @unittest .skipIf (PARSER == 'cyk' or LEXER == 'custom_old0 ' , "match_examples() not supported for CYK/old custom lexer" )
2458
2471
def test_match_examples (self ):
2459
2472
p = _Lark (r"""
2460
2473
start: "a" "b" "c"
@@ -2668,7 +2681,7 @@ def test_strict(self):
2668
2681
"""
2669
2682
self .assertRaises (GrammarError , _Lark , grammar , strict = True )
2670
2683
2671
- @unittest .skipIf (LEXER in ('dynamic' , 'dynamic_complete' , 'custom_old ' ),
2684
+ @unittest .skipIf (LEXER in ('dynamic' , 'dynamic_complete' , 'custom_old0' , 'custom_old1 ' ),
2672
2685
"start_pos and end_pos not compatible with old style custom/dynamic lexer " )
2673
2686
def test_parse_textslice (self ):
2674
2687
grammar = r"""
@@ -2712,7 +2725,7 @@ def test_parse_textslice(self):
2712
2725
assert t .line == 9
2713
2726
2714
2727
2715
- @unittest .skipIf (LEXER not in ('dynamic' , 'dynamic_complete' , 'custom_old ' ),
2728
+ @unittest .skipIf (LEXER not in ('dynamic' , 'dynamic_complete' , 'custom_old0' , 'custom_old1 ' ),
2716
2729
"start_pos and end_pos not compatible with old style custom/dynamic lexer " )
2717
2730
def test_parse_textslice_fails (self ):
2718
2731
parser = _Lark ("start: " )
@@ -2738,7 +2751,8 @@ def test_parse_textslice_fails(self):
2738
2751
2739
2752
('custom_new' , 'lalr' ),
2740
2753
('custom_new' , 'cyk' ),
2741
- ('custom_old' , 'earley' ),
2754
+ ('custom_old0' , 'earley' ),
2755
+ ('custom_old1' , 'earley' ),
2742
2756
]
2743
2757
2744
2758
for _LEXER , _PARSER in _TO_TEST :
0 commit comments