Merge pull request #5358 from Vexu/parser
Fix infinite loop with invalid comptime
This commit is contained in:
commit
eda03354dc
@ -165,6 +165,7 @@ pub const Error = union(enum) {
|
|||||||
ExpectedLoopExpr: ExpectedLoopExpr,
|
ExpectedLoopExpr: ExpectedLoopExpr,
|
||||||
ExpectedDerefOrUnwrap: ExpectedDerefOrUnwrap,
|
ExpectedDerefOrUnwrap: ExpectedDerefOrUnwrap,
|
||||||
ExpectedSuffixOp: ExpectedSuffixOp,
|
ExpectedSuffixOp: ExpectedSuffixOp,
|
||||||
|
ExpectedBlockOrField: ExpectedBlockOrField,
|
||||||
DeclBetweenFields: DeclBetweenFields,
|
DeclBetweenFields: DeclBetweenFields,
|
||||||
InvalidAnd: InvalidAnd,
|
InvalidAnd: InvalidAnd,
|
||||||
|
|
||||||
@ -215,6 +216,7 @@ pub const Error = union(enum) {
|
|||||||
.ExpectedLoopExpr => |*x| return x.render(tokens, stream),
|
.ExpectedLoopExpr => |*x| return x.render(tokens, stream),
|
||||||
.ExpectedDerefOrUnwrap => |*x| return x.render(tokens, stream),
|
.ExpectedDerefOrUnwrap => |*x| return x.render(tokens, stream),
|
||||||
.ExpectedSuffixOp => |*x| return x.render(tokens, stream),
|
.ExpectedSuffixOp => |*x| return x.render(tokens, stream),
|
||||||
|
.ExpectedBlockOrField => |*x| return x.render(tokens, stream),
|
||||||
.DeclBetweenFields => |*x| return x.render(tokens, stream),
|
.DeclBetweenFields => |*x| return x.render(tokens, stream),
|
||||||
.InvalidAnd => |*x| return x.render(tokens, stream),
|
.InvalidAnd => |*x| return x.render(tokens, stream),
|
||||||
}
|
}
|
||||||
@ -267,6 +269,7 @@ pub const Error = union(enum) {
|
|||||||
.ExpectedLoopExpr => |x| return x.token,
|
.ExpectedLoopExpr => |x| return x.token,
|
||||||
.ExpectedDerefOrUnwrap => |x| return x.token,
|
.ExpectedDerefOrUnwrap => |x| return x.token,
|
||||||
.ExpectedSuffixOp => |x| return x.token,
|
.ExpectedSuffixOp => |x| return x.token,
|
||||||
|
.ExpectedBlockOrField => |x| return x.token,
|
||||||
.DeclBetweenFields => |x| return x.token,
|
.DeclBetweenFields => |x| return x.token,
|
||||||
.InvalidAnd => |x| return x.token,
|
.InvalidAnd => |x| return x.token,
|
||||||
}
|
}
|
||||||
@ -306,6 +309,7 @@ pub const Error = union(enum) {
|
|||||||
pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'");
|
pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'");
|
||||||
pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'");
|
pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'");
|
||||||
pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
|
pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
|
||||||
|
pub const ExpectedBlockOrField = SingleTokenError("Expected block or field, found '{}'");
|
||||||
|
|
||||||
pub const ExpectedParamType = SimpleError("Expected parameter type");
|
pub const ExpectedParamType = SimpleError("Expected parameter type");
|
||||||
pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
|
pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
|
||||||
|
@ -231,6 +231,12 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree, top
|
|||||||
const next = it.peek().?.id;
|
const next = it.peek().?.id;
|
||||||
switch (next) {
|
switch (next) {
|
||||||
.Eof => break,
|
.Eof => break,
|
||||||
|
.Keyword_comptime => {
|
||||||
|
_ = nextToken(it);
|
||||||
|
try tree.errors.push(.{
|
||||||
|
.ExpectedBlockOrField = .{ .token = it.index },
|
||||||
|
});
|
||||||
|
},
|
||||||
else => {
|
else => {
|
||||||
const index = it.index;
|
const index = it.index;
|
||||||
if (next == .RBrace) {
|
if (next == .RBrace) {
|
||||||
|
@ -200,6 +200,14 @@ test "recovery: missing semicolon after if, for, while stmt" {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "recovery: invalid comptime" {
|
||||||
|
try testError(
|
||||||
|
\\comptime
|
||||||
|
, &[_]Error{
|
||||||
|
.ExpectedBlockOrField,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test "zig fmt: top-level fields" {
|
test "zig fmt: top-level fields" {
|
||||||
try testCanonical(
|
try testCanonical(
|
||||||
\\a: did_you_know,
|
\\a: did_you_know,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user