From 97cf5e5bea4be24fd1a0df3013f25aa05b08351b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 9 Oct 2015 17:23:43 +0300 Subject: [PATCH] retrying with the root of the directory comes from finally tightning the root and not allowing random expression code ala ruby --- README.md | 6 +++--- test/parser_helper.rb | 2 +- test/setup.rb | 7 ------- test/test_all.rb | 8 +++++++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 930db3d..f2e4c63 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Syntax (and semantics) of Phisol are just forming, but some things are clear: - call syntax as already discussed, ie message based Some things we shall leave behind from the ruby approach are a lot of sugar, like missing brackets, -random code everywhere, expressions galore . . . +random code everywhere, statements galore . . . ### Parser @@ -52,10 +52,10 @@ Most names are quite self explanatory, but here is a list: - call_site is a function call. May be qualified, but currently must still have braches - compound types are hash and array definitions. Hashes still need curlies - control is if statement which still must have an else -- expression is a helper for all code allowed in a function +- statement is a helper for all code allowed in a function - function definition must have braces too - keywords is just a list of them -- operator expression are binary operators (see also below). There's a surprising amount +- operator statement are binary operators (see also below). There's a surprising amount - return statement are straightforward - while still needs a do, though i think in ruby a newline is sufficient diff --git a/test/parser_helper.rb b/test/parser_helper.rb index 0ed0287..c1630e3 100644 --- a/test/parser_helper.rb +++ b/test/parser_helper.rb @@ -8,7 +8,7 @@ module ParserHelper def self.included(base) base.send :include, InstanceMethods #provides helpers and setup - base.send :include, AST::if_true + base.send :include, AST::true_statements base.send :extend, ClassMethods #gets the method creation going end diff --git a/test/setup.rb b/test/setup.rb index e6048f8..47c8410 100644 --- a/test/setup.rb +++ b/test/setup.rb @@ -17,10 +17,3 @@ require 'salama-reader' require "minitest" require "minitest/autorun" - -# for testing add expression as allowed root -# bit of a hack: the directory name should be passed as the root if the parse fails -# but moving on (and coming back) -Parser::Salama.class_eval do - rule(:root_body) {( class_definition | function_definition | expression )} -end diff --git a/test/test_all.rb b/test/test_all.rb index 81bbb17..3977046 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -10,7 +10,13 @@ class TestAll < MiniTest::Test def check_file file inn , out = File.new(file).read.split(SEPERATOR) sexp = eval(out) - syntax = Parser::Salama.new.parse_with_debug(inn) + begin + syntax = Parser::Salama.new.parse(inn) + rescue + root = file.split("/")[2] + parser = Parser::Salama.new.send root.to_sym + syntax = parser.parse_with_debug(inn ) + end result = Parser::Transform.new.apply(syntax) equal = (sexp == result) unless equal