mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
langref: sync with zig-spec grammar.peg
This commit is contained in:
parent
01b5023868
commit
52de06c3b0
2 changed files with 29 additions and 31 deletions
|
|
@ -7804,11 +7804,11 @@ fn readU32Be() u32 {}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
{#header_open|Grammar#}
|
{#header_open|Grammar#}
|
||||||
{#syntax_block|peg|grammar.y#}
|
{#syntax_block|peg|grammar.peg#}
|
||||||
Root <- skip container_doc_comment? ContainerMembers eof
|
Root <- skip ContainerMembers eof
|
||||||
|
|
||||||
# *** Top level ***
|
# *** Top level ***
|
||||||
ContainerMembers <- ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
|
ContainerMembers <- container_doc_comment? ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
|
||||||
|
|
||||||
ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
|
ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
|
||||||
|
|
||||||
|
|
@ -7837,7 +7837,6 @@ Statement
|
||||||
/ KEYWORD_errdefer Payload? BlockExprStatement
|
/ KEYWORD_errdefer Payload? BlockExprStatement
|
||||||
/ IfStatement
|
/ IfStatement
|
||||||
/ LabeledStatement
|
/ LabeledStatement
|
||||||
/ SwitchExpr
|
|
||||||
/ VarDeclExprStatement
|
/ VarDeclExprStatement
|
||||||
|
|
||||||
ComptimeStatement
|
ComptimeStatement
|
||||||
|
|
@ -7848,7 +7847,7 @@ IfStatement
|
||||||
<- IfPrefix BlockExpr ( KEYWORD_else Payload? Statement )?
|
<- IfPrefix BlockExpr ( KEYWORD_else Payload? Statement )?
|
||||||
/ IfPrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
|
/ IfPrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
|
||||||
|
|
||||||
LabeledStatement <- BlockLabel? (Block / LoopStatement)
|
LabeledStatement <- BlockLabel? (Block / LoopStatement / SwitchExpr)
|
||||||
|
|
||||||
LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement)
|
LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement)
|
||||||
|
|
||||||
|
|
@ -7902,7 +7901,7 @@ PrimaryExpr
|
||||||
/ KEYWORD_break BreakLabel? Expr?
|
/ KEYWORD_break BreakLabel? Expr?
|
||||||
/ KEYWORD_comptime Expr
|
/ KEYWORD_comptime Expr
|
||||||
/ KEYWORD_nosuspend Expr
|
/ KEYWORD_nosuspend Expr
|
||||||
/ KEYWORD_continue BreakLabel?
|
/ KEYWORD_continue BreakLabel? Expr?
|
||||||
/ KEYWORD_resume Expr
|
/ KEYWORD_resume Expr
|
||||||
/ KEYWORD_return Expr?
|
/ KEYWORD_return Expr?
|
||||||
/ BlockLabel? LoopExpr
|
/ BlockLabel? LoopExpr
|
||||||
|
|
@ -7952,7 +7951,6 @@ PrimaryTypeExpr
|
||||||
/ KEYWORD_anyframe
|
/ KEYWORD_anyframe
|
||||||
/ KEYWORD_unreachable
|
/ KEYWORD_unreachable
|
||||||
/ STRINGLITERAL
|
/ STRINGLITERAL
|
||||||
/ SwitchExpr
|
|
||||||
|
|
||||||
ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
|
ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
|
||||||
|
|
||||||
|
|
@ -7965,6 +7963,7 @@ IfTypeExpr <- IfPrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
|
||||||
LabeledTypeExpr
|
LabeledTypeExpr
|
||||||
<- BlockLabel Block
|
<- BlockLabel Block
|
||||||
/ BlockLabel? LoopTypeExpr
|
/ BlockLabel? LoopTypeExpr
|
||||||
|
/ BlockLabel? SwitchExpr
|
||||||
|
|
||||||
LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
|
LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
|
||||||
|
|
||||||
|
|
@ -8134,7 +8133,7 @@ PtrTypeStart
|
||||||
ArrayTypeStart <- LBRACKET Expr (COLON Expr)? RBRACKET
|
ArrayTypeStart <- LBRACKET Expr (COLON Expr)? RBRACKET
|
||||||
|
|
||||||
# ContainerDecl specific
|
# ContainerDecl specific
|
||||||
ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
|
ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
|
||||||
|
|
||||||
ContainerDeclType
|
ContainerDeclType
|
||||||
<- KEYWORD_struct (LPAREN Expr RPAREN)?
|
<- KEYWORD_struct (LPAREN Expr RPAREN)?
|
||||||
|
|
@ -8154,8 +8153,6 @@ AsmOutputList <- (AsmOutputItem COMMA)* AsmOutputItem?
|
||||||
|
|
||||||
AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
|
AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
|
||||||
|
|
||||||
StringList <- (STRINGLITERAL COMMA)* STRINGLITERAL?
|
|
||||||
|
|
||||||
ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
|
ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
|
||||||
|
|
||||||
ExprList <- (Expr COMMA)* Expr?
|
ExprList <- (Expr COMMA)* Expr?
|
||||||
|
|
@ -8202,7 +8199,7 @@ oxC2_oxDF <- [\302-\337]
|
||||||
# [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
|
# [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
|
||||||
# 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
|
# 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
|
||||||
|
|
||||||
mb_utf8_literal <-
|
multibyte_utf8 <-
|
||||||
oxF4 ox80_ox8F ox80_oxBF ox80_oxBF
|
oxF4 ox80_ox8F ox80_oxBF ox80_oxBF
|
||||||
/ oxF1_oxF3 ox80_oxBF ox80_oxBF ox80_oxBF
|
/ oxF1_oxF3 ox80_oxBF ox80_oxBF ox80_oxBF
|
||||||
/ oxF0 ox90_0xBF ox80_oxBF ox80_oxBF
|
/ oxF0 ox90_0xBF ox80_oxBF ox80_oxBF
|
||||||
|
|
@ -8212,46 +8209,47 @@ mb_utf8_literal <-
|
||||||
/ oxE0 oxA0_oxBF ox80_oxBF
|
/ oxE0 oxA0_oxBF ox80_oxBF
|
||||||
/ oxC2_oxDF ox80_oxBF
|
/ oxC2_oxDF ox80_oxBF
|
||||||
|
|
||||||
ascii_char_not_nl_slash_squote <- [\000-\011\013-\046\050-\133\135-\177]
|
non_control_ascii <- [\040-\176]
|
||||||
|
|
||||||
char_escape
|
char_escape
|
||||||
<- "\\x" hex hex
|
<- "\\x" hex hex
|
||||||
/ "\\u{" hex+ "}"
|
/ "\\u{" hex+ "}"
|
||||||
/ "\\" [nr\\t'"]
|
/ "\\" [nr\\t'"]
|
||||||
char_char
|
char_char
|
||||||
<- mb_utf8_literal
|
<- multibyte_utf8
|
||||||
/ char_escape
|
/ char_escape
|
||||||
/ ascii_char_not_nl_slash_squote
|
/ ![\\'\n] non_control_ascii
|
||||||
|
|
||||||
string_char
|
string_char
|
||||||
<- char_escape
|
<- multibyte_utf8
|
||||||
/ [^\\"\n]
|
/ char_escape
|
||||||
|
/ ![\\"\n] non_control_ascii
|
||||||
|
|
||||||
container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+
|
container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+
|
||||||
doc_comment <- ('///' [^\n]* [ \n]* skip)+
|
doc_comment <- ('///' [^\n]* [ \n]* skip)+
|
||||||
line_comment <- '//' ![!/][^\n]* / '////' [^\n]*
|
line_comment <- '//' ![!/][^\n]* / '////' [^\n]*
|
||||||
line_string <- ("\\\\" [^\n]* [ \n]*)+
|
line_string <- ('\\\\' [^\n]* [ \n]*)+
|
||||||
skip <- ([ \n] / line_comment)*
|
skip <- ([ \n] / line_comment)*
|
||||||
|
|
||||||
CHAR_LITERAL <- "'" char_char "'" skip
|
CHAR_LITERAL <- ['] char_char ['] skip
|
||||||
FLOAT
|
FLOAT
|
||||||
<- "0x" hex_int "." hex_int ([pP] [-+]? dec_int)? skip
|
<- '0x' hex_int '.' hex_int ([pP] [-+]? dec_int)? skip
|
||||||
/ dec_int "." dec_int ([eE] [-+]? dec_int)? skip
|
/ dec_int '.' dec_int ([eE] [-+]? dec_int)? skip
|
||||||
/ "0x" hex_int [pP] [-+]? dec_int skip
|
/ '0x' hex_int [pP] [-+]? dec_int skip
|
||||||
/ dec_int [eE] [-+]? dec_int skip
|
/ dec_int [eE] [-+]? dec_int skip
|
||||||
INTEGER
|
INTEGER
|
||||||
<- "0b" bin_int skip
|
<- '0b' bin_int skip
|
||||||
/ "0o" oct_int skip
|
/ '0o' oct_int skip
|
||||||
/ "0x" hex_int skip
|
/ '0x' hex_int skip
|
||||||
/ dec_int skip
|
/ dec_int skip
|
||||||
STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
|
STRINGLITERALSINGLE <- ["] string_char* ["] skip
|
||||||
STRINGLITERAL
|
STRINGLITERAL
|
||||||
<- STRINGLITERALSINGLE
|
<- STRINGLITERALSINGLE
|
||||||
/ (line_string skip)+
|
/ (line_string skip)+
|
||||||
IDENTIFIER
|
IDENTIFIER
|
||||||
<- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
|
<- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
|
||||||
/ "@" STRINGLITERALSINGLE
|
/ '@' STRINGLITERALSINGLE
|
||||||
BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
|
BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip
|
||||||
|
|
||||||
|
|
||||||
AMPERSAND <- '&' ![=] skip
|
AMPERSAND <- '&' ![=] skip
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ fn failMsg(p: *Parse, msg: Ast.Error) error{ ParseError, OutOfMemory } {
|
||||||
return error.ParseError;
|
return error.ParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Root <- skip container_doc_comment? ContainerMembers eof
|
/// Root <- skip ContainerMembers eof
|
||||||
pub fn parseRoot(p: *Parse) !void {
|
pub fn parseRoot(p: *Parse) !void {
|
||||||
// Root node must be index 0.
|
// Root node must be index 0.
|
||||||
p.nodes.appendAssumeCapacity(.{
|
p.nodes.appendAssumeCapacity(.{
|
||||||
|
|
@ -227,7 +227,7 @@ pub fn parseZon(p: *Parse) !void {
|
||||||
p.nodes.items(.data)[0] = .{ .node = node_index };
|
p.nodes.items(.data)[0] = .{ .node = node_index };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ContainerMembers <- ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
|
/// ContainerMembers <- container_doc_comment? ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
|
||||||
///
|
///
|
||||||
/// ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
|
/// ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
|
||||||
///
|
///
|
||||||
|
|
@ -2423,7 +2423,7 @@ fn parseSuffixExpr(p: *Parse) !?Node.Index {
|
||||||
///
|
///
|
||||||
/// ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
|
/// ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
|
||||||
///
|
///
|
||||||
/// ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
|
/// ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
|
||||||
///
|
///
|
||||||
/// InitList
|
/// InitList
|
||||||
/// <- LBRACE FieldInit (COMMA FieldInit)* COMMA? RBRACE
|
/// <- LBRACE FieldInit (COMMA FieldInit)* COMMA? RBRACE
|
||||||
|
|
@ -3317,7 +3317,7 @@ fn parseSuffixOp(p: *Parse, lhs: Node.Index) !?Node.Index {
|
||||||
|
|
||||||
/// Caller must have already verified the first token.
|
/// Caller must have already verified the first token.
|
||||||
///
|
///
|
||||||
/// ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
|
/// ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
|
||||||
///
|
///
|
||||||
/// ContainerDeclType
|
/// ContainerDeclType
|
||||||
/// <- KEYWORD_struct (LPAREN Expr RPAREN)?
|
/// <- KEYWORD_struct (LPAREN Expr RPAREN)?
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue