Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
cleaning up sexp visitor
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/johnson/trunk@97 54575175-8111-4fdf-a583-07ff49f40e23
  • Loading branch information
aaronp committed Mar 31, 2008
1 parent 06ab37e commit afc18d7
Showing 1 changed file with 33 additions and 70 deletions.
103 changes: 33 additions & 70 deletions lib/johnson/visitors/sexp_visitor.rb
Expand Up @@ -5,80 +5,43 @@ def visit_SourceElements(o)
o.value.map { |x| x.accept(self) }
end

def visit_VarStatement(o)
[:var, o.value.map { |x| x.accept(self) }]
end

def visit_Comma(o)
[:comma, o.value.map { |x| x.accept(self) }]
end

def visit_ObjectLiteral(o)
[:object, o.value.map { |x| x.accept(self) }]
end

def visit_ArrayLiteral(o)
[:array, o.value.map { |x| x.accept(self) }]
end

def visit_New(o)
[:new, o.value.map { |x| x.accept(self) }]
end

def visit_FunctionCall(o)
[:function_call, o.value.map { |x| x.accept(self) }]
end

def visit_Import(o)
[:import, o.value.map { |x| x.accept(self) }]
end

def visit_Export(o)
[:export, o.value.map { |x| x.accept(self) }]
end

def visit_Name(o)
[:name, o.value]
end

def visit_Number(o)
[:lit, o.value]
end

def visit_Regexp(o)
[:lit, o.value]
end

def visit_String(o)
[:str, o.value]
end

def visit_Break(o)
[:break]
end

def visit_Continue(o)
[:continue]
end

def visit_Null(o)
[:nil]
end

def visit_True(o)
[:true]
end

def visit_False(o)
[:false]
{
'VarStatement' => :var,
'Comma' => :comma,
'ObjectLiteral' => :object,
'ArrayLiteral' => :array,
'New' => :new,
'FunctionCall' => :function_call,
'Import' => :import,
'Export' => :export,
}.each do |type,sym|
define_method(:"visit_#{type}") do |o|
[sym, o.value.map { |x| x.accept(self) }]
end
end

def visit_This(o)
[:this]
{
'Name' => :name,
'Number' => :lit,
'Regexp' => :lit,
'String' => :str
}.each do |type,sym|
define_method(:"visit_#{type}") do |o|
[sym, o.value]
end
end

def visit_Semicolon(o)
[:semicolon]
{
'Break' => :break,
'Continue' => :continue,
'Null' => :nil,
'True' => :true,
'False' => :false,
'This' => :this,
}.each do |type,sym|
define_method(:"visit_#{type}") do |o|
[sym]
end
end

def visit_For(o)
Expand Down

0 comments on commit afc18d7

Please sign in to comment.