Skip to content

Commit

Permalink
change use to usingnamespace
Browse files Browse the repository at this point in the history
See #2014

`use` syntax is still accepted for now. `zig fmt` automatically
updates code. After a release cycle the old syntax will be removed.
  • Loading branch information
andrewrk committed May 29, 2019
1 parent 9a7cf73 commit b7a8228
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
std.zig.Token.Id.Keyword_try,
std.zig.Token.Id.Keyword_union,
std.zig.Token.Id.Keyword_unreachable,
std.zig.Token.Id.Keyword_use,
std.zig.Token.Id.Keyword_usingnamespace,
std.zig.Token.Id.Keyword_var,
std.zig.Token.Id.Keyword_volatile,
std.zig.Token.Id.Keyword_allowzero,
Expand Down
4 changes: 2 additions & 2 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -9918,7 +9918,7 @@ KEYWORD_try <- 'try' end_of_word
KEYWORD_undefined <- 'undefined' end_of_word
KEYWORD_union <- 'union' end_of_word
KEYWORD_unreachable <- 'unreachable' end_of_word
KEYWORD_use <- 'use' end_of_word
KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
KEYWORD_var <- 'var' end_of_word
KEYWORD_volatile <- 'volatile' end_of_word
KEYWORD_while <- 'while' end_of_word
Expand All @@ -9935,7 +9935,7 @@ keyword <- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_anyerror
/ KEYWORD_stdcallcc / KEYWORD_struct / KEYWORD_suspend
/ KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
/ KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_use / KEYWORD_var / KEYWORD_volatile / KEYWORD_while</code></pre>
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while</code></pre>
{#header_close#}
{#header_open|Zen#}
<ul>
Expand Down
2 changes: 1 addition & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod) {
return res;
}

Token *use = eat_token_if(pc, TokenIdKeywordUse);
Token *use = eat_token_if(pc, TokenIdKeywordUsingNamespace);
if (use != nullptr) {
AstNode *expr = ast_expect(pc, ast_parse_expr);
expect_token(pc, TokenIdSemicolon);
Expand Down
5 changes: 3 additions & 2 deletions src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static const struct ZigKeyword zig_keywords[] = {
{"undefined", TokenIdKeywordUndefined},
{"union", TokenIdKeywordUnion},
{"unreachable", TokenIdKeywordUnreachable},
{"use", TokenIdKeywordUse},
{"use", TokenIdKeywordUsingNamespace},
{"usingnamespace", TokenIdKeywordUsingNamespace},
{"var", TokenIdKeywordVar},
{"volatile", TokenIdKeywordVolatile},
{"while", TokenIdKeywordWhile},
Expand Down Expand Up @@ -1546,7 +1547,7 @@ const char * token_name(TokenId id) {
case TokenIdKeywordUndefined: return "undefined";
case TokenIdKeywordUnion: return "union";
case TokenIdKeywordUnreachable: return "unreachable";
case TokenIdKeywordUse: return "use";
case TokenIdKeywordUsingNamespace: return "usingnamespace";
case TokenIdKeywordVar: return "var";
case TokenIdKeywordVolatile: return "volatile";
case TokenIdKeywordWhile: return "while";
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum TokenId {
TokenIdKeywordUndefined,
TokenIdKeywordUnion,
TokenIdKeywordUnreachable,
TokenIdKeywordUse,
TokenIdKeywordUsingNamespace,
TokenIdKeywordVar,
TokenIdKeywordVolatile,
TokenIdKeywordWhile,
Expand Down
4 changes: 2 additions & 2 deletions std/zig/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn parseTopLevelComptime(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*
/// TopLevelDecl
/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERAL? / KEYWORD_inline)? FnProto (SEMICOLON / Block)
/// / (KEYWORD_export / KEYWORD_extern STRINGLITERAL?)? KEYWORD_threadlocal? VarDecl
/// / KEYWORD_use Expr SEMICOLON
/// / KEYWORD_usingnamespace Expr SEMICOLON
fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
var lib_name: ?*Node = null;
const extern_export_inline_token = blk: {
Expand Down Expand Up @@ -2809,7 +2809,7 @@ fn parseTry(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
}

fn parseUse(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
const token = eatToken(it, .Keyword_use) orelse return null;
const token = eatToken(it, .Keyword_usingnamespace) orelse return null;
const node = try arena.create(Node.Use);
node.* = Node.Use{
.base = Node{ .id = .Use },
Expand Down
14 changes: 12 additions & 2 deletions std/zig/parser_test.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// TODO remove `use` keyword eventually
test "zig fmt: change use to usingnamespace" {
try testTransform(
\\use @import("std");
,
\\usingnamespace @import("std");
\\
);
}

test "zig fmt: allowzero pointer" {
try testCanonical(
\\const T = [*]allowzero const u8;
Expand Down Expand Up @@ -2090,8 +2100,8 @@ test "zig fmt: Block after if" {

test "zig fmt: use" {
try testCanonical(
\\use @import("std");
\\pub use @import("std");
\\usingnamespace @import("std");
\\pub usingnamespace @import("std");
\\
);
}
Expand Down
4 changes: 3 additions & 1 deletion std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
if (use_decl.visib_token) |visib_token| {
try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
}
try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // use
// TODO after depracating use, go back to this:
//try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // usingnamespace
try stream.write("usingnamespace ");
try renderExpression(allocator, stream, tree, indent, start_col, use_decl.expr, Space.None);
try renderToken(tree, stream, use_decl.semicolon_token, indent, start_col, Space.Newline); // ;
},
Expand Down
5 changes: 3 additions & 2 deletions std/zig/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub const Token = struct {
Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },
Keyword{ .bytes = "union", .id = Id.Keyword_union },
Keyword{ .bytes = "unreachable", .id = Id.Keyword_unreachable },
Keyword{ .bytes = "use", .id = Id.Keyword_use },
Keyword{ .bytes = "use", .id = Id.Keyword_usingnamespace },
Keyword{ .bytes = "usingnamespace", .id = Id.Keyword_usingnamespace },
Keyword{ .bytes = "var", .id = Id.Keyword_var },
Keyword{ .bytes = "volatile", .id = Id.Keyword_volatile },
Keyword{ .bytes = "while", .id = Id.Keyword_while },
Expand Down Expand Up @@ -190,7 +191,7 @@ pub const Token = struct {
Keyword_undefined,
Keyword_union,
Keyword_unreachable,
Keyword_use,
Keyword_usingnamespace,
Keyword_var,
Keyword_volatile,
Keyword_while,
Expand Down

0 comments on commit b7a8228

Please sign in to comment.