Parser can now print out a list of expected token kinds
This commit is contained in:
parent
b3071d4ac9
commit
033e64fc54
@ -77,9 +77,25 @@ func (parser *ParsingOperation) expect (allowed ...lexer.TokenKind) (err error)
|
||||
if parser.token.Is(kind) { return }
|
||||
}
|
||||
|
||||
message :=
|
||||
"unexpected " + parser.token.Kind().Describe() +
|
||||
" token, expected "
|
||||
|
||||
for index, allowedItem := range allowed {
|
||||
if index > 0 {
|
||||
if index == len(allowed) - 1 {
|
||||
message += " or "
|
||||
} else {
|
||||
message += ", "
|
||||
}
|
||||
}
|
||||
|
||||
message += allowedItem.Describe()
|
||||
}
|
||||
|
||||
err = file.NewError (
|
||||
parser.token.Location(),
|
||||
"unexpected token", file.ErrorKindError)
|
||||
message, file.ErrorKindError)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user