make a Visitable module

FossilOrigin-Name: 3ffc71c707c994c44a9f33025ed50ab91d2a7e60be6c639b6ed28798d82728a2
private
alpha 2 years ago
parent b651c84d9b
commit cf72deef8b

@ -1,19 +1,26 @@
module Lox module Lox
module Expr module Expr
module Visitable
def accept(visitor)
klass = self.class.to_s.split("::").last.downcase
visitor.send("visit_#{klass}", self)
end
end
Binary = Struct.new(:left, :op, :right) do Binary = Struct.new(:left, :op, :right) do
def accept(visitor) = visitor.visit_binary(self) include Visitable
end end
Grouping = Struct.new(:expr) do Grouping = Struct.new(:expr) do
def accept(visitor) = visitor.visit_grouping(self) include Visitable
end end
Literal = Struct.new(:value) do Literal = Struct.new(:value) do
def accept(visitor) = visitor.visit_literal(self) include Visitable
end end
Unary = Struct.new(:op, :right) do Unary = Struct.new(:op, :right) do
def accept(visitor) = visitor.visit_unary(self) include Visitable
end end
end end
end end

Loading…
Cancel
Save