diff options
| author | gingerBill <bill@gingerbill.org> | 2018-06-17 21:46:37 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-06-17 21:46:37 +0100 |
| commit | 5fe4c33d0e71250bcedde0bfada91aab75c640ab (patch) | |
| tree | 5254881165858e5e3b688d19acfe1ae7a2f82341 /src/parser.cpp | |
| parent | 4d9d38cc282ab5bb509c54f8ef8c2ba4b607e258 (diff) | |
Allow importation of `core:builtin` to get built-in entities
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 52edf2ee7..fe992eda8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2446,7 +2446,7 @@ Ast *parse_value_decl(AstFile *f, Array<Ast *> names, CommentGroup *docs) { } if (values.data == nullptr) { - values = array_make<Ast *>(heap_allocator()); + values.allocator = heap_allocator(); } if (f->expr_level >= 0) { @@ -2462,6 +2462,12 @@ Ast *parse_value_decl(AstFile *f, Array<Ast *> names, CommentGroup *docs) { } } + if (f->curr_proc == nullptr) { + if (values.count > 0 && names.count != values.count) { + syntax_error(values[0], "Expected %td expressions on the right hand side, got %td", names.count, values.count); + } + } + return ast_value_decl(f, names, type, values, is_mutable, docs, f->line_comment); } @@ -4094,8 +4100,13 @@ bool determine_path_from_string(Parser *p, Ast *node, String base_dir, String or #endif } - String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str)); - *path = fullpath; + + if (file_str == "builtin") { + *path = str_lit("builtin"); + } else { + String fullpath = string_trim_whitespace(get_fullpath_relative(a, base_dir, file_str)); + *path = fullpath; + } return true; } @@ -4155,6 +4166,9 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<Ast *> import_path = string_trim_whitespace(import_path); id->fullpath = import_path; + if (import_path == "builtin") { + continue; + } try_add_import_path(p, import_path, original_string, ast_token(node).pos); } else if (node->kind == Ast_ForeignImportDecl) { ast_node(fl, ForeignImportDecl, node); @@ -4284,6 +4298,8 @@ bool parse_file(Parser *p, AstFile *f) { error(package_name, "Invalid package name '_'"); } else if (f->pkg->kind != Package_Runtime && package_name.string == "runtime") { error(package_name, "Use of reserved package name '%.*s'", LIT(package_name.string)); + } else if (package_name.string == "builtin") { + error(package_name, "Use of reserved package name '%.*s'", LIT(package_name.string)); } } f->package_name = package_name.string; @@ -4418,8 +4434,8 @@ ParseFileError parse_packages(Parser *p, String init_filename) { } } - TokenPos init_pos = {}; + TokenPos init_pos = {}; if (!build_context.generate_docs) { String s = get_fullpath_core(heap_allocator(), str_lit("runtime")); try_add_import_path(p, s, s, init_pos, Package_Runtime); |