authorgravatar for gbell12907@gmail.comCMDRZero <gbell12907@gmail.com> 2026-07-13 15:47:13-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-22 12:21:43+02:00
log12ead9415ca1dfb15803c46d4598141daee314ba
tree321215ab74bd51b648120812f39452275c666657
parent64e4f9db8fa6fc47b0a2ef3143edacf472fb8c48

Update `grammar.peg` to conform to new Partial Operator Ordering


2 files changed, 521 insertions(+), 85 deletions(-)

doc/langref/grammar.peg+44-18
...@@ -127,21 +127,34 @@ AssignExpr <- Expr (AssignOp Expr / (COMMA Expr)+ EQUAL Expr / !AssignOp !COMMA)...@@ -127,21 +127,34 @@ AssignExpr <- Expr (AssignOp Expr / (COMMA Expr)+ EQUAL Expr / !AssignOp !COMMA)
127127
128SingleAssignExpr <- Expr (AssignOp Expr / !AssignOp)128SingleAssignExpr <- Expr (AssignOp Expr / !AssignOp)
129129
130Expr <- BoolOrExpr130Expr <- PrefixExpr (OrElseExpr / CatchExpr / BoolExpr)
131131
132BoolOrExpr <- BoolAndExpr (OrOp BoolAndExpr)* !OrOp132OrElseExpr <- (OrElseOp PrefixExpr)+ !RecoveryNonmixingOp
133CatchExpr <- (CatchOp PrefixExpr)+ !RecoveryNonmixingOp
134RecoveryNonmixingOp <- ControlOp / CompareOp / BitwiseNonmixingOp
135ControlOp <- OrElseOp / CatchOp / AndOp / OrOp
133136
134BoolAndExpr <- CompareExpr (AndOp CompareExpr)* !AndOp137BoolExpr <- CompareExpr (BoolAndExpr / BoolOrExpr / !ControlOp)
138BoolAndExpr <- (AndOp PrefixExpr CompareExpr)+ !ControlOp
139BoolOrExpr <- (OrOp PrefixExpr CompareExpr)+ !ControlOp
135140
136CompareExpr <- BitwiseExpr (CompareOp BitwiseExpr)? !CompareOp141CompareExpr <- CompareOperand (CompareOp PrefixExpr CompareOperand)? !(CompareOp / OrElseOp / CatchOp)
142CompareOperand
143 <- (BitwiseOrOp PrefixExpr)+ !BitwiseNonmixingOp
144 / (BitwiseAndOp PrefixExpr)+ !BitwiseNonmixingOp
145 / (BitwiseXorOp PrefixExpr)+ !BitwiseNonmixingOp
146 / BitShiftOp PrefixExpr !BitwiseNonmixingOp
147 / !BitOp AdditionExpr
137148
138BitwiseExpr <- BitShiftExpr (BitwiseOp BitShiftExpr)* !BitwiseOp149BitOp <- BitwiseOrOp / BitwiseAndOp / BitwiseXorOp / BitShiftOp
150BitwiseNonmixingOp <- MultiplyNonmixingOp / AdditionOp
139151
140BitShiftExpr <- AdditionExpr (BitShiftOp AdditionExpr)* !BitShiftOp152AdditionExpr <- MulOrModExpr (AdditionOp PrefixExpr MulOrModExpr)* !(AdditionOp / BitOp / OrElseOp / CatchOp)
141153
142AdditionExpr <- MultiplyExpr (AdditionOp MultiplyExpr)* !AdditionOp154MulOrModExpr <- ModExpr / !ModOp MultiplyExpr
143155ModExpr <- ModOp PrefixExpr !MultiplyNonmixingOp
144MultiplyExpr <- PrefixExpr (MultiplyOp PrefixExpr)* !MultiplyOp156MultiplyExpr <- (MultiplyOp PrefixExpr)* !MultiplyNonmixingOp
157MultiplyNonmixingOp <- MultiplyOp / ModOp / BitOp / OrElseOp / CatchOp
145158
146PrefixExpr <- PrefixOp* !PrefixOp PrimaryExpr159PrefixExpr <- PrefixOp* !PrefixOp PrimaryExpr
147160
...@@ -323,15 +336,26 @@ CompareOpTok...@@ -323,15 +336,26 @@ CompareOpTok
323 / LARROWEQUAL336 / LARROWEQUAL
324 / RARROWEQUAL337 / RARROWEQUAL
325338
326BitwiseOp <- pre_op_white BitwiseOpTok post_op_white339BitwiseAndOp <- pre_op_white BitwiseAndOpTok post_op_white
327 / !pre_op_white BitwiseOpTok !post_op_white340 / !pre_op_white BitwiseAndOpTok !post_op_white
328 / pre_op_white KEYWORD_catch post_op_white Payload?341BitwiseAndOpTok
329 / !pre_op_white KEYWORD_catch !post_op_white Payload?
330BitwiseOpTok
331 <- AMPERSAND ![&]342 <- AMPERSAND ![&]
332 / CARET343
333 / PIPE344BitwiseOrOp <- pre_op_white BitwiseOrOpTok post_op_white
334 / KEYWORD_orelse345 / !pre_op_white BitwiseOrOpTok !post_op_white
346BitwiseOrOpTok
347 <- PIPE
348
349BitwiseXorOp <- pre_op_white BitwiseXorOpTok post_op_white
350 / !pre_op_white BitwiseXorOpTok !post_op_white
351BitwiseXorOpTok
352 <- CARET
353
354CatchOp <- pre_op_white KEYWORD_catch post_op_white Payload?
355 / !pre_op_white KEYWORD_catch !post_op_white Payload?
356
357OrElseOp <- pre_op_white KEYWORD_orelse post_op_white
358 / !pre_op_white KEYWORD_orelse !post_op_white
335359
336BitShiftOp <- pre_op_white BitShiftOpTok post_op_white360BitShiftOp <- pre_op_white BitShiftOpTok post_op_white
337 / !pre_op_white BitShiftOpTok !post_op_white361 / !pre_op_white BitShiftOpTok !post_op_white
...@@ -357,10 +381,12 @@ MultiplyOpTok...@@ -357,10 +381,12 @@ MultiplyOpTok
357 <- PIPE2381 <- PIPE2
358 / ASTERISK382 / ASTERISK
359 / SLASH383 / SLASH
360 / PERCENT
361 / ASTERISKPERCENT384 / ASTERISKPERCENT
362 / ASTERISKPIPE385 / ASTERISKPIPE
363386
387ModOp <- pre_op_white PERCENT post_op_white
388 / !pre_op_white PERCENT !post_op_white
389
364PrefixOp390PrefixOp
365 <- EXCLAMATIONMARK391 <- EXCLAMATIONMARK
366 / MINUS392 / MINUS
lib/std/zig/parser_generated_oracle.zig+477-67
...@@ -42,13 +42,22 @@ const Def = enum {...@@ -42,13 +42,22 @@ const Def = enum {
42 defAssignExpr,42 defAssignExpr,
43 defSingleAssignExpr,43 defSingleAssignExpr,
44 defExpr,44 defExpr,
45 defBoolOrExpr,45 defOrElseExpr,
46 defCatchExpr,
47 defRecoveryNonmixingOp,
48 defControlOp,
49 defBoolExpr,
46 defBoolAndExpr,50 defBoolAndExpr,
51 defBoolOrExpr,
47 defCompareExpr,52 defCompareExpr,
48 defBitwiseExpr,53 defCompareOperand,
49 defBitShiftExpr,54 defBitOp,
55 defBitwiseNonmixingOp,
50 defAdditionExpr,56 defAdditionExpr,
57 defMulOrModExpr,
58 defModExpr,
51 defMultiplyExpr,59 defMultiplyExpr,
60 defMultiplyNonmixingOp,
52 defPrefixExpr,61 defPrefixExpr,
53 defPrimaryExpr,62 defPrimaryExpr,
54 defIfExpr,63 defIfExpr,
...@@ -103,14 +112,21 @@ const Def = enum {...@@ -103,14 +112,21 @@ const Def = enum {
103 defAndOp,112 defAndOp,
104 defCompareOp,113 defCompareOp,
105 defCompareOpTok,114 defCompareOpTok,
106 defBitwiseOp,115 defBitwiseAndOp,
107 defBitwiseOpTok,116 defBitwiseAndOpTok,
117 defBitwiseOrOp,
118 defBitwiseOrOpTok,
119 defBitwiseXorOp,
120 defBitwiseXorOpTok,
121 defCatchOp,
122 defOrElseOp,
108 defBitShiftOp,123 defBitShiftOp,
109 defBitShiftOpTok,124 defBitShiftOpTok,
110 defAdditionOp,125 defAdditionOp,
111 defAdditionOpTok,126 defAdditionOpTok,
112 defMultiplyOp,127 defMultiplyOp,
113 defMultiplyOpTok,128 defMultiplyOpTok,
129 defModOp,
114 defPrefixOp,130 defPrefixOp,
115 defPrefixTypeOp,131 defPrefixTypeOp,
116 defPtrMods,132 defPtrMods,
...@@ -290,7 +306,7 @@ const Def = enum {...@@ -290,7 +306,7 @@ const Def = enum {
290const Parser = struct {306const Parser = struct {
291 source: []const u8,307 source: []const u8,
292 i: usize,308 i: usize,
293 depths: [272]u8,309 depths: [288]u8,
294 pub fn parseRoot(p: *Parser) Error!bool {310 pub fn parseRoot(p: *Parser) Error!bool {
295 const def_index = @backingInt(Def.defRoot);311 const def_index = @backingInt(Def.defRoot);
296 if (p.depths[def_index] > max_depth) return error.MaxDepth;312 if (p.depths[def_index] > max_depth) return error.MaxDepth;
...@@ -964,33 +980,44 @@ const Parser = struct {...@@ -964,33 +980,44 @@ const Parser = struct {
964 defer p.depths[def_index] -= 1;980 defer p.depths[def_index] -= 1;
965 return blk_0: {981 return blk_0: {
966 const pos_0 = p.i;982 const pos_0 = p.i;
967 if (try p.parseBoolOrExpr()) break :blk_0 true;983 if (try p.parsePrefixExpr() and blk_2: {
984 const pos_2 = p.i;
985 if (try p.parseOrElseExpr()) break :blk_2 true;
986 p.i = pos_2;
987 if (try p.parseCatchExpr()) break :blk_2 true;
988 p.i = pos_2;
989 if (try p.parseBoolExpr()) break :blk_2 true;
990 p.i = pos_2;
991 break :blk_2 false;
992 }) break :blk_0 true;
968 p.i = pos_0;993 p.i = pos_0;
969 break :blk_0 false;994 break :blk_0 false;
970 };995 };
971 }996 }
972 pub fn parseBoolOrExpr(p: *Parser) Error!bool {997 pub fn parseOrElseExpr(p: *Parser) Error!bool {
973 const def_index = @backingInt(Def.defBoolOrExpr);998 const def_index = @backingInt(Def.defOrElseExpr);
974 if (p.depths[def_index] > max_depth) return error.MaxDepth;999 if (p.depths[def_index] > max_depth) return error.MaxDepth;
975 p.depths[def_index] += 1;1000 p.depths[def_index] += 1;
976 defer p.depths[def_index] -= 1;1001 defer p.depths[def_index] -= 1;
977 return blk_0: {1002 return blk_0: {
978 const pos_0 = p.i;1003 const pos_0 = p.i;
979 if (try p.parseBoolAndExpr() and blk_1: {1004 if (blk_1: {
1005 var match_1 = false;
980 var i_1: usize = 0;1006 var i_1: usize = 0;
981 while (blk_3: {1007 while (blk_3: {
982 const pos_3 = p.i;1008 const pos_3 = p.i;
983 if (try p.parseOrOp() and try p.parseBoolAndExpr()) break :blk_3 true;1009 if (try p.parseOrElseOp() and try p.parsePrefixExpr()) break :blk_3 true;
984 p.i = pos_3;1010 p.i = pos_3;
985 break :blk_3 false;1011 break :blk_3 false;
986 }) {1012 }) {
1013 match_1 = true;
987 if (i_1 > max_depth) return error.MaxDepth;1014 if (i_1 > max_depth) return error.MaxDepth;
988 i_1 += 1;1015 i_1 += 1;
989 }1016 }
990 break :blk_1 true;1017 break :blk_1 match_1;
991 } and blk_1: {1018 } and blk_1: {
992 const pos_1 = p.i;1019 const pos_1 = p.i;
993 const match_1 = try p.parseOrOp();1020 const match_1 = try p.parseRecoveryNonmixingOp();
994 p.i = pos_1;1021 p.i = pos_1;
995 break :blk_1 !match_1;1022 break :blk_1 !match_1;
996 }) break :blk_0 true;1023 }) break :blk_0 true;
...@@ -998,28 +1025,30 @@ const Parser = struct {...@@ -998,28 +1025,30 @@ const Parser = struct {
998 break :blk_0 false;1025 break :blk_0 false;
999 };1026 };
1000 }1027 }
1001 pub fn parseBoolAndExpr(p: *Parser) Error!bool {1028 pub fn parseCatchExpr(p: *Parser) Error!bool {
1002 const def_index = @backingInt(Def.defBoolAndExpr);1029 const def_index = @backingInt(Def.defCatchExpr);
1003 if (p.depths[def_index] > max_depth) return error.MaxDepth;1030 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1004 p.depths[def_index] += 1;1031 p.depths[def_index] += 1;
1005 defer p.depths[def_index] -= 1;1032 defer p.depths[def_index] -= 1;
1006 return blk_0: {1033 return blk_0: {
1007 const pos_0 = p.i;1034 const pos_0 = p.i;
1008 if (try p.parseCompareExpr() and blk_1: {1035 if (blk_1: {
1036 var match_1 = false;
1009 var i_1: usize = 0;1037 var i_1: usize = 0;
1010 while (blk_3: {1038 while (blk_3: {
1011 const pos_3 = p.i;1039 const pos_3 = p.i;
1012 if (try p.parseAndOp() and try p.parseCompareExpr()) break :blk_3 true;1040 if (try p.parseCatchOp() and try p.parsePrefixExpr()) break :blk_3 true;
1013 p.i = pos_3;1041 p.i = pos_3;
1014 break :blk_3 false;1042 break :blk_3 false;
1015 }) {1043 }) {
1044 match_1 = true;
1016 if (i_1 > max_depth) return error.MaxDepth;1045 if (i_1 > max_depth) return error.MaxDepth;
1017 i_1 += 1;1046 i_1 += 1;
1018 }1047 }
1019 break :blk_1 true;1048 break :blk_1 match_1;
1020 } and blk_1: {1049 } and blk_1: {
1021 const pos_1 = p.i;1050 const pos_1 = p.i;
1022 const match_1 = try p.parseAndOp();1051 const match_1 = try p.parseRecoveryNonmixingOp();
1023 p.i = pos_1;1052 p.i = pos_1;
1024 break :blk_1 !match_1;1053 break :blk_1 !match_1;
1025 }) break :blk_0 true;1054 }) break :blk_0 true;
...@@ -1027,21 +1056,90 @@ const Parser = struct {...@@ -1027,21 +1056,90 @@ const Parser = struct {
1027 break :blk_0 false;1056 break :blk_0 false;
1028 };1057 };
1029 }1058 }
1030 pub fn parseCompareExpr(p: *Parser) Error!bool {1059 pub fn parseRecoveryNonmixingOp(p: *Parser) Error!bool {
1031 const def_index = @backingInt(Def.defCompareExpr);1060 const def_index = @backingInt(Def.defRecoveryNonmixingOp);
1032 if (p.depths[def_index] > max_depth) return error.MaxDepth;1061 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1033 p.depths[def_index] += 1;1062 p.depths[def_index] += 1;
1034 defer p.depths[def_index] -= 1;1063 defer p.depths[def_index] -= 1;
1035 return blk_0: {1064 return blk_0: {
1036 const pos_0 = p.i;1065 const pos_0 = p.i;
1037 if (try p.parseBitwiseExpr() and (blk_3: {1066 if (try p.parseControlOp()) break :blk_0 true;
1038 const pos_3 = p.i;1067 p.i = pos_0;
1039 if (try p.parseCompareOp() and try p.parseBitwiseExpr()) break :blk_3 true;1068 if (try p.parseCompareOp()) break :blk_0 true;
1040 p.i = pos_3;1069 p.i = pos_0;
1041 break :blk_3 false;1070 if (try p.parseBitwiseNonmixingOp()) break :blk_0 true;
1042 } or true) and blk_1: {1071 p.i = pos_0;
1072 break :blk_0 false;
1073 };
1074 }
1075 pub fn parseControlOp(p: *Parser) Error!bool {
1076 const def_index = @backingInt(Def.defControlOp);
1077 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1078 p.depths[def_index] += 1;
1079 defer p.depths[def_index] -= 1;
1080 return blk_0: {
1081 const pos_0 = p.i;
1082 if (try p.parseOrElseOp()) break :blk_0 true;
1083 p.i = pos_0;
1084 if (try p.parseCatchOp()) break :blk_0 true;
1085 p.i = pos_0;
1086 if (try p.parseAndOp()) break :blk_0 true;
1087 p.i = pos_0;
1088 if (try p.parseOrOp()) break :blk_0 true;
1089 p.i = pos_0;
1090 break :blk_0 false;
1091 };
1092 }
1093 pub fn parseBoolExpr(p: *Parser) Error!bool {
1094 const def_index = @backingInt(Def.defBoolExpr);
1095 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1096 p.depths[def_index] += 1;
1097 defer p.depths[def_index] -= 1;
1098 return blk_0: {
1099 const pos_0 = p.i;
1100 if (try p.parseCompareExpr() and blk_2: {
1101 const pos_2 = p.i;
1102 if (try p.parseBoolAndExpr()) break :blk_2 true;
1103 p.i = pos_2;
1104 if (try p.parseBoolOrExpr()) break :blk_2 true;
1105 p.i = pos_2;
1106 if (blk_3: {
1107 const pos_3 = p.i;
1108 const match_3 = try p.parseControlOp();
1109 p.i = pos_3;
1110 break :blk_3 !match_3;
1111 }) break :blk_2 true;
1112 p.i = pos_2;
1113 break :blk_2 false;
1114 }) break :blk_0 true;
1115 p.i = pos_0;
1116 break :blk_0 false;
1117 };
1118 }
1119 pub fn parseBoolAndExpr(p: *Parser) Error!bool {
1120 const def_index = @backingInt(Def.defBoolAndExpr);
1121 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1122 p.depths[def_index] += 1;
1123 defer p.depths[def_index] -= 1;
1124 return blk_0: {
1125 const pos_0 = p.i;
1126 if (blk_1: {
1127 var match_1 = false;
1128 var i_1: usize = 0;
1129 while (blk_3: {
1130 const pos_3 = p.i;
1131 if (try p.parseAndOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
1132 p.i = pos_3;
1133 break :blk_3 false;
1134 }) {
1135 match_1 = true;
1136 if (i_1 > max_depth) return error.MaxDepth;
1137 i_1 += 1;
1138 }
1139 break :blk_1 match_1;
1140 } and blk_1: {
1043 const pos_1 = p.i;1141 const pos_1 = p.i;
1044 const match_1 = try p.parseCompareOp();1142 const match_1 = try p.parseControlOp();
1045 p.i = pos_1;1143 p.i = pos_1;
1046 break :blk_1 !match_1;1144 break :blk_1 !match_1;
1047 }) break :blk_0 true;1145 }) break :blk_0 true;
...@@ -1049,28 +1147,30 @@ const Parser = struct {...@@ -1049,28 +1147,30 @@ const Parser = struct {
1049 break :blk_0 false;1147 break :blk_0 false;
1050 };1148 };
1051 }1149 }
1052 pub fn parseBitwiseExpr(p: *Parser) Error!bool {1150 pub fn parseBoolOrExpr(p: *Parser) Error!bool {
1053 const def_index = @backingInt(Def.defBitwiseExpr);1151 const def_index = @backingInt(Def.defBoolOrExpr);
1054 if (p.depths[def_index] > max_depth) return error.MaxDepth;1152 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1055 p.depths[def_index] += 1;1153 p.depths[def_index] += 1;
1056 defer p.depths[def_index] -= 1;1154 defer p.depths[def_index] -= 1;
1057 return blk_0: {1155 return blk_0: {
1058 const pos_0 = p.i;1156 const pos_0 = p.i;
1059 if (try p.parseBitShiftExpr() and blk_1: {1157 if (blk_1: {
1158 var match_1 = false;
1060 var i_1: usize = 0;1159 var i_1: usize = 0;
1061 while (blk_3: {1160 while (blk_3: {
1062 const pos_3 = p.i;1161 const pos_3 = p.i;
1063 if (try p.parseBitwiseOp() and try p.parseBitShiftExpr()) break :blk_3 true;1162 if (try p.parseOrOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
1064 p.i = pos_3;1163 p.i = pos_3;
1065 break :blk_3 false;1164 break :blk_3 false;
1066 }) {1165 }) {
1166 match_1 = true;
1067 if (i_1 > max_depth) return error.MaxDepth;1167 if (i_1 > max_depth) return error.MaxDepth;
1068 i_1 += 1;1168 i_1 += 1;
1069 }1169 }
1070 break :blk_1 true;1170 break :blk_1 match_1;
1071 } and blk_1: {1171 } and blk_1: {
1072 const pos_1 = p.i;1172 const pos_1 = p.i;
1073 const match_1 = try p.parseBitwiseOp();1173 const match_1 = try p.parseControlOp();
1074 p.i = pos_1;1174 p.i = pos_1;
1075 break :blk_1 !match_1;1175 break :blk_1 !match_1;
1076 }) break :blk_0 true;1176 }) break :blk_0 true;
...@@ -1078,32 +1178,153 @@ const Parser = struct {...@@ -1078,32 +1178,153 @@ const Parser = struct {
1078 break :blk_0 false;1178 break :blk_0 false;
1079 };1179 };
1080 }1180 }
1081 pub fn parseBitShiftExpr(p: *Parser) Error!bool {1181 pub fn parseCompareExpr(p: *Parser) Error!bool {
1082 const def_index = @backingInt(Def.defBitShiftExpr);1182 const def_index = @backingInt(Def.defCompareExpr);
1083 if (p.depths[def_index] > max_depth) return error.MaxDepth;1183 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1084 p.depths[def_index] += 1;1184 p.depths[def_index] += 1;
1085 defer p.depths[def_index] -= 1;1185 defer p.depths[def_index] -= 1;
1086 return blk_0: {1186 return blk_0: {
1087 const pos_0 = p.i;1187 const pos_0 = p.i;
1088 if (try p.parseAdditionExpr() and blk_1: {1188 if (try p.parseCompareOperand() and (blk_3: {
1189 const pos_3 = p.i;
1190 if (try p.parseCompareOp() and try p.parsePrefixExpr() and try p.parseCompareOperand()) break :blk_3 true;
1191 p.i = pos_3;
1192 break :blk_3 false;
1193 } or true) and blk_1: {
1194 const pos_1 = p.i;
1195 const match_1 = blk_3: {
1196 const pos_3 = p.i;
1197 if (try p.parseCompareOp()) break :blk_3 true;
1198 p.i = pos_3;
1199 if (try p.parseOrElseOp()) break :blk_3 true;
1200 p.i = pos_3;
1201 if (try p.parseCatchOp()) break :blk_3 true;
1202 p.i = pos_3;
1203 break :blk_3 false;
1204 };
1205 p.i = pos_1;
1206 break :blk_1 !match_1;
1207 }) break :blk_0 true;
1208 p.i = pos_0;
1209 break :blk_0 false;
1210 };
1211 }
1212 pub fn parseCompareOperand(p: *Parser) Error!bool {
1213 const def_index = @backingInt(Def.defCompareOperand);
1214 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1215 p.depths[def_index] += 1;
1216 defer p.depths[def_index] -= 1;
1217 return blk_0: {
1218 const pos_0 = p.i;
1219 if (blk_1: {
1220 var match_1 = false;
1089 var i_1: usize = 0;1221 var i_1: usize = 0;
1090 while (blk_3: {1222 while (blk_3: {
1091 const pos_3 = p.i;1223 const pos_3 = p.i;
1092 if (try p.parseBitShiftOp() and try p.parseAdditionExpr()) break :blk_3 true;1224 if (try p.parseBitwiseOrOp() and try p.parsePrefixExpr()) break :blk_3 true;
1093 p.i = pos_3;1225 p.i = pos_3;
1094 break :blk_3 false;1226 break :blk_3 false;
1095 }) {1227 }) {
1228 match_1 = true;
1096 if (i_1 > max_depth) return error.MaxDepth;1229 if (i_1 > max_depth) return error.MaxDepth;
1097 i_1 += 1;1230 i_1 += 1;
1098 }1231 }
1099 break :blk_1 true;1232 break :blk_1 match_1;
1233 } and blk_1: {
1234 const pos_1 = p.i;
1235 const match_1 = try p.parseBitwiseNonmixingOp();
1236 p.i = pos_1;
1237 break :blk_1 !match_1;
1238 }) break :blk_0 true;
1239 p.i = pos_0;
1240 if (blk_1: {
1241 var match_1 = false;
1242 var i_1: usize = 0;
1243 while (blk_3: {
1244 const pos_3 = p.i;
1245 if (try p.parseBitwiseAndOp() and try p.parsePrefixExpr()) break :blk_3 true;
1246 p.i = pos_3;
1247 break :blk_3 false;
1248 }) {
1249 match_1 = true;
1250 if (i_1 > max_depth) return error.MaxDepth;
1251 i_1 += 1;
1252 }
1253 break :blk_1 match_1;
1254 } and blk_1: {
1255 const pos_1 = p.i;
1256 const match_1 = try p.parseBitwiseNonmixingOp();
1257 p.i = pos_1;
1258 break :blk_1 !match_1;
1259 }) break :blk_0 true;
1260 p.i = pos_0;
1261 if (blk_1: {
1262 var match_1 = false;
1263 var i_1: usize = 0;
1264 while (blk_3: {
1265 const pos_3 = p.i;
1266 if (try p.parseBitwiseXorOp() and try p.parsePrefixExpr()) break :blk_3 true;
1267 p.i = pos_3;
1268 break :blk_3 false;
1269 }) {
1270 match_1 = true;
1271 if (i_1 > max_depth) return error.MaxDepth;
1272 i_1 += 1;
1273 }
1274 break :blk_1 match_1;
1100 } and blk_1: {1275 } and blk_1: {
1101 const pos_1 = p.i;1276 const pos_1 = p.i;
1102 const match_1 = try p.parseBitShiftOp();1277 const match_1 = try p.parseBitwiseNonmixingOp();
1103 p.i = pos_1;1278 p.i = pos_1;
1104 break :blk_1 !match_1;1279 break :blk_1 !match_1;
1105 }) break :blk_0 true;1280 }) break :blk_0 true;
1106 p.i = pos_0;1281 p.i = pos_0;
1282 if (try p.parseBitShiftOp() and try p.parsePrefixExpr() and blk_1: {
1283 const pos_1 = p.i;
1284 const match_1 = try p.parseBitwiseNonmixingOp();
1285 p.i = pos_1;
1286 break :blk_1 !match_1;
1287 }) break :blk_0 true;
1288 p.i = pos_0;
1289 if (blk_1: {
1290 const pos_1 = p.i;
1291 const match_1 = try p.parseBitOp();
1292 p.i = pos_1;
1293 break :blk_1 !match_1;
1294 } and try p.parseAdditionExpr()) break :blk_0 true;
1295 p.i = pos_0;
1296 break :blk_0 false;
1297 };
1298 }
1299 pub fn parseBitOp(p: *Parser) Error!bool {
1300 const def_index = @backingInt(Def.defBitOp);
1301 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1302 p.depths[def_index] += 1;
1303 defer p.depths[def_index] -= 1;
1304 return blk_0: {
1305 const pos_0 = p.i;
1306 if (try p.parseBitwiseOrOp()) break :blk_0 true;
1307 p.i = pos_0;
1308 if (try p.parseBitwiseAndOp()) break :blk_0 true;
1309 p.i = pos_0;
1310 if (try p.parseBitwiseXorOp()) break :blk_0 true;
1311 p.i = pos_0;
1312 if (try p.parseBitShiftOp()) break :blk_0 true;
1313 p.i = pos_0;
1314 break :blk_0 false;
1315 };
1316 }
1317 pub fn parseBitwiseNonmixingOp(p: *Parser) Error!bool {
1318 const def_index = @backingInt(Def.defBitwiseNonmixingOp);
1319 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1320 p.depths[def_index] += 1;
1321 defer p.depths[def_index] -= 1;
1322 return blk_0: {
1323 const pos_0 = p.i;
1324 if (try p.parseMultiplyNonmixingOp()) break :blk_0 true;
1325 p.i = pos_0;
1326 if (try p.parseAdditionOp()) break :blk_0 true;
1327 p.i = pos_0;
1107 break :blk_0 false;1328 break :blk_0 false;
1108 };1329 };
1109 }1330 }
...@@ -1114,11 +1335,11 @@ const Parser = struct {...@@ -1114,11 +1335,11 @@ const Parser = struct {
1114 defer p.depths[def_index] -= 1;1335 defer p.depths[def_index] -= 1;
1115 return blk_0: {1336 return blk_0: {
1116 const pos_0 = p.i;1337 const pos_0 = p.i;
1117 if (try p.parseMultiplyExpr() and blk_1: {1338 if (try p.parseMulOrModExpr() and blk_1: {
1118 var i_1: usize = 0;1339 var i_1: usize = 0;
1119 while (blk_3: {1340 while (blk_3: {
1120 const pos_3 = p.i;1341 const pos_3 = p.i;
1121 if (try p.parseAdditionOp() and try p.parseMultiplyExpr()) break :blk_3 true;1342 if (try p.parseAdditionOp() and try p.parsePrefixExpr() and try p.parseMulOrModExpr()) break :blk_3 true;
1122 p.i = pos_3;1343 p.i = pos_3;
1123 break :blk_3 false;1344 break :blk_3 false;
1124 }) {1345 }) {
...@@ -1128,7 +1349,54 @@ const Parser = struct {...@@ -1128,7 +1349,54 @@ const Parser = struct {
1128 break :blk_1 true;1349 break :blk_1 true;
1129 } and blk_1: {1350 } and blk_1: {
1130 const pos_1 = p.i;1351 const pos_1 = p.i;
1131 const match_1 = try p.parseAdditionOp();1352 const match_1 = blk_3: {
1353 const pos_3 = p.i;
1354 if (try p.parseAdditionOp()) break :blk_3 true;
1355 p.i = pos_3;
1356 if (try p.parseBitOp()) break :blk_3 true;
1357 p.i = pos_3;
1358 if (try p.parseOrElseOp()) break :blk_3 true;
1359 p.i = pos_3;
1360 if (try p.parseCatchOp()) break :blk_3 true;
1361 p.i = pos_3;
1362 break :blk_3 false;
1363 };
1364 p.i = pos_1;
1365 break :blk_1 !match_1;
1366 }) break :blk_0 true;
1367 p.i = pos_0;
1368 break :blk_0 false;
1369 };
1370 }
1371 pub fn parseMulOrModExpr(p: *Parser) Error!bool {
1372 const def_index = @backingInt(Def.defMulOrModExpr);
1373 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1374 p.depths[def_index] += 1;
1375 defer p.depths[def_index] -= 1;
1376 return blk_0: {
1377 const pos_0 = p.i;
1378 if (try p.parseModExpr()) break :blk_0 true;
1379 p.i = pos_0;
1380 if (blk_1: {
1381 const pos_1 = p.i;
1382 const match_1 = try p.parseModOp();
1383 p.i = pos_1;
1384 break :blk_1 !match_1;
1385 } and try p.parseMultiplyExpr()) break :blk_0 true;
1386 p.i = pos_0;
1387 break :blk_0 false;
1388 };
1389 }
1390 pub fn parseModExpr(p: *Parser) Error!bool {
1391 const def_index = @backingInt(Def.defModExpr);
1392 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1393 p.depths[def_index] += 1;
1394 defer p.depths[def_index] -= 1;
1395 return blk_0: {
1396 const pos_0 = p.i;
1397 if (try p.parseModOp() and try p.parsePrefixExpr() and blk_1: {
1398 const pos_1 = p.i;
1399 const match_1 = try p.parseMultiplyNonmixingOp();
1132 p.i = pos_1;1400 p.i = pos_1;
1133 break :blk_1 !match_1;1401 break :blk_1 !match_1;
1134 }) break :blk_0 true;1402 }) break :blk_0 true;
...@@ -1143,7 +1411,7 @@ const Parser = struct {...@@ -1143,7 +1411,7 @@ const Parser = struct {
1143 defer p.depths[def_index] -= 1;1411 defer p.depths[def_index] -= 1;
1144 return blk_0: {1412 return blk_0: {
1145 const pos_0 = p.i;1413 const pos_0 = p.i;
1146 if (try p.parsePrefixExpr() and blk_1: {1414 if (blk_1: {
1147 var i_1: usize = 0;1415 var i_1: usize = 0;
1148 while (blk_3: {1416 while (blk_3: {
1149 const pos_3 = p.i;1417 const pos_3 = p.i;
...@@ -1157,7 +1425,7 @@ const Parser = struct {...@@ -1157,7 +1425,7 @@ const Parser = struct {
1157 break :blk_1 true;1425 break :blk_1 true;
1158 } and blk_1: {1426 } and blk_1: {
1159 const pos_1 = p.i;1427 const pos_1 = p.i;
1160 const match_1 = try p.parseMultiplyOp();1428 const match_1 = try p.parseMultiplyNonmixingOp();
1161 p.i = pos_1;1429 p.i = pos_1;
1162 break :blk_1 !match_1;1430 break :blk_1 !match_1;
1163 }) break :blk_0 true;1431 }) break :blk_0 true;
...@@ -1165,6 +1433,26 @@ const Parser = struct {...@@ -1165,6 +1433,26 @@ const Parser = struct {
1165 break :blk_0 false;1433 break :blk_0 false;
1166 };1434 };
1167 }1435 }
1436 pub fn parseMultiplyNonmixingOp(p: *Parser) Error!bool {
1437 const def_index = @backingInt(Def.defMultiplyNonmixingOp);
1438 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1439 p.depths[def_index] += 1;
1440 defer p.depths[def_index] -= 1;
1441 return blk_0: {
1442 const pos_0 = p.i;
1443 if (try p.parseMultiplyOp()) break :blk_0 true;
1444 p.i = pos_0;
1445 if (try p.parseModOp()) break :blk_0 true;
1446 p.i = pos_0;
1447 if (try p.parseBitOp()) break :blk_0 true;
1448 p.i = pos_0;
1449 if (try p.parseOrElseOp()) break :blk_0 true;
1450 p.i = pos_0;
1451 if (try p.parseCatchOp()) break :blk_0 true;
1452 p.i = pos_0;
1453 break :blk_0 false;
1454 };
1455 }
1168 pub fn parsePrefixExpr(p: *Parser) Error!bool {1456 pub fn parsePrefixExpr(p: *Parser) Error!bool {
1169 const def_index = @backingInt(Def.defPrefixExpr);1457 const def_index = @backingInt(Def.defPrefixExpr);
1170 if (p.depths[def_index] > max_depth) return error.MaxDepth;1458 if (p.depths[def_index] > max_depth) return error.MaxDepth;
...@@ -2259,70 +2547,170 @@ const Parser = struct {...@@ -2259,70 +2547,170 @@ const Parser = struct {
2259 break :blk_0 false;2547 break :blk_0 false;
2260 };2548 };
2261 }2549 }
2262 pub fn parseBitwiseOp(p: *Parser) Error!bool {2550 pub fn parseBitwiseAndOp(p: *Parser) Error!bool {
2263 const def_index = @backingInt(Def.defBitwiseOp);2551 const def_index = @backingInt(Def.defBitwiseAndOp);
2264 if (p.depths[def_index] > max_depth) return error.MaxDepth;2552 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2265 p.depths[def_index] += 1;2553 p.depths[def_index] += 1;
2266 defer p.depths[def_index] -= 1;2554 defer p.depths[def_index] -= 1;
2267 return blk_0: {2555 return blk_0: {
2268 const pos_0 = p.i;2556 const pos_0 = p.i;
2269 if (try p.parsepre_op_white() and try p.parseBitwiseOpTok() and try p.parsepost_op_white()) break :blk_0 true;2557 if (try p.parsepre_op_white() and try p.parseBitwiseAndOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2270 p.i = pos_0;2558 p.i = pos_0;
2271 if (blk_1: {2559 if (blk_1: {
2272 const pos_1 = p.i;2560 const pos_1 = p.i;
2273 const match_1 = try p.parsepre_op_white();2561 const match_1 = try p.parsepre_op_white();
2274 p.i = pos_1;2562 p.i = pos_1;
2275 break :blk_1 !match_1;2563 break :blk_1 !match_1;
2276 } and try p.parseBitwiseOpTok() and blk_1: {2564 } and try p.parseBitwiseAndOpTok() and blk_1: {
2277 const pos_1 = p.i;2565 const pos_1 = p.i;
2278 const match_1 = try p.parsepost_op_white();2566 const match_1 = try p.parsepost_op_white();
2279 p.i = pos_1;2567 p.i = pos_1;
2280 break :blk_1 !match_1;2568 break :blk_1 !match_1;
2281 }) break :blk_0 true;2569 }) break :blk_0 true;
2282 p.i = pos_0;2570 p.i = pos_0;
2283 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;2571 break :blk_0 false;
2572 };
2573 }
2574 pub fn parseBitwiseAndOpTok(p: *Parser) Error!bool {
2575 const def_index = @backingInt(Def.defBitwiseAndOpTok);
2576 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2577 p.depths[def_index] += 1;
2578 defer p.depths[def_index] -= 1;
2579 return blk_0: {
2580 const pos_0 = p.i;
2581 if (try p.parseAMPERSAND() and blk_1: {
2582 const pos_1 = p.i;
2583 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {
2584 '&'...'&',
2585 => blk_2: {
2586 p.i += 1;
2587 break :blk_2 true;
2588 },
2589 else => false,
2590 });
2591 p.i = pos_1;
2592 break :blk_1 !match_1;
2593 }) break :blk_0 true;
2594 p.i = pos_0;
2595 break :blk_0 false;
2596 };
2597 }
2598 pub fn parseBitwiseOrOp(p: *Parser) Error!bool {
2599 const def_index = @backingInt(Def.defBitwiseOrOp);
2600 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2601 p.depths[def_index] += 1;
2602 defer p.depths[def_index] -= 1;
2603 return blk_0: {
2604 const pos_0 = p.i;
2605 if (try p.parsepre_op_white() and try p.parseBitwiseOrOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2284 p.i = pos_0;2606 p.i = pos_0;
2285 if (blk_1: {2607 if (blk_1: {
2286 const pos_1 = p.i;2608 const pos_1 = p.i;
2287 const match_1 = try p.parsepre_op_white();2609 const match_1 = try p.parsepre_op_white();
2288 p.i = pos_1;2610 p.i = pos_1;
2289 break :blk_1 !match_1;2611 break :blk_1 !match_1;
2290 } and try p.parseKEYWORD_catch() and blk_1: {2612 } and try p.parseBitwiseOrOpTok() and blk_1: {
2291 const pos_1 = p.i;2613 const pos_1 = p.i;
2292 const match_1 = try p.parsepost_op_white();2614 const match_1 = try p.parsepost_op_white();
2293 p.i = pos_1;2615 p.i = pos_1;
2294 break :blk_1 !match_1;2616 break :blk_1 !match_1;
2295 } and (try p.parsePayload() or true)) break :blk_0 true;2617 }) break :blk_0 true;
2296 p.i = pos_0;2618 p.i = pos_0;
2297 break :blk_0 false;2619 break :blk_0 false;
2298 };2620 };
2299 }2621 }
2300 pub fn parseBitwiseOpTok(p: *Parser) Error!bool {2622 pub fn parseBitwiseOrOpTok(p: *Parser) Error!bool {
2301 const def_index = @backingInt(Def.defBitwiseOpTok);2623 const def_index = @backingInt(Def.defBitwiseOrOpTok);
2302 if (p.depths[def_index] > max_depth) return error.MaxDepth;2624 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2303 p.depths[def_index] += 1;2625 p.depths[def_index] += 1;
2304 defer p.depths[def_index] -= 1;2626 defer p.depths[def_index] -= 1;
2305 return blk_0: {2627 return blk_0: {
2306 const pos_0 = p.i;2628 const pos_0 = p.i;
2307 if (try p.parseAMPERSAND() and blk_1: {2629 if (try p.parsePIPE()) break :blk_0 true;
2630 p.i = pos_0;
2631 break :blk_0 false;
2632 };
2633 }
2634 pub fn parseBitwiseXorOp(p: *Parser) Error!bool {
2635 const def_index = @backingInt(Def.defBitwiseXorOp);
2636 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2637 p.depths[def_index] += 1;
2638 defer p.depths[def_index] -= 1;
2639 return blk_0: {
2640 const pos_0 = p.i;
2641 if (try p.parsepre_op_white() and try p.parseBitwiseXorOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2642 p.i = pos_0;
2643 if (blk_1: {
2308 const pos_1 = p.i;2644 const pos_1 = p.i;
2309 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {2645 const match_1 = try p.parsepre_op_white();
2310 '&'...'&',2646 p.i = pos_1;
2311 => blk_2: {2647 break :blk_1 !match_1;
2312 p.i += 1;2648 } and try p.parseBitwiseXorOpTok() and blk_1: {
2313 break :blk_2 true;2649 const pos_1 = p.i;
2314 },2650 const match_1 = try p.parsepost_op_white();
2315 else => false,
2316 });
2317 p.i = pos_1;2651 p.i = pos_1;
2318 break :blk_1 !match_1;2652 break :blk_1 !match_1;
2319 }) break :blk_0 true;2653 }) break :blk_0 true;
2320 p.i = pos_0;2654 p.i = pos_0;
2655 break :blk_0 false;
2656 };
2657 }
2658 pub fn parseBitwiseXorOpTok(p: *Parser) Error!bool {
2659 const def_index = @backingInt(Def.defBitwiseXorOpTok);
2660 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2661 p.depths[def_index] += 1;
2662 defer p.depths[def_index] -= 1;
2663 return blk_0: {
2664 const pos_0 = p.i;
2321 if (try p.parseCARET()) break :blk_0 true;2665 if (try p.parseCARET()) break :blk_0 true;
2322 p.i = pos_0;2666 p.i = pos_0;
2323 if (try p.parsePIPE()) break :blk_0 true;2667 break :blk_0 false;
2668 };
2669 }
2670 pub fn parseCatchOp(p: *Parser) Error!bool {
2671 const def_index = @backingInt(Def.defCatchOp);
2672 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2673 p.depths[def_index] += 1;
2674 defer p.depths[def_index] -= 1;
2675 return blk_0: {
2676 const pos_0 = p.i;
2677 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;
2324 p.i = pos_0;2678 p.i = pos_0;
2325 if (try p.parseKEYWORD_orelse()) break :blk_0 true;2679 if (blk_1: {
2680 const pos_1 = p.i;
2681 const match_1 = try p.parsepre_op_white();
2682 p.i = pos_1;
2683 break :blk_1 !match_1;
2684 } and try p.parseKEYWORD_catch() and blk_1: {
2685 const pos_1 = p.i;
2686 const match_1 = try p.parsepost_op_white();
2687 p.i = pos_1;
2688 break :blk_1 !match_1;
2689 } and (try p.parsePayload() or true)) break :blk_0 true;
2690 p.i = pos_0;
2691 break :blk_0 false;
2692 };
2693 }
2694 pub fn parseOrElseOp(p: *Parser) Error!bool {
2695 const def_index = @backingInt(Def.defOrElseOp);
2696 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2697 p.depths[def_index] += 1;
2698 defer p.depths[def_index] -= 1;
2699 return blk_0: {
2700 const pos_0 = p.i;
2701 if (try p.parsepre_op_white() and try p.parseKEYWORD_orelse() and try p.parsepost_op_white()) break :blk_0 true;
2702 p.i = pos_0;
2703 if (blk_1: {
2704 const pos_1 = p.i;
2705 const match_1 = try p.parsepre_op_white();
2706 p.i = pos_1;
2707 break :blk_1 !match_1;
2708 } and try p.parseKEYWORD_orelse() and blk_1: {
2709 const pos_1 = p.i;
2710 const match_1 = try p.parsepost_op_white();
2711 p.i = pos_1;
2712 break :blk_1 !match_1;
2713 }) break :blk_0 true;
2326 p.i = pos_0;2714 p.i = pos_0;
2327 break :blk_0 false;2715 break :blk_0 false;
2328 };2716 };
...@@ -2452,8 +2840,6 @@ const Parser = struct {...@@ -2452,8 +2840,6 @@ const Parser = struct {
2452 p.i = pos_0;2840 p.i = pos_0;
2453 if (try p.parseSLASH()) break :blk_0 true;2841 if (try p.parseSLASH()) break :blk_0 true;
2454 p.i = pos_0;2842 p.i = pos_0;
2455 if (try p.parsePERCENT()) break :blk_0 true;
2456 p.i = pos_0;
2457 if (try p.parseASTERISKPERCENT()) break :blk_0 true;2843 if (try p.parseASTERISKPERCENT()) break :blk_0 true;
2458 p.i = pos_0;2844 p.i = pos_0;
2459 if (try p.parseASTERISKPIPE()) break :blk_0 true;2845 if (try p.parseASTERISKPIPE()) break :blk_0 true;
...@@ -2461,6 +2847,30 @@ const Parser = struct {...@@ -2461,6 +2847,30 @@ const Parser = struct {
2461 break :blk_0 false;2847 break :blk_0 false;
2462 };2848 };
2463 }2849 }
2850 pub fn parseModOp(p: *Parser) Error!bool {
2851 const def_index = @backingInt(Def.defModOp);
2852 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2853 p.depths[def_index] += 1;
2854 defer p.depths[def_index] -= 1;
2855 return blk_0: {
2856 const pos_0 = p.i;
2857 if (try p.parsepre_op_white() and try p.parsePERCENT() and try p.parsepost_op_white()) break :blk_0 true;
2858 p.i = pos_0;
2859 if (blk_1: {
2860 const pos_1 = p.i;
2861 const match_1 = try p.parsepre_op_white();
2862 p.i = pos_1;
2863 break :blk_1 !match_1;
2864 } and try p.parsePERCENT() and blk_1: {
2865 const pos_1 = p.i;
2866 const match_1 = try p.parsepost_op_white();
2867 p.i = pos_1;
2868 break :blk_1 !match_1;
2869 }) break :blk_0 true;
2870 p.i = pos_0;
2871 break :blk_0 false;
2872 };
2873 }
2464 pub fn parsePrefixOp(p: *Parser) Error!bool {2874 pub fn parsePrefixOp(p: *Parser) Error!bool {
2465 const def_index = @backingInt(Def.defPrefixOp);2875 const def_index = @backingInt(Def.defPrefixOp);
2466 if (p.depths[def_index] > max_depth) return error.MaxDepth;2876 if (p.depths[def_index] > max_depth) return error.MaxDepth;