package parser import "git.makaay.nl/mauricem/go-parsekit" // Item types that are produced by this parser. const ( ItemComment parsekit.ItemType = iota // Comment string ItemKey // Key of a key/value pair ItemKeyDot // Dot for a dotted key ItemAssignment // Value assignment coming up (=) ItemString // A value of type string ) var ( c = parsekit.C space = parsekit.MatchRune(' ') tab = parsekit.MatchRune('\t') carriageReturn = parsekit.MatchRune('\r') lineFeed = parsekit.MatchRune('\n') hash = parsekit.MatchRune('#') underscore = parsekit.MatchRune('_') dash = parsekit.MatchRune('-') equal = parsekit.MatchRune('=') dot = parsekit.MatchRune('.') singleQuote = parsekit.MatchRune('\'') doubleQuote = parsekit.MatchRune('"') anyRune = c.AnyRune() anyQuote = c.AnyOf(singleQuote, doubleQuote) backslash = parsekit.MatchRune('\\') asciiLower = c.RuneRange('a', 'z') asciiUpper = c.RuneRange('A', 'Z') digit = c.RuneRange('0', '9') whitespace = c.OneOrMore(c.AnyOf(space, tab)) whitespaceOrNewlines = c.OneOrMore(c.AnyOf(space, tab, carriageReturn, lineFeed)) optionalWhitespace = c.Optional(whitespace) endOfLine = c.AnyOf(lineFeed, c.EndOfFile()) ) // NewParser creates a new parser, using the provided input string // as the data to parse. func NewParser(input string) *parsekit.P { return parsekit.New(input, startKeyValuePair) }