This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: svn+ssh://rubyforge.org/var/svn/johnson/trunk@98 54575175-8111-4fdf-a583-07ff49f40e23
- Loading branch information
aaronp
committed
Mar 31, 2008
1 parent
afc18d7
commit 597bdcf
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require 'johnson/visitors/sexp_visitor' | ||
require 'johnson/visitors/ecma_visitor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
module Johnson | ||
module Visitors | ||
class EcmaVisitor | ||
def initialize | ||
@depth = 0 | ||
end | ||
|
||
def visit_SourceElements(o) | ||
(@depth == 0 ? '' : '{') + | ||
o.value.map { |x| "#{indent}#{x.accept(self)}" }.join("\n") + | ||
(@depth == 0 ? '' : '}') | ||
end | ||
|
||
%w{ Name Number Regexp String }.each do |type| | ||
define_method(:"visit_#{type}") do |o| | ||
o.value | ||
end | ||
end | ||
|
||
{ | ||
'OpEqual' => '=', | ||
'StrictNotEqual' => '!==', | ||
'StrictEqual' => '===', | ||
'Or' => '||', | ||
'OpURShift' => '>>>', | ||
'OpURShiftEqual' => '>>>=', | ||
'OpSubtract' => '-', | ||
'OpSubtractEqual' => '-=', | ||
'OpRShift' => '>>', | ||
'OpRShiftEqual' => '>>=', | ||
'OpMultiply' => '*', | ||
'OpMultiplyEqual' => '*=', | ||
'OpMod' => '%', | ||
'OpModEqual' => '%=', | ||
'OpLShift' => '<<', | ||
'OpLShiftEqual' => '<<=', | ||
'OpDivide' => '/', | ||
'OpDivideEqual' => '/=', | ||
'OpBitXor' => '^', | ||
'OpBitXorEqual' => '^=', | ||
'OpBitOr' => '|', | ||
'OpBitOrEqual' => '|=', | ||
'OpBitAnd' => '&', | ||
'OpBitAndEqual' => '&=', | ||
'OpAdd' => '+', | ||
'OpAddEqual' => '+=', | ||
'NotEqual' => '!=', | ||
'LessThan' => '<', | ||
'LessThanOrEqual' => '<=', | ||
'GreaterThan' => '>', | ||
'GreaterThanOrEqual' => '>=', | ||
'And' => '&&', | ||
'InstanceOf' => 'instanceof', | ||
'Equal' => '==', | ||
}.each do |type,op| | ||
define_method(:"visit_#{type}") do |o| | ||
"#{o.left && o.left.accept(self)}" \ | ||
" #{op} " \ | ||
"#{o.right && o.right.accept(self)}" | ||
end | ||
end | ||
|
||
def accept(target) | ||
target.accept(self) | ||
end | ||
|
||
private | ||
def indent; ' ' * @depth * 2; end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters