Skip to content

Commit a82f2dc

Browse files
committed
parser: fix compile error with mod function
1 parent 20e6bd2 commit a82f2dc

File tree

5 files changed

+985
-967
lines changed

5 files changed

+985
-967
lines changed

pkg/parser/ast/expressions.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type BetweenExpr struct {
8585

8686
// Restore implements Node interface.
8787
func (n *BetweenExpr) Restore(ctx *format.RestoreCtx) error {
88+
if ctx.Flags.HasRestoreBracketAroundBetweenExpr() {
89+
ctx.WritePlain("(")
90+
}
8891
if err := n.Expr.Restore(ctx); err != nil {
8992
return errors.Annotate(err, "An error occurred while restore BetweenExpr.Expr")
9093
}
@@ -100,6 +103,9 @@ func (n *BetweenExpr) Restore(ctx *format.RestoreCtx) error {
100103
if err := n.Right.Restore(ctx); err != nil {
101104
return errors.Annotate(err, "An error occurred while restore BetweenExpr.Right ")
102105
}
106+
if ctx.Flags.HasRestoreBracketAroundBetweenExpr() {
107+
ctx.WritePlain(")")
108+
}
103109
return nil
104110
}
105111

@@ -175,6 +181,8 @@ func (n *BinaryOperationExpr) Restore(ctx *format.RestoreCtx) error {
175181
if ctx.Flags.HasRestoreBracketAroundBinaryOperation() {
176182
ctx.WritePlain("(")
177183
}
184+
originalFlags := ctx.Flags
185+
ctx.Flags |= format.RestoreBracketAroundBetweenExpr
178186
if err := n.L.Restore(ctx); err != nil {
179187
return errors.Annotate(err, "An error occurred when restore BinaryOperationExpr.L")
180188
}
@@ -184,6 +192,7 @@ func (n *BinaryOperationExpr) Restore(ctx *format.RestoreCtx) error {
184192
if err := n.R.Restore(ctx); err != nil {
185193
return errors.Annotate(err, "An error occurred when restore BinaryOperationExpr.R")
186194
}
195+
ctx.Flags = originalFlags
187196
if ctx.Flags.HasRestoreBracketAroundBinaryOperation() {
188197
ctx.WritePlain(")")
189198
}

pkg/parser/format/format.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ const (
239239
RestoreWithoutSchemaName
240240
RestoreWithoutTableName
241241
RestoreForNonPrepPlanCache
242+
243+
RestoreBracketAroundBetweenExpr
242244
)
243245

244246
const (
@@ -323,6 +325,12 @@ func (rf RestoreFlags) HasStringWithoutDefaultCharset() bool {
323325
return rf.has(RestoreStringWithoutDefaultCharset)
324326
}
325327

328+
// HasRestoreBracketAroundBetweenExpr returns a boolean indicating
329+
// whether `rf` has `RestoreBracketAroundBetweenExpr` flag.
330+
func (rf RestoreFlags) HasRestoreBracketAroundBetweenExpr() bool {
331+
return rf.has(RestoreBracketAroundBetweenExpr)
332+
}
333+
326334
// HasStringWithoutCharset returns a boolean indicating whether `rf` has `RestoreStringWithoutCharset` flag.
327335
func (rf RestoreFlags) HasStringWithoutCharset() bool {
328336
return rf.has(RestoreStringWithoutCharset)

0 commit comments

Comments
 (0)