Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment for RuleAction #278

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/lrama/grammar/code/rule_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ def initialize(type: nil, token_code: nil, rule: nil)
# * ($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
#
#
# For the first midrule action:
#
# "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
# "Index for yyvsp" 0
def reference_to_c(ref)
case
when ref.type == :dollar && ref.name == "$" # $$
Expand Down Expand Up @@ -45,10 +59,12 @@ def position_in_rhs
@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
Expand Down