Implemented negation
This commit is contained in:
@ -38,8 +38,6 @@ const (
|
||||
Shr // >>
|
||||
LogicalAnd // &&
|
||||
LogicalOr // ||
|
||||
Not // ! (unary)
|
||||
Negate // - (unary)
|
||||
Equal // ==
|
||||
Less // <
|
||||
Greater // >
|
||||
@ -51,6 +49,10 @@ const (
|
||||
Call // x()
|
||||
Array // [x]
|
||||
Separator // ,
|
||||
_unary // <unary>
|
||||
Not // ! (unary)
|
||||
Negate // - (unary)
|
||||
_unaryEnd // </unary>
|
||||
_assignments // <assignments>
|
||||
Assign // =
|
||||
AddAssign // +=
|
||||
|
@ -43,6 +43,11 @@ func (t Token) IsOperator() bool {
|
||||
return t.Kind > _operators && t.Kind < _operatorsEnd
|
||||
}
|
||||
|
||||
// IsUnaryOperator returns true if the token is a unary operator.
|
||||
func (t Token) IsUnaryOperator() bool {
|
||||
return t.Kind > _unary && t.Kind < _unaryEnd
|
||||
}
|
||||
|
||||
// Reset resets the token to default values.
|
||||
func (t *Token) Reset() {
|
||||
t.Position = 0
|
||||
|
@ -27,7 +27,7 @@ func Tokenize(buffer []byte) List {
|
||||
case '\n':
|
||||
tokens = append(tokens, Token{Kind: NewLine, Position: i, Length: 1})
|
||||
case '-':
|
||||
if len(tokens) == 0 || tokens[len(tokens)-1].IsOperator() || tokens[len(tokens)-1].IsExpressionStart() {
|
||||
if len(tokens) == 0 || tokens[len(tokens)-1].IsOperator() || tokens[len(tokens)-1].IsExpressionStart() || tokens[len(tokens)-1].IsKeyword() {
|
||||
tokens = append(tokens, Token{Kind: Negate, Position: i, Length: 1})
|
||||
} else {
|
||||
if i+1 < Position(len(buffer)) && buffer[i+1] == '=' {
|
||||
|
Reference in New Issue
Block a user