-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3621 from jszwedko/add-support-for-negative-literals
Add support for unary operators + and - to the interpolation syntax
- Loading branch information
Showing
8 changed files
with
334 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ast | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// UnaryArithmetic represents a node where the result is arithmetic of | ||
// one operands | ||
type UnaryArithmetic struct { | ||
Op ArithmeticOp | ||
Expr Node | ||
Posx Pos | ||
} | ||
|
||
func (n *UnaryArithmetic) Accept(v Visitor) Node { | ||
n.Expr = n.Expr.Accept(v) | ||
|
||
return v(n) | ||
} | ||
|
||
func (n *UnaryArithmetic) Pos() Pos { | ||
return n.Posx | ||
} | ||
|
||
func (n *UnaryArithmetic) GoString() string { | ||
return fmt.Sprintf("*%#v", *n) | ||
} | ||
|
||
func (n *UnaryArithmetic) String() string { | ||
var sign rune | ||
switch n.Op { | ||
case ArithmeticOpAdd: | ||
sign = '+' | ||
case ArithmeticOpSub: | ||
sign = '-' | ||
} | ||
return fmt.Sprintf("%c%s", sign, n.Expr) | ||
} | ||
|
||
func (n *UnaryArithmetic) Type(Scope) (Type, error) { | ||
return TypeInt, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.