Cleanup parser statements, add delete and insert statement, add TASKS.md for tracking tasks
This commit is contained in:
47
sql/parseSelectStatement.go
Normal file
47
sql/parseSelectStatement.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package sql
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (p *Parser) parseSelect() (*SelectStatement, error) {
|
||||
tok, ok := p.expectOne(ASTERIKS, IDENT)
|
||||
if !ok {
|
||||
return nil, p.unexpectedToken(ASTERIKS, IDENT)
|
||||
}
|
||||
|
||||
fields := make([]string, 1)
|
||||
fields[0] = "*"
|
||||
if tok == IDENT {
|
||||
_, _, n := p.rescan()
|
||||
fields[0] = n
|
||||
for {
|
||||
tok, ok := p.expectOne(COMMA, FROM)
|
||||
if !ok {
|
||||
return nil, p.unexpectedToken(COMMA, FROM)
|
||||
}
|
||||
if tok == FROM {
|
||||
p.unscan()
|
||||
break
|
||||
}
|
||||
|
||||
if !p.expectNext(IDENT) {
|
||||
return nil, p.unexpectedToken(IDENT)
|
||||
}
|
||||
_, _, n := p.rescan()
|
||||
fields = append(fields, n)
|
||||
}
|
||||
}
|
||||
|
||||
if !p.expectSequence(FROM, IDENT) {
|
||||
return nil, p.unexpectedToken()
|
||||
}
|
||||
|
||||
_, _, tableName := p.rescan()
|
||||
if !p.consumeUntilOne(50, SEMI, EOF) {
|
||||
return nil, fmt.Errorf("Expected semicolon but never found after 50 tries")
|
||||
}
|
||||
|
||||
return &SelectStatement{
|
||||
From: tableName,
|
||||
Fields: fields,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user