diff options
-rw-r--r-- | parse.c | 20 | ||||
-rw-r--r-- | test.toc | 13 | ||||
-rw-r--r-- | tokenizer.c | 2 | ||||
-rw-r--r-- | types.h | 1 |
4 files changed, 14 insertions, 22 deletions
@@ -1139,15 +1139,15 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { } } } - if (token_is_kw(t->token, KW_COLONCOLON)) { - tokr_err(t, "The variable(s) in a for loop cannot be constant."); - return false; - } if (!token_is_kw(t->token, KW_COLON)) { tokr_err(t, "Expected : following identifiers in for statement."); return false; } ++t->token; + if (token_is_kw(t->token, KW_COLON)) { + tokr_err(t, "The variable(s) in a for loop cannot be constant."); + return false; + } if (!token_is_kw(t->token, KW_EQ)) { ea->flags |= EACH_ANNOTATED_TYPE; if (!parse_type(p, &ea->type)) @@ -1752,9 +1752,12 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla } if (token_is_kw(t->token, KW_COLON)) { ++t->token; - break; + } else { + + tokr_err(t, "Expected ',' to continue listing variables or ':' / '::' to indicate type."); + goto ret_false; } - if (token_is_kw(t->token, KW_COLONCOLON)) { + if (token_is_kw(t->token, KW_COLON)) { ++t->token; if (token_is_kw(t->token, KW_COLON) && (flags & PARSE_DECL_ALLOW_SEMI_CONST)) { ++t->token; @@ -1764,8 +1767,7 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla } break; } - tokr_err(t, "Expected ',' to continue listing variables or ':' / '::' to indicate type."); - goto ret_false; + break; } if (token_is_kw(t->token, KW_SEMICOLON) || token_is_kw(t->token, KW_RPAREN)) { @@ -1860,7 +1862,7 @@ static bool is_decl(Tokenizer *t) { if (token->kind != TOKEN_IDENT) return false; ++token; if (token->kind != TOKEN_KW) return false; - if (token->kw == KW_COLON || token->kw == KW_COLONCOLON) + if (token->kw == KW_COLON) return true; if (token->kw != KW_COMMA) return false; ++token; @@ -6,16 +6,7 @@ putf ::= fn(x: float) { #C("printf(\"%f\\n\", (double)x); "); }; -f ::= fn(x : int) Type { - if x == 0 { int } else { float } -}; - -r ::= fn(n::=, a :f(n)) int { -n -}; - main ::= fn() { - x :: = 3; - y : f(x); - puti(r(y)); + x : : = 3; + puti(x); };
\ No newline at end of file diff --git a/tokenizer.c b/tokenizer.c index 90b37d3..ae17a4d 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -4,7 +4,7 @@ You should have received a copy of the GNU General Public License along with toc. If not, see <https://www.gnu.org/licenses/>. */ static const char *keywords[KW_COUNT] = - {";", "::", ":", ",", "(", ")", "{", "}", "[", "]", "==", + {";", ":", ",", "(", ")", "{", "}", "[", "]", "==", "+=", "-=", "*=", "/=", "!=", "<=", "<", ">=", ">", "+", "-", "*", "!", "&", "/", "..", ".", @@ -205,7 +205,6 @@ typedef enum { typedef enum { KW_SEMICOLON, - KW_COLONCOLON, KW_COLON, KW_COMMA, KW_LPAREN, |