aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-06-12 21:25:47 +0100
committerGinger Bill <bill@gingerbill.org>2017-06-12 21:25:47 +0100
commit91857e8f16fc5328daa175aa3059bafe7c989ccc (patch)
tree37ba12ecc37620ab813fafc41eb489fa69502feb /src/parser.cpp
parentccda456c0a96f849e408bd707eca0a3baf9202b1 (diff)
Remove redundant paths in parsing
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 747289977..cd0e78c2a 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1615,6 +1615,10 @@ void fix_advance_to_next_stmt(AstFile *f) {
case Token_const:
case Token_let:
case Token_type:
+ case Token_proc:
+ case Token_foreign:
+ case Token_foreign_library:
+ case Token_foreign_system_library:
case Token_if:
case Token_when:
@@ -1760,12 +1764,7 @@ AstNode *parse_ident(AstFile *f) {
AstNode *parse_tag_expr(AstFile *f, AstNode *expression) {
Token token = expect_token(f, Token_Hash);
- Token name = {};
- if (f->curr_token.kind == Token_foreign) {
- name = expect_token(f, Token_foreign);
- } else {
- name = expect_token(f, Token_Ident);
- }
+ Token name = expect_token(f, Token_Ident);
return ast_tag_expr(f, token, name, expression);
}
@@ -2759,6 +2758,31 @@ PARSE_SPEC_FUNC(parse_foreign_library_spec) {
}
}
+AstNode *parse_decl(AstFile *f);
+
+void parse_foreign_block_decl(AstFile *f, Array<AstNode *> *decls) {
+ AstNode *decl = parse_decl(f);
+ switch (decl->kind) {
+ case AstNode_BadDecl:
+ break;
+
+ case AstNode_ProcDecl:
+ array_add(decls, decl);
+ break;
+
+ // case AstNode_GenDecl:
+ // if (decl->GenDecl.token.kind == Token_var) {
+ // array_add(decls, decl);
+ // break;
+ // }
+
+ /* fallthrough */
+ default:
+ error_node(decl, "Only procedures declarations are allowed within a foreign block at the moment");
+ break;
+ }
+}
+
AstNode *parse_decl(AstFile *f) {
ParseSpecFunc *func = NULL;
switch (f->curr_token.kind) {
@@ -2782,6 +2806,29 @@ AstNode *parse_decl(AstFile *f) {
func = parse_foreign_library_spec;
break;
+ case Token_foreign: {
+ Token token = expect_token(f, Token_foreign);
+ AstNode *foreign_library = parse_ident(f);
+ Token open = {};
+ Token close = {};
+ Array<AstNode *> decls = make_ast_node_array(f);
+
+ if (f->curr_token.kind != Token_OpenBrace) {
+ parse_foreign_block_decl(f, &decls);
+ } else {
+ open = expect_token(f, Token_OpenBrace);
+
+ while (f->curr_token.kind != Token_CloseBrace &&
+ f->curr_token.kind != Token_EOF) {
+ parse_foreign_block_decl(f, &decls);
+ }
+
+ close = expect_token(f, Token_CloseBrace);
+ }
+
+ return ast_foreign_block_decl(f, token, foreign_library, open, close, decls);
+ } break;
+
case Token_proc:
return parse_proc_decl(f);
@@ -3847,29 +3894,6 @@ AstNode *parse_asm_stmt(AstFile *f) {
}
-void parse_foreign_block_decl(AstFile *f, Array<AstNode *> *decls) {
- AstNode *decl = parse_decl(f);
- switch (decl->kind) {
- case AstNode_BadDecl:
- break;
-
- case AstNode_ProcDecl:
- array_add(decls, decl);
- break;
-
- // case AstNode_GenDecl:
- // if (decl->GenDecl.token.kind == Token_var) {
- // array_add(decls, decl);
- // break;
- // }
-
- /* fallthrough */
- default:
- error_node(decl, "Only procedures declarations are allowed within a foreign block at the moment");
- break;
- }
-}
-
AstNode *parse_stmt(AstFile *f) {
AstNode *s = NULL;
@@ -3902,34 +3926,11 @@ AstNode *parse_stmt(AstFile *f) {
case Token_type:
case Token_import:
case Token_import_load:
+ case Token_foreign:
case Token_foreign_library:
case Token_foreign_system_library:
return parse_decl(f);
- case Token_foreign: {
- Token token = expect_token(f, Token_foreign);
- AstNode *foreign_library = parse_ident(f);
- Token open = {};
- Token close = {};
- Array<AstNode *> decls = make_ast_node_array(f);
-
- if (f->curr_token.kind != Token_OpenBrace) {
- parse_foreign_block_decl(f, &decls);
- } else {
- open = expect_token(f, Token_OpenBrace);
-
- while (f->curr_token.kind != Token_CloseBrace &&
- f->curr_token.kind != Token_EOF) {
- parse_foreign_block_decl(f, &decls);
- }
-
- close = expect_token(f, Token_CloseBrace);
- }
-
-
- return ast_foreign_block_decl(f, token, foreign_library, open, close, decls);
- } break;
-
case Token_if: return parse_if_stmt(f);
case Token_when: return parse_when_stmt(f);