Пример #1
0
 def it_can_discard_its_current_lexeme(self):
     lexer = Lexer("foobar")
     lexer._pos = 3
     lexer._ignore()
     assert lexer._peek == "b"
Пример #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
Пример #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
Пример #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
Пример #5
0
 def it_can_backup_to_reverse_a_next(self):
     lexer = Lexer("a")
     lexer._next()
     lexer._backup()
     assert lexer._pos == 0
Пример #6
0
 def next_fixture(self, request):
     input_, expected_value, expected_pos = request.param
     lexer = Lexer(input_)
     return lexer, expected_value, expected_pos
Пример #7
0
 def it_raises_if_default_start_state_method_is_used(self):
     lexer = Lexer(None)
     with pytest.raises(NotImplementedError):
         lexer._lex_start()
Пример #8
0
 def it_can_discard_its_current_lexeme(self):
     lexer = Lexer('foobar')
     lexer._pos = 3
     lexer._ignore()
     assert lexer._peek == 'b'
Пример #9
0
 def it_knows_how_many_characters_are_in_the_input(self):
     lexer = Lexer('barfoo')
     assert lexer._len == 6
Пример #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
Пример #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
Пример #12
0
 def it_can_backup_to_reverse_a_next(self):
     lexer = Lexer('a')
     lexer._next()
     lexer._backup()
     assert lexer._pos == 0
Пример #13
0
 def skip_fixture(self, request):
     input_, n, new_pos, exception = request.param
     lexer = Lexer(input_)
     return lexer, n, new_pos, exception
Пример #14
0
 def peek_fixture(self, request):
     input_, expected_value = request.param
     lexer = Lexer(input_)
     return lexer, expected_value
Пример #15
0
 def it_knows_how_many_characters_are_in_its_current_lexeme(self):
     lexer = Lexer("foobar")
     lexer._pos = 3
     assert lexer._llen == 3
Пример #16
0
 def it_knows_how_many_characters_are_in_its_current_lexeme(self):
     lexer = Lexer('foobar')
     lexer._pos = 3
     assert lexer._llen == 3
Пример #17
0
 def it_raises_if_default_start_state_method_is_used(self):
     lexer = Lexer(None)
     with pytest.raises(NotImplementedError):
         lexer._lex_start()
Пример #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