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

Allow keywords to be used as annotation names. #4897

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

ChrisDodd
Copy link
Contributor

The P4 spec says that keywords can be used freely in annotation bodies with no special meaning. That sort-of implies they can be used as an annotation name as well, which we previously weren't allowing.

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Sep 4, 2024
@@ -561,6 +561,60 @@ annotationBody
}
;

annotationName
: ABSTRACT { $$ = new IR::ID(@1, "abstract"_cs); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to just defer to KEYWORD in yacc? Otherwise we have to manually keep track of this every time we add a new keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is the lexer needs to decide what is a keyword without using any contextual info. We could perhaps change all the keywords to contain the string as a sematic value (so all of these actions would become { $$ = new IR::ID(@1, $1); }, but we'd still need to actually add all the rules in the grammar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking of a way to generate these rules automatically based on the KEYWORD list, but it looks like there is no way.

@ChrisDodd ChrisDodd force-pushed the cdodd-annotfix branch 3 times, most recently from c321f99 to 9da1dd7 Compare September 17, 2024 21:25
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
@ChrisDodd ChrisDodd added this pull request to the merge queue Sep 20, 2024
Merged via the queue into p4lang:main with commit d63f2e8 Sep 20, 2024
18 checks passed
@ChrisDodd ChrisDodd deleted the cdodd-annotfix branch September 20, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants