zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ccdaf946b969661220737ec747e5a720b13d0bc7 (tree)
parent 9b7d9c72b09bc268338b66e708b33213bbaae675
Author: LemonBoy <thatlemon@gmail.com>
Date:   Sat, 21 Nov 2020 09:48:21 +0100

Rename back to extern, extend a stage1 parser hack

Make it recognize extern/export symbols prefixed by @ as a builtin
rather than stand-alone keywords.

Diffstat:
Msrc/stage1/codegen.cpp | 2+-
Msrc/stage1/parser.cpp | 13++++++++-----
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp @@ -8826,7 +8826,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2); create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1); create_builtin_fn(g, BuiltinFnIdExport, "export", 2); - create_builtin_fn(g, BuiltinFnIdExtern, "extern1", 2); + create_builtin_fn(g, BuiltinFnIdExtern, "extern", 2); create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0); create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5); create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3); diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp @@ -1652,18 +1652,21 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { // TODO: This is not in line with the grammar. // Because the prev stage 1 tokenizer does not parse // @[a-zA-Z_][a-zA-Z0-9_] as one token, it has to do a - // hack, where it accepts '@' (IDENTIFIER / KEYWORD_export). + // hack, where it accepts '@' (IDENTIFIER / KEYWORD_export / + // KEYWORD_extern). // I'd say that it's better if '@' is part of the builtin // identifier token. Token *at_sign = eat_token_if(pc, TokenIdAtSign); if (at_sign != nullptr) { Buf *name; - Token *token = eat_token_if(pc, TokenIdKeywordExport); - if (token == nullptr) { + Token *token; + if ((token = eat_token_if(pc, TokenIdKeywordExport)) != nullptr) { + name = buf_create_from_str("export"); + } else if ((token = eat_token_if(pc, TokenIdKeywordExtern)) != nullptr) { + name = buf_create_from_str("extern"); + } else { token = expect_token(pc, TokenIdSymbol); name = token_buf(token); - } else { - name = buf_create_from_str("export"); } AstNode *res = ast_expect(pc, ast_parse_fn_call_arguments);