]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
tweak top-level syntax
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 17 Jun 2018 01:39:47 +0000 (21:39 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 17 Jun 2018 01:39:47 +0000 (21:39 -0400)
example.src
source/lexer.l
source/parser.c

index ed810ac83ebbedd32fabfb42c884f4d8316e97ef..1b023c88e6f15bca66502661a5cd1b53e897a088 100644 (file)
@@ -1,6 +1,5 @@
-package main
-requires ("fmt")
-provides (main)
+require ("fmt")
+provide (main)
 
 let const_true bool = true;
 let const_false bool = false;
index 9926b19db390bd553cf4e4924713688c1928e6f2..9916d4b99280352b3346500670183e8c4ffb4233 100644 (file)
@@ -33,9 +33,8 @@ NOSPACE [^ \t\r\n]
 [ \t\r\n] { /* whitespace is insignificant */ }
 #.*[\r\n] { /* skip line comments */ }
 
-"package"  { return T_PACKAGE;  }
-"requires" { return T_REQUIRES; }
-"provides" { return T_PROVIDES; }
+"require" { return T_REQUIRES;  }
+"provide" { return T_PROVIDES;  }
 "let"      { return T_LET;      }
 "var"      { return T_VAR;      }
 "fun"      { return T_FUN;      }
index b15a47a2d6b83c0c548376c0bf27cd31cf89da37..10952db6c01713d6255aabf4ef252eae9d6d8fb7 100644 (file)
@@ -13,7 +13,6 @@ static AST* definition(Parser* p);
 static AST* expression(Parser* p);
 static AST* identifier(Parser* p);
 static AST* function(Parser* p);
-static Type* type_annotation(Parser* p);
 static AST* literal(Parser* p);
 static AST* expr_block(Parser* p);
 static AST* if_stmnt(Parser* p);
@@ -68,16 +67,13 @@ static Tok* expect_val(Parser* p, TokType type) {
     return tok;
 }
 
-
 /* Grammar Definition
  *****************************************************************************/
 AST* toplevel(Parser* p) {
-    expect(p, T_PACKAGE);
-    expect(p, T_ID);
-    if (accept(p, T_REQUIRES)) {
+    if (matches(p, T_REQUIRES)) {
         require_list(p);
     }
-    if (accept(p, T_PROVIDES)) {
+    if (matches(p, T_PROVIDES)) {
         provide_list(p);
     }
     definition_list(p);
@@ -85,6 +81,7 @@ AST* toplevel(Parser* p) {
 }
 
 static void require_list(Parser* p) {
+    accept(p, T_REQUIRES);
     expect(p, T_LPAR);
     while (!matches(p, T_RPAR)) {
         expect(p, T_STRING);
@@ -93,6 +90,7 @@ static void require_list(Parser* p) {
 }
 
 static void provide_list(Parser* p) {
+    accept(p, T_PROVIDES);
     expect(p, T_LPAR);
     while (!matches(p, T_RPAR)) {
         expect(p, T_ID);
@@ -120,10 +118,10 @@ static AST* definition_list(Parser* p) {
 static AST* const_definition(Parser* p, bool constant) {
     if (!accept(p, T_LET) && !accept(p, T_VAR))
         error(p, "constant or variable definition expected");
-    Tok* id = expect_val(p, T_ID);
-    Type* type = type_annotation(p);
+    expect(p, T_ID);
+    type_expression(p);
     expect(p, T_ASSIGN);
-    AST* expr = const_expression(p);
+    const_expression(p);
     expect(p, T_SEMI);
     return NULL;
 }
@@ -177,19 +175,12 @@ static AST* type_expression(Parser* p) {
 
 
 
-
-
 static Type* get_typedef(Parser* p, char* typename) {
    Sym* sym = sym_get(&(p->syms), typename);
     if (!sym) error(p, "unknown type '%s'", typename);
     return sym->type;
 }
 
-static Type* type_annotation(Parser* p) {
-    Tok* id = expect_val(p, T_ID);
-    return get_typedef(p, id->value.text);
-}
-
 static AST* literal(Parser* p) {
     AST* ret = NULL;
     Tok* tok = peek(p);