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
|
||||
|
||||
func (p *Parser) parseCond() (mul []Expr, err error) {
|
||||
func (p *parser) parseCond() (mul []Expr, err error) {
|
||||
|
||||
var tok Token
|
||||
var lit string
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseCreateStatement(explain bool) (stmt *CreateStatement, err error) {
|
||||
func (p *parser) parseCreateStatement(explain bool) (stmt *CreateStatement, err error) {
|
||||
|
||||
stmt = &CreateStatement{}
|
||||
|
||||
|
|
10
sql/data.go
10
sql/data.go
|
@ -14,7 +14,7 @@
|
|||
|
||||
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 {
|
||||
|
||||
|
@ -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 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{}
|
||||
|
||||
|
@ -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{}
|
||||
|
||||
|
@ -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{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineStatement(explain bool) (Statement, error) {
|
||||
func (p *parser) parseDefineStatement(explain bool) (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDeleteStatement(explain bool) (stmt *DeleteStatement, err error) {
|
||||
func (p *parser) parseDeleteStatement(explain bool) (stmt *DeleteStatement, err error) {
|
||||
|
||||
stmt = &DeleteStatement{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseEcho() (exp Token, err error) {
|
||||
func (p *parser) parseEcho() (exp Token, err error) {
|
||||
|
||||
// Next token might be RETURN
|
||||
if _, _, exi := p.mightBe(RETURN); exi {
|
||||
|
|
28
sql/exprs.go
28
sql/exprs.go
|
@ -18,9 +18,9 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
func (p *Parser) parseName() (string, error) {
|
||||
|
||||
_, lit, err := p.shouldBe(IDENT, NUMBER, DOUBLE, DATE, TIME)
|
||||
func (p *parser) parseName() (string, error) {
|
||||
if err != nil {
|
||||
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 {
|
||||
|
||||
|
@ -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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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 lit string
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldStatement, err error) {
|
||||
func (p *parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldStatement, err error) {
|
||||
|
||||
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{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexStatement, err error) {
|
||||
func (p *parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexStatement, err error) {
|
||||
|
||||
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{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err error) {
|
||||
func (p *parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err error) {
|
||||
|
||||
stmt = &ModifyStatement{}
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ import (
|
|||
"github.com/abcum/fibre"
|
||||
)
|
||||
|
||||
// Parser represents a parser.
|
||||
type Parser struct {
|
||||
s *Scanner
|
||||
// parser represents a parser.
|
||||
type parser struct {
|
||||
s *scanner
|
||||
c *fibre.Context
|
||||
v map[string]interface{}
|
||||
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.
|
||||
func Parse(ctx *fibre.Context, i interface{}) (*Query, error) {
|
||||
switch v := i.(type) {
|
||||
func Parse(c *fibre.Context, i interface{}, v map[string]interface{}) (*Query, error) {
|
||||
switch x := i.(type) {
|
||||
default:
|
||||
return nil, &EmptyError{}
|
||||
case []byte:
|
||||
return ParseBytes(ctx, v)
|
||||
return parseBytes(c, x, v)
|
||||
case string:
|
||||
return ParseString(ctx, v)
|
||||
return parseString(c, x, v)
|
||||
case io.Reader:
|
||||
return ParseBuffer(ctx, v)
|
||||
return parseBuffer(c, x, v)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseBytes parses a byte array.
|
||||
func ParseBytes(ctx *fibre.Context, i []byte) (*Query, error) {
|
||||
// parseBytes parses a byte array.
|
||||
func parseBytes(c *fibre.Context, i []byte, v map[string]interface{}) (*Query, error) {
|
||||
r := bytes.NewReader(i)
|
||||
p := &Parser{c: ctx}
|
||||
p.s = NewScanner(p, r)
|
||||
return p.Parse()
|
||||
p := newParser(c, v)
|
||||
p.s = newScanner(p, r)
|
||||
return p.parse()
|
||||
}
|
||||
|
||||
// ParseString parses a string.
|
||||
func ParseString(ctx *fibre.Context, i string) (*Query, error) {
|
||||
// parseString parses a string.
|
||||
func parseString(c *fibre.Context, i string, v map[string]interface{}) (*Query, error) {
|
||||
r := strings.NewReader(i)
|
||||
p := &Parser{c: ctx}
|
||||
p.s = NewScanner(p, r)
|
||||
return p.Parse()
|
||||
p := newParser(c, v)
|
||||
p.s = newScanner(p, r)
|
||||
return p.parse()
|
||||
}
|
||||
|
||||
// ParseBuffer parses a buffer.
|
||||
func ParseBuffer(ctx *fibre.Context, r io.Reader) (*Query, error) {
|
||||
p := &Parser{c: ctx}
|
||||
p.s = NewScanner(p, r)
|
||||
return p.Parse()
|
||||
// parseBuffer parses a buffer.
|
||||
func parseBuffer(c *fibre.Context, r io.Reader, v map[string]interface{}) (*Query, error) {
|
||||
p := newParser(c, v)
|
||||
p.s = newScanner(p, r)
|
||||
return p.parse()
|
||||
}
|
||||
|
||||
// Parse parses single or multiple SQL queries.
|
||||
func (p *Parser) Parse() (*Query, error) {
|
||||
return p.ParseMulti()
|
||||
// parse parses single or multiple SQL queries.
|
||||
func (p *parser) parse() (*Query, error) {
|
||||
return p.parseMulti()
|
||||
}
|
||||
|
||||
// ParseMulti parses multiple SQL SELECT statements.
|
||||
func (p *Parser) ParseMulti() (*Query, error) {
|
||||
// parseMulti parses multiple SQL SELECT statements.
|
||||
func (p *parser) parseMulti() (*Query, error) {
|
||||
|
||||
var statements Statements
|
||||
|
||||
|
@ -96,7 +101,7 @@ func (p *Parser) ParseMulti() (*Query, error) {
|
|||
} else {
|
||||
text = true
|
||||
p.unscan()
|
||||
s, err := p.ParseSingle()
|
||||
s, err := p.parseSingle()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -107,8 +112,8 @@ func (p *Parser) ParseMulti() (*Query, error) {
|
|||
|
||||
}
|
||||
|
||||
// ParseSingle parses a single SQL SELECT statement.
|
||||
func (p *Parser) ParseSingle() (Statement, error) {
|
||||
// parseSingle parses a single SQL SELECT statement.
|
||||
func (p *parser) parseSingle() (Statement, error) {
|
||||
|
||||
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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -183,7 +188,7 @@ func (p *Parser) shouldBe(expected ...Token) (tok Token, lit string, err error)
|
|||
}
|
||||
|
||||
// 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()
|
||||
|
||||
|
@ -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 {
|
||||
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.
|
||||
// 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 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.
|
||||
tok, lit, val = p.s.Scan()
|
||||
tok, lit, val = p.s.scan()
|
||||
|
||||
// Save it to the buffer in case we unscan later.
|
||||
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.
|
||||
func (p *Parser) unscan() {
|
||||
func (p *parser) unscan() {
|
||||
p.buf.n = 1
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseRecordStatement(explain bool) (stmt *RecordStatement, err error) {
|
||||
func (p *parser) parseRecordStatement(explain bool) (stmt *RecordStatement, err error) {
|
||||
|
||||
stmt = &RecordStatement{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseRelateStatement(explain bool) (stmt *RelateStatement, err error) {
|
||||
func (p *parser) parseRelateStatement(explain bool) (stmt *RelateStatement, err error) {
|
||||
|
||||
stmt = &RelateStatement{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseRemoveStatement(explain bool) (Statement, error) {
|
||||
func (p *parser) parseRemoveStatement(explain bool) (Statement, error) {
|
||||
|
||||
// Inspect the next token.
|
||||
tok, _, err := p.shouldBe(RULES, TABLE, FIELD, INDEX)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
|
||||
func (p *parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
|
||||
|
||||
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{}
|
||||
|
||||
|
|
|
@ -23,21 +23,21 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Scanner represents a lexical scanner.
|
||||
type Scanner struct {
|
||||
// scanner represents a lexical scanner.
|
||||
type scanner struct {
|
||||
b []rune // any runes before
|
||||
a []rune // any runes after
|
||||
p *Parser
|
||||
p *parser
|
||||
r *bufio.Reader
|
||||
}
|
||||
|
||||
// NewScanner returns a new instance of Scanner.
|
||||
func NewScanner(p *Parser, r io.Reader) *Scanner {
|
||||
return &Scanner{p: p, r: bufio.NewReader(r)}
|
||||
// newScanner returns a new instance of Scanner.
|
||||
func newScanner(p *parser, r io.Reader) *scanner {
|
||||
return &scanner{p: p, r: bufio.NewReader(r)}
|
||||
}
|
||||
|
||||
// Scan returns the next token and literal value.
|
||||
func (s *Scanner) Scan() (tok Token, lit string, val interface{}) {
|
||||
// scan returns the next token and literal value.
|
||||
func (s *scanner) scan() (tok Token, lit string, val interface{}) {
|
||||
|
||||
// Read the next rune.
|
||||
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.
|
||||
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
|
||||
|
||||
|
@ -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.
|
||||
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
|
||||
|
||||
|
@ -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.
|
||||
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
|
||||
|
||||
|
@ -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...)
|
||||
|
||||
|
@ -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.
|
||||
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
|
||||
|
||||
|
@ -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.
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
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
|
||||
|
||||
|
@ -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]
|
||||
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.
|
||||
// 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 {
|
||||
var r rune
|
||||
|
@ -727,7 +727,7 @@ func (s *Scanner) next() rune {
|
|||
}
|
||||
|
||||
// undo places the previously read rune back on the reader.
|
||||
func (s *Scanner) undo() {
|
||||
func (s *scanner) undo() {
|
||||
|
||||
if len(s.b) > 0 {
|
||||
var r rune
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err error) {
|
||||
func (p *parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err error) {
|
||||
|
||||
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
|
||||
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 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
|
||||
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
|
||||
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
|
||||
if _, _, exi := p.mightBe(VERSION); !exi {
|
||||
|
|
|
@ -45,7 +45,7 @@ func testsql(t *testing.T, test tester) {
|
|||
return
|
||||
}
|
||||
|
||||
s, e := ParseString(c, test.sql)
|
||||
s, e := Parse(c, test.sql, nil)
|
||||
|
||||
Convey(test.sql, t, func() {
|
||||
|
||||
|
@ -77,7 +77,7 @@ func TestMain(t *testing.T) {
|
|||
func Test_Parse_General(t *testing.T) {
|
||||
|
||||
s := `SELECT a FROM b`
|
||||
q, err := ParseString(c, s)
|
||||
q, err := Parse(c, s, nil)
|
||||
|
||||
if err != nil {
|
||||
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) {
|
||||
|
||||
s := `SELECT a FROM b`
|
||||
q, err := ParseString(c, s)
|
||||
q, err := Parse(c, s, nil)
|
||||
|
||||
if err != nil {
|
||||
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) {
|
||||
|
||||
s := `SELECT a FROM b; SELECT c FROM d`
|
||||
q, err := ParseString(c, s)
|
||||
q, err := Parse(c, s, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseDefineTableStatement(explain bool) (stmt *DefineTableStatement, err error) {
|
||||
func (p *parser) parseDefineTableStatement(explain bool) (stmt *DefineTableStatement, err error) {
|
||||
|
||||
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{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err error) {
|
||||
func (p *parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err error) {
|
||||
|
||||
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{}
|
||||
|
||||
|
@ -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{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
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"}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseUpdateStatement(explain bool) (stmt *UpdateStatement, err error) {
|
||||
func (p *parser) parseUpdateStatement(explain bool) (stmt *UpdateStatement, err error) {
|
||||
|
||||
stmt = &UpdateStatement{}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package sql
|
||||
|
||||
func (p *Parser) parseUseStatement(explain bool) (stmt *UseStatement, err error) {
|
||||
func (p *parser) parseUseStatement(explain bool) (stmt *UseStatement, err error) {
|
||||
|
||||
stmt = &UseStatement{}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func (p *Parser) in(token Token, tokens []Token) bool {
|
||||
func (p *parser) in(token Token, tokens []Token) bool {
|
||||
|
||||
for _, t := range tokens {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
return val, nil
|
||||
|
|
Loading…
Reference in a new issue