Use proper public keyword
This commit is contained in:
+29
-4
@@ -52,7 +52,7 @@ Module* parser_parse(TokenStream* ts) {
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
bool is_public = false;
|
||||
if (t.token == TOKEN_IDENTIFIER && strncmp(t.text.data, "public", t.text.length) == 0) {
|
||||
if (t.token == TOKEN_PUBLIC) {
|
||||
is_public = true;
|
||||
t = tokenstream_next(ts);
|
||||
}
|
||||
@@ -106,17 +106,34 @@ Module* parser_parse(TokenStream* ts) {
|
||||
}
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_IDENTIFIER || strncmp(t.text.data, "int32", t.text.length) != 0) {
|
||||
|
||||
TypeExpression type;
|
||||
if (t.token == TOKEN_IDENTIFIER && strncmp(t.text.data, "int32", t.text.length) == 0) {
|
||||
type = (TypeExpression){ .tag = TYPE_EXPRESSION_BUILTIN, .builtin = { .bitSize = 32, .isSigned = true } };
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token == TOKEN_BRACKET_OPEN) {
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_BRACKET_CLOSE) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected ']'");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
TypeExpression* inner = malloc(sizeof(TypeExpression));
|
||||
*inner = type;
|
||||
type = (TypeExpression){ .tag = TYPE_EXPRESSION_ARRAY, .array = { .array = inner } };
|
||||
t = tokenstream_next(ts);
|
||||
}
|
||||
} else {
|
||||
log_on_line(&t.location, t.location.column_end, "expected type");
|
||||
parser_free(module);
|
||||
return NULL;
|
||||
}
|
||||
alias.value = (TypeExpression){ .tag = TYPE_EXPRESSION_BUILTIN, .builtin = { .bitSize = 32, .isSigned = true } };
|
||||
|
||||
alias.value = type;
|
||||
|
||||
module->aliases[module->alias_count] = alias;
|
||||
module->alias_count++;
|
||||
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_SEMICOLON) {
|
||||
log_on_line(&t.location, t.location.column_end, "expected ';'");
|
||||
parser_free(module);
|
||||
@@ -128,6 +145,13 @@ Module* parser_parse(TokenStream* ts) {
|
||||
return module;
|
||||
}
|
||||
|
||||
void free_type_expression(TypeExpression* expr) {
|
||||
if (expr->tag == TYPE_EXPRESSION_ARRAY) {
|
||||
free_type_expression(expr->array.array);
|
||||
free(expr->array.array);
|
||||
}
|
||||
}
|
||||
|
||||
void parser_free(Module* module) {
|
||||
if (module == NULL) return;
|
||||
if (module->imports != NULL) {
|
||||
@@ -139,6 +163,7 @@ void parser_free(Module* module) {
|
||||
if (module->aliases != NULL) {
|
||||
for(size_t i = 0; i < module->alias_count; i++) {
|
||||
free((void*)module->aliases[i].name);
|
||||
free_type_expression(&module->aliases[i].value);
|
||||
}
|
||||
free(module->aliases);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user