Пример #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
}
Пример #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
}
Пример #3
0
func commaState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.Emit(TokenComma)
	return initialState
}
Пример #4
0
func assignmentState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.Emit(TokenAssignment)
	return initialState
}
Пример #5
0
func variableState(l *lexer.Lexer) lexer.StateFunc {
	l.Ignore()
	l.NextUpTo(nonAlphanumeric)
	l.Emit(TokenVariable)
	return initialState
}