From 61339aeae9fa41a2f3d5c289128de3e598568c2a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 26 Jul 2024 21:36:41 -0400 Subject: [PATCH] Avoid recalculating reduce_rules - #28 --- lib/propane/parser.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/propane/parser.rb b/lib/propane/parser.rb index 9882cbd..938c635 100644 --- a/lib/propane/parser.rb +++ b/lib/propane/parser.rb @@ -140,20 +140,20 @@ class Propane if reduce_rules.size == 0 nil else - build_lookahead_reduce_actions_for_item_set(item_set) + build_lookahead_reduce_actions_for_item_set(reduce_rules, item_set) end end # Build the reduce actions for a single item set (parser state). # + # @param reduce_rules [Set] + # Rules to look for lookahead tokens after. # @param item_set [ItemSet] # ItemSet (parser state) # # @return [Hash] # Mapping of lookahead Tokens to the Rules to reduce. - def build_lookahead_reduce_actions_for_item_set(item_set) - reduce_rules = Set.new(item_set.items.select(&:complete?).map(&:rule)) - + def build_lookahead_reduce_actions_for_item_set(reduce_rules, item_set) # We will be looking for all possible tokens that can follow instances of # these rules. Rather than looking through the entire grammar for the # possible following tokens, we will only look in the item sets leading