Closed andersfr closed 4 years ago
I fixed it in my own context-free LALR parser implementation. Perhaps it is better to just fix the Zig compiler after all (the PEG reference in zig-spec can parse it correctly). I already know how to make the patch :)
This parser correctly now.
pub fn main() void {
const identifier: usize = 8;
const test1 = *align(label: { break :label 8; }:1:32) u8;
const test2 = *align(identifier:1:32) u8;
@compileLog(test2); // | *align(8:1:32) u8
}
Resubmission of #2954 as proposal.
The syntax requires lookahead > 1 in the parser to identify and resolve correctly. The problem arises because Expr is parsed first and it expects a labelled block when encountering the colon token when Expr=Identifier.
I propose to change the colon after Expr in the align(...) into a different symbol without conflicting parses. My suggestion is to create a '::' token to preserve the look of the syntax, i.e.
align(Expr::IntegerLiteral:IntegerLiteral)
.Zig compiler fails to handle the syntax:
issue.zig:4:37: error: invalid token: '1' const test2 = *align(identifier:1:32) u8;