d081fe7d1c
Signed-off-by: Alejandro Mery <amery@jpi.io>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package parser
|
|
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type=TokenType
|
|
import (
|
|
"fmt"
|
|
|
|
"asciigoat.org/core/lexer"
|
|
)
|
|
|
|
// A TokenType is a type of Token
|
|
type TokenType uint
|
|
|
|
const (
|
|
// TokenUnknown represents a Token that hasn't been identified
|
|
TokenUnknown TokenType = iota
|
|
// TokenSectionName represents the section name between the squared brackets
|
|
TokenSectionName
|
|
// TokenSectionSubname represents a secondary name in the section represented
|
|
// between quotes after the section name.
|
|
// e.g.
|
|
// [section_name "section_subname"]
|
|
TokenSectionSubname
|
|
// TokenComment represents a comment, including the initial ';' or '#' until
|
|
// the end of the line
|
|
TokenComment
|
|
// TokenFieldKey represents a field name in a `key = value` entry
|
|
TokenFieldKey
|
|
// TokenFieldValue represents a field value in a `key = value` entry
|
|
TokenFieldValue
|
|
)
|
|
|
|
// A Token is an element from the document
|
|
type Token struct {
|
|
Type TokenType
|
|
Position lexer.Position
|
|
Value string
|
|
}
|
|
|
|
func (t Token) String() string {
|
|
return fmt.Sprintf("%v:%v: %s: %q", t.Position.Line, t.Position.Column, t.Type, t.Value)
|
|
}
|