-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for unary operators + and -
This adds support to the configuration interpolation syntax for + and - as unary operators, specifically to represent negative numbers.
- Loading branch information
1 parent
5d91069
commit 41f9ebc
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.