Commit 7cd8c594 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Some fixes, and added some testing functions, although these tests only look...

Some fixes, and added some testing functions, although these tests only look for errors and assertion failures -- they do not check correctness of the shunting yard implementation.  We are, for now, relying on the testing done during development for that.  After integrating this code, the Rosie unit tests will confirm that the transformations were correct.
parent e2248d69
Pipeline #60839644 passed with stage
in 1 minute and 10 seconds
......@@ -31,7 +31,7 @@
-- parenthetical expressions can be recognized by a unique prefix (an open
-- paren), the RPL grammar will parse one as a TERM.
local DEBUG=true
local DEBUG=false
local infix = {}
local list = require("list")
......@@ -293,23 +293,21 @@ local function handle_statement(s)
subs = newsubs}
elseif s.type=="form.grammar_block" then
assert(s.subs[1].type=="form.bindings")
local private_bindings = subs[1].subs
local public_bindings = s.subs[2].subs
local public = {type=private_bindings.type,
s=private_bindings.s,
e=private_bindings.e,
data=private_bindings.data,
subs = map(handle_statement, private_bindings.subs)}
local private = {type=public_bindings.type,
s=public_bindings.s,
e=public_bindings.e,
data=public_bindings.data,
subs = map(handle_statement, public_bindings.subs)}
-- there may be one set of bindings or two
local newsubs = {}
for _, bindings in ipairs(s.subs) do
local pt = {type=bindings.type,
s=bindings.s,
e=bindings.e,
data=bindings.data,
subs=bindings.subs and map(handle_statement, bindings.subs)}
table.insert(newsubs, pt)
end -- for
return {type=s.type,
s=s.s,
e=s.e,
data=s.data,
subs = {public, private}}
subs = newsubs}
elseif s.type=="package_decl" or
s.type=="import_decl" or
s.type=="language_decl" or
......@@ -349,5 +347,69 @@ function infix.to_prefix(pt)
end
end
--------------------------------------------------------------------------------
function slurp(filename)
local f, err = io.open(filename)
if not f then error(err) end
local txt = f:read("a")
f:close()
return txt
end
function test1(filename)
io.stdout:write("Testing " .. filename .. " ... ")
io.stdout:flush()
-- set globals for ease of debugging
src = slurp(filename)
p = stmt:match(src)
ok, x = pcall(infix.to_prefix, p)
if ok then
print("ok")
else
print("ERROR:")
error(x, 1)
end
end
function test()
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/all.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/char.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/csv.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/date.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/json.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/net.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/num.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/os.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/re.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/time.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/ver.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/word.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rcfile.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_1.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_2.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/rosie/rpl_1_3.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Ascii.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Block.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Category.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/GraphemeBreak.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/LineBreak.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/NumericType.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Property.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/Script.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/SentenceBreak.rpl")
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/Unicode/WordBreak.rpl")
end
function setup()
e = rosie.engine.new();
e:import('rosie/rpl_1_3', '.');
exp = e:compile('rpl_expression');
stmt = e:compile('rpl_statements');
import = rosie.import;
infix = dofile("/Users/jennings/Projects/rosie-pattern-language/dev/src/lua/infix.lua")
end
return infix
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment