]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added token type for ':' in preparation for type annotations
authorMike Lowis <mike.lowis@gentex.com>
Tue, 30 Aug 2016 19:48:17 +0000 (15:48 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 30 Aug 2016 19:48:17 +0000 (15:48 -0400)
source/ast.c
source/lexer.l
source/pprint.c
source/sclpl.h
spec/lexer_spec.rb

index 561bef3e2780a4c52c617b29d4babf8102992641..7f2100ff9ee8b85f59eac98424f4d876f3ffd67c 100644 (file)
@@ -2,8 +2,6 @@
 
 static void ast_free(void* ptr)
 {
-//    AST_LET AST_TEMP
-
     AST* ast = (AST*)ptr;
     switch(ast->type) {
         case AST_REQ:
index 13cc63523e525365ba7efdeeb3d5d6e3fef57bc3..9f949a25ac3d0b56a188a5a0c30ecf80088807a1 100644 (file)
@@ -42,6 +42,7 @@ NOSPACE [^ \t\r\n]
 ";"   { return T_END;    }
 ","   { return T_COMMA;  }
 "'"   { return T_SQUOTE; }
+":"   { return T_COLON;  }
 
 \\.       { Value.character = yytext[1];    return T_CHAR; }
 \\space   { Value.character = ' ';          return T_CHAR; }
@@ -115,12 +116,11 @@ false {
     return T_ID;
 }
 
-[^ \r\t\n\[\]\{\}\(\)'\",;]+ {
+[^ \r\t\n\[\]\{\}\(\)'\",;:]+ {
     Value.text = dupstring(yytext);
     return T_ID;
 }
 
-
 %%
 
 static void token_free(void* obj)
index 41bf2f346aca4386ffb1d323d226c95b87a6e450..048e7dff89891b6cfd61dc72750dba727fce48b2 100644 (file)
@@ -27,6 +27,7 @@ static const char* token_type_to_string(TokType type) {
         case T_COMMA:    return "T_COMMA";
         case T_ID:       return "T_ID";
         case T_END:      return "T_END";
+        case T_COLON:    return "T_COLON";
         case T_SQUOTE:   return "T_SQUOTE";
         case T_DQUOTE:   return "T_DQUOTE";
         case T_END_FILE: return "T_END_FILE";
index cd6a437d676bfc6538afacf0c298183869e0c680..64fff927275e11f618f918f347bfb21a10c98fd6 100644 (file)
@@ -51,8 +51,8 @@ void vec_set(vec_t* vec, size_t index, void* data);
  *****************************************************************************/
 typedef enum {
     T_ID, T_CHAR, T_INT, T_FLOAT, T_BOOL, T_STRING, T_LBRACE, T_RBRACE, T_LBRACK,
-    T_RBRACK, T_LPAR, T_RPAR, T_COMMA, T_SQUOTE, T_DQUOTE, T_END, T_REQUIRE,
-    T_DEF, T_IF, T_FN, T_THEN, T_ELSE, T_END_FILE
+    T_RBRACK, T_LPAR, T_RPAR, T_COMMA, T_SQUOTE, T_DQUOTE, T_END, T_COLON,
+    T_REQUIRE, T_DEF, T_IF, T_FN, T_THEN, T_ELSE, T_END_FILE
 } TokType;
 
 typedef struct {
@@ -190,6 +190,68 @@ AST* let_val(AST* let);
 AST* let_body(AST* let);
 void let_set_body(AST* let, AST* body);
 
+/* Symbol Table
+ *****************************************************************************/
+typedef struct SymTable {
+    struct SymTable* next;
+    char* name;
+} SymTable;
+
+SymTable* symbol_new(void);
+//void symbol_free(SymTable* sym);
+SymTable* symbol_push(SymTable* top, SymTable* newtop);
+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 65d9711ddf700d3c93df6499c68b09e268e7b116..030bb2e71f60f3d691a31220af15f77d71caa1ec 100644 (file)
@@ -38,6 +38,10 @@ describe "lexer" do
       expect(lexer(';')).to eq ['T_END']
     end
 
+    it "should recognize :" do
+      expect(lexer(':')).to eq ['T_COLON']
+    end
+
     it "should recognize all punctuation" do
       expect(lexer('[](){}\',;')).to eq(
         ["T_LBRACK", "T_RBRACK", "T_LPAR", "T_RPAR", "T_LBRACE", "T_RBRACE",