mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-16 11:21:32 +00:00
Add support for not equals (!=) infix operation.
This commit is contained in:
@ -5,5 +5,6 @@ enum class InfixOperator(val token: String) {
|
||||
Minus("-"),
|
||||
Multiply("*"),
|
||||
Divide("/"),
|
||||
Equals("==")
|
||||
Equals("=="),
|
||||
NotEquals("!=")
|
||||
}
|
||||
|
@ -81,6 +81,9 @@ class PorkEvaluator(root: Scope) : NodeVisitor<Any> {
|
||||
InfixOperator.Equals -> {
|
||||
return left == right
|
||||
}
|
||||
InfixOperator.NotEquals -> {
|
||||
return left != right
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,8 @@ class PorkParser(source: PeekableSource<Token>) {
|
||||
TokenType.Minus,
|
||||
TokenType.Multiply,
|
||||
TokenType.Divide,
|
||||
TokenType.Equality)) {
|
||||
TokenType.Equality,
|
||||
TokenType.Inequality)) {
|
||||
val infixToken = next()
|
||||
val infixOperator = convertInfixOperator(infixToken)
|
||||
return InfixOperation(expression, infixOperator, readExpression())
|
||||
@ -133,6 +134,7 @@ class PorkParser(source: PeekableSource<Token>) {
|
||||
TokenType.Multiply -> InfixOperator.Multiply
|
||||
TokenType.Divide -> InfixOperator.Divide
|
||||
TokenType.Equality -> InfixOperator.Equals
|
||||
TokenType.Inequality -> InfixOperator.NotEquals
|
||||
else -> throw RuntimeException("Unknown Infix Operator")
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
Symbol,
|
||||
IntLiteral,
|
||||
Equality,
|
||||
Inequality,
|
||||
Equals(SingleChar('='), Promotion('=', Equality)),
|
||||
Plus(SingleChar('+')),
|
||||
Minus(SingleChar('-')),
|
||||
@ -17,7 +18,7 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
|
||||
RightBracket(SingleChar(']')),
|
||||
LeftParentheses(SingleChar('(')),
|
||||
RightParentheses(SingleChar(')')),
|
||||
Negation(SingleChar('!')),
|
||||
Negation(SingleChar('!'), Promotion('=', Inequality)),
|
||||
Comma(SingleChar(',')),
|
||||
False(Keyword("false")),
|
||||
True(Keyword("true")),
|
||||
|
Reference in New Issue
Block a user