update grammar in langref

This commit is contained in:
Vexu 2020-11-22 21:15:12 +02:00
parent 2fbe9519ac
commit 98d5bfbd4d
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 58 additions and 47 deletions

View File

@ -11042,15 +11042,15 @@ TestDecl <- KEYWORD_test STRINGLITERALSINGLE Block
TopLevelComptime <- KEYWORD_comptime BlockExpr
TopLevelDecl
<- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / KEYWORD_inline)? FnProto (SEMICOLON / Block)
<- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / (KEYWORD_inline / KEYWORD_noinline))? FnProto (SEMICOLON / Block)
/ (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
/ KEYWORD_usingnamespace Expr SEMICOLON
FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr)
FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? CallConv? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr)
VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? LinkSection? (EQUAL Expr)? SEMICOLON
ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON TypeExpr)? (EQUAL Expr)?
ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON TypeExpr ByteAlign?)? (EQUAL Expr)?
# *** Block Level ***
Statement
@ -11090,7 +11090,7 @@ BlockExpr <- BlockLabel? Block
# *** Expression Level ***
AssignExpr <- Expr (AssignOp Expr)?
Expr <- KEYWORD_try* BoolOrExpr
Expr <- BoolOrExpr
BoolOrExpr <- BoolAndExpr (KEYWORD_or BoolAndExpr)*
@ -11215,6 +11215,8 @@ WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN
LinkSection <- KEYWORD_linksection LPAREN Expr RPAREN
CallConv <- KEYWORD_callconv LPAREN Expr RPAREN
ParamDecl <- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType
ParamType
@ -11321,19 +11323,20 @@ SuffixOp
FnCallArguments <- LPAREN ExprList RPAREN
# Ptr specific
ArrayTypeStart <- LBRACKET Expr? RBRACKET
ArrayTypeStart <- LBRACKET Expr? (COLON Expr)? RBRACKET
PtrTypeStart
<- ASTERISK
/ ASTERISK2
/ PTRUNKNOWN
/ PTRC
/ LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET
# ContainerDecl specific
ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
ContainerDeclType
<- (KEYWORD_struct / KEYWORD_enum / KEYWORD_opaque) (LPAREN Expr RPAREN)?
<- KEYWORD_struct
/ KEYWORD_opaque
/ KEYWORD_enum (LPAREN Expr RPAREN)?
/ KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)?
# Alignment
@ -11357,44 +11360,51 @@ ExprList <- (Expr COMMA)* Expr?
# *** Tokens ***
eof <- !.
hex <- [0-9a-fA-F]
hex_ <- ('_'/hex)
dec <- [0-9]
dec_ <- ('_'/dec)
dec_int <- dec (dec_* dec)?
hex_int <- hex (hex_* dec)?
char_escape
<- "\\x" hex hex
/ "\\u{" hex+ "}"
/ "\\" [nr\\t'"]
<- "\\x" hex hex
/ "\\u{" hex+ "}"
/ "\\" [nr\\t'"]
char_char
<- char_escape
/ [^\\'\n]
string_char
<- char_escape
/ [^\\"\n]
/ [^\\"\n]
line_comment <- '//'[^\n]*
line_string <- ("\\\\" [^\n]* [ \n]*)+
line_string <- ("\\\\" [^\n]* [ \n]*)+
skip <- ([ \n] / line_comment)*
CHAR_LITERAL <- "'" char_char "'" skip
CHAR_LITERAL <- "'" char_char "'" skip
FLOAT
<- "0x" hex+ "." hex+ ([pP] [-+]? hex+)? skip
/ [0-9]+ "." [0-9]+ ([eE] [-+]? [0-9]+)? skip
/ "0x" hex+ "."? [pP] [-+]? hex+ skip
/ [0-9]+ "."? [eE] [-+]? [0-9]+ skip
<- "0x" hex_* hex "." hex_int ([pP] [-+]? hex_int)? skip
/ dec_int "." dec_int ([eE] [-+]? dec_int)? skip
/ "0x" hex_* hex "."? [pP] [-+]? hex_int skip
/ dec_int "."? [eE] [-+]? dec_int skip
INTEGER
<- "0b" [01]+ skip
/ "0o" [0-7]+ skip
/ "0x" hex+ skip
/ [0-9]+ skip
STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
<- "0b" [_01]* [01] skip
/ "0o" [_0-7]* [0-7] skip
/ "0x" hex_* hex skip
/ dec_int skip
STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
STRINGLITERAL
<- STRINGLITERALSINGLE
/ line_string skip
IDENTIFIER
<- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
/ "@\"" string_char* "\"" skip
BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
/ "@\"" string_char* "\"" skip
BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
AMPERSAND <- '&' ![=] skip
AMPERSANDEQUAL <- '&=' skip
AMPERSAND <- '&' ![=] skip
AMPERSANDEQUAL <- '&=' skip
ASTERISK <- '*' ![*%=] skip
ASTERISK2 <- '**' skip
ASTERISKEQUAL <- '*=' skip
@ -11419,7 +11429,7 @@ LARROW2 <- '<<' ![=] skip
LARROW2EQUAL <- '<<=' skip
LARROWEQUAL <- '<=' skip
LBRACE <- '{' skip
LBRACKET <- '[' ![*] skip
LBRACKET <- '[' skip
LPAREN <- '(' skip
MINUS <- '-' ![%=>] skip
MINUSEQUAL <- '-=' skip
@ -11436,8 +11446,7 @@ PLUS2 <- '++' skip
PLUSEQUAL <- '+=' skip
PLUSPERCENT <- '+%' ![=] skip
PLUSPERCENTEQUAL <- '+%=' skip
PTRC <- '[*c]' skip
PTRUNKNOWN <- '[*]' skip
LETTERC <- 'c' skip
QUESTIONMARK <- '?' skip
RARROW <- '>' ![>=] skip
RARROW2 <- '>>' ![=] skip
@ -11461,6 +11470,7 @@ KEYWORD_asm <- 'asm' end_of_word
KEYWORD_async <- 'async' end_of_word
KEYWORD_await <- 'await' end_of_word
KEYWORD_break <- 'break' end_of_word
KEYWORD_callconv <- 'callconv' end_of_word
KEYWORD_catch <- 'catch' end_of_word
KEYWORD_comptime <- 'comptime' end_of_word
KEYWORD_const <- 'const' end_of_word
@ -11479,6 +11489,7 @@ KEYWORD_if <- 'if' end_of_word
KEYWORD_inline <- 'inline' end_of_word
KEYWORD_noalias <- 'noalias' end_of_word
KEYWORD_nosuspend <- 'nosuspend' end_of_word
KEYWORD_noinline <- 'noinline' end_of_word
KEYWORD_null <- 'null' end_of_word
KEYWORD_opaque <- 'opaque' end_of_word
KEYWORD_or <- 'or' end_of_word
@ -11503,19 +11514,20 @@ KEYWORD_var <- 'var' end_of_word
KEYWORD_volatile <- 'volatile' end_of_word
KEYWORD_while <- 'while' end_of_word
keyword <- KEYWORD_align / KEYWORD_and / KEYWORD_anyframe / KEYWORD_anytype
/ KEYWORD_allowzero / KEYWORD_asm / KEYWORD_async / KEYWORD_await / KEYWORD_break
/ KEYWORD_catch / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue
/ KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer
/ KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false
/ KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline
/ KEYWORD_noalias / KEYWORD_null / KEYWORD_opaque / KEYWORD_or
/ KEYWORD_orelse / KEYWORD_packed / KEYWORD_pub
/ KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend
/ KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
keyword <- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe
/ KEYWORD_anytype / KEYWORD_asm / KEYWORD_async / KEYWORD_await
/ KEYWORD_break / KEYWORD_callconv / KEYWORD_catch / KEYWORD_comptime
/ KEYWORD_const / KEYWORD_continue / KEYWORD_defer / KEYWORD_else
/ KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
/ KEYWORD_extern / KEYWORD_false / KEYWORD_fn / KEYWORD_for / KEYWORD_if
/ KEYWORD_inline / KEYWORD_noalias / KEYWORD_nosuspend / KEYWORD_noinline
/ KEYWORD_null / KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
/ KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch
/ KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
/ KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while</code></pre>
/ KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while
</code></pre>
{#header_close#}
{#header_open|Zen#}
<ul>

View File

@ -488,7 +488,7 @@ const Parser = struct {
return &node.base;
}
/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (Keyword_anytype / TypeExpr)
/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? CallConv? EXCLAMATIONMARK? (Keyword_anytype / TypeExpr)
fn parseFnProto(p: *Parser, level: enum { top_level, as_type }, fields: struct {
doc_comments: ?*Node.DocComment = null,
visib_token: ?TokenIndex = null,
@ -1023,7 +1023,7 @@ const Parser = struct {
return p.parseBinOpExpr(parseAssignOp, parseExpr, .Once);
}
/// Expr <- KEYWORD_try* BoolOrExpr
/// Expr <- BoolOrExpr
fn parseExpr(p: *Parser) Error!?*Node {
return p.parsePrefixOpExpr(parseTry, parseBoolOrExpr);
}
@ -2758,7 +2758,7 @@ const Parser = struct {
rparen: TokenIndex,
};
/// ArrayTypeStart <- LBRACKET Expr? RBRACKET
/// ArrayTypeStart <- LBRACKET Expr? (COLON Expr)? RBRACKET
fn parseArrayTypeStart(p: *Parser) !?*Node {
const lbracket = p.eatToken(.LBracket) orelse return null;
const expr = try p.parseExpr();
@ -2803,8 +2803,7 @@ const Parser = struct {
/// PtrTypeStart
/// <- ASTERISK
/// / ASTERISK2
/// / PTRUNKNOWN
/// / PTRC
/// / LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET
fn parsePtrTypeStart(p: *Parser) !?*Node {
if (p.eatToken(.Asterisk)) |asterisk| {
const sentinel = if (p.eatToken(.Colon)) |_|