diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-12 21:30:40 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-12 21:30:40 +0900 |
commit | 71577d39f48d129cae48f9d242f407560360862d (patch) | |
tree | 9d9b8d055e41b09b7bb3f077e6f0f1b59d1aecc8 | |
parent | Fix counting of token positions (diff) | |
download | urubu-71577d39f48d129cae48f9d242f407560360862d.tar.gz urubu-71577d39f48d129cae48f9d242f407560360862d.tar.xz |
Set token positions for the EOF symbol
vartan intentionally had not set positional information for the EOF symbol in a token because the corresponding character does not exist in the source code.
However, to be able to include the positional information in a syntax error message when a syntax error occurs due to the detection of the EOF symbol during parsing,
this commit sets the position next to the last character in the source code as the position of the EOF symbol.
-rw-r--r-- | driver/lexer/lexer.go | 4 | ||||
-rw-r--r-- | driver/lexer/lexer_test.go | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/driver/lexer/lexer.go b/driver/lexer/lexer.go index e63d0ac..9dee6e3 100644 --- a/driver/lexer/lexer.go +++ b/driver/lexer/lexer.go @@ -221,8 +221,8 @@ func (l *Lexer) next() (*Token, error) { return &Token{ ModeID: mode, ModeKindID: 0, - Row: 0, - Col: 0, + Row: row, + Col: col, EOF: true, }, nil } diff --git a/driver/lexer/lexer_test.go b/driver/lexer/lexer_test.go index 247cc73..66efe1f 100644 --- a/driver/lexer/lexer_test.go +++ b/driver/lexer/lexer_test.go @@ -876,7 +876,7 @@ func TestLexer_Next_WithPosition(t *testing.T) { // the line number where a lexeme first appears. withPos(newTokenDefault(1, 1, []byte{0x0A, 0x0A, 0x0A}), 3, 6), - withPos(newEOFTokenDefault(), 0, 0), + withPos(newEOFTokenDefault(), 6, 0), } lexer, err := NewLexer(NewLexSpec(clspec), strings.NewReader(src)) |