MCPcopy Create free account
hub / github.com/ControlCplusControlV/Scribe / parse_yul_syntax

Function parse_yul_syntax

crates/papyrus/src/parser.rs:19–50  ·  view source on GitHub ↗

To see examples for each Expr, check out types.rs

(syntax: &str)

Source from the content-addressed store, hash-verified

17
18//To see examples for each Expr, check out types.rs
19pub fn parse_yul_syntax(syntax: &str) -> Vec<Expr> {
20 let file = IdentParser::parse(Rule::file, syntax)
21 .expect("unsuccessful parse")
22 .next()
23 .unwrap();
24
25 //Parse each statement that matches a grammar pattern inside the file, add them the to Vec<Expr> and return the Vec
26 let mut expressions: Vec<Expr> = vec![];
27 for statement in file.clone().into_inner() {
28 match statement.as_rule() {
29 Rule::statement => {
30 expressions.push(parse_statement(statement));
31 }
32
33 Rule::object => {
34 // TODO: create an object type
35 let mut parts = statement.into_inner();
36 let object_name = parts.next().unwrap();
37 dbg!(&object_name);
38 let code = parts.next().unwrap();
39 expressions.push(parse_statement(code));
40 }
41
42 Rule::EOI => (),
43 r => {
44 dbg!(&statement);
45 panic!("Unreachable rule: {:?}", r);
46 }
47 }
48 }
49 expressions
50}
51
52//Parses a Yul statement. This function matches a grammar rule and return an Expr struct
53//which is later added into the Abstract Syntax Tree

Callers 4

parse_to_treeFunction · 0.85
run_exampleFunction · 0.85
compile_exampleFunction · 0.85
write_yul_to_masmFunction · 0.85

Calls 2

parse_statementFunction · 0.85
pushMethod · 0.80

Tested by 2

run_exampleFunction · 0.68
compile_exampleFunction · 0.68