mirror of
https://github.com/minio/minio.git
synced 2024-12-31 17:43:21 -05:00
2786055df4
- New parser written from scratch, allows easier and complete parsing of the full S3 Select SQL syntax. Parser definition is directly provided by the AST defined for the SQL grammar. - Bring support to parse and interpret SQL involving JSON path expressions; evaluation of JSON path expressions will be subsequently added. - Bring automatic type inference and conversion for untyped values (e.g. CSV data).
38 lines
695 B
Go
38 lines
695 B
Go
package lexer
|
|
|
|
// Upgrade a Lexer to a PeekingLexer with arbitrary lookahead.
|
|
func Upgrade(lexer Lexer) PeekingLexer {
|
|
if peeking, ok := lexer.(PeekingLexer); ok {
|
|
return peeking
|
|
}
|
|
return &lookaheadLexer{Lexer: lexer}
|
|
}
|
|
|
|
type lookaheadLexer struct {
|
|
Lexer
|
|
peeked []Token
|
|
}
|
|
|
|
func (l *lookaheadLexer) Peek(n int) (Token, error) {
|
|
for len(l.peeked) <= n {
|
|
t, err := l.Lexer.Next()
|
|
if err != nil {
|
|
return Token{}, err
|
|
}
|
|
if t.EOF() {
|
|
return t, nil
|
|
}
|
|
l.peeked = append(l.peeked, t)
|
|
}
|
|
return l.peeked[n], nil
|
|
}
|
|
|
|
func (l *lookaheadLexer) Next() (Token, error) {
|
|
if len(l.peeked) > 0 {
|
|
t := l.peeked[0]
|
|
l.peeked = l.peeked[1:]
|
|
return t, nil
|
|
}
|
|
return l.Lexer.Next()
|
|
}
|