Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Commit 5fda333

Browse files
authored
Merge pull request #296 from phrwlk/docs/update-expr-bnf-grammar
docs: align expression BNF with parser syntax
2 parents 22605e2 + a32ca70 commit 5fda333

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/parser/expr.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,37 @@ use super::{
1616
//~
1717
//~ ## Expression
1818
//~
19-
//~ Backus–Naur Form (BNF) grammar:
19+
//~ Backus–Naur Form (BNF) grammar (informal):
2020
//~
2121
//~ expr ::=
22-
//~ | expr { bin_op expr }
23-
//~ | "-" expr
24-
//~ | "(" expr ")"
22+
//~ | "-" expr // arithmetic negation
23+
//~ | "!" expr // boolean negation
24+
//~ | "(" expr ")" // parenthesized expression
25+
//~ | "(" expr "," { expr } ")" // tuple declaration
26+
//~ | "[" expr { "," expr } "]" // array declaration
27+
//~ | "[" expr ";" expr "]" // repeated array initialisation
28+
//~ | "if" expr "{" expr "}" "else" "{" expr "}" // conditional expression
29+
//~ | ident // variable
30+
//~ | path // qualified variable (mod::Name)
31+
//~ | fn_call // free function call
32+
//~ | method_call // method call
33+
//~ | field_access // field access
34+
//~ | index_access // array/tuple index
35+
//~ | custom_type_init // struct-like literal
36+
//~ | string_literal
2537
//~ | numeric
26-
//~ | ident
27-
//~ | fn_call
28-
//~ | array_access
29-
//~ bin_op ::= "+" | "-" | "/" | "*" | "=="
38+
//~ | expr bin_op expr
39+
//~
40+
//~ bin_op ::= "+" | "-" | "/" | "*" | "==" | "!=" | "&&" | "||"
3041
//~ numeric ::= /[0-9]+/
3142
//~ ident ::= /[A-Za-z_][A-Za-z_0-9]*/
32-
//~ fn_call ::= ident "(" expr { "," expr } ")"
33-
//~ array_access ::= ident "[" expr "]"
43+
//~ path ::= ident "::" ident
44+
//~ fn_call ::= [ "unsafe" ] path "(" [ expr { "," expr } ] ")"
45+
//~ method_call ::= expr "." ident "(" [ expr { "," expr } ] ")"
46+
//~ field_access ::= expr "." ident
47+
//~ index_access ::= expr "[" expr "]"
48+
//~ custom_type_init ::= ident "{" ident ":" expr { "," ident ":" expr } "}"
3449
//~
35-
3650
#[derive(Debug, Clone, Serialize, Deserialize)]
3751
pub struct Expr {
3852
pub node_id: usize,

0 commit comments

Comments
 (0)