Skip to content

Commit

Permalink
Merge pull request #80 from Maumagnaguagno/token_scanner-next
Browse files Browse the repository at this point in the history
Minimize current_token calls in Lrama::Parser::TokenScanner
  • Loading branch information
yui-knk authored Aug 12, 2023
2 parents 4fb4f94 + 4cf8b51 commit 575fd0c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/lrama/parser/token_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def current_token
end

def current_type
current_token && current_token.type
current_token&.type
end

def previous_token
Expand All @@ -26,9 +26,7 @@ def next

def consume(*token_types)
if token_types.include?(current_type)
token = current_token
self.next
return token
return self.next
end

return nil
Expand All @@ -42,8 +40,7 @@ def consume_multi(*token_types)
a = []

while token_types.include?(current_type)
a << current_token
self.next
a << self.next
end

raise "No token is consumed. #{token_types}" if a.empty?
Expand Down

0 comments on commit 575fd0c

Please sign in to comment.