-
Notifications
You must be signed in to change notification settings - Fork 27
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 support for aliased Named References for actions of rhs in Parameterizing rules #410
Add support for aliased Named References for actions of rhs in Parameterizing rules #410
Conversation
Can I ask the use case of this functionality? We can use arbitrary name for the variable ( |
@yui-knk I changed it to an appropriate example in PR description. For example, I think it makes sense to set an alias for nterms, which is not a parameter in rhs for parameterization rules. WDYT? |
@@ -16,7 +16,7 @@ static int yyerror(YYLTYPE *loc, const char *str); | |||
%token <i> number | |||
%token <s> string | |||
|
|||
%rule pair(X, Y): X ',' Y { printf("(%d, %d)\n", $X, $3); } | |||
%rule pair(X, Y): X ',' Y[alias] { printf("(%d, %d)\n", $X, $alias); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention makes sense for me. Could you update the test case grammar to match with the intention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it is. I updated this PR.
IIUC aliased Named References for non parameter in RHS is already supported. |
b6c3170
to
2acfc92
Compare
@yui-knk Is there any blocker left for this pull request? |
@ydah I'm bit confused because:
diff --git a/lib/lrama/grammar/binding.rb b/lib/lrama/grammar/binding.rb
index 21b6ad5..d215ad0 100644
--- a/lib/lrama/grammar/binding.rb
+++ b/lib/lrama/grammar/binding.rb
@@ -16,7 +16,7 @@ module Lrama
resolved_args = symbol.args.map { |arg| resolve_symbol(arg) }
Lrama::Lexer::Token::InstantiateRule.new(s_value: symbol.s_value, location: symbol.location, args: resolved_args, lhs_tag: symbol.lhs_tag)
else
- parameter_to_arg(symbol) || symbol
+ @parameter_to_arg[symbol.s_value] || symbol
end
end $ bundle exec rake
...
Finished in 9.62 seconds (files took 0.27494 seconds to load)
219 examples, 0 failures
But I guess Could you check them? |
2acfc92
to
36e8e25
Compare
It is correct to specify a Named Reference for the parameter.
36e8e25
to
db76b63
Compare
|
LGTM! |
This PR support for aliased Named References for actions of rhs in Parameterizing rules.
Motivation
If there is a non-terminal symbol in the RHS of parameterizing rules as shown below, I want to access it in the Named Reference.