lib/lrama/grammar/code/rule_action.rb in lrama-0.5.11 vs lib/lrama/grammar/code/rule_action.rb in lrama-0.5.12
- old
+ new
@@ -12,13 +12,27 @@
# * ($$) yyval
# * (@$) yyloc
# * ($1) yyvsp[i]
# * (@1) yylsp[i]
#
+ #
+ # Consider a rule like
+ #
+ # class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
+ #
+ # For the semantic action of original rule:
+ #
# "Rule" class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
- # "Position in grammar" $1 $2 $3 $4 $5 $6
- # "Index for yyvsp" -4 -3 -2 -1 0
+ # "Position in grammar" $1 $2 $3 $4 $5 $6
+ # "Index for yyvsp" -4 -3 -2 -1 0
+ #
+ #
+ # For the first midrule action:
+ #
+ # "Rule" class: keyword_class { $1 } tSTRING { $2 + $3 } keyword_end { $class = $1 + $keyword_end }
+ # "Position in grammar" $1
+ # "Index for yyvsp" 0
def reference_to_c(ref)
case
when ref.type == :dollar && ref.name == "$" # $$
tag = ref.ex_tag || lhs.tag
raise_tag_not_found_error(ref) unless tag
@@ -43,13 +57,15 @@
# the end of rule RHS. In such case, the action is located on
# `@rule.rhs.count`.
@rule.position_in_original_rule_rhs || @rule.rhs.count
end
+ # If this is midrule action, RHS is a RHS of the original rule.
def rhs
(@rule.original_rule || @rule).rhs
end
+ # Unlike `rhs`, LHS is always a LHS of the rule.
def lhs
@rule.lhs
end
def raise_tag_not_found_error(ref)