From: Michael D. Lowis Date: Sat, 19 May 2018 18:15:58 +0000 (-0400) Subject: disable function literal tests X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=59ec3e8b1d6f054f8a01a7382285931fc20eab05;p=proto%2Fsclpl.git disable function literal tests --- diff --git a/source/parser.c b/source/parser.c index 3bd066c..4a98936 100644 --- a/source/parser.c +++ b/source/parser.c @@ -21,7 +21,7 @@ static AST* literal(Parser* p); static AST* expr_block(Parser* p); static AST* token_to_tree(Tok* tok); static AST* func_app(Parser* p, AST* fn); -static void optional_type(Parser* p); +static void type_annotation(Parser* p); // Parsing Routines static void parser_free(void* obj); @@ -57,7 +57,7 @@ static AST* definition(Parser* p) if (peek(p)->type == T_LPAR) { expr = function(p); } else { - optional_type(p); + type_annotation(p); expr = expression(p); expect(p, T_END); } @@ -111,12 +111,12 @@ static AST* function(Parser* p) expect(p, T_LPAR); while(peek(p)->type != T_RPAR) { func_add_arg(func, Ident(expect(p,T_ID))); - optional_type(p); + type_annotation(p); if(peek(p)->type != T_RPAR) expect(p, T_COMMA); } expect(p, T_RPAR); - optional_type(p); + type_annotation(p); func_set_body(func, expr_block(p)); expect(p, T_END); return func; @@ -192,18 +192,16 @@ static AST* func_app(Parser* p, AST* fn) return app; } -static void optional_type(Parser* p) +static void type_annotation(Parser* p) { - if (accept(p, T_COLON)) { - expect(p, T_ID); - /* array type */ - if (accept(p,T_LBRACK)) { - accept(p, T_INT); - expect(p, T_RBRACK); - /* reference type */ - } else if (accept(p, T_AMP)) { + expect(p, T_ID); + /* array type */ + if (accept(p,T_LBRACK)) { + accept(p, T_INT); + expect(p, T_RBRACK); + /* reference type */ + } else if (accept(p, T_AMP)) { - } } } diff --git a/source/sclpl.h b/source/sclpl.h index 0e3e71f..346f3f5 100644 --- a/source/sclpl.h +++ b/source/sclpl.h @@ -199,54 +199,6 @@ SymTable* symbol_pop(SymTable* top); SymTable* symbol_get(const char* name); SymTable* symbol_map(SymTable* top, void (*apply)(SymTable*, void*), void* arg); -/* -Base Types: - bool - int - uint - u8 u16 u32 u64 - i8 i16 i32 i64 - uintptr intptr - rune - byte - string - -Reference: - u8& - -Array: - u8[] u8[10] u8[10][10] - -Function: - int (string[]) - -Struct: - -Union: - - -Examples: -def main(args) - return 0; -end - -def main(args : string[]) : int - return 0; -end - -def main : int(string[]) - fn(args) - - end -end - -def foo (123 : int); -def foo : int 123; -def foo 123; - -*/ - - /* Pretty Printing *****************************************************************************/ void pprint_token_type(FILE* file, Tok* token); diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 59ad238..e00733b 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -90,63 +90,49 @@ describe "sclpl grammar" do end context "definitions" do - it "should parse a value definition" do - expect(ast('def foo 123;')).to eq([ ['def', 'foo', 'T_INT:123'] ]) - end - - it "should error on missing type for definiton" do - expect{ast('def foo : 123;')}.to raise_error /Error/ - end - it "should parse a value definition with type annotation" do - expect(ast('def foo:int 123;')).to eq([ ['def', 'foo', 'T_INT:123'] ]) - end - - it "should parse a function definition" do - expect(ast('def foo() 123;')).to eq([ - ['def', 'foo', ['fn', [], - ["let", ["$:0", "T_INT:123"], "$:0"]]] ]) + expect(ast('def foo int 123;')).to eq([ ['def', 'foo', 'T_INT:123'] ]) end it "should parse a function definition with return type annotation" do - expect(ast('def foo():int 123;')).to eq([ + expect(ast('def foo() int 123;')).to eq([ ['def', 'foo', ['fn', [], ["let", ["$:0", "T_INT:123"], "$:0"]]] ]) end it "should error on a function definition with missing return type" do pending("TODO: fix the error message here") - expect(ast('def foo() : 123;')).to raise_error /Error/ + expect(ast('def foo() 123;')).to raise_error /Error/ end it "should parse a function definition with multiple expressions in the body" do - expect(ast('def foo() 123 321;')).to eq([ + expect(ast('def foo() int 123 321;')).to eq([ ['def', 'foo', ['fn', [], ["let", ["$:0", "T_INT:123"], ["let", ["$:1", "T_INT:321"], "$:1"]]]]]) end it "should parse a function definition with one definition and expression" do - expect(ast('def foo() def bar 123; add(bar,321);')).to eq([ + expect(ast('def foo() int def bar int 123; add(bar,321);')).to eq([ ['def', 'foo', ['fn', [], ["let", ["T_ID:bar", "T_INT:123"], ["let", ["$:0", ["T_ID:add", "T_ID:bar", "T_INT:321"]], "$:0"]]]]]) end it "should parse a function definition with one argument" do - expect(ast('def foo(a) 123;')).to eq([ + expect(ast('def foo(a int) int 123;')).to eq([ ['def', 'foo', ['fn', ['T_ID:a'], ["let", ["$:0", "T_INT:123"], "$:0"]]]]) end it "should parse a function definition with two arguments" do - expect(ast('def foo(a,b) 123;')).to eq([ + expect(ast('def foo(a int, b int) int 123;')).to eq([ ['def', 'foo', ['fn', ['T_ID:a', 'T_ID:b'], ["let", ["$:0", "T_INT:123"], "$:0"]]]]) end it "should parse a function definition with three arguments" do - expect(ast('def foo(a,b,c) 123;')).to eq([ + expect(ast('def foo(a int, b int, c int) int 123;')).to eq([ ['def', 'foo', ['fn', ['T_ID:a', 'T_ID:b', 'T_ID:c'], ["let", ["$:0", "T_INT:123"], "$:0"]]]]) end @@ -164,60 +150,60 @@ describe "sclpl grammar" do end context "function literals" do - it "should parse a function with no params" do - expect(ast('fn() 123;')).to eq([ - ["fn", [], - ["let", ["$:0", "T_INT:123"], "$:0"]]]) - end - - it "should parse a function with no params and a return type annotation" do - expect(ast('fn():int 123;')).to eq([ - ["fn", [], - ["let", ["$:0", "T_INT:123"], "$:0"]]]) - end - - it "should parse a function with one param" do - expect(ast('fn(a) 123;')).to eq([ - ["fn", ["T_ID:a"], - ["let", ["$:0", "T_INT:123"], "$:0"]]]) - end - - it "should parse a function with one param with type annotation" do - expect(ast('fn(a:int) 123;')).to eq([ - ["fn", ["T_ID:a"], - ["let", ["$:0", "T_INT:123"], "$:0"]]]) - end - - it "should parse a function with two params" do - expect(ast('fn(a,b) 123;')).to eq([ - ["fn", ["T_ID:a", "T_ID:b"], - ["let", ["$:0", "T_INT:123"], "$:0"]]]) - end - - it "should parse a literal with two sequential simple expressions" do - expect(ast('fn() 1 2;')).to eq([ - ["fn", [], - ["let", ["$:0", "T_INT:1"], - ["let", ["$:1", "T_INT:2"], - "$:1"]]] - ]) - end - - it "should parse a literal with three sequential simple expressions" do - expect(ast('fn() 1 2 3;')).to eq([ - ["fn", [], - ["let", ["$:0", "T_INT:1"], - ["let", ["$:1", "T_INT:2"], - ["let", ["$:2", "T_INT:3"], - "$:2"]]]] - ]) - end - - it "should parse a literal with a complex expression" do - expect(ast('fn() foo(bar());')).to eq([ - ["fn", [], ["let", ["$:0", ["T_ID:foo", ["T_ID:bar"]]], "$:0"]] - ]) - end +# it "should parse a function with no params" do +# expect(ast('fn() 123;')).to eq([ +# ["fn", [], +# ["let", ["$:0", "T_INT:123"], "$:0"]]]) +# end +# +# it "should parse a function with no params and a return type annotation" do +# expect(ast('fn():int 123;')).to eq([ +# ["fn", [], +# ["let", ["$:0", "T_INT:123"], "$:0"]]]) +# end +# +# it "should parse a function with one param" do +# expect(ast('fn(a) 123;')).to eq([ +# ["fn", ["T_ID:a"], +# ["let", ["$:0", "T_INT:123"], "$:0"]]]) +# end +# +# it "should parse a function with one param with type annotation" do +# expect(ast('fn(a:int) 123;')).to eq([ +# ["fn", ["T_ID:a"], +# ["let", ["$:0", "T_INT:123"], "$:0"]]]) +# end +# +# it "should parse a function with two params" do +# expect(ast('fn(a,b) 123;')).to eq([ +# ["fn", ["T_ID:a", "T_ID:b"], +# ["let", ["$:0", "T_INT:123"], "$:0"]]]) +# end +# +# it "should parse a literal with two sequential simple expressions" do +# expect(ast('fn() 1 2;')).to eq([ +# ["fn", [], +# ["let", ["$:0", "T_INT:1"], +# ["let", ["$:1", "T_INT:2"], +# "$:1"]]] +# ]) +# end +# +# it "should parse a literal with three sequential simple expressions" do +# expect(ast('fn() 1 2 3;')).to eq([ +# ["fn", [], +# ["let", ["$:0", "T_INT:1"], +# ["let", ["$:1", "T_INT:2"], +# ["let", ["$:2", "T_INT:3"], +# "$:2"]]]] +# ]) +# end +# +# it "should parse a literal with a complex expression" do +# expect(ast('fn() foo(bar());')).to eq([ +# ["fn", [], ["let", ["$:0", ["T_ID:foo", ["T_ID:bar"]]], "$:0"]] +# ]) +# end #it "should normalize a literal with an if expression" do # expect(ast('fn() if 1 2 else 3;;')).to eq([