Example #1
0
 def it_can_discard_its_current_lexeme(self):
     lexer = Lexer("foobar")
     lexer._pos = 3
     lexer._ignore()
     assert lexer._peek == "b"
Example #2
0
 def it_can_accept_a_run_of_chars_in_a_charset(self):
     lexer = Lexer("ohsofoobaric")
     lexer._accept_run("fhos")
     assert lexer._pos == 7
Example #3
0
 def it_can_accept_a_run_of_chars_not_in_a_charset(self):
     lexer = Lexer('x:foo="bar"')
     lexer._accept_until("=")
     assert lexer._pos == 5
Example #4
0
 def emit_fixture(self, Token_, token_):
     lexer = Lexer("foobar")
     lexer._pos = 3
     terminal_symbol, lexeme = 42, "foo"
     Token_.return_value = token_
     return lexer, terminal_symbol, lexeme, Token_, token_, lexer._pos
Example #5
0
 def it_can_backup_to_reverse_a_next(self):
     lexer = Lexer("a")
     lexer._next()
     lexer._backup()
     assert lexer._pos == 0
Example #6
0
 def next_fixture(self, request):
     input_, expected_value, expected_pos = request.param
     lexer = Lexer(input_)
     return lexer, expected_value, expected_pos
Example #7
0
 def it_raises_if_default_start_state_method_is_used(self):
     lexer = Lexer(None)
     with pytest.raises(NotImplementedError):
         lexer._lex_start()
Example #8
0
 def it_can_discard_its_current_lexeme(self):
     lexer = Lexer('foobar')
     lexer._pos = 3
     lexer._ignore()
     assert lexer._peek == 'b'
Example #9
0
 def it_knows_how_many_characters_are_in_the_input(self):
     lexer = Lexer('barfoo')
     assert lexer._len == 6
Example #10
0
 def it_can_accept_a_run_of_chars_in_a_charset(self):
     lexer = Lexer('ohsofoobaric')
     lexer._accept_run('fhos')
     assert lexer._pos == 7
Example #11
0
 def it_can_accept_a_run_of_chars_not_in_a_charset(self):
     lexer = Lexer('x:foo="bar"')
     lexer._accept_until('=')
     assert lexer._pos == 5
Example #12
0
 def it_can_backup_to_reverse_a_next(self):
     lexer = Lexer('a')
     lexer._next()
     lexer._backup()
     assert lexer._pos == 0
Example #13
0
 def skip_fixture(self, request):
     input_, n, new_pos, exception = request.param
     lexer = Lexer(input_)
     return lexer, n, new_pos, exception
Example #14
0
 def peek_fixture(self, request):
     input_, expected_value = request.param
     lexer = Lexer(input_)
     return lexer, expected_value
Example #15
0
 def it_knows_how_many_characters_are_in_its_current_lexeme(self):
     lexer = Lexer("foobar")
     lexer._pos = 3
     assert lexer._llen == 3
Example #16
0
 def it_knows_how_many_characters_are_in_its_current_lexeme(self):
     lexer = Lexer('foobar')
     lexer._pos = 3
     assert lexer._llen == 3
Example #17
0
 def it_raises_if_default_start_state_method_is_used(self):
     lexer = Lexer(None)
     with pytest.raises(NotImplementedError):
         lexer._lex_start()
Example #18
0
 def emit_fixture(self, Token_, token_):
     lexer = Lexer('foobar')
     lexer._pos = 3
     terminal_symbol, lexeme = 42, 'foo'
     Token_.return_value = token_
     return lexer, terminal_symbol, lexeme, Token_, token_, lexer._pos