func lexSection(l *lex.Lexer) lex.StateFn { for { switch l.Next() { case lex.EOF: return l.Errorf("Unexpected EOF in section") case '\n': return l.Errorf("Section: Missing right bracket") case rightBracket: l.Backup() l.Emit(tSection) return lexRightBracket } } }
func lexKey(l *lex.Lexer) lex.StateFn { for { switch l.Next() { case lex.EOF: return l.Errorf("Unexpected EOF") case equalSign: if l.Pos > l.Start { l.Backup() l.Emit(tKey) return lexEqualSign } return l.Errorf("Unexpected equal sign") } } }
func lexStart(l *lex.Lexer) lex.StateFn { l.AcceptWhitespace(lex.Ignore) r := l.Next() switch r { case lex.EOF: l.Emit(lex.TEOF) return nil case leftBracket: l.Backup() return lexLeftBracket default: if lex.IsAlphaNumeric(r) { return lexKey } return l.Errorf("Unknown charecter: %v", string(r)) } }
func lexValue(l *lex.Lexer) lex.StateFn { for { switch l.Next() { case lex.EOF: if l.Pos > l.Start { l.Backup() l.Emit(tValue) l.Emit(lex.TEOF) return nil } return l.Errorf("Unexpected equal sign") case '\n': l.Backup() l.Emit(tValue) l.Next(lex.Ignore) return lexStart } } }