]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
disable function literal tests
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 19 May 2018 18:15:58 +0000 (14:15 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 19 May 2018 18:15:58 +0000 (14:15 -0400)
source/parser.c
source/sclpl.h
spec/parser_spec.rb

index 3bd066c92ead00fe22e04a34631f592aacd163d8..4a98936f9422ada97091abd70d5126cbf5e45077 100644 (file)
@@ -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)) {
 
-        }
     }
 }
 
index 0e3e71f931b1f2787baf707e02db78b1ed7ece79..346f3f551b7c398445980b90cf4719aa84942947 100644 (file)
@@ -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);
index 59ad238afd8562444016d22793936c6c85291adb..e00733bd2f2556b04a8586d1c13bd3d03832aa9f 100644 (file)
@@ -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([