go-toml/toml.go

53 lines
1.2 KiB
Go

package parser
import (
"fmt"
"strings"
"git.makaay.nl/mauricem/go-parsekit/tokenize"
)
// Easy access to the parsekit.tokenize definitions.
var c, a, m, tok = tokenize.C, tokenize.A, tokenize.M, tokenize.T
type cmdType string
// Command types that are emitted by the parser.
const (
cComment cmdType = "comment" // a # comment at the end of the line
cKey = "key" // set key name
cNewKeyLvl = "keydot" // new key stack level
cAssign = "assign" // assign a value
csetStrVal = "string" // set a string value
)
type parser struct {
commands []cmd
keyStack []string
}
type cmd struct {
command cmdType
args []interface{}
}
func (cmd *cmd) String() string {
args := make([]string, len(cmd.args))
for i, arg := range cmd.args {
args[i] = fmt.Sprintf("%q", arg)
}
return fmt.Sprintf("%s(%s)", cmd.command, strings.Join(args, ", "))
}
func (p *parser) emitCommand(command cmdType, args ...interface{}) {
c := cmd{command: command, args: args}
p.commands = append(p.commands, c)
}
// Parse starts the parser for the provided input.
// func Parse(input interface{}) []cmd {
// p := &parser{}
// parse.New(p.startKeyValuePair)(input)
// return p.commands
// }