Module: Potter::AST

Defined in:
lib/potter/ast.rb,
lib/potter/ast/dsl.rb,
lib/potter/ast/node.rb,
lib/potter/ast/proxy.rb,
lib/potter/ast/unary.rb,
lib/potter/ast/value.rb,
lib/potter/ast/binary.rb,
lib/potter/ast/variable.rb

Defined Under Namespace

Modules: DSL Classes: Binary, Node, Proxy, Unary, Value, Variable

Class Method Summary collapse

Class Method Details

.define_binary(const, symbol, name = const.underscore) ⇒ Object



18
19
20
# File 'lib/potter/ast/binary.rb', line 18

def self.define_binary(const, symbol, name = const.underscore, &)
  define_node(const, Binary, symbol:, name:, &)
end

.define_node(const, parent = Node, symbol: nil, name: const.underscore) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/potter/ast/node.rb', line 18

def self.define_node(const, parent = Node, symbol: nil, name: const.underscore, &)
  define_class(const, parent) do
    const_set(:SYMBOL, symbol) if symbol
    const_set(:NAME,   name)   if name
    class_exec(&) if block_given?
    klass = self

    if name
      Node.define_method(name)  {|*args| Proxy klass.new(self, *args.map { Node _1 }) }
      DSL.define_singleton_method(name)   {|*args| klass.new(*args.map { Node _1 }) }
      Proxy.define_method(name) {|*args| Proxy klass.new(@node, *args.map { Node _1 }) }
    end

    if symbol
      Proxy.define_method(symbol) {|*args| Proxy klass.new(@node, *args.map { Node _1 }) }
    end
  end
end

.define_unary(const, symbol) ⇒ Object



14
15
16
# File 'lib/potter/ast/unary.rb', line 14

def self.define_unary(const, symbol)
  define_node(const, Unary, symbol:)
end

.Node(o) ⇒ Object



13
14
15
# File 'lib/potter/ast.rb', line 13

def Node(o)
  o.is_a?(Node) ? o : Value.new(o)
end

.proxy(o) ⇒ Object



21
# File 'lib/potter/ast.rb', line 21

def proxy(o) = Proxy(o)

.Proxy(o) ⇒ Object



5
6
7
# File 'lib/potter/ast.rb', line 5

def Proxy(o)
  o.is_a?(Proxy) ? o : Proxy.new(Node o)
end

.Value(o) ⇒ Object



9
10
11
# File 'lib/potter/ast.rb', line 9

def Value(o)
  o.is_a?(Value) ? o : Value.new(o)
end

.value(o) ⇒ Object



22
# File 'lib/potter/ast.rb', line 22

def value(o) = Value(o)

.var(o) ⇒ Object



23
# File 'lib/potter/ast.rb', line 23

def var(o)   = Variable(o)

.Variable(o) ⇒ Object



17
18
19
# File 'lib/potter/ast.rb', line 17

def Variable(o)
  o.is_a?(Variable) ? o : Variable.new(o)
end