From 673d166311366090866055457a8eb128d9a34634 Mon Sep 17 00:00:00 2001 From: x Date: Mon, 17 Oct 2022 09:11:20 +0000 Subject: [PATCH] zkas: add code comments --- src/zkas/parser.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/zkas/parser.rs b/src/zkas/parser.rs index 9cb7901f5..1175f5f81 100644 --- a/src/zkas/parser.rs +++ b/src/zkas/parser.rs @@ -53,8 +53,11 @@ impl Parser { let mut contract_tokens = vec![]; let mut circuit_tokens = vec![]; + // Tokens belonging to the current statement let mut circuit_stmt = vec![]; + // All completed statements are pushed here let mut circuit_stmts = vec![]; + // Contains constant and contract sections let mut ast_inner = IndexMap::new(); let mut ast = IndexMap::new(); @@ -239,8 +242,10 @@ impl Parser { self.check_section_structure("circuit", circuit_tokens.clone()); check_namespace!(circuit_tokens); + // Grab tokens for each statement for i in circuit_tokens[2..circuit_tokens.len() - 1].iter() { if i.token_type == TokenType::Semicolon { + // Push completed statement to the stack circuit_stmts.push(circuit_stmt.clone()); circuit_stmt = vec![]; continue @@ -253,6 +258,8 @@ impl Parser { } } + // Tokens have been processed and ast is complete + let ns = namespace.unwrap(); ast.insert(ns.clone(), ast_inner); @@ -286,6 +293,7 @@ impl Parser { (ns, constants, witnesses, statements) } + /// Routine checks on section structure fn check_section_structure(&self, section: &str, tokens: Vec) { if tokens[0].token_type != TokenType::String { self.error.abort( @@ -338,7 +346,7 @@ impl Parser { ); } } - _ => panic!(), + _ => unreachable!(), }; }