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

Implement named references #41

Merged
merged 7 commits into from Jun 13, 2023
Merged

Conversation

junk0612
Copy link
Collaborator

Summary

In this pull request, I have implemented the Named References concept from bison.
By merging this pull request, it will be possible to refer to the value by its symbol in the rule or its alias from within the action.

Changes made

  • Detect and tokenize the named references declaration
  • Make references from named references in actions
  • Change some grammar parameters
    • Add alias to Token class
    • Rename number in the Reference class to value because there is now a case where a string is assigned in addition to a number.
  • Add a test case

@@ -257,6 +288,9 @@ def lex_user_code(ss, line, column, lines)
when ss.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
tag = ss[1] ? create_token(Token::Tag, ss[1], line, str.length) : nil
references << [:dollar, Integer(ss[2]), tag, str.length, str.length + ss[0].length - 1]
when ss.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z0-9_]+)/) # $foo, $expr, $<long>program
Copy link
Collaborator

@yui-knk yui-knk Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the second capture ([a-zA-Z0-9_]+) might be same with the capture for Token::Named_Ref except for [] (so that [a-zA-Z_.][-a-zA-Z0-9_.]*).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, exactly saying ...
It might be same with one of two:

  1. Token::Ident ([a-zA-Z_.][-a-zA-Z0-9_.]*)
  2. Token::Named_Ref except for [] (so that [a-zA-Z_.][-a-zA-Z0-9_.]*)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing. Is this the change you were suggesting?
3b8d4e5#diff-816037370d9ebaadd970a429ac66cdf5597623e3f285642396489c85b05b89c5R266

Copy link
Collaborator

@yui-knk yui-knk Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if you have concerns, please let me know :)

@yui-knk
Copy link
Collaborator

yui-knk commented Jun 12, 2023

Thanks for your PR, I left a comment. Other seems good.

@yui-knk yui-knk merged commit dd57055 into ruby:master Jun 13, 2023
9 checks passed
@yui-knk
Copy link
Collaborator

yui-knk commented Jun 13, 2023

Thank you!!

@junk0612 junk0612 deleted the implement-named-references branch June 14, 2023 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants