Exemplo n.º 1
0
func textState(l *lexer.Lexer) lexer.StateFunc {
	l.NextUpTo(func(r rune) bool {
		return variable(r) || assignment(r) || comma(r) || whitespace(r)
	})
	l.Emit(TokenText)
	return initialState
}
Exemplo n.º 2
0
func initialState(l *lexer.Lexer) lexer.StateFunc {
	r := l.IgnoreUpTo(func(r rune) bool {
		return variable(r) || assignment(r) || comma(r) || nonWhitespace(r)
	})
	switch {
	case variable(r):
		return variableState
	case assignment(r):
		return assignmentState
	case comma(r):
		return commaState
	case nonWhitespace(r) && r != lexer.EOF:
		return textState
	}
	l.Emit(TokenEOF)
	return nil
}
Exemplo n.º 3
0
func commaState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.Emit(TokenComma)
	return initialState
}
Exemplo n.º 4
0
func assignmentState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.Emit(TokenAssignment)
	return initialState
}
Exemplo n.º 5
0
func variableState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.NextUpTo(nonAlphanumeric)
	l.Emit(TokenVariable)
	return initialState
}