peggy icon indicating copy to clipboard operation
peggy copied to clipboard

Relative offset for grammar source

Open hildjj opened this issue 2 years ago • 1 comments

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 avatar Jun 30 '22 12:06 hildjj

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.

hildjj avatar Jul 03 '22 18:07 hildjj