Uunexport methods which don’t need to be public
This commit is contained in:
parent
9bbbf4491a
commit
974f75eea0
24 changed files with 119 additions and 114 deletions
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseCond() (mul []Expr, err error) {
|
func (p *parser) parseCond() (mul []Expr, err error) {
|
||||||
|
|
||||||
var tok Token
|
var tok Token
|
||||||
var lit string
|
var lit string
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseCreateStatement(explain bool) (stmt *CreateStatement, err error) {
|
func (p *parser) parseCreateStatement(explain bool) (stmt *CreateStatement, err error) {
|
||||||
|
|
||||||
stmt = &CreateStatement{}
|
stmt = &CreateStatement{}
|
||||||
|
|
||||||
|
|
10
sql/data.go
10
sql/data.go
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseData() (exp []Expr, err error) {
|
func (p *parser) parseData() (exp []Expr, err error) {
|
||||||
|
|
||||||
if tok, _, exi := p.mightBe(SET, MERGE, CONTENT); exi {
|
if tok, _, exi := p.mightBe(SET, MERGE, CONTENT); exi {
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func (p *Parser) parseData() (exp []Expr, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseSet() (mul []Expr, err error) {
|
func (p *parser) parseSet() (mul []Expr, err error) {
|
||||||
|
|
||||||
var tok Token
|
var tok Token
|
||||||
var lit string
|
var lit string
|
||||||
|
@ -90,7 +90,7 @@ func (p *Parser) parseSet() (mul []Expr, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseDiff() (exp []Expr, err error) {
|
func (p *parser) parseDiff() (exp []Expr, err error) {
|
||||||
|
|
||||||
one := &DiffExpression{}
|
one := &DiffExpression{}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func (p *Parser) parseDiff() (exp []Expr, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseMerge() (exp []Expr, err error) {
|
func (p *parser) parseMerge() (exp []Expr, err error) {
|
||||||
|
|
||||||
one := &MergeExpression{}
|
one := &MergeExpression{}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func (p *Parser) parseMerge() (exp []Expr, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseContent() (exp []Expr, err error) {
|
func (p *parser) parseContent() (exp []Expr, err error) {
|
||||||
|
|
||||||
one := &ContentExpression{}
|
one := &ContentExpression{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDefineStatement(explain bool) (Statement, error) {
|
func (p *parser) parseDefineStatement(explain bool) (Statement, error) {
|
||||||
|
|
||||||
// Inspect the next token.
|
// Inspect the next token.
|
||||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDeleteStatement(explain bool) (stmt *DeleteStatement, err error) {
|
func (p *parser) parseDeleteStatement(explain bool) (stmt *DeleteStatement, err error) {
|
||||||
|
|
||||||
stmt = &DeleteStatement{}
|
stmt = &DeleteStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseEcho() (exp Token, err error) {
|
func (p *parser) parseEcho() (exp Token, err error) {
|
||||||
|
|
||||||
// Next token might be RETURN
|
// Next token might be RETURN
|
||||||
if _, _, exi := p.mightBe(RETURN); exi {
|
if _, _, exi := p.mightBe(RETURN); exi {
|
||||||
|
|
28
sql/exprs.go
28
sql/exprs.go
|
@ -18,9 +18,9 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Parser) parseName() (string, error) {
|
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(IDENT, NUMBER, DOUBLE, DATE, TIME)
|
_, lit, err := p.shouldBe(IDENT, NUMBER, DOUBLE, DATE, TIME)
|
||||||
|
func (p *parser) parseName() (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return string(""), &ParseError{Found: lit, Expected: []string{"name"}}
|
return string(""), &ParseError{Found: lit, Expected: []string{"name"}}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func (p *Parser) parseName() (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseNames() (mul []string, err error) {
|
func (p *parser) parseNames() (mul []string, err error) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func (p *Parser) parseNames() (mul []string, err error) {
|
||||||
//
|
//
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
func (p *Parser) parseIdent() (*Ident, error) {
|
func (p *parser) parseIdent() (*Ident, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(IDENT)
|
_, lit, err := p.shouldBe(IDENT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -70,7 +70,7 @@ func (p *Parser) parseIdent() (*Ident, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseThing() (*Thing, error) {
|
func (p *parser) parseThing() (*Thing, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(THING)
|
_, lit, err := p.shouldBe(THING)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -83,7 +83,7 @@ func (p *Parser) parseThing() (*Thing, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseArray() ([]interface{}, error) {
|
func (p *parser) parseArray() ([]interface{}, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(ARRAY)
|
_, lit, err := p.shouldBe(ARRAY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,7 +96,7 @@ func (p *Parser) parseArray() ([]interface{}, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseNumber() (int64, error) {
|
func (p *parser) parseNumber() (int64, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(NUMBER)
|
_, lit, err := p.shouldBe(NUMBER)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +109,7 @@ func (p *Parser) parseNumber() (int64, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseDouble() (float64, error) {
|
func (p *parser) parseDouble() (float64, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(NUMBER, DOUBLE)
|
_, lit, err := p.shouldBe(NUMBER, DOUBLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -122,7 +122,7 @@ func (p *Parser) parseDouble() (float64, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseString() (string, error) {
|
func (p *parser) parseString() (string, error) {
|
||||||
|
|
||||||
_, lit, err := p.shouldBe(STRING)
|
_, lit, err := p.shouldBe(STRING)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -135,7 +135,7 @@ func (p *Parser) parseString() (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRegion() (string, error) {
|
func (p *parser) parseRegion() (string, error) {
|
||||||
|
|
||||||
tok, lit, err := p.shouldBe(IDENT, STRING, REGION)
|
tok, lit, err := p.shouldBe(IDENT, STRING, REGION)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,7 +148,7 @@ func (p *Parser) parseRegion() (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseScript() (string, error) {
|
func (p *parser) parseScript() (string, error) {
|
||||||
|
|
||||||
tok, lit, err := p.shouldBe(STRING, REGION)
|
tok, lit, err := p.shouldBe(STRING, REGION)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -161,7 +161,7 @@ func (p *Parser) parseScript() (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRegexp() (string, error) {
|
func (p *parser) parseRegexp() (string, error) {
|
||||||
|
|
||||||
tok, lit, err := p.shouldBe(REGEX)
|
tok, lit, err := p.shouldBe(REGEX)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -174,7 +174,7 @@ func (p *Parser) parseRegexp() (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseBoolean() (bool, error) {
|
func (p *parser) parseBoolean() (bool, error) {
|
||||||
|
|
||||||
tok, lit, err := p.shouldBe(TRUE, FALSE)
|
tok, lit, err := p.shouldBe(TRUE, FALSE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -187,7 +187,7 @@ func (p *Parser) parseBoolean() (bool, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseDefault() (interface{}, error) {
|
func (p *parser) parseDefault() (interface{}, error) {
|
||||||
|
|
||||||
tok, lit, err := p.shouldBe(NULL, NOW, DATE, TIME, TRUE, FALSE, NUMBER, DOUBLE, STRING, REGION, IDENT, ARRAY, JSON)
|
tok, lit, err := p.shouldBe(NULL, NOW, DATE, TIME, TRUE, FALSE, NUMBER, DOUBLE, STRING, REGION, IDENT, ARRAY, JSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -198,7 +198,7 @@ func (p *Parser) parseDefault() (interface{}, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseExpr() (mul []*Field, err error) {
|
func (p *parser) parseExpr() (mul []*Field, err error) {
|
||||||
|
|
||||||
var tok Token
|
var tok Token
|
||||||
var lit string
|
var lit string
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldStatement, err error) {
|
func (p *parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldStatement, err error) {
|
||||||
|
|
||||||
stmt = &DefineFieldStatement{}
|
stmt = &DefineFieldStatement{}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func (p *Parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldState
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRemoveFieldStatement(explain bool) (stmt *RemoveFieldStatement, err error) {
|
func (p *parser) parseRemoveFieldStatement(explain bool) (stmt *RemoveFieldStatement, err error) {
|
||||||
|
|
||||||
stmt = &RemoveFieldStatement{}
|
stmt = &RemoveFieldStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexStatement, err error) {
|
func (p *parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexStatement, err error) {
|
||||||
|
|
||||||
stmt = &DefineIndexStatement{}
|
stmt = &DefineIndexStatement{}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func (p *Parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexState
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRemoveIndexStatement(explain bool) (stmt *RemoveIndexStatement, err error) {
|
func (p *parser) parseRemoveIndexStatement(explain bool) (stmt *RemoveIndexStatement, err error) {
|
||||||
|
|
||||||
stmt = &RemoveIndexStatement{}
|
stmt = &RemoveIndexStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err error) {
|
func (p *parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err error) {
|
||||||
|
|
||||||
stmt = &ModifyStatement{}
|
stmt = &ModifyStatement{}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ import (
|
||||||
"github.com/abcum/fibre"
|
"github.com/abcum/fibre"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parser represents a parser.
|
// parser represents a parser.
|
||||||
type Parser struct {
|
type parser struct {
|
||||||
s *Scanner
|
s *scanner
|
||||||
c *fibre.Context
|
c *fibre.Context
|
||||||
v map[string]interface{}
|
v map[string]interface{}
|
||||||
buf struct {
|
buf struct {
|
||||||
|
@ -35,50 +35,55 @@ type Parser struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newParser returns a new instance of Parser.
|
||||||
|
func newParser(c *fibre.Context, v map[string]interface{}) *parser {
|
||||||
|
return &parser{c: c, v: v}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse parses sql from a []byte, string, or io.Reader.
|
// Parse parses sql from a []byte, string, or io.Reader.
|
||||||
func Parse(ctx *fibre.Context, i interface{}) (*Query, error) {
|
func Parse(c *fibre.Context, i interface{}, v map[string]interface{}) (*Query, error) {
|
||||||
switch v := i.(type) {
|
switch x := i.(type) {
|
||||||
default:
|
default:
|
||||||
return nil, &EmptyError{}
|
return nil, &EmptyError{}
|
||||||
case []byte:
|
case []byte:
|
||||||
return ParseBytes(ctx, v)
|
return parseBytes(c, x, v)
|
||||||
case string:
|
case string:
|
||||||
return ParseString(ctx, v)
|
return parseString(c, x, v)
|
||||||
case io.Reader:
|
case io.Reader:
|
||||||
return ParseBuffer(ctx, v)
|
return parseBuffer(c, x, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseBytes parses a byte array.
|
// parseBytes parses a byte array.
|
||||||
func ParseBytes(ctx *fibre.Context, i []byte) (*Query, error) {
|
func parseBytes(c *fibre.Context, i []byte, v map[string]interface{}) (*Query, error) {
|
||||||
r := bytes.NewReader(i)
|
r := bytes.NewReader(i)
|
||||||
p := &Parser{c: ctx}
|
p := newParser(c, v)
|
||||||
p.s = NewScanner(p, r)
|
p.s = newScanner(p, r)
|
||||||
return p.Parse()
|
return p.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseString parses a string.
|
// parseString parses a string.
|
||||||
func ParseString(ctx *fibre.Context, i string) (*Query, error) {
|
func parseString(c *fibre.Context, i string, v map[string]interface{}) (*Query, error) {
|
||||||
r := strings.NewReader(i)
|
r := strings.NewReader(i)
|
||||||
p := &Parser{c: ctx}
|
p := newParser(c, v)
|
||||||
p.s = NewScanner(p, r)
|
p.s = newScanner(p, r)
|
||||||
return p.Parse()
|
return p.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseBuffer parses a buffer.
|
// parseBuffer parses a buffer.
|
||||||
func ParseBuffer(ctx *fibre.Context, r io.Reader) (*Query, error) {
|
func parseBuffer(c *fibre.Context, r io.Reader, v map[string]interface{}) (*Query, error) {
|
||||||
p := &Parser{c: ctx}
|
p := newParser(c, v)
|
||||||
p.s = NewScanner(p, r)
|
p.s = newScanner(p, r)
|
||||||
return p.Parse()
|
return p.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses single or multiple SQL queries.
|
// parse parses single or multiple SQL queries.
|
||||||
func (p *Parser) Parse() (*Query, error) {
|
func (p *parser) parse() (*Query, error) {
|
||||||
return p.ParseMulti()
|
return p.parseMulti()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMulti parses multiple SQL SELECT statements.
|
// parseMulti parses multiple SQL SELECT statements.
|
||||||
func (p *Parser) ParseMulti() (*Query, error) {
|
func (p *parser) parseMulti() (*Query, error) {
|
||||||
|
|
||||||
var statements Statements
|
var statements Statements
|
||||||
|
|
||||||
|
@ -96,7 +101,7 @@ func (p *Parser) ParseMulti() (*Query, error) {
|
||||||
} else {
|
} else {
|
||||||
text = true
|
text = true
|
||||||
p.unscan()
|
p.unscan()
|
||||||
s, err := p.ParseSingle()
|
s, err := p.parseSingle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -107,8 +112,8 @@ func (p *Parser) ParseMulti() (*Query, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseSingle parses a single SQL SELECT statement.
|
// parseSingle parses a single SQL SELECT statement.
|
||||||
func (p *Parser) ParseSingle() (Statement, error) {
|
func (p *parser) parseSingle() (Statement, error) {
|
||||||
|
|
||||||
var explain bool
|
var explain bool
|
||||||
|
|
||||||
|
@ -157,7 +162,7 @@ func (p *Parser) ParseSingle() (Statement, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) mightBe(expected ...Token) (tok Token, lit string, found bool) {
|
func (p *parser) mightBe(expected ...Token) (tok Token, lit string, found bool) {
|
||||||
|
|
||||||
tok, lit, _ = p.scan()
|
tok, lit, _ = p.scan()
|
||||||
|
|
||||||
|
@ -169,7 +174,7 @@ func (p *Parser) mightBe(expected ...Token) (tok Token, lit string, found bool)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) shouldBe(expected ...Token) (tok Token, lit string, err error) {
|
func (p *parser) shouldBe(expected ...Token) (tok Token, lit string, err error) {
|
||||||
|
|
||||||
tok, lit, _ = p.scan()
|
tok, lit, _ = p.scan()
|
||||||
|
|
||||||
|
@ -183,7 +188,7 @@ func (p *Parser) shouldBe(expected ...Token) (tok Token, lit string, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// scan scans the next non-whitespace token.
|
// scan scans the next non-whitespace token.
|
||||||
func (p *Parser) scan() (tok Token, lit string, val interface{}) {
|
func (p *parser) scan() (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok, lit, val = p.seek()
|
tok, lit, val = p.seek()
|
||||||
|
|
||||||
|
@ -199,7 +204,7 @@ func (p *Parser) scan() (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) hold(tok Token) (val interface{}) {
|
func (p *parser) hold(tok Token) (val interface{}) {
|
||||||
if tok == p.buf.tok {
|
if tok == p.buf.tok {
|
||||||
return p.buf.val
|
return p.buf.val
|
||||||
}
|
}
|
||||||
|
@ -208,7 +213,7 @@ func (p *Parser) hold(tok Token) (val interface{}) {
|
||||||
|
|
||||||
// seek returns the next token from the underlying scanner.
|
// seek returns the next token from the underlying scanner.
|
||||||
// If a token has been unscanned then read that instead.
|
// If a token has been unscanned then read that instead.
|
||||||
func (p *Parser) seek() (tok Token, lit string, val interface{}) {
|
func (p *parser) seek() (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
// If we have a token on the buffer, then return it.
|
// If we have a token on the buffer, then return it.
|
||||||
if p.buf.n != 0 {
|
if p.buf.n != 0 {
|
||||||
|
@ -217,7 +222,7 @@ func (p *Parser) seek() (tok Token, lit string, val interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise read the next token from the scanner.
|
// Otherwise read the next token from the scanner.
|
||||||
tok, lit, val = p.s.Scan()
|
tok, lit, val = p.s.scan()
|
||||||
|
|
||||||
// Save it to the buffer in case we unscan later.
|
// Save it to the buffer in case we unscan later.
|
||||||
p.buf.tok, p.buf.lit, p.buf.val = tok, lit, val
|
p.buf.tok, p.buf.lit, p.buf.val = tok, lit, val
|
||||||
|
@ -227,6 +232,6 @@ func (p *Parser) seek() (tok Token, lit string, val interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unscan pushes the previously read token back onto the buffer.
|
// unscan pushes the previously read token back onto the buffer.
|
||||||
func (p *Parser) unscan() {
|
func (p *parser) unscan() {
|
||||||
p.buf.n = 1
|
p.buf.n = 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseRecordStatement(explain bool) (stmt *RecordStatement, err error) {
|
func (p *parser) parseRecordStatement(explain bool) (stmt *RecordStatement, err error) {
|
||||||
|
|
||||||
stmt = &RecordStatement{}
|
stmt = &RecordStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseRelateStatement(explain bool) (stmt *RelateStatement, err error) {
|
func (p *parser) parseRelateStatement(explain bool) (stmt *RelateStatement, err error) {
|
||||||
|
|
||||||
stmt = &RelateStatement{}
|
stmt = &RelateStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseRemoveStatement(explain bool) (Statement, error) {
|
func (p *parser) parseRemoveStatement(explain bool) (Statement, error) {
|
||||||
|
|
||||||
// Inspect the next token.
|
// Inspect the next token.
|
||||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
|
func (p *parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
|
||||||
|
|
||||||
stmt = &DefineRulesStatement{}
|
stmt = &DefineRulesStatement{}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (p *Parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesState
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRemoveRulesStatement(explain bool) (stmt *RemoveRulesStatement, err error) {
|
func (p *parser) parseRemoveRulesStatement(explain bool) (stmt *RemoveRulesStatement, err error) {
|
||||||
|
|
||||||
stmt = &RemoveRulesStatement{}
|
stmt = &RemoveRulesStatement{}
|
||||||
|
|
||||||
|
|
|
@ -23,21 +23,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Scanner represents a lexical scanner.
|
// scanner represents a lexical scanner.
|
||||||
type Scanner struct {
|
type scanner struct {
|
||||||
b []rune // any runes before
|
b []rune // any runes before
|
||||||
a []rune // any runes after
|
a []rune // any runes after
|
||||||
p *Parser
|
p *parser
|
||||||
r *bufio.Reader
|
r *bufio.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewScanner returns a new instance of Scanner.
|
// newScanner returns a new instance of Scanner.
|
||||||
func NewScanner(p *Parser, r io.Reader) *Scanner {
|
func newScanner(p *parser, r io.Reader) *scanner {
|
||||||
return &Scanner{p: p, r: bufio.NewReader(r)}
|
return &scanner{p: p, r: bufio.NewReader(r)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan returns the next token and literal value.
|
// scan returns the next token and literal value.
|
||||||
func (s *Scanner) Scan() (tok Token, lit string, val interface{}) {
|
func (s *scanner) scan() (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
// Read the next rune.
|
// Read the next rune.
|
||||||
ch := s.next()
|
ch := s.next()
|
||||||
|
@ -236,7 +236,7 @@ func (s *Scanner) Scan() (tok Token, lit string, val interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanBlank consumes the current rune and all contiguous whitespace.
|
// scanBlank consumes the current rune and all contiguous whitespace.
|
||||||
func (s *Scanner) scanBlank(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanBlank(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = WS
|
tok = WS
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ func (s *Scanner) scanBlank(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanCommentSingle consumes the current rune and all contiguous whitespace.
|
// scanCommentSingle consumes the current rune and all contiguous whitespace.
|
||||||
func (s *Scanner) scanCommentSingle(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanCommentSingle(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = WS
|
tok = WS
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ func (s *Scanner) scanCommentSingle(chp ...rune) (tok Token, lit string, val int
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanCommentMultiple consumes the current rune and all contiguous whitespace.
|
// scanCommentMultiple consumes the current rune and all contiguous whitespace.
|
||||||
func (s *Scanner) scanCommentMultiple(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanCommentMultiple(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = WS
|
tok = WS
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ func (s *Scanner) scanCommentMultiple(chp ...rune) (tok Token, lit string, val i
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scanParams(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanParams(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok, lit, val = s.scanIdent(chp...)
|
tok, lit, val = s.scanIdent(chp...)
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ func (s *Scanner) scanParams(chp ...rune) (tok Token, lit string, val interface{
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanIdent consumes the current rune and all contiguous ident runes.
|
// scanIdent consumes the current rune and all contiguous ident runes.
|
||||||
func (s *Scanner) scanIdent(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanIdent(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = IDENT
|
tok = IDENT
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ func (s *Scanner) scanIdent(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanThing consumes the current rune and all contiguous ident runes.
|
// scanThing consumes the current rune and all contiguous ident runes.
|
||||||
func (s *Scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = THING
|
tok = THING
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ func (s *Scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scanNumber(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanNumber(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = NUMBER
|
tok = NUMBER
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ func (s *Scanner) scanQuoted(chp ...rune) (tok Token, lit string, val interface{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scanString(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanString(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
beg := chp[0]
|
beg := chp[0]
|
||||||
end := beg
|
end := beg
|
||||||
|
@ -613,7 +613,7 @@ func (s *Scanner) scanString(chp ...rune) (tok Token, lit string, val interface{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scanRegexp(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanRegexp(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
tok = IDENT
|
tok = IDENT
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ func (s *Scanner) scanRegexp(chp ...rune) (tok Token, lit string, val interface{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) scanObject(chp ...rune) (tok Token, lit string, val interface{}) {
|
func (s *scanner) scanObject(chp ...rune) (tok Token, lit string, val interface{}) {
|
||||||
|
|
||||||
beg := chp[0]
|
beg := chp[0]
|
||||||
end := beg
|
end := beg
|
||||||
|
@ -708,7 +708,7 @@ func (s *Scanner) scanObject(chp ...rune) (tok Token, lit string, val interface{
|
||||||
|
|
||||||
// next reads the next rune from the bufferred reader.
|
// next reads the next rune from the bufferred reader.
|
||||||
// Returns the rune(0) if an error occurs (or io.EOF is returned).
|
// Returns the rune(0) if an error occurs (or io.EOF is returned).
|
||||||
func (s *Scanner) next() rune {
|
func (s *scanner) next() rune {
|
||||||
|
|
||||||
if len(s.a) > 0 {
|
if len(s.a) > 0 {
|
||||||
var r rune
|
var r rune
|
||||||
|
@ -727,7 +727,7 @@ func (s *Scanner) next() rune {
|
||||||
}
|
}
|
||||||
|
|
||||||
// undo places the previously read rune back on the reader.
|
// undo places the previously read rune back on the reader.
|
||||||
func (s *Scanner) undo() {
|
func (s *scanner) undo() {
|
||||||
|
|
||||||
if len(s.b) > 0 {
|
if len(s.b) > 0 {
|
||||||
var r rune
|
var r rune
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err error) {
|
func (p *parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err error) {
|
||||||
|
|
||||||
stmt = &SelectStatement{}
|
stmt = &SelectStatement{}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ func (p *Parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseGroup() (mul []*Group, err error) {
|
func (p *parser) parseGroup() (mul []*Group, err error) {
|
||||||
|
|
||||||
// Remove the GROUP keyword
|
// Remove the GROUP keyword
|
||||||
if _, _, exi := p.mightBe(GROUP); !exi {
|
if _, _, exi := p.mightBe(GROUP); !exi {
|
||||||
|
@ -87,7 +87,7 @@ func (p *Parser) parseGroup() (mul []*Group, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseOrder() (mul []*Order, err error) {
|
func (p *parser) parseOrder() (mul []*Order, err error) {
|
||||||
|
|
||||||
var tok Token
|
var tok Token
|
||||||
var lit string
|
var lit string
|
||||||
|
@ -138,7 +138,7 @@ func (p *Parser) parseOrder() (mul []*Order, err error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseLimit() (Expr, error) {
|
func (p *parser) parseLimit() (Expr, error) {
|
||||||
|
|
||||||
// Remove the LIMIT keyword
|
// Remove the LIMIT keyword
|
||||||
if _, _, exi := p.mightBe(LIMIT); !exi {
|
if _, _, exi := p.mightBe(LIMIT); !exi {
|
||||||
|
@ -157,7 +157,7 @@ func (p *Parser) parseLimit() (Expr, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseStart() (Expr, error) {
|
func (p *parser) parseStart() (Expr, error) {
|
||||||
|
|
||||||
// Remove the START keyword
|
// Remove the START keyword
|
||||||
if _, _, exi := p.mightBe(START); !exi {
|
if _, _, exi := p.mightBe(START); !exi {
|
||||||
|
@ -191,7 +191,7 @@ func (p *Parser) parseStart() (Expr, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseVersion() (Expr, error) {
|
func (p *parser) parseVersion() (Expr, error) {
|
||||||
|
|
||||||
// Remove the VERSION keyword
|
// Remove the VERSION keyword
|
||||||
if _, _, exi := p.mightBe(VERSION); !exi {
|
if _, _, exi := p.mightBe(VERSION); !exi {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func testsql(t *testing.T, test tester) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s, e := ParseString(c, test.sql)
|
s, e := Parse(c, test.sql, nil)
|
||||||
|
|
||||||
Convey(test.sql, t, func() {
|
Convey(test.sql, t, func() {
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func TestMain(t *testing.T) {
|
||||||
func Test_Parse_General(t *testing.T) {
|
func Test_Parse_General(t *testing.T) {
|
||||||
|
|
||||||
s := `SELECT a FROM b`
|
s := `SELECT a FROM b`
|
||||||
q, err := ParseString(c, s)
|
q, err := Parse(c, s, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
@ -91,7 +91,7 @@ func Test_Parse_General(t *testing.T) {
|
||||||
func Test_Parse_General_Single(t *testing.T) {
|
func Test_Parse_General_Single(t *testing.T) {
|
||||||
|
|
||||||
s := `SELECT a FROM b`
|
s := `SELECT a FROM b`
|
||||||
q, err := ParseString(c, s)
|
q, err := Parse(c, s, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
@ -105,7 +105,7 @@ func Test_Parse_General_Single(t *testing.T) {
|
||||||
func Test_Parse_General_Multi(t *testing.T) {
|
func Test_Parse_General_Multi(t *testing.T) {
|
||||||
|
|
||||||
s := `SELECT a FROM b; SELECT c FROM d`
|
s := `SELECT a FROM b; SELECT c FROM d`
|
||||||
q, err := ParseString(c, s)
|
q, err := Parse(c, s, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseDefineTableStatement(explain bool) (stmt *DefineTableStatement, err error) {
|
func (p *parser) parseDefineTableStatement(explain bool) (stmt *DefineTableStatement, err error) {
|
||||||
|
|
||||||
stmt = &DefineTableStatement{}
|
stmt = &DefineTableStatement{}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func (p *Parser) parseDefineTableStatement(explain bool) (stmt *DefineTableState
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseRemoveTableStatement(explain bool) (stmt *RemoveTableStatement, err error) {
|
func (p *parser) parseRemoveTableStatement(explain bool) (stmt *RemoveTableStatement, err error) {
|
||||||
|
|
||||||
stmt = &RemoveTableStatement{}
|
stmt = &RemoveTableStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err error) {
|
func (p *parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err error) {
|
||||||
|
|
||||||
stmt = &BeginStatement{}
|
stmt = &BeginStatement{}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func (p *Parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err er
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseCancelStatement(explain bool) (stmt *CancelStatement, err error) {
|
func (p *parser) parseCancelStatement(explain bool) (stmt *CancelStatement, err error) {
|
||||||
|
|
||||||
stmt = &CancelStatement{}
|
stmt = &CancelStatement{}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func (p *Parser) parseCancelStatement(explain bool) (stmt *CancelStatement, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) parseCommitStatement(explain bool) (stmt *CommitStatement, err error) {
|
func (p *parser) parseCommitStatement(explain bool) (stmt *CommitStatement, err error) {
|
||||||
|
|
||||||
stmt = &CommitStatement{}
|
stmt = &CommitStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseType() (exp string, err error) {
|
func (p *parser) parseType() (exp string, err error) {
|
||||||
|
|
||||||
allowed := []string{"any", "url", "uuid", "color", "email", "phone", "array", "object", "domain", "string", "number", "custom", "boolean", "datetime", "latitude", "longitude"}
|
allowed := []string{"any", "url", "uuid", "color", "email", "phone", "array", "object", "domain", "string", "number", "custom", "boolean", "datetime", "latitude", "longitude"}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseUpdateStatement(explain bool) (stmt *UpdateStatement, err error) {
|
func (p *parser) parseUpdateStatement(explain bool) (stmt *UpdateStatement, err error) {
|
||||||
|
|
||||||
stmt = &UpdateStatement{}
|
stmt = &UpdateStatement{}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
func (p *Parser) parseUseStatement(explain bool) (stmt *UseStatement, err error) {
|
func (p *parser) parseUseStatement(explain bool) (stmt *UseStatement, err error) {
|
||||||
|
|
||||||
stmt = &UseStatement{}
|
stmt = &UseStatement{}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Parser) in(token Token, tokens []Token) bool {
|
func (p *parser) in(token Token, tokens []Token) bool {
|
||||||
|
|
||||||
for _, t := range tokens {
|
for _, t := range tokens {
|
||||||
if token == t {
|
if token == t {
|
||||||
|
@ -34,7 +34,7 @@ func (p *Parser) in(token Token, tokens []Token) bool {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) is(token Token, tokens ...Token) bool {
|
func (p *parser) is(token Token, tokens ...Token) bool {
|
||||||
|
|
||||||
for _, t := range tokens {
|
for _, t := range tokens {
|
||||||
if token == t {
|
if token == t {
|
||||||
|
@ -46,7 +46,7 @@ func (p *Parser) is(token Token, tokens ...Token) bool {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) contains(search string, strings []string) bool {
|
func (p *parser) contains(search string, strings []string) bool {
|
||||||
|
|
||||||
for _, str := range strings {
|
for _, str := range strings {
|
||||||
if str == search {
|
if str == search {
|
||||||
|
@ -58,7 +58,7 @@ func (p *Parser) contains(search string, strings []string) bool {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) declare(tok Token, lit string) (interface{}, error) {
|
func (p *parser) declare(tok Token, lit string) (interface{}, error) {
|
||||||
|
|
||||||
if val := p.hold(tok); val != nil {
|
if val := p.hold(tok); val != nil {
|
||||||
return val, nil
|
return val, nil
|
||||||
|
|
Loading…
Reference in a new issue