added symbol '..' and '...'; improved some error reports in parser.go

This commit is contained in:
2024-05-04 18:47:00 +02:00
parent 2c5f02cc69
commit a2c0a24494
4 changed files with 36 additions and 15 deletions
+11 -1
View File
@@ -46,7 +46,7 @@ func NewValueToken(row, col int, sym Symbol, source string, value any) *Token {
func NewErrorToken(row, col int, err error) *Token {
if err == io.EOF {
return NewToken(row, col, SymEos, "")
return NewToken(row, col, SymEos, "<EOF>")
}
return NewValueToken(row, col, SymError, fmt.Sprintf("[%d:%d]", row, col), err)
}
@@ -81,3 +81,13 @@ func (self *Token) Errors(msg string) (err error) {
err = fmt.Errorf("[%d:%d] %v", self.row, self.col, msg)
return
}
func (self *Token) ErrorExpectedGot(symbol string) (err error) {
err = fmt.Errorf("[%d:%d] expected %q, got %q", self.row, self.col, symbol, self)
return
}
func (self *Token) ErrorExpectedGotString(symbol, got string) (err error) {
err = fmt.Errorf("[%d:%d] expected %q, got %q", self.row, self.col, symbol, got)
return
}