2015-07-14 13:08:28 +02:00
|
|
|
require 'bundler'
|
|
|
|
Bundler.require
|
2015-08-20 02:14:33 +02:00
|
|
|
require 'tilt/erb'
|
|
|
|
|
2015-07-14 13:08:28 +02:00
|
|
|
require "opal"
|
2015-08-20 00:53:39 +02:00
|
|
|
require 'opal-browser'
|
|
|
|
|
2015-07-14 13:08:28 +02:00
|
|
|
Opal.use_gem("salama")
|
2015-10-02 19:25:54 +02:00
|
|
|
Opal.use_gem("ast")
|
2015-08-19 22:34:39 +02:00
|
|
|
Opal.use_gem("salama-arm")
|
2015-10-27 11:46:39 +01:00
|
|
|
Register.machine.boot
|
2015-07-14 13:08:28 +02:00
|
|
|
|
2015-07-14 15:03:06 +02:00
|
|
|
class DebugServer < Opal::Server
|
|
|
|
def call(env)
|
2015-10-21 13:03:02 +02:00
|
|
|
path = env["REQUEST_PATH"]
|
|
|
|
return super(env) unless path.include?("json")
|
|
|
|
route = path[1 .. path.index(".") - 1]
|
|
|
|
if( route == "codes")
|
|
|
|
[200, { 'Content-Type' => 'text/json' }, codes ]
|
2015-07-14 15:03:06 +02:00
|
|
|
else
|
2015-10-21 13:03:02 +02:00
|
|
|
[200, { 'Content-Type' => 'text/json' }, code(route) ]
|
2015-07-14 15:03:06 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-21 13:03:02 +02:00
|
|
|
def codes
|
2015-10-27 17:09:24 +01:00
|
|
|
[Dir["codes/*.saml"].collect{|f| f.sub("codes/","").sub(".saml","")}.join("----")]
|
2015-10-21 13:03:02 +02:00
|
|
|
end
|
|
|
|
def code at
|
2015-10-27 17:09:24 +01:00
|
|
|
saml = File.new("codes/#{at}.saml").read
|
|
|
|
syntax = Parser::Salama.new.parse_with_debug(saml)
|
2015-10-21 13:03:02 +02:00
|
|
|
parts = Parser::Transform.new.apply(syntax)
|
|
|
|
[parts.inspect]
|
|
|
|
end
|
2015-07-14 15:03:06 +02:00
|
|
|
end
|
|
|
|
run DebugServer.new { |s|
|
2015-07-14 13:08:28 +02:00
|
|
|
s.main = 'debugger'
|
|
|
|
s.append_path 'lib'
|
2015-08-20 02:14:33 +02:00
|
|
|
s.append_path 'assets'
|
2015-08-22 01:35:21 +02:00
|
|
|
s.debug = !ENV["DEBUG"].nil?
|
2015-08-20 02:14:33 +02:00
|
|
|
|
|
|
|
s.index_path = "index.html.erb"
|
2015-08-20 00:53:39 +02:00
|
|
|
s.sprockets.cache = Sprockets::Cache::MemoryStore.new(5000)
|
2015-07-14 13:08:28 +02:00
|
|
|
}
|