peggy
peggy copied to clipboard
Relative offset for grammar source
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 placesgrammarSource
goes. It will have the same shape as that returned bylocation()
for easily passing it through from a wrapper grammar. Only thestart
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
, andoffset
of bothstart
andend
.
Compatibility:
- Will break anyone currently using
grammarLocation
as a parameter to their grammar. We should document that thegrammar*
namespace is for internal use.
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.