Browse Source

Changes due to code review by @MegaIng

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.0
Erez Sh 4 years ago
parent
commit
45467e1f61
3 changed files with 13 additions and 5 deletions
  1. +5
    -1
      lark/parser_frontends.py
  2. +5
    -2
      lark/parsers/lalr_parser.py
  3. +3
    -2
      lark/parsers/lalr_puppet.py

+ 5
- 1
lark/parser_frontends.py View File

@@ -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:


+ 5
- 2
lark/parsers/lalr_parser.py View File

@@ -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


+ 3
- 2
lark/parsers/lalr_puppet.py View File

@@ -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."""


Loading…
Cancel
Save