diff --git a/sql/data.go b/sql/data.go index 18d1ea93..403271e5 100644 --- a/sql/data.go +++ b/sql/data.go @@ -18,25 +18,25 @@ func (p *parser) parseData() (exp Expr, err error) { if tok, _, exi := p.mightBe(SET, DIFF, MERGE, CONTENT); exi { - if p.is(tok, SET) { + if is(tok, SET) { if exp, err = p.parseSet(); err != nil { return nil, err } } - if p.is(tok, DIFF) { + if is(tok, DIFF) { if exp, err = p.parseDiff(); err != nil { return nil, err } } - if p.is(tok, MERGE) { + if is(tok, MERGE) { if exp, err = p.parseMerge(); err != nil { return nil, err } } - if p.is(tok, CONTENT) { + if is(tok, CONTENT) { if exp, err = p.parseContent(); err != nil { return nil, err } diff --git a/sql/exprs.go b/sql/exprs.go index 7e32fcaf..dd8e9dfa 100644 --- a/sql/exprs.go +++ b/sql/exprs.go @@ -239,7 +239,7 @@ func (p *parser) parseType() (t, k string, err error) { return } - if !p.contains(t, allowedTypes) { + if !contains(t, allowedTypes) { err = &ParseError{Found: t, Expected: allowedTypes} return } @@ -520,7 +520,7 @@ func (p *parser) parsePart() (exp Expr, err error) { // then we will parse anything from here on // as an IF expression clause. - if p.is(tok, IF) { + if is(tok, IF) { return p.parseIfel() } @@ -528,7 +528,7 @@ func (p *parser) parsePart() (exp Expr, err error) { // bracket, then we will parse this complete // expression part as a subquery. - if p.is(tok, LPAREN) { + if is(tok, LPAREN) { return p.parseSubq() } @@ -544,7 +544,7 @@ func (p *parser) parsePart() (exp Expr, err error) { // function call, then check to see if the // token is in the list of allowed tokens. - if !p.in(tok, toks) { + if !in(tok, toks) { err = &ParseError{Found: lit, Expected: []string{"expression"}} } @@ -860,7 +860,7 @@ func (p *parser) parseJoin() (exp Expr, err error) { tok, _, _ := p.scan() - if !p.in(tok, toks) { + if !in(tok, toks) { p.unscan() return } @@ -890,7 +890,7 @@ func (p *parser) parseStep() (exp Expr, err error) { // bracket, then we will parse this complete // expression part as a subquery. - if p.is(tok, LPAREN) { + if is(tok, LPAREN) { return p.parseSubp() } @@ -898,7 +898,7 @@ func (p *parser) parseStep() (exp Expr, err error) { // expression, then check to see if the // token is in the list of allowed tokens. - if !p.in(tok, toks) { + if !in(tok, toks) { p.unscan() exp = nil } diff --git a/sql/field.go b/sql/field.go index eeb6b948..3e55c7b6 100644 --- a/sql/field.go +++ b/sql/field.go @@ -41,31 +41,31 @@ func (p *parser) parseDefineFieldStatement() (stmt *DefineFieldStatement, err er break } - if p.is(tok, TYPE) { + if is(tok, TYPE) { if stmt.Type, stmt.Kind, err = p.parseType(); err != nil { return nil, err } } - if p.is(tok, VALUE) { + if is(tok, VALUE) { if stmt.Value, err = p.parseExpr(); err != nil { return nil, err } } - if p.is(tok, ASSERT) { + if is(tok, ASSERT) { if stmt.Assert, err = p.parseExpr(); err != nil { return nil, err } } - if p.is(tok, PRIORITY) { + if is(tok, PRIORITY) { if stmt.Priority, err = p.parsePriority(); err != nil { return nil, err } } - if p.is(tok, PERMISSIONS) { + if is(tok, PERMISSIONS) { if stmt.Perms, err = p.parsePerms(); err != nil { return nil, err } diff --git a/sql/info.go b/sql/info.go index 6b6e7845..c771b6cf 100644 --- a/sql/info.go +++ b/sql/info.go @@ -26,19 +26,19 @@ func (p *parser) parseInfoStatement() (stmt *InfoStatement, err error) { return nil, err } - if p.is(stmt.Kind, NAMESPACE) { + if is(stmt.Kind, NAMESPACE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { return nil, err } } - if p.is(stmt.Kind, DATABASE) { + if is(stmt.Kind, DATABASE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } } - if p.is(stmt.Kind, TABLE) { + if is(stmt.Kind, TABLE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } diff --git a/sql/login.go b/sql/login.go index e6afd1a5..29c6537f 100644 --- a/sql/login.go +++ b/sql/login.go @@ -30,13 +30,13 @@ func (p *parser) parseDefineLoginStatement() (stmt *DefineLoginStatement, err er return nil, err } - if p.is(stmt.Kind, NAMESPACE) { + if is(stmt.Kind, NAMESPACE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { return nil, err } } - if p.is(stmt.Kind, DATABASE) { + if is(stmt.Kind, DATABASE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } @@ -70,13 +70,13 @@ func (p *parser) parseRemoveLoginStatement() (stmt *RemoveLoginStatement, err er return nil, err } - if p.is(stmt.Kind, NAMESPACE) { + if is(stmt.Kind, NAMESPACE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { return nil, err } } - if p.is(stmt.Kind, DATABASE) { + if is(stmt.Kind, DATABASE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } diff --git a/sql/parser.go b/sql/parser.go index f9fbe608..4ebaf9cf 100644 --- a/sql/parser.go +++ b/sql/parser.go @@ -66,7 +66,7 @@ func newParser(c *fibre.Context) *parser { func parseBytes(c *fibre.Context, i []byte) (*Query, error) { p := newParser(c) r := bytes.NewReader(i) - p.s = newScanner(p, r) + p.s = newScanner(r) return p.parse() } @@ -74,14 +74,14 @@ func parseBytes(c *fibre.Context, i []byte) (*Query, error) { func parseString(c *fibre.Context, i string) (*Query, error) { p := newParser(c) r := strings.NewReader(i) - p.s = newScanner(p, r) + p.s = newScanner(r) return p.parse() } // parseBuffer parses a buffer. func parseBuffer(c *fibre.Context, r io.Reader) (*Query, error) { p := newParser(c) - p.s = newScanner(p, r) + p.s = newScanner(r) return p.parse() } @@ -234,7 +234,7 @@ func (p *parser) mightBe(expected ...Token) (tok Token, lit string, found bool) tok, lit, _ = p.scan() - if found = p.in(tok, expected); !found { + if found = in(tok, expected); !found { p.unscan() } @@ -246,7 +246,7 @@ func (p *parser) shouldBe(expected ...Token) (tok Token, lit string, err error) tok, lit, _ = p.scan() - if !p.in(tok, expected) { + if !in(tok, expected) { p.unscan() err = &ParseError{Found: lit, Expected: lookup(expected)} } diff --git a/sql/perms.go b/sql/perms.go index 79a7ca6d..4b9903c0 100644 --- a/sql/perms.go +++ b/sql/perms.go @@ -28,7 +28,7 @@ func (p *parser) parsePerms() (exp *PermExpression, err error) { return exp, err } - if p.is(tok, NONE, FULL, WHERE) { + if is(tok, NONE, FULL, WHERE) { var expr Expr @@ -52,7 +52,7 @@ func (p *parser) parsePerms() (exp *PermExpression, err error) { } - if p.is(tok, FOR) { + if is(tok, FOR) { for { diff --git a/sql/scanner.go b/sql/scanner.go index 6b904a7c..52a5a438 100644 --- a/sql/scanner.go +++ b/sql/scanner.go @@ -28,13 +28,12 @@ import ( type scanner struct { b []rune // any runes before a []rune // any runes after - 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)} +func newScanner(r io.Reader) *scanner { + return &scanner{r: bufio.NewReader(r)} } // scan returns the next token and literal value. @@ -352,15 +351,15 @@ func (s *scanner) scanParams(chp ...rune) (tok Token, lit string, val interface{ tok, lit, _ = s.scanIdiom() - if s.p.is(tok, THING) { + if is(tok, THING) { return ILLEGAL, lit, val } - if s.p.is(tok, REGION) { + if is(tok, REGION) { return ILLEGAL, lit, val } - if s.p.is(tok, ILLEGAL) { + if is(tok, ILLEGAL) { return ILLEGAL, lit, val } @@ -378,11 +377,11 @@ func (s *scanner) scanQuoted(chp ...rune) (tok Token, lit string, val interface{ tok, lit, _ = s.scanString(chp...) - if s.p.is(tok, REGION) { + if is(tok, REGION) { return ILLEGAL, lit, val } - if s.p.is(tok, ILLEGAL) { + if is(tok, ILLEGAL) { return ILLEGAL, lit, val } @@ -415,11 +414,11 @@ func (s *scanner) scanSection(chp ...rune) (tok Token, lit string, val interface tok, lit, _ = s.scanString(chp...) - if s.p.is(tok, REGION) { + if is(tok, REGION) { return ILLEGAL, lit, val } - if s.p.is(tok, ILLEGAL) { + if is(tok, ILLEGAL) { return ILLEGAL, lit, val } diff --git a/sql/scope.go b/sql/scope.go index b069ff1a..b6c71ad6 100644 --- a/sql/scope.go +++ b/sql/scope.go @@ -33,27 +33,27 @@ func (p *parser) parseDefineScopeStatement() (stmt *DefineScopeStatement, err er break } - if p.is(tok, SESSION) { + if is(tok, SESSION) { if stmt.Time, err = p.parseDuration(); err != nil { return nil, err } } - if p.is(tok, SIGNUP) { + if is(tok, SIGNUP) { _, _, _ = p.mightBe(AS) if stmt.Signup, err = p.parseExpr(); err != nil { return nil, err } } - if p.is(tok, SIGNIN) { + if is(tok, SIGNIN) { _, _, _ = p.mightBe(AS) if stmt.Signin, err = p.parseExpr(); err != nil { return nil, err } } - if p.is(tok, CONNECT) { + if is(tok, CONNECT) { _, _, _ = p.mightBe(AS) if stmt.Connect, err = p.parseExpr(); err != nil { return nil, err diff --git a/sql/table.go b/sql/table.go index ed5736bc..28d3363e 100644 --- a/sql/table.go +++ b/sql/table.go @@ -33,25 +33,25 @@ func (p *parser) parseDefineTableStatement() (stmt *DefineTableStatement, err er break } - if p.is(tok, DROP) { + if is(tok, DROP) { stmt.Drop = true } - if p.is(tok, SCHEMAFULL) { + if is(tok, SCHEMAFULL) { stmt.Full = true } - if p.is(tok, SCHEMALESS) { + if is(tok, SCHEMALESS) { stmt.Full = false } - if p.is(tok, PERMISSIONS) { + if is(tok, PERMISSIONS) { if stmt.Perms, err = p.parsePerms(); err != nil { return nil, err } } - if p.is(tok, AS) { + if is(tok, AS) { stmt.Lock = true diff --git a/sql/token.go b/sql/token.go index 6e3a32fc..c59ac7c3 100644 --- a/sql/token.go +++ b/sql/token.go @@ -30,19 +30,19 @@ func (p *parser) parseDefineTokenStatement() (stmt *DefineTokenStatement, err er return nil, err } - if p.is(stmt.Kind, NAMESPACE) { + if is(stmt.Kind, NAMESPACE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { return nil, err } } - if p.is(stmt.Kind, DATABASE) { + if is(stmt.Kind, DATABASE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } } - if p.is(stmt.Kind, SCOPE) { + if is(stmt.Kind, SCOPE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } @@ -55,13 +55,13 @@ func (p *parser) parseDefineTokenStatement() (stmt *DefineTokenStatement, err er break } - if p.is(tok, TYPE) { + if is(tok, TYPE) { if stmt.Type, err = p.parseAlgorithm(); err != nil { return nil, err } } - if p.is(tok, VALUE) { + if is(tok, VALUE) { if stmt.Code, err = p.parseBinary(); err != nil { return nil, err } @@ -97,19 +97,19 @@ func (p *parser) parseRemoveTokenStatement() (stmt *RemoveTokenStatement, err er return nil, err } - if p.is(stmt.Kind, NAMESPACE) { + if is(stmt.Kind, NAMESPACE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil { return nil, err } } - if p.is(stmt.Kind, DATABASE) { + if is(stmt.Kind, DATABASE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } } - if p.is(stmt.Kind, SCOPE) { + if is(stmt.Kind, SCOPE) { if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil { return nil, err } diff --git a/sql/use.go b/sql/use.go index b6eea78d..958d8520 100644 --- a/sql/use.go +++ b/sql/use.go @@ -32,7 +32,7 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) { for { - if p.is(tok, NAMESPACE, NS) { + if is(tok, NAMESPACE, NS) { _, stmt.NS, err = p.shouldBe(IDENT, STRING, NUMBER, DOUBLE, DATE, TIME) if err != nil { @@ -49,7 +49,7 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) { } - if p.is(tok, DATABASE, DB) { + if is(tok, DATABASE, DB) { _, stmt.DB, err = p.shouldBe(IDENT, STRING, NUMBER, DOUBLE, DATE, TIME) if err != nil { diff --git a/sql/util.go b/sql/util.go index d5d11681..3f07c316 100644 --- a/sql/util.go +++ b/sql/util.go @@ -24,7 +24,7 @@ import ( json "github.com/hjson/hjson-go" ) -func (p *parser) in(token Token, tokens []Token) bool { +func in(token Token, tokens []Token) bool { for _, t := range tokens { if token == t { @@ -36,7 +36,7 @@ func (p *parser) in(token Token, tokens []Token) bool { } -func (p *parser) is(token Token, tokens ...Token) bool { +func is(token Token, tokens ...Token) bool { for _, t := range tokens { if token == t { @@ -48,7 +48,7 @@ func (p *parser) is(token Token, tokens ...Token) bool { } -func (p *parser) contains(search string, strings []string) bool { +func contains(search string, strings []string) bool { for _, str := range strings { if str == search {