@@ -34,7 +34,11 @@ def get_frontend(parser, lexer): | |||||
super(LALR_CustomLexerWrapper, self).__init__( | super(LALR_CustomLexerWrapper, self).__init__( | ||||
lexer, lexer_conf, parser_conf, options=options) | lexer, lexer_conf, parser_conf, options=options) | ||||
def init_lexer(self): | def init_lexer(self): | ||||
self.lexer = CustomLexerWrapper(self.lexer_conf) | |||||
future_interface = getattr(lexer, '__future_interface__', False) | |||||
if future_interface: | |||||
self.lexer = lexer(self.lexer_conf) | |||||
else: | |||||
self.lexer = CustomLexerWrapper(self.lexer_conf) | |||||
return LALR_CustomLexerWrapper | return LALR_CustomLexerWrapper | ||||
else: | else: | ||||
@@ -2,7 +2,7 @@ | |||||
""" | """ | ||||
# Author: Erez Shinan (2017) | # Author: Erez Shinan (2017) | ||||
# Email : erezshin@gmail.com | # Email : erezshin@gmail.com | ||||
from copy import deepcopy | |||||
from copy import deepcopy, copy | |||||
from ..exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedToken | from ..exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedToken | ||||
from ..lexer import Token | from ..lexer import Token | ||||
@@ -61,10 +61,13 @@ class ParserState: | |||||
self.lexer, # XXX copy | self.lexer, # XXX copy | ||||
self.callbacks, | self.callbacks, | ||||
self.start, | self.start, | ||||
list(self.state_stack), | |||||
copy(self.state_stack), | |||||
deepcopy(self.value_stack), | deepcopy(self.value_stack), | ||||
) | ) | ||||
def copy(self): | |||||
return copy(self) | |||||
def feed_token(self, token, is_end=False): | def feed_token(self, token, is_end=False): | ||||
state_stack = self.state_stack | state_stack = self.state_stack | ||||
value_stack = self.value_stack | value_stack = self.value_stack | ||||
@@ -41,8 +41,9 @@ class ParserPuppet(object): | |||||
return self.parser_state == other.parser_state and self.lexer_state == other.lexer_state | return self.parser_state == other.parser_state and self.lexer_state == other.lexer_state | ||||
def __hash__(self): | |||||
return hash((self.parser_state, self.lexer_state)) | |||||
# TODO Provide with an immutable puppet instance | |||||
# def __hash__(self): | |||||
# return hash((self.parser_state, self.lexer_state)) | |||||
def pretty(self): | def pretty(self): | ||||
"""Print the output of ``choices()`` in a way that's easier to read.""" | """Print the output of ``choices()`` in a way that's easier to read.""" | ||||