Skip to content

Commit

Permalink
Merge pull request #1224 from lark-parser/dec3_ip_last_token
Browse files Browse the repository at this point in the history
Fix EOF line information in InteractiveParser.resume_parse()
  • Loading branch information
erezsh authored Dec 5, 2022
2 parents ea125d1 + dd5ceba commit b962bb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lark/parsers/lalr_interactive_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def accepts(self):
return accepts

def resume_parse(self):
"""Resume automated parsing from the current state."""
return self.parser.parse_from_state(self.parser_state)
"""Resume automated parsing from the current state.
"""
return self.parser.parse_from_state(self.parser_state, last_token=self.lexer_state.state.last_token)



Expand Down
11 changes: 8 additions & 3 deletions lark/parsers/lalr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,15 @@ def parse(self, lexer, start, value_stack=None, state_stack=None, start_interact
return self.parse_from_state(parser_state)


def parse_from_state(self, state):
# Main LALR-parser loop
def parse_from_state(self, state, last_token=None):
"""Run the main LALR parser loop
Parameters:
state (ParseState) - the initial state. Changed in-place.
last_token (optional, Token) - Used only for line information in case of an empty lexer.
"""
try:
token = None
token = last_token
for token in state.lexer.lex(state):
state.feed_token(token)

Expand Down

0 comments on commit b962bb6

Please sign in to comment.