From: Michael D. Lowis Date: Sat, 10 Oct 2015 03:23:20 +0000 (-0400) Subject: Comment out unused specs temporarily X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=48ac9534d0df4ad8370d4353f2bd282c6d2a3f80;p=proto%2Fsclpl.git Comment out unused specs temporarily --- diff --git a/build.rb b/build.rb index adfac4e..9f4095d 100755 --- a/build.rb +++ b/build.rb @@ -13,38 +13,6 @@ base_env = BuildEnv.new do |env| # Move the object files to the build dir env.build_dir('source','build/obj/source') env.build_dir('modules','build/obj/modules') - - env.add_builder :Install do |target, sources, cache, env, vars| - is_dir = (sources.length > 1) || Dir.exists?(sources.first) || Dir.exists?(target) - outdir = is_dir ? target : File.dirname(target) - # Collect the list of files to copy over - file_map = {} - if is_dir - sources.each do |src| - if Dir.exists? src - Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).each do |subfile| - subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s - file_map[subfile] = "#{outdir}/#{subpath}" - end - else - file_map[src] = "#{outdir}/#{File.basename(src)}" - end - end - else - file_map[sources.first] = target - end - # Check the cache and copy if necessary - unless cache.up_to_date?(target, :Install, file_map.keys, env) - puts "INSTALL #{target}" - file_map.each do |k,v| - cache.mkdir_p(File.dirname(v)) - FileUtils.cp(k, v, :preserve => true) - end - cache.register_build(target, :Install, file_map.keys, env) - end - target if (is_dir ? Dir.exists?(target) : File.exists?(target)) - end - # Compiler options env["CFLAGS"] += ['-DLEAK_DETECT_LEVEL=1', '--std=c99', '-Wall', '-Wextra']#, '-Werror'] env["CPPPATH"] += Dir['modules/libcds/source/**/'] + [ @@ -80,10 +48,6 @@ end sources = FileList['source/*.c', 'modules/libopts/source/*.c'] main_env.Program('build/bin/sclpl', sources) -# Build the runtime library -main_env.Library('build/lib/libsrt.a', FileList['source/runtime/*.c']) -main_env.Install('build/include/sclpl.h', 'source/runtime/sclpl.h') - #------------------------------------------------------------------------------ # Test Build Targets #------------------------------------------------------------------------------ diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 3924281..cfb2a70 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -1,70 +1,70 @@ require 'spec_helper' -describe "cli" do - context "token mode" do - it "should accept input from stdin" do - expect(cli(['--tokens'])).to eq("") - end - - it "should translate the input file" do - expect(cli(['--tokens', 'spec/src/sample.scl'])).to eq("") - expect(File.exists? 'spec/src/sample.tok').to be(true) - FileUtils.rm('spec/src/sample.tok') - end - end - - context "ast mode" do - it "should accept input from stdin" do - expect(cli(['--ast'])).to eq("") - end - - it "should translate the input file" do - expect(cli(['--ast', 'spec/src/sample.scl'])).to eq("") - expect(File.exists? 'spec/src/sample.ast').to be(true) - FileUtils.rm('spec/src/sample.ast') - end - end - - context "c source mode" do - it "should accept input from stdin" do - expect(cli(['--csource'])).not_to eq("") - end - - it "should translate the input file" do - expect(cli(['--csource', 'spec/src/sample.scl'])).to eq("") - expect(File.exists? 'spec/src/sample.c').to be(true) - FileUtils.rm('spec/src/sample.c') - end - end - - context "object mode" do - it "should error when too few input files provided" do - expect{cli(['--object'])}.to raise_error(/too few files/) - end - - it "should error when too many input files provided" do - expect{cli(['--object', 'spec/src/sample.scl', 'spec/src/sample.scl'])}.to raise_error(/too many files/) - end - - it "should compile the input file in verbose mode (short flag)" do - expect(cli(['-v', '--object', 'spec/src/sample.scl'])).to eq( - "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") - expect(File.exists? 'spec/src/sample.o').to be(true) - FileUtils.rm('spec/src/sample.o') - end - - it "should compile the input file in verbose mode (long flag)" do - expect(cli(['--verbose', '--object', 'spec/src/sample.scl'])).to eq( - "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") - expect(File.exists? 'spec/src/sample.o').to be(true) - FileUtils.rm('spec/src/sample.o') - end - - it "should compile the input file" do - expect(cli(['--object', 'spec/src/sample.scl'])).to eq("") - expect(File.exists? 'spec/src/sample.o').to be(true) - FileUtils.rm('spec/src/sample.o') - end - end -end +#describe "cli" do +# context "token mode" do +# it "should accept input from stdin" do +# expect(cli(['--tokens'])).to eq("") +# end +# +# it "should translate the input file" do +# expect(cli(['--tokens', 'spec/src/sample.scl'])).to eq("") +# expect(File.exists? 'spec/src/sample.tok').to be(true) +# FileUtils.rm('spec/src/sample.tok') +# end +# end +# +# context "ast mode" do +# it "should accept input from stdin" do +# expect(cli(['--ast'])).to eq("") +# end +# +# it "should translate the input file" do +# expect(cli(['--ast', 'spec/src/sample.scl'])).to eq("") +# expect(File.exists? 'spec/src/sample.ast').to be(true) +# FileUtils.rm('spec/src/sample.ast') +# end +# end +# +# context "c source mode" do +# it "should accept input from stdin" do +# expect(cli(['--csource'])).not_to eq("") +# end +# +# it "should translate the input file" do +# expect(cli(['--csource', 'spec/src/sample.scl'])).to eq("") +# expect(File.exists? 'spec/src/sample.c').to be(true) +# FileUtils.rm('spec/src/sample.c') +# end +# end +# +# context "object mode" do +# it "should error when too few input files provided" do +# expect{cli(['--object'])}.to raise_error(/too few files/) +# end +# +# it "should error when too many input files provided" do +# expect{cli(['--object', 'spec/src/sample.scl', 'spec/src/sample.scl'])}.to raise_error(/too many files/) +# end +# +# it "should compile the input file in verbose mode (short flag)" do +# expect(cli(['-v', '--object', 'spec/src/sample.scl'])).to eq( +# "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") +# expect(File.exists? 'spec/src/sample.o').to be(true) +# FileUtils.rm('spec/src/sample.o') +# end +# +# it "should compile the input file in verbose mode (long flag)" do +# expect(cli(['--verbose', '--object', 'spec/src/sample.scl'])).to eq( +# "cc -c -o spec/src/sample.o -I ./build/bin/../include/ spec/src/sample.c\n") +# expect(File.exists? 'spec/src/sample.o').to be(true) +# FileUtils.rm('spec/src/sample.o') +# end +# +# it "should compile the input file" do +# expect(cli(['--object', 'spec/src/sample.scl'])).to eq("") +# expect(File.exists? 'spec/src/sample.o').to be(true) +# FileUtils.rm('spec/src/sample.o') +# end +# end +#end diff --git a/spec/codegen_spec.rb b/spec/codegen_spec.rb index 09b9010..3e928c3 100644 --- a/spec/codegen_spec.rb +++ b/spec/codegen_spec.rb @@ -1,137 +1,137 @@ require 'spec_helper' -InputSource = <<-eos -require "foo"; -def a 123; -def b +123; -def c -123; -def d 321.0; -def e +321.0; -def f -321.0; -def g 0b101; -def h 0o707; -def i 0d909; -def j 0hF0F; -def k 0hf0f; -def l \\space; -def m \\tab; -def n \\return; -def o \\newline; -def p \\vtab; -def q \\c; -def r ""; -def s " -"; -def t true; -def u false; -def v l; -def w() 0; -def x(a) 1; -def y(a,b) 2; -def z fn(a,b,c) 3;; - -w() -x(1) -y(1,2) -z(1,2,3) -eos - -ExpectedCode = <<-eos -#include "sclpl.h" - -_Value a; -_Value b; -_Value c; -_Value d; -_Value e; -_Value f; -_Value g; -_Value h; -_Value i; -_Value j; -_Value k; -_Value l; -_Value m; -_Value n; -_Value o; -_Value p; -_Value q; -_Value r; -_Value s; -_Value t; -_Value u; -_Value v; -_Value w; -_Value x; -_Value y; -_Value z; - -static _Value fn0(); -static _Value fn1(_Value a); -static _Value fn2(_Value a, _Value b); -static _Value fn3(_Value a, _Value b, _Value c); - -static _Value fn0() { - return __int(0); -} - -static _Value fn1(_Value a) { - return __int(1); -} - -static _Value fn2(_Value a, _Value b) { - return __int(2); -} - -static _Value fn3(_Value a, _Value b, _Value c) { - return __int(3); -} - -void toplevel(void) { - extern void foo_toplevel(void); - foo_toplevel(); - a = __int(123); - b = __int(123); - c = __int(-123); - d = __float(321.000000); - e = __float(321.000000); - f = __float(-321.000000); - g = __int(5); - h = __int(455); - i = __int(909); - j = __int(3855); - k = __int(3855); - l = __char(' '); - m = __char('\\t'); - n = __char('\\r'); - o = __char('\\n'); - p = __char('\\v'); - q = __char('c'); - r = __string(""); - s = __string("\\n"); - t = __bool(true); - u = __bool(false); - v = l; - w = __func(&fn0); - x = __func(&fn1); - y = __func(&fn2); - z = __func(&fn3); - (void)(__call0(w)); - (void)(__calln(x, 1, __int(1))); - (void)(__calln(y, 2, __int(1), __int(2))); - (void)(__calln(z, 3, __int(1), __int(2), __int(3))); -} - -int main(int argc, char** argv) { - (void)argc; - (void)argv; - toplevel(); - return 0; -} -eos - -describe "code generation" do - it "should generate some code" do - expect(ccode(InputSource)).to eq ExpectedCode - end -end +#InputSource = <<-eos +#require "foo"; +#def a 123; +#def b +123; +#def c -123; +#def d 321.0; +#def e +321.0; +#def f -321.0; +#def g 0b101; +#def h 0o707; +#def i 0d909; +#def j 0hF0F; +#def k 0hf0f; +#def l \\space; +#def m \\tab; +#def n \\return; +#def o \\newline; +#def p \\vtab; +#def q \\c; +#def r ""; +#def s " +#"; +#def t true; +#def u false; +#def v l; +#def w() 0; +#def x(a) 1; +#def y(a,b) 2; +#def z fn(a,b,c) 3;; +# +#w() +#x(1) +#y(1,2) +#z(1,2,3) +#eos +# +#ExpectedCode = <<-eos +##include "sclpl.h" +# +#_Value a; +#_Value b; +#_Value c; +#_Value d; +#_Value e; +#_Value f; +#_Value g; +#_Value h; +#_Value i; +#_Value j; +#_Value k; +#_Value l; +#_Value m; +#_Value n; +#_Value o; +#_Value p; +#_Value q; +#_Value r; +#_Value s; +#_Value t; +#_Value u; +#_Value v; +#_Value w; +#_Value x; +#_Value y; +#_Value z; +# +#static _Value fn0(); +#static _Value fn1(_Value a); +#static _Value fn2(_Value a, _Value b); +#static _Value fn3(_Value a, _Value b, _Value c); +# +#static _Value fn0() { +# return __int(0); +#} +# +#static _Value fn1(_Value a) { +# return __int(1); +#} +# +#static _Value fn2(_Value a, _Value b) { +# return __int(2); +#} +# +#static _Value fn3(_Value a, _Value b, _Value c) { +# return __int(3); +#} +# +#void toplevel(void) { +# extern void foo_toplevel(void); +# foo_toplevel(); +# a = __int(123); +# b = __int(123); +# c = __int(-123); +# d = __float(321.000000); +# e = __float(321.000000); +# f = __float(-321.000000); +# g = __int(5); +# h = __int(455); +# i = __int(909); +# j = __int(3855); +# k = __int(3855); +# l = __char(' '); +# m = __char('\\t'); +# n = __char('\\r'); +# o = __char('\\n'); +# p = __char('\\v'); +# q = __char('c'); +# r = __string(""); +# s = __string("\\n"); +# t = __bool(true); +# u = __bool(false); +# v = l; +# w = __func(&fn0); +# x = __func(&fn1); +# y = __func(&fn2); +# z = __func(&fn3); +# (void)(__call0(w)); +# (void)(__calln(x, 1, __int(1))); +# (void)(__calln(y, 2, __int(1), __int(2))); +# (void)(__calln(z, 3, __int(1), __int(2), __int(3))); +#} +# +#int main(int argc, char** argv) { +# (void)argc; +# (void)argv; +# toplevel(); +# return 0; +#} +#eos +# +#describe "code generation" do +# it "should generate some code" do +# expect(ccode(InputSource)).to eq ExpectedCode +# end +#end diff --git a/spec/lexer_spec.rb b/spec/lexer_spec.rb index c167cdb..65d9711 100644 --- a/spec/lexer_spec.rb +++ b/spec/lexer_spec.rb @@ -213,9 +213,9 @@ describe "lexer" do "T_STRING:\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\""] end - it "should raise an assertion exception when the file ends before a string terminates" do - expect{lexer("\"abc")}.to raise_error(/AssertionException/) - end + #it "should raise an assertion exception when the file ends before a string terminates" do + # expect{lexer("\"abc")}.to raise_error(/AssertionException/) + #end end end diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index a7262cd..ac424b1 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -1,226 +1,226 @@ require 'open3' -describe "sclpl grammar" do - context "requires" do - it "should parse a require statement" do - expect(ast('require "foo";')).to eq([ ['T_ID:require', 'T_STRING:"foo"'] ]) - end - - it "should parse a require statement using end keyword" do - expect(ast('require "foo" end')).to eq([ ['T_ID:require', 'T_STRING:"foo"'] ]) - end - - it "should error on missing semicolon" do - expect{ast('require "foo"')}.to raise_error /Error/ - end - - it "should error on missing filename" do - expect{ast('require ;')}.to raise_error /Error/ - end - - it "should error on invalid filename type" do - expect{ast('require 123;')}.to raise_error /Error/ - end - - it "should error on too many parameters" do - expect{ast('require foo bar;')}.to raise_error /Error/ - end - end - - context "type definitions" do - it "should parse a simple type definition" do - expect(ast('type foo is int;')).to eq([ ['T_ID:type', 'T_ID:foo', 'T_ID:is', 'T_ID:int'] ]) - end - - it "should parse a function type definition with no args" do - expect(ast('type foo is int();')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', []]] ]) - end - - it "should parse a function type definition with one arg" do - expect(ast('type foo is int(int);')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int']]] ]) - end - - it "should parse a function type definition with two args" do - expect(ast('type foo is int(int,int);')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int', 'T_ID:int']]] ]) - end - - it "should parse a function type definition with three args" do - expect(ast('type foo is int(int,int,int);')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int', 'T_ID:int', 'T_ID:int']]] ]) - end - - it "should parse a tuple type definition with one field" do - expect(ast('type foo is {int};')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int']] ]) - end - - it "should parse a tuple type definition with two fields" do - expect(ast('type foo is {int,int};')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int', 'T_ID:int']] ]) - end - - it "should parse a tuple type definition with three fields" do - expect(ast('type foo is {int,int,int};')).to eq([ - ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int', 'T_ID:int', 'T_ID:int']] ]) - end - - it "should parse a record type definition with one field" do - pending "Type annotations have not been implemented yet" - expect(ast('type foo is { int a };')).to eq([ - ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a']]] ]) - end - - it "should parse a record type definition with two fields" do - pending "Type annotations have not been implemented yet" - expect(ast('type foo is { int a, int b };')).to eq([ - ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b']]] ]) - end - - it "should parse a record type definition with three fields" do - pending "Type annotations have not been implemented yet" - expect(ast('type foo is { int a, int b };')).to eq([ - ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b'], ['T_ID:int', 'T_ID:c']]] ]) - end - end - - context "definitions" do - it "should parse a value definition" do - expect(ast('def foo 123;')).to eq([ ['T_ID:def', 'T_ID:foo', 'T_INT:123'] ]) - end - - it "should parse a function definition" do - expect(ast('def foo() 123;')).to eq([ - ['T_ID:def', 'T_ID:foo', ['T_ID:fn', [], 'T_INT:123']] ]) - end - - it "should parse a function definition with multiple expressions in the body" do - expect(ast('def foo() 123 321;')).to eq([ - ['T_ID:def', 'T_ID:foo', ['T_ID:fn', [], 'T_INT:123', 'T_INT:321']] ]) - end - - it "should parse a function definition with one argument" do - expect(ast('def foo(a) 123;')).to eq([ - ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a'], 'T_INT:123']] ]) - end - - it "should parse a function definition with two arguments" do - expect(ast('def foo(a,b) 123;')).to eq([ - ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a', 'T_ID:b'], 'T_INT:123']] ]) - end - - it "should parse a function definition with three arguments" do - expect(ast('def foo(a,b,c) 123;')).to eq([ - ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a', 'T_ID:b', 'T_ID:c'], 'T_INT:123']] ]) - end - end - - context "annotations" do - it "should parse a type annotation for a simple type" do - expect(ast('ann foo int;')).to eq([ ['T_ID:ann', 'T_ID:foo', 'T_ID:int'] ]) - end - - it "should parse a type annotation for a function type" do - expect(ast('ann foo int();')).to eq([ ['T_ID:ann', 'T_ID:foo', ['T_ID:int', []]] ]) - end - - it "should parse a type annotation for a tuple type" do - expect(ast('ann foo {int, int};')).to eq([ ['T_ID:ann', 'T_ID:foo', ['T_ID:tuple', 'T_ID:int', 'T_ID:int']] ]) - end - - it "should parse a type annotation with a generic type" do - pending "Type annotations have not been implemented yet" - expect(ast('ann foo Pair[int,int];')).to eq([ - ['T_ID:ann', 'T_ID:foo', ['T_ID:Pair', 'T_ID:int', 'T_ID:int']] ]) - end - end - - context "expressions" do - context "parenthese grouping" do - it "should parse a parenthesized expression" do - expect(ast('(123)')).to eq([['T_INT:123']]) - end - - it "should parse a nested parenthesized expression" do - expect(ast('((123))')).to eq([[['T_INT:123']]]) - end - end - - context "if statements" do - it "should parse an if statement with no else clause" do - expect(ast('if 123 321 end')).to eq([["T_ID:if", "T_INT:123", "T_INT:321"]]) - end - - it "should parse an if statement with an else clause " do - expect(ast('if 123 321 else 456 end')).to eq([ - ["T_ID:if", "T_INT:123", "T_INT:321", "T_ID:else", "T_INT:456"]]) - end - end - - context "function literals" do - it "should parse a function with no params" do - expect(ast('fn() 123;')).to eq([["T_ID:fn", [], "T_INT:123"]]) - end - - it "should parse a function with one param" do - expect(ast('fn(a) 123;')).to eq([["T_ID:fn", ["T_ID:a"], "T_INT:123"]]) - end - - it "should parse a function with two params" do - expect(ast('fn(a,b) 123;')).to eq([["T_ID:fn", ["T_ID:a", "T_ID:b"], "T_INT:123"]]) - end - end - - context "function application" do - it "should parse an application with no params " do - expect(ast('foo()')).to eq([["T_ID:foo"]]) - end - - it "should parse an application with one param" do - expect(ast('foo(a)')).to eq([["T_ID:foo", "T_ID:a"]]) - end - - it "should parse an application with two params" do - expect(ast('foo(a,b)')).to eq([["T_ID:foo", "T_ID:a", "T_ID:b"]]) - end - end - end - - context "literals" do - it "should parse a string" do - expect(ast('"foo"')).to eq(['T_STRING:"foo"']) - end - - it "should parse a character" do - expect(ast('\\c')).to eq(['T_CHAR:\\c']) - end - - it "should parse an integer" do - expect(ast('123')).to eq(['T_INT:123']) - end - - it "should parse a float" do - expect(ast('123.0')).to eq(['T_FLOAT:123.000000']) - end - - it "should parse boolean" do - expect(ast('true')).to eq(['T_BOOL:true']) - end - - it "should parse an identifier" do - expect(ast('foo')).to eq(['T_ID:foo']) - end - end - - context "corner cases" do - it "an unexpected terminator should error" do - expect{ast(';')}.to raise_error /Error/ - end - - it "an invalid literal should error" do - expect{ast('\'')}.to raise_error /Error/ - end - end -end +#describe "sclpl grammar" do +# context "requires" do +# it "should parse a require statement" do +# expect(ast('require "foo";')).to eq([ ['T_ID:require', 'T_STRING:"foo"'] ]) +# end +# +# it "should parse a require statement using end keyword" do +# expect(ast('require "foo" end')).to eq([ ['T_ID:require', 'T_STRING:"foo"'] ]) +# end +# +# it "should error on missing semicolon" do +# expect{ast('require "foo"')}.to raise_error /Error/ +# end +# +# it "should error on missing filename" do +# expect{ast('require ;')}.to raise_error /Error/ +# end +# +# it "should error on invalid filename type" do +# expect{ast('require 123;')}.to raise_error /Error/ +# end +# +# it "should error on too many parameters" do +# expect{ast('require foo bar;')}.to raise_error /Error/ +# end +# end +# +# context "type definitions" do +# it "should parse a simple type definition" do +# expect(ast('type foo is int;')).to eq([ ['T_ID:type', 'T_ID:foo', 'T_ID:is', 'T_ID:int'] ]) +# end +# +# it "should parse a function type definition with no args" do +# expect(ast('type foo is int();')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', []]] ]) +# end +# +# it "should parse a function type definition with one arg" do +# expect(ast('type foo is int(int);')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int']]] ]) +# end +# +# it "should parse a function type definition with two args" do +# expect(ast('type foo is int(int,int);')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int', 'T_ID:int']]] ]) +# end +# +# it "should parse a function type definition with three args" do +# expect(ast('type foo is int(int,int,int);')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:int', ['T_ID:int', 'T_ID:int', 'T_ID:int']]] ]) +# end +# +# it "should parse a tuple type definition with one field" do +# expect(ast('type foo is {int};')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int']] ]) +# end +# +# it "should parse a tuple type definition with two fields" do +# expect(ast('type foo is {int,int};')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int', 'T_ID:int']] ]) +# end +# +# it "should parse a tuple type definition with three fields" do +# expect(ast('type foo is {int,int,int};')).to eq([ +# ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:tuple', 'T_ID:int', 'T_ID:int', 'T_ID:int']] ]) +# end +# +# it "should parse a record type definition with one field" do +# pending "Type annotations have not been implemented yet" +# expect(ast('type foo is { int a };')).to eq([ +# ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a']]] ]) +# end +# +# it "should parse a record type definition with two fields" do +# pending "Type annotations have not been implemented yet" +# expect(ast('type foo is { int a, int b };')).to eq([ +# ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b']]] ]) +# end +# +# it "should parse a record type definition with three fields" do +# pending "Type annotations have not been implemented yet" +# expect(ast('type foo is { int a, int b };')).to eq([ +# ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b'], ['T_ID:int', 'T_ID:c']]] ]) +# end +# end +# +# context "definitions" do +# it "should parse a value definition" do +# expect(ast('def foo 123;')).to eq([ ['T_ID:def', 'T_ID:foo', 'T_INT:123'] ]) +# end +# +# it "should parse a function definition" do +# expect(ast('def foo() 123;')).to eq([ +# ['T_ID:def', 'T_ID:foo', ['T_ID:fn', [], 'T_INT:123']] ]) +# end +# +# it "should parse a function definition with multiple expressions in the body" do +# expect(ast('def foo() 123 321;')).to eq([ +# ['T_ID:def', 'T_ID:foo', ['T_ID:fn', [], 'T_INT:123', 'T_INT:321']] ]) +# end +# +# it "should parse a function definition with one argument" do +# expect(ast('def foo(a) 123;')).to eq([ +# ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a'], 'T_INT:123']] ]) +# end +# +# it "should parse a function definition with two arguments" do +# expect(ast('def foo(a,b) 123;')).to eq([ +# ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a', 'T_ID:b'], 'T_INT:123']] ]) +# end +# +# it "should parse a function definition with three arguments" do +# expect(ast('def foo(a,b,c) 123;')).to eq([ +# ['T_ID:def', 'T_ID:foo', ['T_ID:fn', ['T_ID:a', 'T_ID:b', 'T_ID:c'], 'T_INT:123']] ]) +# end +# end +# +# context "annotations" do +# it "should parse a type annotation for a simple type" do +# expect(ast('ann foo int;')).to eq([ ['T_ID:ann', 'T_ID:foo', 'T_ID:int'] ]) +# end +# +# it "should parse a type annotation for a function type" do +# expect(ast('ann foo int();')).to eq([ ['T_ID:ann', 'T_ID:foo', ['T_ID:int', []]] ]) +# end +# +# it "should parse a type annotation for a tuple type" do +# expect(ast('ann foo {int, int};')).to eq([ ['T_ID:ann', 'T_ID:foo', ['T_ID:tuple', 'T_ID:int', 'T_ID:int']] ]) +# end +# +# it "should parse a type annotation with a generic type" do +# pending "Type annotations have not been implemented yet" +# expect(ast('ann foo Pair[int,int];')).to eq([ +# ['T_ID:ann', 'T_ID:foo', ['T_ID:Pair', 'T_ID:int', 'T_ID:int']] ]) +# end +# end +# +# context "expressions" do +# context "parenthese grouping" do +# it "should parse a parenthesized expression" do +# expect(ast('(123)')).to eq([['T_INT:123']]) +# end +# +# it "should parse a nested parenthesized expression" do +# expect(ast('((123))')).to eq([[['T_INT:123']]]) +# end +# end +# +# context "if statements" do +# it "should parse an if statement with no else clause" do +# expect(ast('if 123 321 end')).to eq([["T_ID:if", "T_INT:123", "T_INT:321"]]) +# end +# +# it "should parse an if statement with an else clause " do +# expect(ast('if 123 321 else 456 end')).to eq([ +# ["T_ID:if", "T_INT:123", "T_INT:321", "T_ID:else", "T_INT:456"]]) +# end +# end +# +# context "function literals" do +# it "should parse a function with no params" do +# expect(ast('fn() 123;')).to eq([["T_ID:fn", [], "T_INT:123"]]) +# end +# +# it "should parse a function with one param" do +# expect(ast('fn(a) 123;')).to eq([["T_ID:fn", ["T_ID:a"], "T_INT:123"]]) +# end +# +# it "should parse a function with two params" do +# expect(ast('fn(a,b) 123;')).to eq([["T_ID:fn", ["T_ID:a", "T_ID:b"], "T_INT:123"]]) +# end +# end +# +# context "function application" do +# it "should parse an application with no params " do +# expect(ast('foo()')).to eq([["T_ID:foo"]]) +# end +# +# it "should parse an application with one param" do +# expect(ast('foo(a)')).to eq([["T_ID:foo", "T_ID:a"]]) +# end +# +# it "should parse an application with two params" do +# expect(ast('foo(a,b)')).to eq([["T_ID:foo", "T_ID:a", "T_ID:b"]]) +# end +# end +# end +# +# context "literals" do +# it "should parse a string" do +# expect(ast('"foo"')).to eq(['T_STRING:"foo"']) +# end +# +# it "should parse a character" do +# expect(ast('\\c')).to eq(['T_CHAR:\\c']) +# end +# +# it "should parse an integer" do +# expect(ast('123')).to eq(['T_INT:123']) +# end +# +# it "should parse a float" do +# expect(ast('123.0')).to eq(['T_FLOAT:123.000000']) +# end +# +# it "should parse boolean" do +# expect(ast('true')).to eq(['T_BOOL:true']) +# end +# +# it "should parse an identifier" do +# expect(ast('foo')).to eq(['T_ID:foo']) +# end +# end +# +# context "corner cases" do +# it "an unexpected terminator should error" do +# expect{ast(';')}.to raise_error /Error/ +# end +# +# it "an invalid literal should error" do +# expect{ast('\'')}.to raise_error /Error/ +# end +# end +#end