feat: new parser strategy
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package saccharine
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.maximhutz.com/max/lambda/pkg/token"
|
||||
)
|
||||
|
||||
// A TokenType is an identifier for any token in the Saccharine language.
|
||||
type TokenType int
|
||||
@@ -21,7 +25,7 @@ const (
|
||||
TokenAssign
|
||||
// TokenAtom denotes an alpha-numeric variable.
|
||||
TokenAtom
|
||||
// TokenSlash denotes the '/' token.
|
||||
// TokenSlash denotes the '\\' token.
|
||||
TokenSlash
|
||||
// TokenDot denotes the '.' token.
|
||||
TokenDot
|
||||
@@ -29,24 +33,6 @@ const (
|
||||
TokenSoftBreak
|
||||
)
|
||||
|
||||
// A Token in the Saccharine language.
|
||||
type Token struct {
|
||||
Column int // Where the token begins in the source text.
|
||||
Type TokenType // What type the token is.
|
||||
Value string // The value of the token.
|
||||
}
|
||||
|
||||
// NewToken creates a [Token] of the given type at the given column.
|
||||
// The token's value is derived from its [TokenType].
|
||||
func NewToken(typ TokenType, column int) *Token {
|
||||
return &Token{Type: typ, Column: column, Value: typ.Name()}
|
||||
}
|
||||
|
||||
// NewTokenAtom creates a [TokenAtom] with the given name at the given column.
|
||||
func NewTokenAtom(name string, column int) *Token {
|
||||
return &Token{Type: TokenAtom, Column: column, Value: name}
|
||||
}
|
||||
|
||||
// Name returns the type of the TokenType, as a string.
|
||||
func (t TokenType) Name() string {
|
||||
switch t {
|
||||
@@ -75,7 +61,5 @@ func (t TokenType) Name() string {
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the type of the Token, as a string.
|
||||
func (t Token) Name() string {
|
||||
return t.Type.Name()
|
||||
}
|
||||
// Token is the concrete token type for the Saccharine language.
|
||||
type Token = token.Token[TokenType]
|
||||
|
||||
Reference in New Issue
Block a user