simple server api to return possible programs and their parses

Parsley doesn’t work on opal (though it is pure ruby)
thus have to jump through  (client server) hoops
This commit is contained in:
Torsten Ruger 2015-10-21 14:03:02 +03:00
parent 8eade695a4
commit 45a2c707da

View File

@ -10,15 +10,28 @@ require 'opal-browser'
Opal.use_gem("salama") Opal.use_gem("salama")
Opal.use_gem("ast") Opal.use_gem("ast")
Opal.use_gem("salama-arm") Opal.use_gem("salama-arm")
Virtual.machine.boot
class DebugServer < Opal::Server class DebugServer < Opal::Server
def call(env) def call(env)
if( env["REQUEST_PATH"] == "/tasks.json") path = env["REQUEST_PATH"]
[200, { 'Content-Type' => 'text/json' }, [ParseTask.new.parse(1).to_json]] return super(env) unless path.include?("json")
route = path[1 .. path.index(".") - 1]
if( route == "codes")
[200, { 'Content-Type' => 'text/json' }, codes ]
else else
super(env) [200, { 'Content-Type' => 'text/json' }, code(route) ]
end end
end end
def codes
[Dir["codes/*.psol"].collect{|f| f.sub("codes/","").sub(".psol","")}.join("----")]
end
def code at
phisol = File.new("codes/#{at}.psol").read
syntax = Parser::Salama.new.parse_with_debug(phisol)
parts = Parser::Transform.new.apply(syntax)
[parts.inspect]
end
end end
run DebugServer.new { |s| run DebugServer.new { |s|
s.main = 'debugger' s.main = 'debugger'