sqlparser: add LIST_ARG to grammar and AST.

This commit is contained in:
Sugu Sougoumarane 2014-10-22 22:25:10 -07:00
Родитель cc4eaaeb3e
Коммит b5bed9f0f4
3 изменённых файлов: 443 добавлений и 419 удалений

Просмотреть файл

@ -461,6 +461,7 @@ func (*NullVal) IExpr() {}
func (*ColName) IExpr() {}
func (ValTuple) IExpr() {}
func (*Subquery) IExpr() {}
func (ListArg) IExpr() {}
func (*BinaryExpr) IExpr() {}
func (*UnaryExpr) IExpr() {}
func (*FuncExpr) IExpr() {}
@ -597,6 +598,7 @@ func (*NullVal) IValExpr() {}
func (*ColName) IValExpr() {}
func (ValTuple) IValExpr() {}
func (*Subquery) IValExpr() {}
func (ListArg) IValExpr() {}
func (*BinaryExpr) IValExpr() {}
func (*UnaryExpr) IValExpr() {}
func (*FuncExpr) IValExpr() {}
@ -652,15 +654,6 @@ func escape(buf *TrackedBuffer, name []byte) {
}
}
// RowTuple represents a row of values. It can be ValTuple, Subquery.
type RowTuple interface {
IRowTuple()
ValExpr
}
func (ValTuple) IRowTuple() {}
func (*Subquery) IRowTuple() {}
// ColTuple represents a list of column values.
// It can be ValTuple, Subquery, ListArg.
type ColTuple interface {
@ -670,6 +663,7 @@ type ColTuple interface {
func (ValTuple) IColTuple() {}
func (*Subquery) IColTuple() {}
func (ListArg) IColTuple() {}
// ValTuple represents a tuple of actual values.
type ValTuple ValExprs
@ -699,6 +693,13 @@ func (node *Subquery) Format(buf *TrackedBuffer) {
buf.Myprintf("(%v)", node.Select)
}
// ListArg represents a named list argument.
type ListArg []byte
func (node ListArg) Format(buf *TrackedBuffer) {
buf.WriteArg(string(node))
}
// BinaryExpr represents a binary value expression.
type BinaryExpr struct {
Operator byte
@ -784,17 +785,6 @@ func (node *When) Format(buf *TrackedBuffer) {
buf.Myprintf("when %v then %v", node.Cond, node.Val)
}
// Values represents a VALUES clause.
type Values []RowTuple
func (node Values) Format(buf *TrackedBuffer) {
prefix := "values "
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}
// GroupBy represents a GROUP BY clause.
type GroupBy []ValExpr
@ -892,6 +882,26 @@ func (node *Limit) Limits() (offset, rowcount interface{}, err error) {
return offset, rowcount, nil
}
// Values represents a VALUES clause.
type Values []RowTuple
func (node Values) Format(buf *TrackedBuffer) {
prefix := "values "
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}
// RowTuple represents a row of values. It can be ValTuple, Subquery.
type RowTuple interface {
IRowTuple()
ValExpr
}
func (ValTuple) IRowTuple() {}
func (*Subquery) IRowTuple() {}
// UpdateExprs represents a list of update expressions.
type UpdateExprs []*UpdateExpr

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -48,10 +48,10 @@ var (
expr Expr
boolExpr BoolExpr
valExpr ValExpr
rowTuple RowTuple
colTuple ColTuple
valExprs ValExprs
values Values
rowTuple RowTuple
subquery *Subquery
caseExpr *CaseExpr
whens []*When
@ -116,10 +116,10 @@ var (
%type <str> compare
%type <insRows> row_list
%type <valExpr> value value_expression
%type <rowTuple> row_tuple
%type <colTuple> col_tuple
%type <valExprs> value_expression_list
%type <values> tuple_list
%type <rowTuple> row_tuple
%type <bytes> keyword_as_func
%type <subquery> subquery
%type <byt> unary_operator
@ -609,36 +609,6 @@ compare:
$$ = AST_NSE
}
row_list:
VALUES tuple_list
{
$$ = $2
}
| select_statement
{
$$ = $1
}
tuple_list:
row_tuple
{
$$ = Values{$1}
}
| tuple_list ',' row_tuple
{
$$ = append($1, $3)
}
row_tuple:
'(' value_expression_list ')'
{
$$ = ValTuple($2)
}
| subquery
{
$$ = $1
}
col_tuple:
'(' value_expression_list ')'
{
@ -648,6 +618,10 @@ col_tuple:
{
$$ = $1
}
| LIST_ARG
{
$$ = ListArg($1)
}
subquery:
'(' select_statement ')'
@ -956,6 +930,36 @@ on_dup_opt:
$$ = $5
}
row_list:
VALUES tuple_list
{
$$ = $2
}
| select_statement
{
$$ = $1
}
tuple_list:
row_tuple
{
$$ = Values{$1}
}
| tuple_list ',' row_tuple
{
$$ = append($1, $3)
}
row_tuple:
'(' value_expression_list ')'
{
$$ = ValTuple($2)
}
| subquery
{
$$ = $1
}
update_list:
update_expression
{