diff --git a/sql/cond.go b/sql/cond.go index f207a25d..accec7ff 100644 --- a/sql/cond.go +++ b/sql/cond.go @@ -28,7 +28,7 @@ func (p *Parser) parseCond() (mul []Expr, err error) { one := &BinaryExpression{} - tok, lit, err = p.shouldBe(ID, IDENT, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, BOUNDPARAM) + tok, lit, err = p.shouldBe(ID, IDENT, THING, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, PARAM) if err != nil { return nil, &ParseError{Found: lit, Expected: []string{"field name"}} } @@ -70,7 +70,7 @@ func (p *Parser) parseCond() (mul []Expr, err error) { } } - tok, lit, err = p.shouldBe(ID, IDENT, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, BOUNDPARAM) + tok, lit, err = p.shouldBe(ID, IDENT, THING, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, PARAM) if err != nil { return nil, &ParseError{Found: lit, Expected: []string{"field value"}} } diff --git a/sql/data.go b/sql/data.go index 205e3a01..d0a7942d 100644 --- a/sql/data.go +++ b/sql/data.go @@ -67,7 +67,7 @@ func (p *Parser) parseSet() (mul []Expr, err error) { } one.Op = tok - tok, lit, err = p.shouldBe(IDENT, NULL, VOID, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, JSON, ARRAY, BOUNDPARAM) + tok, lit, err = p.shouldBe(IDENT, NULL, VOID, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, JSON, ARRAY, PARAM) if err != nil { return nil, &ParseError{Found: lit, Expected: []string{"field value"}} } diff --git a/sql/parser.go b/sql/parser.go index 890451ad..c375fd5f 100644 --- a/sql/parser.go +++ b/sql/parser.go @@ -26,6 +26,7 @@ import ( type Parser struct { s *Scanner c *fibre.Context + v map[string]interface{} buf struct { tok Token // last read token lit string // last read literal diff --git a/sql/token.go b/sql/token.go index 953f8e4d..d3d9c859 100644 --- a/sql/token.go +++ b/sql/token.go @@ -29,19 +29,20 @@ const ( literalsBeg - DATE // 1970-01-01 - TIME // 1970-01-01T00:00:00+00:00 - PATH // person->like->person - JSON // {"test":true} - IDENT // something - STRING // "something" - REGION // "a multiline \n string" - NUMBER // 123456 - DOUBLE // 123.456 - REGEX // /.*/ - ARRAY // [0,1,2] - DURATION // 13h - BOUNDPARAM // $1 + DATE // 1970-01-01 + TIME // 1970-01-01T00:00:00+00:00 + PATH // person->like->person + JSON // {"test":true} + IDENT // something + THING // @class:id + STRING // "something" + REGION // "a multiline \n string" + NUMBER // 123456 + DOUBLE // 123.456 + REGEX // /.*/ + ARRAY // [0,1,2] + DURATION // 13h + PARAM // $1 EAT // @ DOT // . @@ -199,19 +200,20 @@ var tokens = [...]string{ // literals - DATE: "DATE", - TIME: "TIME", - PATH: "PATH", - JSON: "JSON", - IDENT: "IDENT", - STRING: "STRING", - REGION: "REGION", - NUMBER: "NUMBER", - DOUBLE: "DOUBLE", - REGEX: "REGEX", - ARRAY: "ARRAY", - DURATION: "DURATION", - BOUNDPARAM: "BOUNDPARAM", + DATE: "DATE", + TIME: "TIME", + PATH: "PATH", + JSON: "JSON", + IDENT: "IDENT", + THING: "THING", + STRING: "STRING", + REGION: "REGION", + NUMBER: "NUMBER", + DOUBLE: "DOUBLE", + REGEX: "REGEX", + ARRAY: "ARRAY", + DURATION: "DURATION", + PARAM: "PARAM", EAT: "@", DOT: ".", diff --git a/sql/util.go b/sql/util.go index 1a6e5aad..c30f8050 100644 --- a/sql/util.go +++ b/sql/util.go @@ -138,6 +138,12 @@ func (p *Parser) declare(tok Token, lit string) (interface{}, error) { } return j, nil + case PARAM: + if p, ok := p.v[lit]; ok { + return p, nil + } + return nil, fmt.Errorf("Param %s is not defined", lit) + } return lit, nil