Skip to content

Commit

Permalink
stage2: delete keywords true, false, undefined, null
Browse files Browse the repository at this point in the history
The grammar does not need these as keywords; they are merely primitives
provided by the language the same as `void`, `u32`, etc.
  • Loading branch information
andrewrk committed Aug 28, 2021
1 parent 6a6e2cd commit 05cf449
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 125 deletions.
29 changes: 14 additions & 15 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -887,16 +887,6 @@ fn tokenizeAndPrintRaw(
next_tok_is_fn = true;
},

.keyword_undefined,
.keyword_null,
.keyword_true,
.keyword_false,
=> {
try out.writeAll("<span class=\"tok-null\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},

.string_literal,
.multiline_string_literal_line,
.char_literal,
Expand All @@ -921,9 +911,18 @@ fn tokenizeAndPrintRaw(
},

.identifier => {
if (prev_tok_was_fn) {
const tok_bytes = src[token.loc.start..token.loc.end];
if (mem.eql(u8, tok_bytes, "undefined") or
mem.eql(u8, tok_bytes, "null") or
mem.eql(u8, tok_bytes, "true") or
mem.eql(u8, tok_bytes, "false"))
{
try out.writeAll("<span class=\"tok-null\">");
try writeEscaped(out, tok_bytes);
try out.writeAll("</span>");
} else if (prev_tok_was_fn) {
try out.writeAll("<span class=\"tok-fn\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try writeEscaped(out, tok_bytes);
try out.writeAll("</span>");
} else {
const is_int = blk: {
Expand All @@ -938,12 +937,12 @@ fn tokenizeAndPrintRaw(
}
break :blk true;
};
if (is_int or isType(src[token.loc.start..token.loc.end])) {
if (is_int or isType(tok_bytes)) {
try out.writeAll("<span class=\"tok-type\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try writeEscaped(out, tok_bytes);
try out.writeAll("</span>");
} else {
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try writeEscaped(out, tok_bytes);
}
}
},
Expand Down
16 changes: 4 additions & 12 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -11564,11 +11564,7 @@ PrimaryTypeExpr
/ INTEGER
/ KEYWORD_comptime TypeExpr
/ KEYWORD_error DOT IDENTIFIER
/ KEYWORD_false
/ KEYWORD_null
/ KEYWORD_anyframe
/ KEYWORD_true
/ KEYWORD_undefined
/ KEYWORD_unreachable
/ STRINGLITERAL
/ SwitchExpr
Expand Down Expand Up @@ -11937,15 +11933,13 @@ KEYWORD_errdefer &lt;- 'errdefer' end_of_word
KEYWORD_error &lt;- 'error' end_of_word
KEYWORD_export &lt;- 'export' end_of_word
KEYWORD_extern &lt;- 'extern' end_of_word
KEYWORD_false &lt;- 'false' end_of_word
KEYWORD_fn &lt;- 'fn' end_of_word
KEYWORD_for &lt;- 'for' end_of_word
KEYWORD_if &lt;- 'if' end_of_word
KEYWORD_inline &lt;- 'inline' end_of_word
KEYWORD_noalias &lt;- 'noalias' end_of_word
KEYWORD_nosuspend &lt;- 'nosuspend' end_of_word
KEYWORD_noinline &lt;- 'noinline' end_of_word
KEYWORD_null &lt;- 'null' end_of_word
KEYWORD_opaque &lt;- 'opaque' end_of_word
KEYWORD_or &lt;- 'or' end_of_word
KEYWORD_orelse &lt;- 'orelse' end_of_word
Expand All @@ -11959,9 +11953,7 @@ KEYWORD_suspend &lt;- 'suspend' end_of_word
KEYWORD_switch &lt;- 'switch' end_of_word
KEYWORD_test &lt;- 'test' end_of_word
KEYWORD_threadlocal &lt;- 'threadlocal' end_of_word
KEYWORD_true &lt;- 'true' end_of_word
KEYWORD_try &lt;- 'try' end_of_word
KEYWORD_undefined &lt;- 'undefined' end_of_word
KEYWORD_union &lt;- 'union' end_of_word
KEYWORD_unreachable &lt;- 'unreachable' end_of_word
KEYWORD_usingnamespace &lt;- 'usingnamespace' end_of_word
Expand All @@ -11974,13 +11966,13 @@ keyword &lt;- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe
/ KEYWORD_break / KEYWORD_callconv / KEYWORD_catch / KEYWORD_comptime
/ KEYWORD_const / KEYWORD_continue / KEYWORD_defer / KEYWORD_else
/ KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
/ KEYWORD_extern / KEYWORD_false / KEYWORD_fn / KEYWORD_for / KEYWORD_if
/ KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
/ KEYWORD_inline / KEYWORD_noalias / KEYWORD_nosuspend / KEYWORD_noinline
/ KEYWORD_null / KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
/ KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
/ KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch
/ KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
/ KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_test / KEYWORD_threadlocal / KEYWORD_try
/ KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
</code></pre>
{#header_close#}
Expand Down
16 changes: 0 additions & 16 deletions lib/std/zig/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ pub const Tree = struct {
.char_literal,
.integer_literal,
.float_literal,
.false_literal,
.true_literal,
.null_literal,
.undefined_literal,
.unreachable_literal,
.string_literal,
.multiline_string_literal,
Expand Down Expand Up @@ -711,10 +707,6 @@ pub const Tree = struct {
.char_literal,
.integer_literal,
.float_literal,
.false_literal,
.true_literal,
.null_literal,
.undefined_literal,
.unreachable_literal,
.identifier,
.deref,
Expand Down Expand Up @@ -2757,14 +2749,6 @@ pub const Node = struct {
/// Both lhs and rhs unused.
float_literal,
/// Both lhs and rhs unused.
false_literal,
/// Both lhs and rhs unused.
true_literal,
/// Both lhs and rhs unused.
null_literal,
/// Both lhs and rhs unused.
undefined_literal,
/// Both lhs and rhs unused.
unreachable_literal,
/// Both lhs and rhs unused.
/// Most identifiers will not have explicit AST nodes, however for expressions
Expand Down
36 changes: 0 additions & 36 deletions lib/std/zig/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2226,11 +2226,7 @@ const Parser = struct {
/// / INTEGER
/// / KEYWORD_comptime TypeExpr
/// / KEYWORD_error DOT IDENTIFIER
/// / KEYWORD_false
/// / KEYWORD_null
/// / KEYWORD_anyframe
/// / KEYWORD_true
/// / KEYWORD_undefined
/// / KEYWORD_unreachable
/// / STRINGLITERAL
/// / SwitchExpr
Expand Down Expand Up @@ -2273,38 +2269,6 @@ const Parser = struct {
.rhs = undefined,
},
}),
.keyword_false => return p.addNode(.{
.tag = .false_literal,
.main_token = p.nextToken(),
.data = .{
.lhs = undefined,
.rhs = undefined,
},
}),
.keyword_true => return p.addNode(.{
.tag = .true_literal,
.main_token = p.nextToken(),
.data = .{
.lhs = undefined,
.rhs = undefined,
},
}),
.keyword_null => return p.addNode(.{
.tag = .null_literal,
.main_token = p.nextToken(),
.data = .{
.lhs = undefined,
.rhs = undefined,
},
}),
.keyword_undefined => return p.addNode(.{
.tag = .undefined_literal,
.main_token = p.nextToken(),
.data = .{
.lhs = undefined,
.rhs = undefined,
},
}),
.keyword_unreachable => return p.addNode(.{
.tag = .unreachable_literal,
.main_token = p.nextToken(),
Expand Down
4 changes: 0 additions & 4 deletions lib/std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
.integer_literal,
.float_literal,
.char_literal,
.true_literal,
.false_literal,
.null_literal,
.unreachable_literal,
.undefined_literal,
.anyframe_literal,
.string_literal,
=> return renderToken(ais, tree, main_tokens[node], space),
Expand Down
12 changes: 0 additions & 12 deletions lib/std/zig/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ pub const Token = struct {
.{ "error", .keyword_error },
.{ "export", .keyword_export },
.{ "extern", .keyword_extern },
.{ "false", .keyword_false },
.{ "fn", .keyword_fn },
.{ "for", .keyword_for },
.{ "if", .keyword_if },
.{ "inline", .keyword_inline },
.{ "noalias", .keyword_noalias },
.{ "noinline", .keyword_noinline },
.{ "nosuspend", .keyword_nosuspend },
.{ "null", .keyword_null },
.{ "opaque", .keyword_opaque },
.{ "or", .keyword_or },
.{ "orelse", .keyword_orelse },
Expand All @@ -54,9 +52,7 @@ pub const Token = struct {
.{ "switch", .keyword_switch },
.{ "test", .keyword_test },
.{ "threadlocal", .keyword_threadlocal },
.{ "true", .keyword_true },
.{ "try", .keyword_try },
.{ "undefined", .keyword_undefined },
.{ "union", .keyword_union },
.{ "unreachable", .keyword_unreachable },
.{ "usingnamespace", .keyword_usingnamespace },
Expand Down Expand Up @@ -157,15 +153,13 @@ pub const Token = struct {
keyword_error,
keyword_export,
keyword_extern,
keyword_false,
keyword_fn,
keyword_for,
keyword_if,
keyword_inline,
keyword_noalias,
keyword_noinline,
keyword_nosuspend,
keyword_null,
keyword_opaque,
keyword_or,
keyword_orelse,
Expand All @@ -179,9 +173,7 @@ pub const Token = struct {
keyword_switch,
keyword_test,
keyword_threadlocal,
keyword_true,
keyword_try,
keyword_undefined,
keyword_union,
keyword_unreachable,
keyword_usingnamespace,
Expand Down Expand Up @@ -280,15 +272,13 @@ pub const Token = struct {
.keyword_error => "error",
.keyword_export => "export",
.keyword_extern => "extern",
.keyword_false => "false",
.keyword_fn => "fn",
.keyword_for => "for",
.keyword_if => "if",
.keyword_inline => "inline",
.keyword_noalias => "noalias",
.keyword_noinline => "noinline",
.keyword_nosuspend => "nosuspend",
.keyword_null => "null",
.keyword_opaque => "opaque",
.keyword_or => "or",
.keyword_orelse => "orelse",
Expand All @@ -302,9 +292,7 @@ pub const Token = struct {
.keyword_switch => "switch",
.keyword_test => "test",
.keyword_threadlocal => "threadlocal",
.keyword_true => "true",
.keyword_try => "try",
.keyword_undefined => "undefined",
.keyword_union => "union",
.keyword_unreachable => "unreachable",
.keyword_usingnamespace => "usingnamespace",
Expand Down
20 changes: 0 additions & 20 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Ins
.bool_not,
.address_of,
.float_literal,
.undefined_literal,
.true_literal,
.false_literal,
.null_literal,
.optional_type,
.block,
.block_semicolon,
Expand Down Expand Up @@ -759,10 +755,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
const result = try expr(gz, scope, .ref, node_datas[node].lhs);
return rvalue(gz, rl, result, node);
},
.undefined_literal => return rvalue(gz, rl, .undef, node),
.true_literal => return rvalue(gz, rl, .bool_true, node),
.false_literal => return rvalue(gz, rl, .bool_false, node),
.null_literal => return rvalue(gz, rl, .null_value, node),
.optional_type => {
const operand = try typeExpr(gz, scope, node_datas[node].lhs);
const result = try gz.addUnNode(.optional_type, operand, node);
Expand Down Expand Up @@ -7852,10 +7844,6 @@ fn nodeMayNeedMemoryLocation(tree: *const ast.Tree, start_node: ast.Node.Index)
.string_literal,
.multiline_string_literal,
.char_literal,
.true_literal,
.false_literal,
.null_literal,
.undefined_literal,
.unreachable_literal,
.identifier,
.error_set_decl,
Expand Down Expand Up @@ -8092,10 +8080,6 @@ fn nodeMayEvalToError(tree: *const ast.Tree, start_node: ast.Node.Index) enum {
.string_literal,
.multiline_string_literal,
.char_literal,
.true_literal,
.false_literal,
.null_literal,
.undefined_literal,
.unreachable_literal,
.error_set_decl,
.container_decl,
Expand Down Expand Up @@ -8265,10 +8249,6 @@ fn nodeImpliesRuntimeBits(tree: *const ast.Tree, start_node: ast.Node.Index) boo
.string_literal,
.multiline_string_literal,
.char_literal,
.true_literal,
.false_literal,
.null_literal,
.undefined_literal,
.unreachable_literal,
.identifier,
.error_set_decl,
Expand Down
20 changes: 10 additions & 10 deletions src/translate_c/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -928,23 +928,23 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
return renderCall(c, lhs, payload.args);
},
.null_literal => return c.addNode(.{
.tag = .null_literal,
.main_token = try c.addToken(.keyword_null, "null"),
.tag = .identifier,
.main_token = try c.addToken(.identifier, "null"),
.data = undefined,
}),
.undefined_literal => return c.addNode(.{
.tag = .undefined_literal,
.main_token = try c.addToken(.keyword_undefined, "undefined"),
.tag = .identifier,
.main_token = try c.addToken(.identifier, "undefined"),
.data = undefined,
}),
.true_literal => return c.addNode(.{
.tag = .true_literal,
.main_token = try c.addToken(.keyword_true, "true"),
.tag = .identifier,
.main_token = try c.addToken(.identifier, "true"),
.data = undefined,
}),
.false_literal => return c.addNode(.{
.tag = .false_literal,
.main_token = try c.addToken(.keyword_false, "false"),
.tag = .identifier,
.main_token = try c.addToken(.identifier, "false"),
.data = undefined,
}),
.zero_literal => return c.addNode(.{
Expand Down Expand Up @@ -1599,8 +1599,8 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
const while_tok = try c.addToken(.keyword_while, "while");
_ = try c.addToken(.l_paren, "(");
const cond = try c.addNode(.{
.tag = .true_literal,
.main_token = try c.addToken(.keyword_true, "true"),
.tag = .identifier,
.main_token = try c.addToken(.identifier, "true"),
.data = undefined,
});
_ = try c.addToken(.r_paren, ")");
Expand Down

1 comment on commit 05cf449

@haze
Copy link
Contributor

@haze haze commented on 05cf449 Aug 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Epic

Please sign in to comment.