change use to usingnamespace

See #2014

`use` syntax is still accepted for now. `zig fmt` automatically
updates code. After a release cycle the old syntax will be removed.
This commit is contained in:
Andrew Kelley 2019-05-29 17:39:26 -04:00
parent 9a7cf73b3b
commit b7a82288ad
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
9 changed files with 28 additions and 14 deletions

View File

@ -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,

View File

@ -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
@ -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>

View File

@ -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);

View File

@ -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},
@ -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";

View File

@ -96,7 +96,7 @@ enum TokenId {
TokenIdKeywordUndefined,
TokenIdKeywordUnion,
TokenIdKeywordUnreachable,
TokenIdKeywordUse,
TokenIdKeywordUsingNamespace,
TokenIdKeywordVar,
TokenIdKeywordVolatile,
TokenIdKeywordWhile,

View File

@ -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: {
@ -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 },

View File

@ -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;
@ -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");
\\
);
}

View File

@ -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); // ;
},

View File

@ -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 },
@ -190,7 +191,7 @@ pub const Token = struct {
Keyword_undefined,
Keyword_union,
Keyword_unreachable,
Keyword_use,
Keyword_usingnamespace,
Keyword_var,
Keyword_volatile,
Keyword_while,