In the source there is func (yylex *Lexer) Line() intfunc (yylex *Lexer) Column() int. I think it would also be useful to have func (yylex *Lexer) Size() int which returns position in bytes relative to the start of the files.
Current approach
I'd like to lex and parse a number of different files together. The approach I'm attempting is the concatenate them together with a https://golang.org/pkg/io/#MultiWriter. I also store a list of cumulative file.Size() offsets for each file. I get this via Stat when opening each file for the MultiWriter.
At the end of lexing/parsing if I get an error, I work backwards from position of error to line number and file.
Problem
The problem is that I'm doing the "math" with line numbers instead of Size offsets. This means that I need to loop through each file (before lexing/parsing) and count all the newlines. If Size was available in addition to Column and Row, then this would be much more direct.
I haven't yet worked out how I'd get from the correct size offset to Column and Line, but I figure that's doable somehow.
Help
Help is appreciated if anyone can contribute. This currently works with line number alone, but as I mentioned a Size offset might be preferable. If there's an alternative technique for lexing/parsing multiple files together as one, please let me know!
Description
In the source there is
func (yylex *Lexer) Line() int
func (yylex *Lexer) Column() int
. I think it would also be useful to havefunc (yylex *Lexer) Size() int
which returns position in bytes relative to the start of the files.Current approach
I'd like to lex and parse a number of different files together. The approach I'm attempting is the concatenate them together with a https://golang.org/pkg/io/#MultiWriter. I also store a list of cumulative
file.Size()
offsets for each file. I get this viaStat
when opening each file for the MultiWriter.At the end of lexing/parsing if I get an error, I work backwards from position of error to line number and file.
Problem
The problem is that I'm doing the "math" with line numbers instead of
Size
offsets. This means that I need to loop through each file (before lexing/parsing) and count all the newlines. IfSize
was available in addition toColumn
andRow
, then this would be much more direct.I haven't yet worked out how I'd get from the correct size offset to Column and Line, but I figure that's doable somehow.
Help
Help is appreciated if anyone can contribute. This currently works with line number alone, but as I mentioned a
Size
offset might be preferable. If there's an alternative technique for lexing/parsing multiple files together as one, please let me know!Thanks!