aboutsummaryrefslogtreecommitdiff
path: root/spec/lexer.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-07-28 23:00:33 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-07-28 23:00:33 +0900
commitd2aaffc083bb1aa54301d0e908be0a0e412af8c9 (patch)
tree5616e785ecafd489c28bab9c558d604cc1e5eaa8 /spec/lexer.go
parentCount the number of each line in consecutive lines (diff)
downloadurubu-d2aaffc083bb1aa54301d0e908be0a0e412af8c9.tar.gz
urubu-d2aaffc083bb1aa54301d0e908be0a0e412af8c9.tar.xz
Add a token position and detailed info to a lexical error message
Diffstat (limited to 'spec/lexer.go')
-rw-r--r--spec/lexer.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/spec/lexer.go b/spec/lexer.go
index 1f50a27..30757c6 100644
--- a/spec/lexer.go
+++ b/spec/lexer.go
@@ -88,10 +88,11 @@ func newEOFToken() *token {
}
}
-func newInvalidToken(text string) *token {
+func newInvalidToken(text string, pos Position) *token {
return &token{
kind: tokenKindInvalid,
text: text,
+ pos: pos,
}
}
@@ -157,7 +158,7 @@ func (l *lexer) lexAndSkipWSs() (*token, error) {
return nil, err
}
if tok.Invalid {
- newInvalidToken(tok.Text())
+ return newInvalidToken(tok.Text(), newPosition(l.row)), nil
}
if tok.EOF {
return newEOFToken(), nil
@@ -182,8 +183,9 @@ func (l *lexer) lexAndSkipWSs() (*token, error) {
case "identifier":
if strings.HasPrefix(tok.Text(), "_") {
return nil, &verr.SpecError{
- Cause: synErrAutoGenID,
- Row: l.row,
+ Cause: synErrAutoGenID,
+ Detail: tok.Text(),
+ Row: l.row,
}
}
return newIDToken(tok.Text(), newPosition(l.row)), nil
@@ -257,6 +259,6 @@ func (l *lexer) lexAndSkipWSs() (*token, error) {
case "expansion":
return newSymbolToken(tokenKindExpantion, newPosition(l.row)), nil
default:
- return newInvalidToken(tok.Text()), nil
+ return newInvalidToken(tok.Text(), newPosition(l.row)), nil
}
}