Skip to content

Commit

Permalink
*: fix a parser bug
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger committed Feb 8, 2023
1 parent 2b4cdeb commit 64eeca2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions ddl/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func TestResourceGroupBasic(t *testing.T) {
tk.MustContainErrMsg("create resource group x ru_per_sec=1000 ru_per_sec=200, ru_per_sec=300", "Dupliated options specified")
tk.MustGetErrCode("create resource group x burstable, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, burstable", "Dupliated options specified")
tk.MustGetErrCode("create resource group x ru_per_sec=1000, burstable, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x ru_per_sec=1000, burstable, burstable", "Dupliated options specified")
tk.MustGetErrCode("create resource group x burstable, ru_per_sec=1000, burstable", mysql.ErrParse)
tk.MustContainErrMsg("create resource group x burstable, ru_per_sec=1000, burstable", "Dupliated options specified")
groups, err := infosync.ListResourceGroups(context.TODO())
require.Equal(t, 0, len(groups))
require.NoError(t, err)
Expand Down
10 changes: 6 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11960,19 +11960,21 @@ yynewstate:
}
case 10:
{
parser.yyVAL.item = append(yyS[yypt-1].item.([]*ast.ResourceGroupOption), yyS[yypt-0].item.(*ast.ResourceGroupOption))
if yyS[yypt-1].item.([]*ast.ResourceGroupOption)[0].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp {
if yyS[yypt-1].item.([]*ast.ResourceGroupOption)[0].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp ||
(len(yyS[yypt-1].item.([]*ast.ResourceGroupOption)) > 1 && yyS[yypt-1].item.([]*ast.ResourceGroupOption)[1].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
parser.yyVAL.item = append(yyS[yypt-1].item.([]*ast.ResourceGroupOption), yyS[yypt-0].item.(*ast.ResourceGroupOption))
}
case 11:
{
parser.yyVAL.item = append(yyS[yypt-2].item.([]*ast.ResourceGroupOption), yyS[yypt-0].item.(*ast.ResourceGroupOption))
if yyS[yypt-2].item.([]*ast.ResourceGroupOption)[0].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp {
if yyS[yypt-2].item.([]*ast.ResourceGroupOption)[0].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp ||
(len(yyS[yypt-2].item.([]*ast.ResourceGroupOption)) > 1 && yyS[yypt-2].item.([]*ast.ResourceGroupOption)[1].Tp == yyS[yypt-0].item.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
parser.yyVAL.item = append(yyS[yypt-2].item.([]*ast.ResourceGroupOption), yyS[yypt-0].item.(*ast.ResourceGroupOption))
}
case 12:
{
Expand Down
14 changes: 8 additions & 6 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1598,19 +1598,21 @@ ResourceGroupOptionList:
}
| ResourceGroupOptionList DirectResourceGroupOption
{
$$ = append($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption))
if $1.([]*ast.ResourceGroupOption)[0].Tp == $2.(*ast.ResourceGroupOption).Tp {
if $1.([]*ast.ResourceGroupOption)[0].Tp == $2.(*ast.ResourceGroupOption).Tp ||
(len($1.([]*ast.ResourceGroupOption)) > 1 && $1.([]*ast.ResourceGroupOption)[1].Tp == $2.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
$$ = append($1.([]*ast.ResourceGroupOption), $2.(*ast.ResourceGroupOption))
}
| ResourceGroupOptionList ',' DirectResourceGroupOption
{
if $1.([]*ast.ResourceGroupOption)[0].Tp == $3.(*ast.ResourceGroupOption).Tp ||
(len($1.([]*ast.ResourceGroupOption)) > 1 && $1.([]*ast.ResourceGroupOption)[1].Tp == $3.(*ast.ResourceGroupOption).Tp) {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
$$ = append($1.([]*ast.ResourceGroupOption), $3.(*ast.ResourceGroupOption))
if $1.([]*ast.ResourceGroupOption)[0].Tp == $3.(*ast.ResourceGroupOption).Tp {
yylex.AppendError(yylex.Errorf("Dupliated options specified"))
return 1
}
}

DirectResourceGroupOption:
Expand Down

0 comments on commit 64eeca2

Please sign in to comment.