diff --git a/doc/langref/grammar.peg b/doc/langref/grammar.peg index 35888b70cd63fe4fd15401f8710ccca13ab0ffe4..8ce61adb9edea6ab7594fb3982c518a3463152c2 100644 --- a/doc/langref/grammar.peg +++ b/doc/langref/grammar.peg @@ -134,17 +134,16 @@ PrimaryTypeExpr / DOT IDENTIFIER / DOT InitList / ErrorSetDecl - / FLOAT / FnProto / GroupedExpr / LabeledTypeExpr / IDENTIFIER !(COLON LabelableExpr) / IfTypeExpr - / INTEGER / KEYWORD_comptime TypeExpr !ExprSuffix / KEYWORD_error DOT IDENTIFIER / KEYWORD_anyframe / KEYWORD_unreachable + / NUMBERLITERAL / STRINGLITERAL ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto @@ -369,19 +368,6 @@ ExprList <- (Expr COMMA)* Expr? # *** Tokens *** eof <- !. -bin <- [01] -bin_ <- '_'? bin -oct <- [0-7] -oct_ <- '_'? oct -hex <- [0-9a-fA-F] -hex_ <- '_'? hex -dec <- [0-9] -dec_ <- '_'? dec - -bin_int <- bin bin_* -oct_int <- oct oct_* -dec_int <- dec dec_* -hex_int <- hex hex_* ox80_oxBF <- [\200-\277] oxF4 <- '\364' @@ -422,6 +408,9 @@ multibyte_utf8 <- non_control_ascii <- [\040-\176] non_control_utf8 <- [\040-\377] +hex <- [0-9a-fA-F] +hex_ <- '_'? hex + char_escape <- "\\x" hex hex / "\\u{" hex+ "}" @@ -443,16 +432,14 @@ line_string <- '\\\\' non_control_utf8* [ \n]* skip <- ([ \n] / line_comment)* CHAR_LITERAL <- ['] char_char ['] skip -FLOAT - <- '0x' hex_int '.' hex_int ([pP] [-+]? dec_int)? skip - / dec_int '.' dec_int ([eE] [-+]? dec_int)? skip - / '0x' hex_int [pP] [-+]? dec_int skip - / dec_int [eE] [-+]? dec_int skip -INTEGER - <- '0b' bin_int skip - / '0o' oct_int skip - / '0x' hex_int skip - / dec_int skip + +digit <- [_0-9A-DF-OQ-Za-df-oq-z] +digit_int <- digit / [eEpP] +digit_float <- digit / [eEpP] [-+]? +NUMBERLITERAL + <- [0-9] digit_int* '.' digit_float+ skip + / [0-9] digit_float* skip + STRINGLITERALSINGLE <- ["] string_char* ["] skip STRINGLITERAL <- STRINGLITERALSINGLE diff --git a/lib/std/zig/parser_generated_oracle.zig b/lib/std/zig/parser_generated_oracle.zig index ad3e7b2bf8335d4d9db1457687a692836523af2f..4bb549e64e31b6fb4cbcf46b21bb233b087231c5 100644 --- a/lib/std/zig/parser_generated_oracle.zig +++ b/lib/std/zig/parser_generated_oracle.zig @@ -921,8 +921,6 @@ const Parser = struct { p.i = pos_0; if (p.parseErrorSetDecl()) break :blk_0 true; p.i = pos_0; - if (p.parseFLOAT()) break :blk_0 true; - p.i = pos_0; if (p.parseFnProto()) break :blk_0 true; p.i = pos_0; if (p.parseGroupedExpr()) break :blk_0 true; @@ -943,8 +941,6 @@ const Parser = struct { p.i = pos_0; if (p.parseIfTypeExpr()) break :blk_0 true; p.i = pos_0; - if (p.parseINTEGER()) break :blk_0 true; - p.i = pos_0; if (p.parseKEYWORD_comptime() and p.parseTypeExpr() and blk_1: { const pos_1 = p.i; const match_1 = p.parseExprSuffix(); @@ -958,6 +954,8 @@ const Parser = struct { p.i = pos_0; if (p.parseKEYWORD_unreachable()) break :blk_0 true; p.i = pos_0; + if (p.parseNUMBERLITERAL()) break :blk_0 true; + p.i = pos_0; if (p.parseSTRINGLITERAL()) break :blk_0 true; p.i = pos_0; break :blk_0 false; @@ -1880,169 +1878,6 @@ const Parser = struct { break :blk_0 false; }; } - pub fn parsebin(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - '0'...'0', - '1'...'1', - => blk_1: { - p.i += 1; - break :blk_1 true; - }, - else => false, - })) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsebin_(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((blk_2: { - if (std.mem.startsWith(u8, p.source[p.i..], "_")) { - p.i += 1; - break :blk_2 true; - } - break :blk_2 false; - } or true) and p.parsebin()) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parseoct(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - '0'...'7', - => blk_1: { - p.i += 1; - break :blk_1 true; - }, - else => false, - })) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parseoct_(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((blk_2: { - if (std.mem.startsWith(u8, p.source[p.i..], "_")) { - p.i += 1; - break :blk_2 true; - } - break :blk_2 false; - } or true) and p.parseoct()) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsehex(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - '0'...'9', - 'a'...'f', - 'A'...'F', - => blk_1: { - p.i += 1; - break :blk_1 true; - }, - else => false, - })) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsehex_(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((blk_2: { - if (std.mem.startsWith(u8, p.source[p.i..], "_")) { - p.i += 1; - break :blk_2 true; - } - break :blk_2 false; - } or true) and p.parsehex()) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsedec(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - '0'...'9', - => blk_1: { - p.i += 1; - break :blk_1 true; - }, - else => false, - })) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsedec_(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if ((blk_2: { - if (std.mem.startsWith(u8, p.source[p.i..], "_")) { - p.i += 1; - break :blk_2 true; - } - break :blk_2 false; - } or true) and p.parsedec()) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsebin_int(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if (p.parsebin() and blk_1: { - while (p.parsebin_()) {} - break :blk_1 true; - }) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parseoct_int(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if (p.parseoct() and blk_1: { - while (p.parseoct_()) {} - break :blk_1 true; - }) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsedec_int(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if (p.parsedec() and blk_1: { - while (p.parsedec_()) {} - break :blk_1 true; - }) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } - pub fn parsehex_int(p: *Parser) bool { - return blk_0: { - const pos_0 = p.i; - if (p.parsehex() and blk_1: { - while (p.parsehex_()) {} - break :blk_1 true; - }) break :blk_0 true; - p.i = pos_0; - break :blk_0 false; - }; - } pub fn parseox80_oxBF(p: *Parser) bool { return blk_0: { const pos_0 = p.i; @@ -2286,6 +2121,37 @@ const Parser = struct { break :blk_0 false; }; } + pub fn parsehex(p: *Parser) bool { + return blk_0: { + const pos_0 = p.i; + if ((p.i < p.source.len and switch (p.source[p.i]) { + '0'...'9', + 'a'...'f', + 'A'...'F', + => blk_1: { + p.i += 1; + break :blk_1 true; + }, + else => false, + })) break :blk_0 true; + p.i = pos_0; + break :blk_0 false; + }; + } + pub fn parsehex_(p: *Parser) bool { + return blk_0: { + const pos_0 = p.i; + if ((blk_2: { + if (std.mem.startsWith(u8, p.source[p.i..], "_")) { + p.i += 1; + break :blk_2 true; + } + break :blk_2 false; + } or true) and p.parsehex()) break :blk_0 true; + p.i = pos_0; + break :blk_0 false; + }; + } pub fn parsechar_escape(p: *Parser) bool { return blk_0: { const pos_0 = p.i; @@ -2587,80 +2453,36 @@ const Parser = struct { break :blk_0 false; }; } - pub fn parseFLOAT(p: *Parser) bool { + pub fn parsedigit(p: *Parser) bool { return blk_0: { const pos_0 = p.i; - if (blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], "0x")) { - p.i += 2; - break :blk_1 true; - } - break :blk_1 false; - } and p.parsehex_int() and blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], ".")) { + if ((p.i < p.source.len and switch (p.source[p.i]) { + '_'...'_', + '0'...'9', + 'A'...'D', + 'F'...'O', + 'Q'...'Z', + 'a'...'d', + 'f'...'o', + 'q'...'z', + => blk_1: { p.i += 1; break :blk_1 true; - } - break :blk_1 false; - } and p.parsehex_int() and (blk_3: { - const pos_3 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - 'p'...'p', - 'P'...'P', - => blk_4: { - p.i += 1; - break :blk_4 true; - }, - else => false, - }) and ((p.i < p.source.len and switch (p.source[p.i]) { - '-'...'-', - '+'...'+', - => blk_5: { - p.i += 1; - break :blk_5 true; - }, - else => false, - }) or true) and p.parsedec_int()) break :blk_3 true; - p.i = pos_3; - break :blk_3 false; - } or true) and p.parseskip()) break :blk_0 true; + }, + else => false, + })) break :blk_0 true; p.i = pos_0; - if (p.parsedec_int() and blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], ".")) { - p.i += 1; - break :blk_1 true; - } - break :blk_1 false; - } and p.parsedec_int() and (blk_3: { - const pos_3 = p.i; - if ((p.i < p.source.len and switch (p.source[p.i]) { - 'e'...'e', - 'E'...'E', - => blk_4: { - p.i += 1; - break :blk_4 true; - }, - else => false, - }) and ((p.i < p.source.len and switch (p.source[p.i]) { - '-'...'-', - '+'...'+', - => blk_5: { - p.i += 1; - break :blk_5 true; - }, - else => false, - }) or true) and p.parsedec_int()) break :blk_3 true; - p.i = pos_3; - break :blk_3 false; - } or true) and p.parseskip()) break :blk_0 true; + break :blk_0 false; + }; + } + pub fn parsedigit_int(p: *Parser) bool { + return blk_0: { + const pos_0 = p.i; + if (p.parsedigit()) break :blk_0 true; p.i = pos_0; - if (blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], "0x")) { - p.i += 2; - break :blk_1 true; - } - break :blk_1 false; - } and p.parsehex_int() and (p.i < p.source.len and switch (p.source[p.i]) { + if ((p.i < p.source.len and switch (p.source[p.i]) { + 'e'...'e', + 'E'...'E', 'p'...'p', 'P'...'P', => blk_1: { @@ -2668,19 +2490,21 @@ const Parser = struct { break :blk_1 true; }, else => false, - }) and ((p.i < p.source.len and switch (p.source[p.i]) { - '-'...'-', - '+'...'+', - => blk_2: { - p.i += 1; - break :blk_2 true; - }, - else => false, - }) or true) and p.parsedec_int() and p.parseskip()) break :blk_0 true; + })) break :blk_0 true; + p.i = pos_0; + break :blk_0 false; + }; + } + pub fn parsedigit_float(p: *Parser) bool { + return blk_0: { + const pos_0 = p.i; + if (p.parsedigit()) break :blk_0 true; p.i = pos_0; - if (p.parsedec_int() and (p.i < p.source.len and switch (p.source[p.i]) { + if ((p.i < p.source.len and switch (p.source[p.i]) { 'e'...'e', 'E'...'E', + 'p'...'p', + 'P'...'P', => blk_1: { p.i += 1; break :blk_1 true; @@ -2694,39 +2518,49 @@ const Parser = struct { break :blk_2 true; }, else => false, - }) or true) and p.parsedec_int() and p.parseskip()) break :blk_0 true; + }) or true)) break :blk_0 true; p.i = pos_0; break :blk_0 false; }; } - pub fn parseINTEGER(p: *Parser) bool { + pub fn parseNUMBERLITERAL(p: *Parser) bool { return blk_0: { const pos_0 = p.i; - if (blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], "0b")) { - p.i += 2; + if ((p.i < p.source.len and switch (p.source[p.i]) { + '0'...'9', + => blk_1: { + p.i += 1; break :blk_1 true; - } - break :blk_1 false; - } and p.parsebin_int() and p.parseskip()) break :blk_0 true; - p.i = pos_0; - if (blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], "0o")) { - p.i += 2; + }, + else => false, + }) and blk_1: { + while (p.parsedigit_int()) {} + break :blk_1 true; + } and blk_1: { + if (std.mem.startsWith(u8, p.source[p.i..], ".")) { + p.i += 1; break :blk_1 true; } break :blk_1 false; - } and p.parseoct_int() and p.parseskip()) break :blk_0 true; - p.i = pos_0; - if (blk_1: { - if (std.mem.startsWith(u8, p.source[p.i..], "0x")) { - p.i += 2; - break :blk_1 true; + } and blk_1: { + var match_1 = false; + while (p.parsedigit_float()) { + match_1 = true; } - break :blk_1 false; - } and p.parsehex_int() and p.parseskip()) break :blk_0 true; + break :blk_1 match_1; + } and p.parseskip()) break :blk_0 true; p.i = pos_0; - if (p.parsedec_int() and p.parseskip()) break :blk_0 true; + if ((p.i < p.source.len and switch (p.source[p.i]) { + '0'...'9', + => blk_1: { + p.i += 1; + break :blk_1 true; + }, + else => false, + }) and blk_1: { + while (p.parsedigit_float()) {} + break :blk_1 true; + } and p.parseskip()) break :blk_0 true; p.i = pos_0; break :blk_0 false; };