lib/lrama/grammar/code/rule_action.rb in lrama-0.6.9 vs lib/lrama/grammar/code/rule_action.rb in lrama-0.6.10
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Lrama
class Grammar
class Code
class RuleAction < Code
def initialize(type:, token_code:, rule:)
@@ -39,19 +41,21 @@
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
+ # @type var tag: Lexer::Token::Tag
"(yyval.#{tag.member})"
when ref.type == :at && ref.name == "$" # @$
"(yyloc)"
when ref.type == :index && ref.name == "$" # $:$
raise "$:$ is not supported"
when ref.type == :dollar # $n
i = -position_in_rhs + ref.index
tag = ref.ex_tag || rhs[ref.index - 1].tag
raise_tag_not_found_error(ref) unless tag
+ # @type var tag: Lexer::Token::Tag
"(yyvsp[#{i}].#{tag.member})"
when ref.type == :at # @n
i = -position_in_rhs + ref.index
"(yylsp[#{i}])"
when ref.type == :index # $:n
@@ -67,21 +71,21 @@
# 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.
+ # If this is midrule action, RHS is an RHS of the original rule.
def rhs
(@rule.original_rule || @rule).rhs
end
- # Unlike `rhs`, LHS is always a LHS of the rule.
+ # Unlike `rhs`, LHS is always an LHS of the rule.
def lhs
@rule.lhs
end
def raise_tag_not_found_error(ref)
- raise "Tag is not specified for '$#{ref.value}' in '#{@rule}'"
+ raise "Tag is not specified for '$#{ref.value}' in '#{@rule.display_name}'"
end
end
end
end
end