separate std.zig.parse and std.zig.render
parent
69ef6ae0f9
commit
0cb65b266a
|
@ -576,7 +576,8 @@ set(ZIG_STD_FILES
|
|||
"unicode.zig"
|
||||
"zig/ast.zig"
|
||||
"zig/index.zig"
|
||||
"zig/parser.zig"
|
||||
"zig/parse.zig"
|
||||
"zig/render.zig"
|
||||
"zig/tokenizer.zig"
|
||||
)
|
||||
|
||||
|
|
|
@ -336,6 +336,80 @@ pub const Node = struct {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
pub fn requireSemiColon(base: &const Node) bool {
|
||||
var n = base;
|
||||
while (true) {
|
||||
switch (n.id) {
|
||||
Id.Root,
|
||||
Id.StructField,
|
||||
Id.UnionTag,
|
||||
Id.EnumTag,
|
||||
Id.ParamDecl,
|
||||
Id.Block,
|
||||
Id.Payload,
|
||||
Id.PointerPayload,
|
||||
Id.PointerIndexPayload,
|
||||
Id.Switch,
|
||||
Id.SwitchCase,
|
||||
Id.SwitchElse,
|
||||
Id.FieldInitializer,
|
||||
Id.DocComment,
|
||||
Id.LineComment,
|
||||
Id.TestDecl => return false,
|
||||
Id.While => {
|
||||
const while_node = @fieldParentPtr(While, "base", n);
|
||||
if (while_node.@"else") |@"else"| {
|
||||
n = @"else".base;
|
||||
continue;
|
||||
}
|
||||
|
||||
return while_node.body.id != Id.Block;
|
||||
},
|
||||
Id.For => {
|
||||
const for_node = @fieldParentPtr(For, "base", n);
|
||||
if (for_node.@"else") |@"else"| {
|
||||
n = @"else".base;
|
||||
continue;
|
||||
}
|
||||
|
||||
return for_node.body.id != Id.Block;
|
||||
},
|
||||
Id.If => {
|
||||
const if_node = @fieldParentPtr(If, "base", n);
|
||||
if (if_node.@"else") |@"else"| {
|
||||
n = @"else".base;
|
||||
continue;
|
||||
}
|
||||
|
||||
return if_node.body.id != Id.Block;
|
||||
},
|
||||
Id.Else => {
|
||||
const else_node = @fieldParentPtr(Else, "base", n);
|
||||
n = else_node.body;
|
||||
continue;
|
||||
},
|
||||
Id.Defer => {
|
||||
const defer_node = @fieldParentPtr(Defer, "base", n);
|
||||
return defer_node.expr.id != Id.Block;
|
||||
},
|
||||
Id.Comptime => {
|
||||
const comptime_node = @fieldParentPtr(Comptime, "base", n);
|
||||
return comptime_node.expr.id != Id.Block;
|
||||
},
|
||||
Id.Suspend => {
|
||||
const suspend_node = @fieldParentPtr(Suspend, "base", n);
|
||||
if (suspend_node.body) |body| {
|
||||
return body.id != Id.Block;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
else => return true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub const Root = struct {
|
||||
base: Node,
|
||||
doc_comments: ?&DocComment,
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
const tokenizer = @import("tokenizer.zig");
|
||||
pub const Token = tokenizer.Token;
|
||||
pub const Tokenizer = tokenizer.Tokenizer;
|
||||
pub const parse = @import("parser.zig").parse;
|
||||
pub const render = @import("parser.zig").renderSource;
|
||||
pub const parse = @import("parse.zig").parse;
|
||||
pub const render = @import("render.zig").render;
|
||||
pub const ast = @import("ast.zig");
|
||||
|
||||
test "std.zig tests" {
|
||||
_ = @import("tokenizer.zig");
|
||||
_ = @import("parser.zig");
|
||||
_ = @import("ast.zig");
|
||||
_ = @import("parse.zig");
|
||||
_ = @import("render.zig");
|
||||
_ = @import("tokenizer.zig");
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue