Parser can now print out a list of expected token kinds

This commit is contained in:
Sasha Koshka 2022-08-12 17:09:37 -05:00
parent b3071d4ac9
commit 033e64fc54
1 changed files with 17 additions and 1 deletions

View File

@ -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
}