extract the converter into own file
and small cleanups
This commit is contained in:
parent
d19e89567f
commit
a167a87b1f
@ -30,7 +30,7 @@ GIT
|
|||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/whitequark/ast.git
|
remote: git://github.com/whitequark/ast.git
|
||||||
revision: 3814fb102af82a30bf334005ebe17332744f9dad
|
revision: 63db4686b33228e8f703cb7328e5e5c62aa3cd92
|
||||||
specs:
|
specs:
|
||||||
ast (2.1.0)
|
ast (2.1.0)
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ $susy: (
|
|||||||
.statement {
|
.statement {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ticker{
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
.act{
|
.act{
|
||||||
background-color: #00B3FF;
|
background-color: #00B3FF;
|
||||||
-moz-border-radius: 7px;
|
-moz-border-radius: 7px;
|
||||||
|
98
lib/views/html_converter.rb
Normal file
98
lib/views/html_converter.rb
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
class HtmlConverter < AST::Processor
|
||||||
|
|
||||||
|
alias :old_process :process
|
||||||
|
def process s
|
||||||
|
return "" unless s
|
||||||
|
old_process(s)
|
||||||
|
end
|
||||||
|
def handler_missing s
|
||||||
|
puts "Missing: " + s.type
|
||||||
|
end
|
||||||
|
def div statement , html
|
||||||
|
"<div class='statement' id='i#{statement.object_id}'>" + html + "</div>"
|
||||||
|
end
|
||||||
|
def span statement , html
|
||||||
|
"<span class='expression' id='i#{statement.object_id}'>" + html + "</span>"
|
||||||
|
end
|
||||||
|
def on_function statement
|
||||||
|
return_type , name , parameters, kids , receiver = *statement
|
||||||
|
str = return_type + " "
|
||||||
|
str += receiver + "." if receiver
|
||||||
|
str += name.to_a.first + "("
|
||||||
|
str += process(parameters) + ")<br>"
|
||||||
|
str += process(kids) + "end<br>"
|
||||||
|
div(statement,str)
|
||||||
|
end
|
||||||
|
def on_parameters statement
|
||||||
|
process_all(statement.children).join(",")
|
||||||
|
end
|
||||||
|
def on_parameter p
|
||||||
|
type , name = *p
|
||||||
|
span(type,type) + " " + span(name,name)
|
||||||
|
end
|
||||||
|
def on_string s
|
||||||
|
span(s, "'" + s.first + "'")
|
||||||
|
end
|
||||||
|
def on_field_def statement
|
||||||
|
type , name , value = *statement
|
||||||
|
str = span(type, type) + " " + span(name,name)
|
||||||
|
str += " = #{process(value)}" if value
|
||||||
|
div(statement,str)
|
||||||
|
end
|
||||||
|
def on_return statement
|
||||||
|
str = "return " + process(statement.first )
|
||||||
|
div(statement,str)
|
||||||
|
end
|
||||||
|
def on_false_statements s
|
||||||
|
on_statements s
|
||||||
|
end
|
||||||
|
def on_true_statements s
|
||||||
|
on_statements s
|
||||||
|
end
|
||||||
|
def on_statements s
|
||||||
|
str = ""
|
||||||
|
s.children.each do |c|
|
||||||
|
str += process(c).to_s
|
||||||
|
end
|
||||||
|
div(s,str)
|
||||||
|
end
|
||||||
|
def on_if_statement statement
|
||||||
|
branch_type , condition , if_true , if_false = *statement
|
||||||
|
condition = condition.first
|
||||||
|
ret = "if_#{branch_type}(" + process(condition) + ")<br>" + process(if_true)
|
||||||
|
ret += "else" + "<br>" + process(if_false) if if_false
|
||||||
|
ret += "end"
|
||||||
|
div(statement,ret)
|
||||||
|
end
|
||||||
|
def on_assignment statement
|
||||||
|
name , value = *statement
|
||||||
|
name = process(name)
|
||||||
|
v = process(value)
|
||||||
|
str = name + " = " + v
|
||||||
|
div(statement,str)
|
||||||
|
end
|
||||||
|
def on_call c
|
||||||
|
name , arguments , receiver = *c
|
||||||
|
ret = process(name)
|
||||||
|
ret = process(receiver.first) + "." + ret if receiver
|
||||||
|
ret += "("
|
||||||
|
ret += process(arguments).join(",")
|
||||||
|
ret += ")"
|
||||||
|
span(c,ret)
|
||||||
|
end
|
||||||
|
def on_operator_value statement
|
||||||
|
operator , left_e , right_e = *statement
|
||||||
|
left_reg = process(left_e)
|
||||||
|
right_reg = process(right_e)
|
||||||
|
span(statement , left_reg + " " + operator + " " + right_reg )
|
||||||
|
end
|
||||||
|
def on_arguments args
|
||||||
|
args.children.collect{|c| process(c)}
|
||||||
|
end
|
||||||
|
def on_name name
|
||||||
|
span(name,name.first)
|
||||||
|
end
|
||||||
|
def on_int i
|
||||||
|
span(i , i.first.to_s)
|
||||||
|
end
|
||||||
|
end
|
@ -1,3 +1,5 @@
|
|||||||
|
require_relative "html_converter"
|
||||||
|
|
||||||
class SourceView < ElementView
|
class SourceView < ElementView
|
||||||
|
|
||||||
def initialize interpreter
|
def initialize interpreter
|
||||||
@ -7,7 +9,7 @@ class SourceView < ElementView
|
|||||||
|
|
||||||
def draw
|
def draw
|
||||||
@text = div(".text")
|
@text = div(".text")
|
||||||
@ticker = div
|
@ticker = div(".ticker")
|
||||||
@element = div(".source_view") << div("h4.source" , "Class.Method") << @ticker << @text
|
@element = div(".source_view") << div("h4.source" , "Class.Method") << @ticker << @text
|
||||||
@element
|
@element
|
||||||
end
|
end
|
||||||
@ -15,134 +17,44 @@ class SourceView < ElementView
|
|||||||
def instruction_changed
|
def instruction_changed
|
||||||
i = @interpreter.instruction
|
i = @interpreter.instruction
|
||||||
return "" unless i
|
return "" unless i
|
||||||
if( i.is_a?(Register::Label) and i.name.include?("."))
|
update_method
|
||||||
update_method
|
|
||||||
end
|
|
||||||
case i.source
|
case i.source
|
||||||
when AST::Node
|
when AST::Node
|
||||||
id = i.source.object_id
|
id = i.source.object_id
|
||||||
text = i.source.type + ":#{id}"
|
|
||||||
if e = @text.at_css("#i#{id}")
|
if e = @text.at_css("#i#{id}")
|
||||||
if (old = @text.at_css(".fade_in"))
|
if (old = @text.at_css(".fade_in"))
|
||||||
old.remove_class("fade_in")
|
old.remove_class("fade_in")
|
||||||
end
|
end
|
||||||
text += " found"
|
|
||||||
e.add_class "fade_in"
|
e.add_class "fade_in"
|
||||||
end
|
end
|
||||||
@ticker.text = text
|
|
||||||
when String
|
when String
|
||||||
@ticker.text = i.source
|
@ticker.text = i.source
|
||||||
else
|
else
|
||||||
raise i.source.class.name
|
raise i.source.class.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_method
|
def update_method
|
||||||
@element.at_css(".source").text = @interpreter.instruction.name
|
i = @interpreter.instruction
|
||||||
cl_name , method_name = *@interpreter.instruction.name.split(".")
|
case i
|
||||||
clazz = Register.machine.space.get_class_by_name cl_name
|
when Register::Label
|
||||||
method = clazz.get_instance_method( method_name)
|
if i.name.include?(".")
|
||||||
@text.inner_html = ToCode.new.process( method.source )
|
cl_name , method_name = *i.name.split(".")
|
||||||
end
|
clazz = Register.machine.space.get_class_by_name cl_name
|
||||||
|
method = clazz.get_instance_method( method_name)
|
||||||
def update_code
|
else
|
||||||
@text.inner_html = ToCode.new.process( @interpreter.instruction.source)
|
return
|
||||||
end
|
end
|
||||||
end
|
@element.at_css(".source").text = i.name
|
||||||
class ToCode < AST::Processor
|
when Register::FunctionReturn
|
||||||
|
object = @interpreter.object_for( i.register )
|
||||||
alias :old_process :process
|
link = object.internal_object_get( i.index )
|
||||||
def process s
|
method = link.method
|
||||||
return "" unless s
|
@element.at_css(".source").text = method.name
|
||||||
old_process(s)
|
else
|
||||||
end
|
return
|
||||||
def handler_missing s
|
|
||||||
puts "Missing: " + s.type
|
|
||||||
end
|
|
||||||
def div statement , html
|
|
||||||
"<div class='statement' id='i#{statement.object_id}'>" + html + "</div>"
|
|
||||||
end
|
|
||||||
def span statement , html
|
|
||||||
"<span class='expression' id='i#{statement.object_id}'>" + html + "</span>"
|
|
||||||
end
|
|
||||||
def on_function statement
|
|
||||||
return_type , name , parameters, kids , receiver = *statement
|
|
||||||
str = return_type + " "
|
|
||||||
str += receiver + "." if receiver
|
|
||||||
str += name.to_a.first + "("
|
|
||||||
str += process(parameters) + ")<br>"
|
|
||||||
str += process(kids) + "end<br>"
|
|
||||||
div(statement,str)
|
|
||||||
end
|
|
||||||
def on_parameters statement
|
|
||||||
process_all(statement.children).join(",")
|
|
||||||
end
|
|
||||||
def on_parameter p
|
|
||||||
type , name = *p
|
|
||||||
span(type,type) + " " + span(name,name)
|
|
||||||
end
|
|
||||||
def on_string s
|
|
||||||
span(s, "'" + s.first + "'")
|
|
||||||
end
|
|
||||||
def on_field_def statement
|
|
||||||
type , name , value = *statement
|
|
||||||
str = span(type, type) + " " + span(name,name)
|
|
||||||
str += " = #{process(value)}" if value
|
|
||||||
div(statement,str)
|
|
||||||
end
|
|
||||||
def on_return statement
|
|
||||||
str = "return " + process(statement.first )
|
|
||||||
div(statement,str)
|
|
||||||
end
|
|
||||||
def on_false_statements s
|
|
||||||
on_statements s
|
|
||||||
end
|
|
||||||
def on_true_statements s
|
|
||||||
on_statements s
|
|
||||||
end
|
|
||||||
def on_statements s
|
|
||||||
str = ""
|
|
||||||
s.children.each do |c|
|
|
||||||
str += process(c).to_s
|
|
||||||
end
|
end
|
||||||
div(s,str)
|
@text.inner_html = HtmlConverter.new.process( method.source )
|
||||||
end
|
|
||||||
def on_if_statement statement
|
|
||||||
branch_type , condition , if_true , if_false = *statement
|
|
||||||
condition = condition.first
|
|
||||||
ret = "if_#{branch_type}(" + process(condition) + ")<br>" + process(if_true)
|
|
||||||
ret += "else" + "<br>" + process(if_false) if if_false
|
|
||||||
ret += "end"
|
|
||||||
div(statement,ret)
|
|
||||||
end
|
|
||||||
def on_assignment statement
|
|
||||||
name , value = *statement
|
|
||||||
name = process(name)
|
|
||||||
v = process(value)
|
|
||||||
str = name + " = " + v
|
|
||||||
div(statement,str)
|
|
||||||
end
|
|
||||||
def on_call c
|
|
||||||
name , arguments , receiver = *c
|
|
||||||
ret = process(name)
|
|
||||||
ret = process(receiver.first) + "." + ret if receiver
|
|
||||||
ret += "("
|
|
||||||
ret += process(arguments).join(",")
|
|
||||||
ret += ")"
|
|
||||||
span(c,ret)
|
|
||||||
end
|
|
||||||
def on_operator_value statement
|
|
||||||
operator , left_e , right_e = *statement
|
|
||||||
left_reg = process(left_e)
|
|
||||||
right_reg = process(right_e)
|
|
||||||
span(statement , left_reg + " " + operator + " " + right_reg )
|
|
||||||
end
|
|
||||||
def on_arguments args
|
|
||||||
args.children.collect{|c| process(c)}
|
|
||||||
end
|
|
||||||
def on_name name
|
|
||||||
span(name,name.first)
|
|
||||||
end
|
|
||||||
def on_int i
|
|
||||||
span(i , i.first.to_s)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user