Class: WebIDL::RubySexpVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/webidl/generator/ruby_sexp_visitor.rb

Instance Method Summary collapse

Instance Method Details

#visit_argument(argument) ⇒ Object



78
79
80
81
82
83
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 78

def visit_argument(argument)
  name = argument.name.snake_case
  arg = argument.variadic? ? "*#{name}" : name

  arg.to_sym
end

#visit_attribute(attribute) ⇒ Object



39
40
41
42
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 39

def visit_attribute(attribute)
  func = attribute.readonly? ? :attr_reader : :attr_accessor
  [:call, nil, func, [:arglist, [:lit, attribute.name.snake_case.to_sym]]]
end

#visit_const(const) ⇒ Object



31
32
33
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 31

def visit_const(const)
  [:cdecl, const.name, [:lit, const.value]] # FIXME: won't always be literals - need Literal AST node?
end

#visit_exception(ex) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 23

def visit_exception(ex)
  [:class, classify(ex.name), [:const, :StandardError],
    [:scope,
      [:block] + ex.members.map { |m| m.accept(self)}
    ]
  ]
end

#visit_field(field) ⇒ Object



35
36
37
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 35

def visit_field(field)
  [:call, nil, :attr_accessor, [:arglist, [:lit, field.name.to_sym]]]
end

#visit_implements_statement(impls) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 89

def visit_implements_statement(impls)
  [:module, classify(impls.implementor),
    [:scope,
      [:call, nil, :include,
        [:arglist,
          [:const, classify(impls.implementee)]
        ]
      ]
    ]
  ]
end

#visit_interface(intf) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 14

def visit_interface(intf)
  [:module, classify(intf.name),
    ([:scope, [:block] + intf.inherits.map { |inherit| [:call, nil, :include, [:arglist, inherit.accept(self)]] }] unless intf.inherits.empty?),
    [:scope,
      [:block] + intf.members.map { |m| m.accept(self) }
    ]
  ].compact
end

#visit_module(mod) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 4

def visit_module(mod)
  [:block,
    [:module, classify(mod.name),
      [:scope,
        [:block] + mod.definitions.map { |d| d.accept(self) }
      ]
    ]
  ]
end

#visit_operation(operation) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 44

def visit_operation(operation)
  if operation.name.empty?
    if operation.setter?
      meth = :[]=
    elsif operation.getter?
      meth = :[]
    elsif operation.creator?
      meth = :initialize
    elsif operation.stringifier?
      meth = :to_s
    elsif operation.deleter?
      meth = :delete!
    else
      raise "no name for operation #{operation.pretty_inspect}"
    end
  else
    meth = operation.name.snake_case
    meth << "=" if operation.setter?
  end

  [:defn, meth.to_sym,
    [:args] + operation.args.map { |a| a.accept(self) },
    [:scope,
      [:block,
        [:call, nil, :raise,
          [:arglist,
            [:const, :NotImplementedError]
          ]
        ]
      ]
    ]
  ]
end

#visit_scoped_name(sn) ⇒ Object



101
102
103
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 101

def visit_scoped_name(sn)
  [:const, classify(sn.qualified_name)]
end

#visit_type_def(typedef) ⇒ Object



85
86
87
# File 'lib/webidl/generator/ruby_sexp_visitor.rb', line 85

def visit_type_def(typedef)
  # don't care
end