diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-28 23:00:33 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-28 23:00:33 +0900 |
commit | d2aaffc083bb1aa54301d0e908be0a0e412af8c9 (patch) | |
tree | 5616e785ecafd489c28bab9c558d604cc1e5eaa8 /spec/parser.go | |
parent | Count the number of each line in consecutive lines (diff) | |
download | urubu-d2aaffc083bb1aa54301d0e908be0a0e412af8c9.tar.gz urubu-d2aaffc083bb1aa54301d0e908be0a0e412af8c9.tar.xz |
Add a token position and detailed info to a lexical error message
Diffstat (limited to 'spec/parser.go')
-rw-r--r-- | spec/parser.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/spec/parser.go b/spec/parser.go index 4773da6..29248f4 100644 --- a/spec/parser.go +++ b/spec/parser.go @@ -76,6 +76,14 @@ func raiseSyntaxError(row int, synErr *SyntaxError) { }) } +func raiseSyntaxErrorWithDetail(row int, synErr *SyntaxError, detail string) { + panic(&verr.SpecError{ + Cause: synErr, + Detail: detail, + Row: row, + }) +} + func Parse(src io.Reader) (*RootNode, error) { p, err := newParser(src) if err != nil { @@ -426,7 +434,7 @@ func (p *parser) consume(expected tokenKind) bool { } p.pos = tok.pos if tok.kind == tokenKindInvalid { - raiseSyntaxError(p.pos.Row, synErrInvalidToken) + raiseSyntaxErrorWithDetail(p.pos.Row, synErrInvalidToken, tok.text) } if tok.kind == expected { p.lastTok = tok |