Appendix

Containers

A container in Zig is any syntactical construct that acts as a namespace to hold variable and function declarations. Containers are also type definitions which can be instantiated. Structs, enums, unions, opaques, and even Zig source files themselves are containers.

Although containers (except Zig source files) use curly braces to surround their definition, they should not be confused with blocks or functions. Containers do not contain statements.

Grammar

grammar.y

  1. Root <- skip container_doc_comment? ContainerMembers eof
  2. # *** Top level ***
  3. ContainerMembers <- ContainerDeclarations (ContainerField COMMA)* (ContainerField / ContainerDeclarations)
  4. ContainerDeclarations
  5. <- TestDecl ContainerDeclarations
  6. / ComptimeDecl ContainerDeclarations
  7. / doc_comment? KEYWORD_pub? Decl ContainerDeclarations
  8. /
  9. TestDecl <- KEYWORD_test (STRINGLITERALSINGLE / IDENTIFIER)? Block
  10. ComptimeDecl <- KEYWORD_comptime Block
  11. Decl
  12. <- (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE? / (KEYWORD_inline / KEYWORD_noinline))? FnProto (SEMICOLON / Block)
  13. / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
  14. / KEYWORD_usingnamespace Expr SEMICOLON
  15. FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
  16. VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? AddrSpace? LinkSection? (EQUAL Expr)? SEMICOLON
  17. ContainerField
  18. <- doc_comment? KEYWORD_comptime? IDENTIFIER (COLON TypeExpr)? ByteAlign? (EQUAL Expr)?
  19. / doc_comment? KEYWORD_comptime? (IDENTIFIER COLON)? !KEYWORD_fn TypeExpr ByteAlign? (EQUAL Expr)?
  20. # *** Block Level ***
  21. Statement
  22. <- KEYWORD_comptime? VarDecl
  23. / KEYWORD_comptime BlockExprStatement
  24. / KEYWORD_nosuspend BlockExprStatement
  25. / KEYWORD_suspend BlockExprStatement
  26. / KEYWORD_defer BlockExprStatement
  27. / KEYWORD_errdefer Payload? BlockExprStatement
  28. / IfStatement
  29. / LabeledStatement
  30. / SwitchExpr
  31. / AssignExpr SEMICOLON
  32. IfStatement
  33. <- IfPrefix BlockExpr ( KEYWORD_else Payload? Statement )?
  34. / IfPrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
  35. LabeledStatement <- BlockLabel? (Block / LoopStatement)
  36. LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement)
  37. ForStatement
  38. <- ForPrefix BlockExpr ( KEYWORD_else Statement )?
  39. / ForPrefix AssignExpr ( SEMICOLON / KEYWORD_else Statement )
  40. WhileStatement
  41. <- WhilePrefix BlockExpr ( KEYWORD_else Payload? Statement )?
  42. / WhilePrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
  43. BlockExprStatement
  44. <- BlockExpr
  45. / AssignExpr SEMICOLON
  46. BlockExpr <- BlockLabel? Block
  47. # *** Expression Level ***
  48. AssignExpr <- Expr (AssignOp Expr)?
  49. Expr <- BoolOrExpr
  50. BoolOrExpr <- BoolAndExpr (KEYWORD_or BoolAndExpr)*
  51. BoolAndExpr <- CompareExpr (KEYWORD_and CompareExpr)*
  52. CompareExpr <- BitwiseExpr (CompareOp BitwiseExpr)?
  53. BitwiseExpr <- BitShiftExpr (BitwiseOp BitShiftExpr)*
  54. BitShiftExpr <- AdditionExpr (BitShiftOp AdditionExpr)*
  55. AdditionExpr <- MultiplyExpr (AdditionOp MultiplyExpr)*
  56. MultiplyExpr <- PrefixExpr (MultiplyOp PrefixExpr)*
  57. PrefixExpr <- PrefixOp* PrimaryExpr
  58. PrimaryExpr
  59. <- AsmExpr
  60. / IfExpr
  61. / KEYWORD_break BreakLabel? Expr?
  62. / KEYWORD_comptime Expr
  63. / KEYWORD_nosuspend Expr
  64. / KEYWORD_continue BreakLabel?
  65. / KEYWORD_resume Expr
  66. / KEYWORD_return Expr?
  67. / BlockLabel? LoopExpr
  68. / Block
  69. / CurlySuffixExpr
  70. IfExpr <- IfPrefix Expr (KEYWORD_else Payload? Expr)?
  71. Block <- LBRACE Statement* RBRACE
  72. LoopExpr <- KEYWORD_inline? (ForExpr / WhileExpr)
  73. ForExpr <- ForPrefix Expr (KEYWORD_else Expr)?
  74. WhileExpr <- WhilePrefix Expr (KEYWORD_else Payload? Expr)?
  75. CurlySuffixExpr <- TypeExpr InitList?
  76. InitList
  77. <- LBRACE FieldInit (COMMA FieldInit)* COMMA? RBRACE
  78. / LBRACE Expr (COMMA Expr)* COMMA? RBRACE
  79. / LBRACE RBRACE
  80. TypeExpr <- PrefixTypeOp* ErrorUnionExpr
  81. ErrorUnionExpr <- SuffixExpr (EXCLAMATIONMARK TypeExpr)?
  82. SuffixExpr
  83. <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
  84. / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
  85. PrimaryTypeExpr
  86. <- BUILTINIDENTIFIER FnCallArguments
  87. / CHAR_LITERAL
  88. / ContainerDecl
  89. / DOT IDENTIFIER
  90. / DOT InitList
  91. / ErrorSetDecl
  92. / FLOAT
  93. / FnProto
  94. / GroupedExpr
  95. / LabeledTypeExpr
  96. / IDENTIFIER
  97. / IfTypeExpr
  98. / INTEGER
  99. / KEYWORD_comptime TypeExpr
  100. / KEYWORD_error DOT IDENTIFIER
  101. / KEYWORD_anyframe
  102. / KEYWORD_unreachable
  103. / STRINGLITERAL
  104. / SwitchExpr
  105. ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
  106. ErrorSetDecl <- KEYWORD_error LBRACE IdentifierList RBRACE
  107. GroupedExpr <- LPAREN Expr RPAREN
  108. IfTypeExpr <- IfPrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
  109. LabeledTypeExpr
  110. <- BlockLabel Block
  111. / BlockLabel? LoopTypeExpr
  112. LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
  113. ForTypeExpr <- ForPrefix TypeExpr (KEYWORD_else TypeExpr)?
  114. WhileTypeExpr <- WhilePrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
  115. SwitchExpr <- KEYWORD_switch LPAREN Expr RPAREN LBRACE SwitchProngList RBRACE
  116. # *** Assembly ***
  117. AsmExpr <- KEYWORD_asm KEYWORD_volatile? LPAREN Expr AsmOutput? RPAREN
  118. AsmOutput <- COLON AsmOutputList AsmInput?
  119. AsmOutputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN (MINUSRARROW TypeExpr / IDENTIFIER) RPAREN
  120. AsmInput <- COLON AsmInputList AsmClobbers?
  121. AsmInputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN Expr RPAREN
  122. AsmClobbers <- COLON StringList
  123. # *** Helper grammar ***
  124. BreakLabel <- COLON IDENTIFIER
  125. BlockLabel <- IDENTIFIER COLON
  126. FieldInit <- DOT IDENTIFIER EQUAL Expr
  127. WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN
  128. LinkSection <- KEYWORD_linksection LPAREN Expr RPAREN
  129. AddrSpace <- KEYWORD_addrspace LPAREN Expr RPAREN
  130. # Fn specific
  131. CallConv <- KEYWORD_callconv LPAREN Expr RPAREN
  132. ParamDecl
  133. <- doc_comment? (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType
  134. / DOT3
  135. ParamType
  136. <- KEYWORD_anytype
  137. / TypeExpr
  138. # Control flow prefixes
  139. IfPrefix <- KEYWORD_if LPAREN Expr RPAREN PtrPayload?
  140. WhilePrefix <- KEYWORD_while LPAREN Expr RPAREN PtrPayload? WhileContinueExpr?
  141. ForPrefix <- KEYWORD_for LPAREN Expr RPAREN PtrIndexPayload
  142. # Payloads
  143. Payload <- PIPE IDENTIFIER PIPE
  144. PtrPayload <- PIPE ASTERISK? IDENTIFIER PIPE
  145. PtrIndexPayload <- PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE
  146. # Switch specific
  147. SwitchProng <- KEYWORD_inline? SwitchCase EQUALRARROW PtrIndexPayload? AssignExpr
  148. SwitchCase
  149. <- SwitchItem (COMMA SwitchItem)* COMMA?
  150. / KEYWORD_else
  151. SwitchItem <- Expr (DOT3 Expr)?
  152. # Operators
  153. AssignOp
  154. <- ASTERISKEQUAL
  155. / ASTERISKPIPEEQUAL
  156. / SLASHEQUAL
  157. / PERCENTEQUAL
  158. / PLUSEQUAL
  159. / PLUSPIPEEQUAL
  160. / MINUSEQUAL
  161. / MINUSPIPEEQUAL
  162. / LARROW2EQUAL
  163. / LARROW2PIPEEQUAL
  164. / RARROW2EQUAL
  165. / AMPERSANDEQUAL
  166. / CARETEQUAL
  167. / PIPEEQUAL
  168. / ASTERISKPERCENTEQUAL
  169. / PLUSPERCENTEQUAL
  170. / MINUSPERCENTEQUAL
  171. / EQUAL
  172. CompareOp
  173. <- EQUALEQUAL
  174. / EXCLAMATIONMARKEQUAL
  175. / LARROW
  176. / RARROW
  177. / LARROWEQUAL
  178. / RARROWEQUAL
  179. BitwiseOp
  180. <- AMPERSAND
  181. / CARET
  182. / PIPE
  183. / KEYWORD_orelse
  184. / KEYWORD_catch Payload?
  185. BitShiftOp
  186. <- LARROW2
  187. / RARROW2
  188. / LARROW2PIPE
  189. AdditionOp
  190. <- PLUS
  191. / MINUS
  192. / PLUS2
  193. / PLUSPERCENT
  194. / MINUSPERCENT
  195. / PLUSPIPE
  196. / MINUSPIPE
  197. MultiplyOp
  198. <- PIPE2
  199. / ASTERISK
  200. / SLASH
  201. / PERCENT
  202. / ASTERISK2
  203. / ASTERISKPERCENT
  204. / ASTERISKPIPE
  205. PrefixOp
  206. <- EXCLAMATIONMARK
  207. / MINUS
  208. / TILDE
  209. / MINUSPERCENT
  210. / AMPERSAND
  211. / KEYWORD_try
  212. / KEYWORD_await
  213. PrefixTypeOp
  214. <- QUESTIONMARK
  215. / KEYWORD_anyframe MINUSRARROW
  216. / SliceTypeStart (ByteAlign / AddrSpace / KEYWORD_const / KEYWORD_volatile / KEYWORD_allowzero)*
  217. / PtrTypeStart (AddrSpace / KEYWORD_align LPAREN Expr (COLON Expr COLON Expr)? RPAREN / KEYWORD_const / KEYWORD_volatile / KEYWORD_allowzero)*
  218. / ArrayTypeStart
  219. SuffixOp
  220. <- LBRACKET Expr (DOT2 (Expr? (COLON Expr)?)?)? RBRACKET
  221. / DOT IDENTIFIER
  222. / DOTASTERISK
  223. / DOTQUESTIONMARK
  224. FnCallArguments <- LPAREN ExprList RPAREN
  225. # Ptr specific
  226. SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET
  227. PtrTypeStart
  228. <- ASTERISK
  229. / ASTERISK2
  230. / LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET
  231. ArrayTypeStart <- LBRACKET Expr (COLON Expr)? RBRACKET
  232. # ContainerDecl specific
  233. ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
  234. ContainerDeclType
  235. <- KEYWORD_struct (LPAREN Expr RPAREN)?
  236. / KEYWORD_opaque
  237. / KEYWORD_enum (LPAREN Expr RPAREN)?
  238. / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)?
  239. # Alignment
  240. ByteAlign <- KEYWORD_align LPAREN Expr RPAREN
  241. # Lists
  242. IdentifierList <- (doc_comment? IDENTIFIER COMMA)* (doc_comment? IDENTIFIER)?
  243. SwitchProngList <- (SwitchProng COMMA)* SwitchProng?
  244. AsmOutputList <- (AsmOutputItem COMMA)* AsmOutputItem?
  245. AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
  246. StringList <- (STRINGLITERAL COMMA)* STRINGLITERAL?
  247. ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
  248. ExprList <- (Expr COMMA)* Expr?
  249. # *** Tokens ***
  250. eof <- !.
  251. bin <- [01]
  252. bin_ <- '_'? bin
  253. oct <- [0-7]
  254. oct_ <- '_'? oct
  255. hex <- [0-9a-fA-F]
  256. hex_ <- '_'? hex
  257. dec <- [0-9]
  258. dec_ <- '_'? dec
  259. bin_int <- bin bin_*
  260. oct_int <- oct oct_*
  261. dec_int <- dec dec_*
  262. hex_int <- hex hex_*
  263. ox80_oxBF <- [\200-\277]
  264. oxF4 <- '\364'
  265. ox80_ox8F <- [\200-\217]
  266. oxF1_oxF3 <- [\361-\363]
  267. oxF0 <- '\360'
  268. ox90_0xBF <- [\220-\277]
  269. oxEE_oxEF <- [\356-\357]
  270. oxED <- '\355'
  271. ox80_ox9F <- [\200-\237]
  272. oxE1_oxEC <- [\341-\354]
  273. oxE0 <- '\340'
  274. oxA0_oxBF <- [\240-\277]
  275. oxC2_oxDF <- [\302-\337]
  276. # From https://lemire.me/blog/2018/05/09/how-quickly-can-you-check-that-a-string-is-valid-unicode-utf-8/
  277. # First Byte Second Byte Third Byte Fourth Byte
  278. # [0x00,0x7F]
  279. # [0xC2,0xDF] [0x80,0xBF]
  280. # 0xE0 [0xA0,0xBF] [0x80,0xBF]
  281. # [0xE1,0xEC] [0x80,0xBF] [0x80,0xBF]
  282. # 0xED [0x80,0x9F] [0x80,0xBF]
  283. # [0xEE,0xEF] [0x80,0xBF] [0x80,0xBF]
  284. # 0xF0 [0x90,0xBF] [0x80,0xBF] [0x80,0xBF]
  285. # [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
  286. # 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
  287. mb_utf8_literal <-
  288. oxF4 ox80_ox8F ox80_oxBF ox80_oxBF
  289. / oxF1_oxF3 ox80_oxBF ox80_oxBF ox80_oxBF
  290. / oxF0 ox90_0xBF ox80_oxBF ox80_oxBF
  291. / oxEE_oxEF ox80_oxBF ox80_oxBF
  292. / oxED ox80_ox9F ox80_oxBF
  293. / oxE1_oxEC ox80_oxBF ox80_oxBF
  294. / oxE0 oxA0_oxBF ox80_oxBF
  295. / oxC2_oxDF ox80_oxBF
  296. ascii_char_not_nl_slash_squote <- [\000-\011\013-\046-\050-\133\135-\177]
  297. char_escape
  298. <- "\\x" hex hex
  299. / "\\u{" hex+ "}"
  300. / "\\" [nr\\t'"]
  301. char_char
  302. <- mb_utf8_literal
  303. / char_escape
  304. / ascii_char_not_nl_slash_squote
  305. string_char
  306. <- char_escape
  307. / [^\\"\n]
  308. container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+
  309. doc_comment <- ('///' [^\n]* [ \n]* skip)+
  310. line_comment <- '//' ![!/][^\n]* / '////' [^\n]*
  311. line_string <- ("\\\\" [^\n]* [ \n]*)+
  312. skip <- ([ \n] / line_comment)*
  313. CHAR_LITERAL <- "'" char_char "'" skip
  314. FLOAT
  315. <- "0x" hex_int "." hex_int ([pP] [-+]? dec_int)? skip
  316. / dec_int "." dec_int ([eE] [-+]? dec_int)? skip
  317. / "0x" hex_int [pP] [-+]? dec_int skip
  318. / dec_int [eE] [-+]? dec_int skip
  319. INTEGER
  320. <- "0b" bin_int skip
  321. / "0o" oct_int skip
  322. / "0x" hex_int skip
  323. / dec_int skip
  324. STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
  325. STRINGLITERAL
  326. <- STRINGLITERALSINGLE
  327. / (line_string skip)+
  328. IDENTIFIER
  329. <- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
  330. / "@\"" string_char* "\"" skip
  331. BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
  332. AMPERSAND <- '&' ![=] skip
  333. AMPERSANDEQUAL <- '&=' skip
  334. ASTERISK <- '*' ![*%=|] skip
  335. ASTERISK2 <- '**' skip
  336. ASTERISKEQUAL <- '*=' skip
  337. ASTERISKPERCENT <- '*%' ![=] skip
  338. ASTERISKPERCENTEQUAL <- '*%=' skip
  339. ASTERISKPIPE <- '*|' ![=] skip
  340. ASTERISKPIPEEQUAL <- '*|=' skip
  341. CARET <- '^' ![=] skip
  342. CARETEQUAL <- '^=' skip
  343. COLON <- ':' skip
  344. COMMA <- ',' skip
  345. DOT <- '.' ![*.?] skip
  346. DOT2 <- '..' ![.] skip
  347. DOT3 <- '...' skip
  348. DOTASTERISK <- '.*' skip
  349. DOTQUESTIONMARK <- '.?' skip
  350. EQUAL <- '=' ![>=] skip
  351. EQUALEQUAL <- '==' skip
  352. EQUALRARROW <- '=>' skip
  353. EXCLAMATIONMARK <- '!' ![=] skip
  354. EXCLAMATIONMARKEQUAL <- '!=' skip
  355. LARROW <- '<' ![<=] skip
  356. LARROW2 <- '<<' ![=|] skip
  357. LARROW2EQUAL <- '<<=' skip
  358. LARROW2PIPE <- '<<|' ![=] skip
  359. LARROW2PIPEEQUAL <- '<<|=' skip
  360. LARROWEQUAL <- '<=' skip
  361. LBRACE <- '{' skip
  362. LBRACKET <- '[' skip
  363. LPAREN <- '(' skip
  364. MINUS <- '-' ![%=>|] skip
  365. MINUSEQUAL <- '-=' skip
  366. MINUSPERCENT <- '-%' ![=] skip
  367. MINUSPERCENTEQUAL <- '-%=' skip
  368. MINUSPIPE <- '-|' ![=] skip
  369. MINUSPIPEEQUAL <- '-|=' skip
  370. MINUSRARROW <- '->' skip
  371. PERCENT <- '%' ![=] skip
  372. PERCENTEQUAL <- '%=' skip
  373. PIPE <- '|' ![|=] skip
  374. PIPE2 <- '||' skip
  375. PIPEEQUAL <- '|=' skip
  376. PLUS <- '+' ![%+=|] skip
  377. PLUS2 <- '++' skip
  378. PLUSEQUAL <- '+=' skip
  379. PLUSPERCENT <- '+%' ![=] skip
  380. PLUSPERCENTEQUAL <- '+%=' skip
  381. PLUSPIPE <- '+|' ![=] skip
  382. PLUSPIPEEQUAL <- '+|=' skip
  383. LETTERC <- 'c' skip
  384. QUESTIONMARK <- '?' skip
  385. RARROW <- '>' ![>=] skip
  386. RARROW2 <- '>>' ![=] skip
  387. RARROW2EQUAL <- '>>=' skip
  388. RARROWEQUAL <- '>=' skip
  389. RBRACE <- '}' skip
  390. RBRACKET <- ']' skip
  391. RPAREN <- ')' skip
  392. SEMICOLON <- ';' skip
  393. SLASH <- '/' ![=] skip
  394. SLASHEQUAL <- '/=' skip
  395. TILDE <- '~' skip
  396. end_of_word <- ![a-zA-Z0-9_] skip
  397. KEYWORD_addrspace <- 'addrspace' end_of_word
  398. KEYWORD_align <- 'align' end_of_word
  399. KEYWORD_allowzero <- 'allowzero' end_of_word
  400. KEYWORD_and <- 'and' end_of_word
  401. KEYWORD_anyframe <- 'anyframe' end_of_word
  402. KEYWORD_anytype <- 'anytype' end_of_word
  403. KEYWORD_asm <- 'asm' end_of_word
  404. KEYWORD_async <- 'async' end_of_word
  405. KEYWORD_await <- 'await' end_of_word
  406. KEYWORD_break <- 'break' end_of_word
  407. KEYWORD_callconv <- 'callconv' end_of_word
  408. KEYWORD_catch <- 'catch' end_of_word
  409. KEYWORD_comptime <- 'comptime' end_of_word
  410. KEYWORD_const <- 'const' end_of_word
  411. KEYWORD_continue <- 'continue' end_of_word
  412. KEYWORD_defer <- 'defer' end_of_word
  413. KEYWORD_else <- 'else' end_of_word
  414. KEYWORD_enum <- 'enum' end_of_word
  415. KEYWORD_errdefer <- 'errdefer' end_of_word
  416. KEYWORD_error <- 'error' end_of_word
  417. KEYWORD_export <- 'export' end_of_word
  418. KEYWORD_extern <- 'extern' end_of_word
  419. KEYWORD_fn <- 'fn' end_of_word
  420. KEYWORD_for <- 'for' end_of_word
  421. KEYWORD_if <- 'if' end_of_word
  422. KEYWORD_inline <- 'inline' end_of_word
  423. KEYWORD_noalias <- 'noalias' end_of_word
  424. KEYWORD_nosuspend <- 'nosuspend' end_of_word
  425. KEYWORD_noinline <- 'noinline' end_of_word
  426. KEYWORD_opaque <- 'opaque' end_of_word
  427. KEYWORD_or <- 'or' end_of_word
  428. KEYWORD_orelse <- 'orelse' end_of_word
  429. KEYWORD_packed <- 'packed' end_of_word
  430. KEYWORD_pub <- 'pub' end_of_word
  431. KEYWORD_resume <- 'resume' end_of_word
  432. KEYWORD_return <- 'return' end_of_word
  433. KEYWORD_linksection <- 'linksection' end_of_word
  434. KEYWORD_struct <- 'struct' end_of_word
  435. KEYWORD_suspend <- 'suspend' end_of_word
  436. KEYWORD_switch <- 'switch' end_of_word
  437. KEYWORD_test <- 'test' end_of_word
  438. KEYWORD_threadlocal <- 'threadlocal' end_of_word
  439. KEYWORD_try <- 'try' end_of_word
  440. KEYWORD_union <- 'union' end_of_word
  441. KEYWORD_unreachable <- 'unreachable' end_of_word
  442. KEYWORD_usingnamespace <- 'usingnamespace' end_of_word
  443. KEYWORD_var <- 'var' end_of_word
  444. KEYWORD_volatile <- 'volatile' end_of_word
  445. KEYWORD_while <- 'while' end_of_word
  446. keyword <- KEYWORD_addrspace / KEYWORD_align / KEYWORD_allowzero / KEYWORD_and
  447. / KEYWORD_anyframe / KEYWORD_anytype / KEYWORD_asm / KEYWORD_async
  448. / KEYWORD_await / KEYWORD_break / KEYWORD_callconv / KEYWORD_catch
  449. / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue / KEYWORD_defer
  450. / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer / KEYWORD_error / KEYWORD_export
  451. / KEYWORD_extern / KEYWORD_fn / KEYWORD_for / KEYWORD_if
  452. / KEYWORD_inline / KEYWORD_noalias / KEYWORD_nosuspend / KEYWORD_noinline
  453. / KEYWORD_opaque / KEYWORD_or / KEYWORD_orelse / KEYWORD_packed
  454. / KEYWORD_pub / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
  455. / KEYWORD_struct / KEYWORD_suspend / KEYWORD_switch / KEYWORD_test
  456. / KEYWORD_threadlocal / KEYWORD_try / KEYWORD_union / KEYWORD_unreachable
  457. / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while

Zen

  • Communicate intent precisely.
  • Edge cases matter.
  • Favor reading code over writing code.
  • Only one obvious way to do things.
  • Runtime crashes are better than bugs.
  • Compile errors are better than runtime crashes.
  • Incremental improvements.
  • Avoid local maximums.
  • Reduce the amount one must remember.
  • Focus on code rather than style.
  • Resource allocation may fail; resource deallocation must succeed.
  • Memory is a resource.
  • Together we serve the users.