Enable parameters in @thing:id in sql parser
This commit is contained in:
parent
c53efdb06f
commit
fdbf38f833
1 changed files with 48 additions and 1 deletions
|
@ -422,6 +422,14 @@ func (s *scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
|
|
||||||
tok = THING
|
tok = THING
|
||||||
|
|
||||||
|
// Store whether params
|
||||||
|
var tbp bool
|
||||||
|
var idp bool
|
||||||
|
|
||||||
|
// Store section values
|
||||||
|
var tbv interface{}
|
||||||
|
var idv interface{}
|
||||||
|
|
||||||
// Create a buffer
|
// Create a buffer
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
var beg bytes.Buffer
|
var beg bytes.Buffer
|
||||||
|
@ -440,6 +448,11 @@ func (s *scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
tok, lit, _ = s.scanIdent(ch)
|
tok, lit, _ = s.scanIdent(ch)
|
||||||
beg.WriteString(lit)
|
beg.WriteString(lit)
|
||||||
break
|
break
|
||||||
|
} else if ch == '$' {
|
||||||
|
tbp = true // The TB is a param
|
||||||
|
tok, lit, _ = s.scanParams(ch)
|
||||||
|
beg.WriteString(lit)
|
||||||
|
break
|
||||||
} else if ch == '`' {
|
} else if ch == '`' {
|
||||||
tok, lit, _ = s.scanQuoted(ch)
|
tok, lit, _ = s.scanQuoted(ch)
|
||||||
beg.WriteString(lit)
|
beg.WriteString(lit)
|
||||||
|
@ -483,6 +496,11 @@ func (s *scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
tok, lit, _ = s.scanIdent(ch)
|
tok, lit, _ = s.scanIdent(ch)
|
||||||
end.WriteString(lit)
|
end.WriteString(lit)
|
||||||
break
|
break
|
||||||
|
} else if ch == '$' {
|
||||||
|
idp = true // The ID is a param
|
||||||
|
tok, lit, _ = s.scanParams(ch)
|
||||||
|
end.WriteString(lit)
|
||||||
|
break
|
||||||
} else if ch == '`' {
|
} else if ch == '`' {
|
||||||
tok, lit, _ = s.scanQuoted(ch)
|
tok, lit, _ = s.scanQuoted(ch)
|
||||||
end.WriteString(lit)
|
end.WriteString(lit)
|
||||||
|
@ -505,7 +523,36 @@ func (s *scanner) scanThing(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
}
|
}
|
||||||
|
|
||||||
val = NewThing(beg.String(), end.String())
|
tbv = beg.String()
|
||||||
|
idv = end.String()
|
||||||
|
|
||||||
|
if tbp { // The TB is a param
|
||||||
|
if p, ok := s.p.v[tbv.(string)]; ok {
|
||||||
|
switch p.(type) {
|
||||||
|
case bool, int64, float64, string, []interface{}, map[string]interface{}:
|
||||||
|
tbv = p
|
||||||
|
default:
|
||||||
|
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if idp { // The ID is a param
|
||||||
|
if p, ok := s.p.v[idv.(string)]; ok {
|
||||||
|
switch p.(type) {
|
||||||
|
case bool, int64, float64, string, []interface{}, map[string]interface{}:
|
||||||
|
idv = p
|
||||||
|
default:
|
||||||
|
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ILLEGAL, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val = NewThing(tbv, idv)
|
||||||
|
|
||||||
// Otherwise return as a regular thing.
|
// Otherwise return as a regular thing.
|
||||||
return THING, buf.String() + beg.String() + mid.String() + end.String(), val
|
return THING, buf.String() + beg.String() + mid.String() + end.String(), val
|
||||||
|
|
Loading…
Reference in a new issue