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

[ruby] Calls with reserved keywords #4776

Merged
merged 9 commits into from
Jul 16, 2024

Conversation

AndreiDreyer
Copy link
Contributor

An issue was picked up where having a reserved keyword as the call on a member (e.g. batch.retry!) was causing a syntax error due to lexer and parser issues.

This PR handles:

  • Changed precedence of keywords in the ANTLR Lexer to come after LOCAL_VARIABLE_IDENTIFIER
  • Added handling to LOCAL_VARIABLE_IDENTIFIER tokens to determine whether a token should be marked as reserved keyword or not. We check if the previous nonWs token is ., : or ::, or if the next token is . or :. If this holds, we know it cannot be a reserved keyword and is instead marked as a LOCAL_VARIABLE_IDENTIFIER.
  • Added debug flag to ANTLR parser to print out the parse tree. Hidden and off by default.

Resolves #4748

@AndreiDreyer AndreiDreyer added the ruby Relates to rubysrc2cpg label Jul 16, 2024
@AndreiDreyer AndreiDreyer self-assigned this Jul 16, 2024
@AndreiDreyer AndreiDreyer marked this pull request as draft July 16, 2024 09:42
@AndreiDreyer AndreiDreyer marked this pull request as ready for review July 16, 2024 09:45
Copy link
Collaborator

@DavidBakerEffendi DavidBakerEffendi left a comment

Choose a reason for hiding this comment

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

Very nice!

@DavidBakerEffendi
Copy link
Collaborator

cc @spingARbor: This bug affected a lot of GitLab files (#4732), so once it's merged there will be a lot more content.

@AndreiDreyer AndreiDreyer merged commit 6426120 into master Jul 16, 2024
5 checks passed
@max-leuthaeuser max-leuthaeuser deleted the andrei/ruby/member-calls-with-emark branch July 22, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Relates to rubysrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ruby] Member Calls with Keyword Names and (EMARK|QMARK) Suffix
2 participants