remove Visitable

FossilOrigin-Name: e45d353b7eddcab310ec5059d9ddc51a202526b145aa121d3c77815af59e43d1
private
alpha 2 years ago
parent cd50d4283e
commit ce8c69136a

@ -1,33 +1,21 @@
require_relative "visitable"
module Lox module Lox
module Expr module Expr
Assign = Struct.new(:name, :value) do def self.expr(name, *children)
include Visitable klass = Struct.new(name.to_s, *children) do
end def accept(visitor)
klass = self.class.to_s.split("::").last.downcase
Binary = Struct.new(:left, :op, :right) do visitor.send("visit_#{klass}", self)
include Visitable end
end end
const_set(name, klass)
Grouping = Struct.new(:expr) do
include Visitable
end
Literal = Struct.new(:value) do
include Visitable
end
Logical = Struct.new(:left, :op, :right) do
include Visitable
end end
Unary = Struct.new(:op, :right) do expr :Assign, :name, :value
include Visitable expr :Binary, :left, :op, :right
end expr :Grouping, :expr
expr :Literal, :value
Variable = Struct.new(:name) do expr :Logical, :left, :op, :right
include Visitable expr :Unary, :op, :right
end expr :Variable, :name
end end
end end

@ -1,25 +1,21 @@
require_relative "visitable" require_relative "expr"
module Lox module Lox
module Stmt module Stmt
Block = Struct.new(:stmts) do def self.stmt(name, *children)
include Visitable klass = Struct.new(name.to_s, *children) do
def accept(visitor)
klass = self.class.to_s.split("::").last.downcase
visitor.send("visit_#{klass}", self)
end
end
const_set(name, klass)
end end
Expr = Struct.new(:expr) do stmt :Block, :stmts
include Visitable stmt :Expr, :expr
end stmt :If, :cond, :then, :else
stmt :Print, :expr
If = Struct.new(:cond, :then, :else) do stmt :Var, :name, :initializer
include Visitable
end
Print = Struct.new(:expr) do
include Visitable
end
Var = Struct.new(:name, :initializer) do
include Visitable
end
end end
end end

@ -1,8 +0,0 @@
module Lox
module Visitable
def accept(visitor)
klass = self.class.to_s.split("::").last.downcase
visitor.send("visit_#{klass}", self)
end
end
end
Loading…
Cancel
Save