func ParseTransitionDirective(config string, callbacks map[string]ParsedFunc) (TransitionDirective, error) {
	escape := strings.NewReplacer("\\n", "\n", "\\r", "\r", "\\t", "\t", "\\:", "\b")
	restore := strings.NewReplacer("\b", ":")
	tokens := strings.Split(escape.Replace(config), ":")
	if len(tokens) != 5 {
		return TransitionDirective{}, fmt.Errorf("Parser directive requires 5 tokens.")
	}
	for i, token := range tokens {
		tokens[i] = restore.Replace(token)
	}
	flags := ParserFlag(0)
	flagStrings := strings.Split(tokens[3], ",")
	for _, flagName := range flagStrings {
		switch strings.ToLower(strings.TrimSpace(flagName)) {
		case "continue":
			flags |= ParserFlagContinue
		case "append":
			flags |= ParserFlagAppend
		case "include":
			flags |= ParserFlagInclude
		case "push":
			flags |= ParserFlagPush
		case "pop":
			flags |= ParserFlagPop
		}
	}
	callback, _ := callbacks[strings.TrimSpace(tokens[4])]
	dir := TransitionDirective{
		State:     strings.TrimSpace(tokens[0]),
		Token:     tokens[1],
		NextState: strings.TrimSpace(tokens[2]),
		Flags:     flags,
		Callback:  callback,
	}
	return dir, nil
}
ParseTransitionDirective creates a transition directive from a string.
This string must be of the following format:

State:Token:NextState:Flag,Flag,...:Function

Spaces will be stripped from all fields but Token. If a fields requires a
colon it has to be escaped with a backslash. Other escape characters
supported are \n, \r and \t.
Flag can be a set of the
following flags (input will be converted to lowercase):

* continue -> ParserFlagContinue
* append   -> ParserFlagAppend
* include  -> ParserFlagInclude
* push     -> ParserFlagPush
* pop      -> ParserFlagPop

The name passed to the function token must be in the callbacks map. If it is
not the data of the token will not be written. I.e. in empty string equals
"do not write" here.
An empty NextState will be translated to the "Stop" state as ususal.
package tstrings
import (
	"fmt"
	"github.com/trivago/tgo/tcontainer"
	"strings"
)
type ParserFlag int
type ParserStateID uint32
type ParsedFunc func([]byte, ParserStateID)
const (
	ParserFlagContinue = ParserFlag(1 << iota)
	ParserFlagAppend = ParserFlag(1 << iota)
	ParserFlagInclude = ParserFlag(1 << iota)
	ParserFlagPush = ParserFlag(1 << iota)
	ParserFlagPop = ParserFlag(1 << iota)
	ParserStateStop = ParserStateID(0xFFFFFFFF)
)
type Transition struct {
	nextState ParserStateID
	flags     ParserFlag
	callback  ParsedFunc
}
type TransitionDirective struct {
	State     string
	Token     string
	NextState string
	Flags     ParserFlag
	Callback  ParsedFunc
}
type TransitionParser struct {
	lookup []string
	tokens []*tcontainer.TrieNode
	stack  []ParserStateID
}
func NewTransition(nextState ParserStateID, flags ParserFlag, callback ParsedFunc) Transition {
	return Transition{
		nextState: nextState,
		flags:     flags,
		callback:  callback,
	}
}
func NewTransitionParser() TransitionParser {
	return TransitionParser{
		lookup: []string{},
		tokens: []*tcontainer.TrieNode{},
		stack:  []ParserStateID{},
	}
}