feat: better error messages
This commit is contained in:
@@ -4,26 +4,19 @@ package token
|
||||
type Type int
|
||||
|
||||
const (
|
||||
// Denotes the '(' token.
|
||||
OpenParen Type = iota
|
||||
// Denotes the ')' token.
|
||||
CloseParen
|
||||
// Denotes an alpha-numeric variable.
|
||||
Atom
|
||||
// Denotes the '/' token.
|
||||
Slash
|
||||
// Denotes the '.' token.
|
||||
Dot
|
||||
OpenParen Type = iota // Denotes the '(' token.
|
||||
CloseParen // Denotes the ')' token.
|
||||
Atom // Denotes an alpha-numeric variable.
|
||||
Slash // Denotes the '/' token.
|
||||
Dot // Denotes the '.' token.
|
||||
Newline // Denotes a new-line.
|
||||
)
|
||||
|
||||
// A representation of a token in source code.
|
||||
type Token struct {
|
||||
// Where the token begins in the source text.
|
||||
Index int
|
||||
// What type the token is.
|
||||
Type Type
|
||||
// The value of the token.
|
||||
Value string
|
||||
Index int // Where the token begins in the source text.
|
||||
Type Type // What type the token is.
|
||||
Value string // The value of the token.
|
||||
}
|
||||
|
||||
func NewOpenParen(index int) *Token {
|
||||
@@ -46,6 +39,10 @@ func NewAtom(name string, index int) *Token {
|
||||
return &Token{Type: Atom, Index: index, Value: name}
|
||||
}
|
||||
|
||||
func NewNewline(index int) *Token {
|
||||
return &Token{Type: Newline, Index: index, Value: "\\n"}
|
||||
}
|
||||
|
||||
func Name(typ Type) string {
|
||||
switch typ {
|
||||
case OpenParen:
|
||||
@@ -58,6 +55,8 @@ func Name(typ Type) string {
|
||||
return "."
|
||||
case Atom:
|
||||
return "ATOM"
|
||||
case Newline:
|
||||
return "\\n"
|
||||
default:
|
||||
return "?"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user