token.go: replaced self receiver

This commit is contained in:
Celestino Amoroso 2024-07-07 16:19:58 +02:00
parent dd6404c786
commit 6d9a379c92

View File

@ -33,7 +33,7 @@ func (tk *Token) String() string {
return fmt.Sprintf("%v", tk.Value) return fmt.Sprintf("%v", tk.Value)
} }
} }
return fmt.Sprintf("%s", tk.source) return tk.source
} }
func NewToken(row, col int, sym Symbol, source string) *Token { func NewToken(row, col int, sym Symbol, source string) *Token {
@ -71,31 +71,31 @@ func (tk *Token) IsSymbol(sym Symbol) bool {
return tk.Sym == sym return tk.Sym == sym
} }
func (self *Token) Errorf(template string, args ...any) (err error) { func (tk *Token) Errorf(template string, args ...any) (err error) {
err = fmt.Errorf(fmt.Sprintf("[%d:%d] ", self.row, self.col)+template, args...) err = fmt.Errorf(fmt.Sprintf("[%d:%d] ", tk.row, tk.col)+template, args...)
return return
} }
func (self *Token) Error() (err error) { func (tk *Token) Error() (err error) {
if self.Sym == SymError { if tk.Sym == SymError {
if msg, ok := self.Value.(error); ok { if msg, ok := tk.Value.(error); ok {
err = fmt.Errorf("[%d:%d] %v", self.row, self.col, msg) err = fmt.Errorf("[%d:%d] %v", tk.row, tk.col, msg)
} }
} }
return return
} }
func (self *Token) Errors(msg string) (err error) { func (tk *Token) Errors(msg string) (err error) {
err = fmt.Errorf("[%d:%d] %v", self.row, self.col, msg) err = fmt.Errorf("[%d:%d] %v", tk.row, tk.col, msg)
return return
} }
func (self *Token) ErrorExpectedGot(symbol string) (err error) { func (tk *Token) ErrorExpectedGot(symbol string) (err error) {
err = fmt.Errorf("[%d:%d] expected %q, got %q", self.row, self.col, symbol, self) err = fmt.Errorf("[%d:%d] expected %q, got %q", tk.row, tk.col, symbol, tk)
return return
} }
func (self *Token) ErrorExpectedGotString(symbol, got string) (err error) { func (tk *Token) ErrorExpectedGotString(symbol, got string) (err error) {
err = fmt.Errorf("[%d:%d] expected %q, got %q", self.row, self.col, symbol, got) err = fmt.Errorf("[%d:%d] expected %q, got %q", tk.row, tk.col, symbol, got)
return return
} }