add support for unary plus/minus

This commit is contained in:
2026-03-16 14:35:49 +03:00
parent 3f0f8ab5e7
commit 8a59e0a57f
2 changed files with 44 additions and 37 deletions

View File

@@ -151,23 +151,6 @@ module RubyAlgebra
end
end
class Subtraction < Addition
attr_reader :lhs, :rhs
def to_s
need_parentheses_left = lhs.op_priority < op_priority || (lhs.op_priority == op_priority && op_assoc_type == :right)
need_parentheses_right = rhs.op_priority < op_priority || (rhs.op_priority == op_priority && op_assoc_type == :left)
result = need_parentheses_left ? "(#{lhs}) - " : "#{lhs} - "
result + (need_parentheses_right ? "(#{rhs})" : rhs.to_s)
end
def type
:sub
end
end
class Constant < Expression
attr_reader :value