MCPcopy Create free account
hub / github.com/SeaQL/FireDBG.for.Rust / parse_body

Function parse_body

parser/src/parsing/body.rs:8–28  ·  view source on GitHub ↗

Entry point of statement and expression parsing

(syn_stmts: &[syn::Stmt])

Source from the content-addressed store, hash-verified

6
7// Entry point of statement and expression parsing
8pub(crate) fn parse_body(syn_stmts: &[syn::Stmt]) -> Vec<StmtOrExpr> {
9 syn_stmts.iter().fold(Vec::new(), |mut acc, syn_stmt| {
10 match syn_stmt {
11 // Parse `let a;` let or `let a = 1;` let assign declaration
12 syn::Stmt::Local(local) => acc.extend(local.parse_body()),
13 // Parse statements or expressions
14 // - a statement should ends with a `;`
15 // - a expression does NOT end with a `;`
16 syn::Stmt::Expr(expr, semi) => acc.extend((expr, semi).parse_body()),
17 // Parse items, we only interested in these two items
18 // - `const PI_CONST: f64 = 3.14;`
19 // - `static PI_STATIC: f64 = 3.14;`
20 syn::Stmt::Item(item) => acc.extend(item.parse_body()),
21 // Parse macro invocation, it can be a
22 // - a statement: `println!("HI");`
23 // - a expression: `format!("HI")`
24 syn::Stmt::Macro(stmt_macro) => acc.extend(stmt_macro.parse_body()),
25 }
26 acc
27 })
28}
29
30// Parse any AST into statement or expression
31pub(crate) trait ParseBody {

Callers 1

parse_bodyMethod · 0.85

Calls 2

parse_bodyMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected