From 45a2c707da96141d312384676833c052ad7dbade Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 21 Oct 2015 14:03:02 +0300 Subject: [PATCH] simple server api to return possible programs and their parses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parsley doesn’t work on opal (though it is pure ruby) thus have to jump through (client server) hoops --- config.ru | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/config.ru b/config.ru index 349ebb0..ee7300c 100644 --- a/config.ru +++ b/config.ru @@ -10,15 +10,28 @@ require 'opal-browser' Opal.use_gem("salama") Opal.use_gem("ast") Opal.use_gem("salama-arm") +Virtual.machine.boot class DebugServer < Opal::Server def call(env) - if( env["REQUEST_PATH"] == "/tasks.json") - [200, { 'Content-Type' => 'text/json' }, [ParseTask.new.parse(1).to_json]] + 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 ] else - super(env) + [200, { 'Content-Type' => 'text/json' }, code(route) ] 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 run DebugServer.new { |s| s.main = 'debugger'