From 085cd4e9efed73df69c384afd6c36c4e75424b53 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 28 Jan 2024 19:00:38 +0900 Subject: [PATCH] Use `def_delegators` in Lrama::States::Item --- lib/lrama/states/item.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/lrama/states/item.rb b/lib/lrama/states/item.rb index 08352772..31b74b9d 100644 --- a/lib/lrama/states/item.rb +++ b/lib/lrama/states/item.rb @@ -1,8 +1,14 @@ # TODO: Validate position is not over rule rhs +require "forwardable" + module Lrama class States class Item < Struct.new(:rule, :position, keyword_init: true) + extend Forwardable + + def_delegators "rule", :lhs, :rhs + # Optimization for States#setup_state def hash [rule_id, position].hash @@ -20,14 +26,6 @@ def number_of_rest_symbols rhs.count - position end - def lhs - rule.lhs - end - - def rhs - rule.rhs - end - def next_sym rhs[position] end