Skip to content

Allow keywords as identifiers#313

Merged
TethysSvensson merged 1 commit into
planus-org:mainfrom
parched:keyword-identifiers
Jul 12, 2026
Merged

Allow keywords as identifiers#313
TethysSvensson merged 1 commit into
planus-org:mainfrom
parched:keyword-identifiers

Conversation

@parched

@parched parched commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

This matches the behavior of flatc.

This feels a little hacky but this is my first time seeing larlpop so I'm unsure if there's a better way.
Guidance on suitable tests would be appreciated too.

The specific use case I have is fields called attribute.

Checklist

  • Updated CHANGELOG.md with relevant changes
  • Added tests for any new/fixed functionality
  • Added/updated documentation for new/changed code
  • Checked that README.md still makes sense (and updated it if necessary)

@TethysSvensson

Copy link
Copy Markdown
Collaborator

I don't know if there is a better way either but I think this approach is probably good enough.

You can add tests in the test/files/invalid and test/files/valid directories to test the core parsing.

However I think it also makes sense to test the code generation in this case. That would be in test/rust-test-2021/api_files.

I think using keywords as identifiers is a bit cursed, but I'm not inherently against it. I'll take a better look later.

@TethysSvensson

Copy link
Copy Markdown
Collaborator

By the way, is there anything preventing you from simply renaming the field to something that isn't a reserved keyword?

@parched

parched commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

By the way, is there anything preventing you from simply renaming the field to something that isn't a reserved keyword?

I would have to update the thousand-odd places we currently use it in our codebase -- it isn't a simple find-and-replace because the word is used in other contexts too.

@parched
parched force-pushed the keyword-identifiers branch 2 times, most recently from 3453178 to 583f84c Compare May 6, 2026 10:52
@parched
parched marked this pull request as ready for review May 6, 2026 10:53
This matches the behavior of flatc
@parched
parched force-pushed the keyword-identifiers branch from 583f84c to 0828066 Compare July 12, 2026 06:43
@parched

parched commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@TethysSvensson I've rebased and added the changelog entry, so this should be good to go if you're happy with it.

@TethysSvensson
TethysSvensson merged commit b1c1c16 into planus-org:main Jul 12, 2026
3 checks passed
@parched
parched deleted the keyword-identifiers branch July 13, 2026 08:10
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.

2 participants