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

Relative offset for grammar source #307

Closed
hildjj opened this issue Jun 30, 2022 · 1 comment · Fixed by #309
Closed

Relative offset for grammar source #307

hildjj opened this issue Jun 30, 2022 · 1 comment · Fixed by #309
Assignees
Labels
enhancement New feature or request

Comments

@hildjj
Copy link
Contributor

hildjj commented Jun 30, 2022

In peggy-test and peggy-tag, I'd like to be able to pass in a grammar location along with the grammar source, so that offset, line, and column in reported errors start at something other than zero. This is useful when the grammar is embedded into a larger document, and only a portion of that larger document is passed into peggy.

Proposal:

  • Add a grammarLocation to the API. Carry it around all of the places grammarSource goes. It will have the same shape as that returned by location() for easily passing it through from a wrapper grammar. Only the start portion is likely to be used, however.
  • Do not apply the offset until the very last moment, on output in format. Otherwise the arrow pointing to the error will be in the wrong place.
  • Default offsets are all zero. Check for off-by-one errors in line, column, and offset of both start and end.

Compatibility:

  • Will break anyone currently using grammarLocation as a parameter to their grammar. We should document that the grammar* namespace is for internal use.
@hildjj hildjj added the enhancement New feature or request label Jun 30, 2022
@hildjj hildjj self-assigned this Jun 30, 2022
@hildjj
Copy link
Contributor Author

hildjj commented Jul 3, 2022

I'm going about this a slightly different way that changes the interface a lot less. There's a special type you'll be able to pass in for grammarSource, called GrammarLocation, which keeps the offsets and the name of the source file as text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant