| ... | @@ -2053,44 +2053,49 @@ pub const Parser = struct { | ... | @@ -2053,44 +2053,49 @@ pub const Parser = struct { |
| 2053 | | 2053 | |
| 2054 | State.Semicolon => |node_ptr| { | 2054 | State.Semicolon => |node_ptr| { |
| 2055 | const node = *node_ptr; | 2055 | const node = *node_ptr; |
| 2056 | switch (node.id) { | 2056 | if (requireSemiColon(node)) { |
| 2057 | ast.Node.Id.Root, | 2057 | _ = (try self.eatToken(&stack, Token.Id.Semicolon)) ?? continue; |
| 2058 | ast.Node.Id.StructField, | | |
| 2059 | ast.Node.Id.UnionTag, | | |
| 2060 | ast.Node.Id.EnumTag, | | |
| 2061 | ast.Node.Id.ParamDecl, | | |
| 2062 | ast.Node.Id.Block, | | |
| 2063 | ast.Node.Id.Payload, | | |
| 2064 | ast.Node.Id.Switch, | | |
| 2065 | ast.Node.Id.SwitchCase, | | |
| 2066 | ast.Node.Id.SwitchElse, | | |
| 2067 | ast.Node.Id.FieldInitializer, | | |
| 2068 | ast.Node.Id.LineComment, | | |
| 2069 | ast.Node.Id.TestDecl => continue, | | |
| 2070 | ast.Node.Id.While => { | | |
| 2071 | const while_node = @fieldParentPtr(ast.NodeWhile, "base", node); | | |
| 2072 | if (while_node.@"else") |@"else"| { | | |
| 2073 | stack.append(State { .Semicolon = &@"else".base }) catch unreachable; | | |
| 2074 | continue; | | |
| 2075 | } | | |
| 2076 | | | |
| 2077 | stack.append(State { .Semicolon = &while_node.body }) catch unreachable; | | |
| 2078 | continue; | | |
| 2079 | }, | | |
| 2080 | ast.Node.Id.Else => { | | |
| 2081 | const else_node = @fieldParentPtr(ast.NodeElse, "base", node); | | |
| 2082 | stack.append(State { .Semicolon = &else_node.body }) catch unreachable; | | |
| 2083 | continue; | | |
| 2084 | }, | | |
| 2085 | else => { | | |
| 2086 | _ = (try self.eatToken(&stack, Token.Id.Semicolon)) ?? continue; | | |
| 2087 | } | | |
| 2088 | } | 2058 | } |
| 2089 | } | 2059 | } |
| 2090 | } | 2060 | } |
| 2091 | } | 2061 | } |
| 2092 | } | 2062 | } |
| 2093 | | 2063 | |
| | 2064 | fn requireSemiColon(node: &const ast.Node) bool { |
| | 2065 | var n = node; |
| | 2066 | while (true) { |
| | 2067 | switch (n.id) { |
| | 2068 | ast.Node.Id.Root, |
| | 2069 | ast.Node.Id.StructField, |
| | 2070 | ast.Node.Id.UnionTag, |
| | 2071 | ast.Node.Id.EnumTag, |
| | 2072 | ast.Node.Id.ParamDecl, |
| | 2073 | ast.Node.Id.Block, |
| | 2074 | ast.Node.Id.Payload, |
| | 2075 | ast.Node.Id.Switch, |
| | 2076 | ast.Node.Id.SwitchCase, |
| | 2077 | ast.Node.Id.SwitchElse, |
| | 2078 | ast.Node.Id.FieldInitializer, |
| | 2079 | ast.Node.Id.LineComment, |
| | 2080 | ast.Node.Id.TestDecl => return false, |
| | 2081 | ast.Node.Id.While => { |
| | 2082 | const while_node = @fieldParentPtr(ast.NodeWhile, "base", n); |
| | 2083 | if (while_node.@"else") |@"else"| { |
| | 2084 | n = @"else".base; |
| | 2085 | continue; |
| | 2086 | } |
| | 2087 | |
| | 2088 | n = while_node.body; |
| | 2089 | }, |
| | 2090 | ast.Node.Id.Else => { |
| | 2091 | const else_node = @fieldParentPtr(ast.NodeElse, "base", n); |
| | 2092 | n = else_node.body; |
| | 2093 | }, |
| | 2094 | else => return true, |
| | 2095 | } |
| | 2096 | } |
| | 2097 | } |
| | 2098 | |
| 2094 | fn commaOrEnd(self: &Parser, stack: &ArrayList(State), end: &const Token.Id, maybe_ptr: ?&Token, state_after_comma: &const State) !void { | 2099 | fn commaOrEnd(self: &Parser, stack: &ArrayList(State), end: &const Token.Id, maybe_ptr: ?&Token, state_after_comma: &const State) !void { |
| 2095 | var token = self.getNextToken(); | 2100 | var token = self.getNextToken(); |
| 2096 | switch (token.id) { | 2101 | switch (token.id) { |
| ... | @@ -2559,7 +2564,6 @@ pub const Parser = struct { | ... | @@ -2559,7 +2564,6 @@ pub const Parser = struct { |
| 2559 | Expression: &ast.Node, | 2564 | Expression: &ast.Node, |
| 2560 | VarDecl: &ast.NodeVarDecl, | 2565 | VarDecl: &ast.NodeVarDecl, |
| 2561 | Statement: &ast.Node, | 2566 | Statement: &ast.Node, |
| 2562 | Semicolon: &ast.Node, | | |
| 2563 | FieldInitializer: &ast.NodeFieldInitializer, | 2567 | FieldInitializer: &ast.NodeFieldInitializer, |
| 2564 | PrintIndent, | 2568 | PrintIndent, |
| 2565 | Indent: usize, | 2569 | Indent: usize, |
| ... | @@ -3344,44 +3348,11 @@ pub const Parser = struct { | ... | @@ -3344,44 +3348,11 @@ pub const Parser = struct { |
| 3344 | try stack.append(RenderState { .VarDecl = var_decl}); | 3348 | try stack.append(RenderState { .VarDecl = var_decl}); |
| 3345 | }, | 3349 | }, |
| 3346 | else => { | 3350 | else => { |
| 3347 | try stack.append(RenderState { .Semicolon = base }); | 3351 | if (requireSemiColon(base)) { |
| 3348 | try stack.append(RenderState { .Expression = base }); | 3352 | try stack.append(RenderState { .Text = ";" }); |
| 3349 | }, | | |
| 3350 | } | | |
| 3351 | }, | | |
| 3352 | RenderState.Semicolon => |base| { | | |
| 3353 | switch (base.id) { | | |
| 3354 | ast.Node.Id.Root, | | |
| 3355 | ast.Node.Id.StructField, | | |
| 3356 | ast.Node.Id.UnionTag, | | |
| 3357 | ast.Node.Id.EnumTag, | | |
| 3358 | ast.Node.Id.ParamDecl, | | |
| 3359 | ast.Node.Id.Block, | | |
| 3360 | ast.Node.Id.Payload, | | |
| 3361 | ast.Node.Id.Switch, | | |
| 3362 | ast.Node.Id.SwitchCase, | | |
| 3363 | ast.Node.Id.SwitchElse, | | |
| 3364 | ast.Node.Id.FieldInitializer, | | |
| 3365 | ast.Node.Id.LineComment, | | |
| 3366 | ast.Node.Id.TestDecl => {}, | | |
| 3367 | ast.Node.Id.While => { | | |
| 3368 | const while_node = @fieldParentPtr(ast.NodeWhile, "base", base); | | |
| 3369 | if (while_node.@"else") |@"else"| { | | |
| 3370 | stack.append(RenderState { .Semicolon = &@"else".base }) catch unreachable; | | |
| 3371 | continue; | | |
| 3372 | } | 3353 | } |
| 3373 | | 3354 | try stack.append(RenderState { .Expression = base }); |
| 3374 | stack.append(RenderState { .Semicolon = while_node.body }) catch unreachable; | | |
| 3375 | continue; | | |
| 3376 | }, | | |
| 3377 | ast.Node.Id.Else => { | | |
| 3378 | const else_node = @fieldParentPtr(ast.NodeElse, "base", base); | | |
| 3379 | stack.append(RenderState { .Semicolon = else_node.body }) catch unreachable; | | |
| 3380 | continue; | | |
| 3381 | }, | 3355 | }, |
| 3382 | else => { | | |
| 3383 | try stack.append(RenderState { .Text = ";" }); | | |
| 3384 | } | | |
| 3385 | } | 3356 | } |
| 3386 | }, | 3357 | }, |
| 3387 | RenderState.Indent => |new_indent| indent = new_indent, | 3358 | RenderState.Indent => |new_indent| indent = new_indent, |