From 5f669059a8466dc98ad35563e61fdf93b9bdf1df Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sat, 9 Nov 2024 15:01:55 +0700 Subject: [PATCH 01/71] skip trivial first tokens in parsing --- crates/parser/src/grammar.rs | 12 ++ crates/parser/src/input.rs | 48 ++++- crates/parser/src/parser.rs | 2 +- crates/parser/src/token_kind.rs | 4 +- crates/syntax/src/lib.rs | 2 + crates/syntax/src/syntax.rs | 330 ++++++++++++++++++----------- crates/syntax/src/test_programs.rs | 135 ++++++++++++ 7 files changed, 402 insertions(+), 131 deletions(-) create mode 100644 crates/syntax/src/test_programs.rs diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 63d498f..98832cc 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -18,10 +18,22 @@ mod template; pub mod entry { + use crate::token_kind::TokenKind; + use super::*; pub fn circom_program(p: &mut Parser) { let m = p.open(); + + while p.at_any(&[ + TokenKind::BlockComment, + TokenKind::CommentLine, + TokenKind::EndLine, + TokenKind::WhiteSpace, + ]) { + p.skip(); + } + pragma::pragma(p); while !p.eof() { match p.current() { diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index 0819515..c8e17c8 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -4,7 +4,7 @@ use logos::Lexer; use crate::token_kind::TokenKind; -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct Input<'a> { kind: Vec, source: &'a str, @@ -71,7 +71,9 @@ impl<'a> Input<'a> { #[cfg(test)] mod tests { - use std::cmp::min; + // use std::cmp::min; + + use crate::token_kind::TokenKind; use super::Input; @@ -83,11 +85,45 @@ mod tests { "# .to_string(); + let expected_input = Input { + kind: vec![ + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::BlockComment, + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::Identifier, + TokenKind::WhiteSpace, + TokenKind::Add, + TokenKind::WhiteSpace, + TokenKind::Number, + TokenKind::EndLine, + TokenKind::WhiteSpace + ], + source: &source, + position: vec![ + {0..1}, + {1..9}, + {9..24}, + {24..25}, + {25..33}, + {33..34}, + {34..35}, + {35..36}, + {36..37}, + {37..39}, + {39..40}, + {40..44}, + ] + }; + let input = Input::new(&source); - for i in 0..min(input.size(), 10) { - println!("kind = {:?}", input.kind[i]); - println!("position {:?}", input.position[i]); - } + assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); + + // for i in 0..min(input.size(), 10) { + // println!("kind = {:?}", input.kind[i]); + // println!("position {:?}", input.position[i]); + // } } } diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index e3d461c..23c4dde 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -113,7 +113,7 @@ impl<'a> Parser<'a> { let mut kind: TokenKind; loop { kind = self.input.kind_of(self.pos); - if !kind.is_travial() { + if !kind.is_trivial() { break; } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 300028f..26145bf 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -248,10 +248,10 @@ impl TokenKind { pub fn is_declaration_kw(self) -> bool { matches!(self, Self::VarKw | Self::ComponentKw | Self::SignalKw) } - pub fn is_travial(self) -> bool { + pub fn is_trivial(self) -> bool { matches!( self, - Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::Error + Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error ) } } diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 7ca0f92..adeb8b0 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -2,3 +2,5 @@ pub mod syntax; pub mod syntax_node; pub mod abstract_syntax_tree; + +pub mod test_programs; \ No newline at end of file diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 78c0ab2..3483b61 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -45,8 +45,10 @@ impl<'a> SyntaxTreeBuilder<'a> { pub fn syntax_tree(source: &str) -> SyntaxNode { let input = Input::new(source); - let mut builder = SyntaxTreeBuilder::new(&input); + let output = Parser::parsing(&input); + + let mut builder = SyntaxTreeBuilder::new(&input); builder.build(output); let green = builder.finish(); SyntaxNode::new_root(green) @@ -55,35 +57,127 @@ impl<'a> SyntaxTreeBuilder<'a> { #[cfg(test)] mod tests { - + use parser::token_kind::TokenKind::{self, *}; use std::hash::{DefaultHasher, Hash, Hasher}; - use rowan::ast::AstNode; + use rowan::{ast::AstNode, TextRange}; - use crate::abstract_syntax_tree::AstCircomProgram; + use crate::{abstract_syntax_tree::AstCircomProgram, test_programs}; use super::SyntaxTreeBuilder; + fn generate_expected_token_kind(ast: &AstCircomProgram) { + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next); + + println!("vec!["); + for child in children { + println!("{:?},", child.kind()); + } + println!("];"); + } + + fn generate_expected_token_range(ast: &AstCircomProgram) { + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next); + + println!("vec!["); + for child in children { + println!( + "TextRange::new({:?}.into(), {:?}.into()), ", + child.text_range().start(), + child.text_range().end() + ); + } + println!("];"); + } + + fn check_ast_children( + ast: &AstCircomProgram, + expected_kinds: &Vec, + expected_ranges: &Vec, + ) { + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next); + + let mut kind_iterator = expected_kinds.iter(); + let mut range_iterator = expected_ranges.iter(); + + for child in children { + if let (Some(expected_kind), Some(expected_range)) = + (kind_iterator.next(), range_iterator.next()) + { + assert_eq!(child.kind(), *expected_kind); + assert_eq!(child.text_range(), *expected_range); + } else { + panic!("Mismatched number of children and expected values"); + } + } + println!(); + } + #[test] - fn other_parser_test() { - let source: String = r#"pragma circom 2.0.0; + fn parser_test_1() { + let source: &str = test_programs::PARSER_TEST_1; + + let expected_pragma = "pragma circom 2.0.0;".to_string(); + let expected_kinds = vec![ + Pragma, + EndLine, + EndLine, + WhiteSpace, + EndLine, + WhiteSpace, + TemplateDef, + EndLine, + WhiteSpace, + TemplateDef, + WhiteSpace, + EndLine, + WhiteSpace, + ]; + let expected_ranges = vec![ + TextRange::new(0.into(), 20.into()), + TextRange::new(20.into(), 21.into()), + TextRange::new(21.into(), 22.into()), + TextRange::new(22.into(), 26.into()), + TextRange::new(26.into(), 27.into()), + TextRange::new(27.into(), 31.into()), + TextRange::new(31.into(), 57.into()), + TextRange::new(57.into(), 58.into()), + TextRange::new(58.into(), 62.into()), + TextRange::new(62.into(), 88.into()), + TextRange::new(88.into(), 89.into()), + TextRange::new(89.into(), 90.into()), + TextRange::new(90.into(), 94.into()), + ]; + + let syntax = SyntaxTreeBuilder::syntax_tree(source); - template Multiplier2 () {} - template Multiplier2 () {} - "# - .to_string(); + if let Some(ast) = AstCircomProgram::cast(syntax) { + check_ast_children(&ast, &expected_kinds, &expected_ranges); - let syntax = SyntaxTreeBuilder::syntax_tree(&source); + // check pragma + let pragma = ast.pragma().unwrap().syntax().text().to_string(); + assert_eq!(pragma, expected_pragma, "Pragma is not correct!"); - if let Some(ast) = AstCircomProgram::cast(syntax) { + // check ast hash let mut hasher = DefaultHasher::default(); ast.syntax().hash(&mut hasher); - // println!("{:#?}", syntax); - println!("{:?}", hasher.finish()); + let _ast_hash = hasher.finish(); + // check template hash let mut h1 = DefaultHasher::default(); - let mut h2 = DefaultHasher::default(); let template = ast.template_list(); @@ -91,124 +185,116 @@ mod tests { template[0].syntax().hash(&mut h1); template[1].syntax().hash(&mut h2); - println!("{}", h1.finish()); - println!("{}", h2.finish()); - println!("{:?}", template[0].syntax().text()); - println!("{:?}", template[1].syntax().text()); - println!("{}", template[0].syntax() == template[0].syntax()); - println!( - "{}", - template[0].syntax().green() == template[1].syntax().green() + assert_ne!( + h1.finish(), + h2.finish(), + "Templates with same syntax should have different hashes!" + ); + + // check template syntax (text & green node) + assert_eq!( + template[0].syntax().text(), + template[1].syntax().text(), + "The syntax (as text) of template 1 and 2 must be the same!" + ); + assert_eq!( + template[0].syntax().green(), + template[1].syntax().green(), + "The syntax (as green node) of template 1 and 2 must be the same!!" ); } + } + + #[test] + fn parser_test_2() { + let source = test_programs::PARSER_TEST_2; + + let syntax = SyntaxTreeBuilder::syntax_tree(source); + + if let Some(ast) = AstCircomProgram::cast(syntax) { + // print_ast_children(&ast); + + println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); - // find token + print!("Templates: "); + let templates = ast.template_list(); + for template in templates.iter() { + // print!("{:?} ", template.name().unwrap().name().unwrap().syntax().text()); + print!("{:?} ", template.name().unwrap().syntax().text()); // leading whitespaces + // print!("{:?} ", template.syntax().text()); // leading whitespaces + } + println!(); + + print!("Functions: "); + let functions = ast.function_list(); + for function in functions.iter() { + print!("{:?} ", function.function_name().unwrap().syntax().text()); + // leading whitespaces + // print!("{:?} ", function.syntax().text()); // leading whitespaces + } + println!(); + } } #[test] - fn parser_test() { - let source = r#"/* - Copyright 2018 0KIMS association. - - This file is part of circom (Zero Knowledge Circuit Compiler). - - circom is a free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - circom is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU General Public License - along with circom. If not, see . - */ - /* - - Binary Sum - ========== - - This component creates a binary sum componet of ops operands and n bits each operand. - - e is Number of carries: Depends on the number of operands in the input. - - Main Constraint: - in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + - + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + - + .. - + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) + - === - out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1) - - To waranty binary outputs: - - out[0] * (out[0] - 1) === 0 - out[1] * (out[0] - 1) === 0 - . - . - . - out[n+e-1] * (out[n+e-1] - 1) == 0 - - */ - - - /* - This function calculates the number of extra bits in the output to do the full sum. - */ - pragma circom 2.0.0; - - function nbits(a) { - var n = 1; - var r = 0; - while (n-1> k) & 1; - - // Ensure out is binary - out[k] * (out[k] - 1) === 0; - - lout += out[k] * e2; - - e2 = e2+e2; + } + + #[test] + fn parser_test_5() { + let source = test_programs::PARSER_TEST_5; + + let syntax = SyntaxTreeBuilder::syntax_tree(source); + + if let Some(ast) = AstCircomProgram::cast(syntax) { + // print_ast_children(&ast); + + println!("{:?}", ast.pragma()); + // assert!(ast.pragma().is_none(), "No pragma in source code"); } - - // Ensure the sum; - - lin === lout; } - "#; - let _syntax = SyntaxTreeBuilder::syntax_tree(source); + #[test] + fn parser_test_6() { + let source = test_programs::PARSER_TEST_6; + + let syntax = SyntaxTreeBuilder::syntax_tree(source); + + if let Some(ast) = AstCircomProgram::cast(syntax) { + // print_ast_children(&ast); + + println!("{:?}", ast.pragma()); + // assert!(ast.pragma().is_none(), "No pragma in source code"); + } } } diff --git a/crates/syntax/src/test_programs.rs b/crates/syntax/src/test_programs.rs new file mode 100644 index 0000000..0879679 --- /dev/null +++ b/crates/syntax/src/test_programs.rs @@ -0,0 +1,135 @@ +pub const PARSER_TEST_1: &str = r#"pragma circom 2.0.0; + + + template Multiplier2 () {} + template Multiplier2 () {} + "#; + +pub const PARSER_TEST_2: &str = r#"/* + Copyright 2018 0KIMS association. + + This file is part of circom (Zero Knowledge Circuit Compiler). + + circom is a free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + circom is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with circom. If not, see . +*/ +/* + +Binary Sum +========== + +This component creates a binary sum componet of ops operands and n bits each operand. + +e is Number of carries: Depends on the number of operands in the input. + +Main Constraint: + in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + + + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + + + .. + + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) + + === + out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1) + +To waranty binary outputs: + + out[0] * (out[0] - 1) === 0 + out[1] * (out[0] - 1) === 0 + . + . + . + out[n+e-1] * (out[n+e-1] - 1) == 0 + + */ + + +/* + This function calculates the number of extra bits in the output to do the full sum. + */ + pragma circom 2.0.0; + +function nbits(a) { + var n = 1; + var r = 0; + while (n-1> k) & 1; + + // Ensure out is binary + out[k] * (out[k] - 1) === 0; + + lout += out[k] * e2; + + e2 = e2+e2; + } + + // Ensure the sum; + + lin === lout; + } + "#; + +pub const PARSER_TEST_3: &str = r#" + +// comment :> + + pragma circom 2.0.0; + + "#; + +pub const PARSER_TEST_4: &str = r#" + +/* +comment +blocks +*/ +pragma circom 2.0.0; + "#; + +pub const PARSER_TEST_5: &str = r#" +// no pragma here + template Multiplier2 () {} + "#; + +pub const PARSER_TEST_6: &str = r#" +/* T _ T */ + template Multiplier2 () {} + "#; + \ No newline at end of file From 6913c55cf23105829d5cf8f4b956f38775d17546 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Wed, 13 Nov 2024 13:20:34 +0700 Subject: [PATCH 02/71] remove comment in input test --- crates/parser/src/input.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index c8e17c8..cdfd5d8 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -120,10 +120,5 @@ mod tests { let input = Input::new(&source); assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); - - // for i in 0..min(input.size(), 10) { - // println!("kind = {:?}", input.kind[i]); - // println!("position {:?}", input.position[i]); - // } } } From caac481857e878c4dd3113c2ca2e8c1d345d1dd7 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 18 Nov 2024 19:55:59 +0700 Subject: [PATCH 03/71] manage out-of-bound case, update input test --- crates/parser/src/input.rs | 297 +++++++++++++++++++++---------------- 1 file changed, 173 insertions(+), 124 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index cdfd5d8..bb37613 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -1,124 +1,173 @@ -use std::ops::Range; - -use logos::Lexer; - -use crate::token_kind::TokenKind; - -#[derive(Debug, PartialEq)] -pub struct Input<'a> { - kind: Vec, - source: &'a str, - position: Vec>, -} - -impl<'a> Input<'a> { - pub fn new(source: &'a str) -> Self { - let mut input = Input { - source, - kind: Vec::new(), - position: Vec::new(), - }; - - let mut lex = Lexer::::new(source); - - while let Some(tk) = lex.next() { - if tk == TokenKind::CommentBlockOpen { - let mut closed = false; - let mut join_span = lex.span(); - while let Some(t) = lex.next() { - join_span.end = lex.span().end; - if t == TokenKind::CommentBlockClose { - closed = true; - break; - } - } - - if closed { - input.kind.push(TokenKind::BlockComment); - } else { - input.kind.push(TokenKind::Error); - } - input.position.push(join_span); - } else { - input.kind.push(tk); - input.position.push(lex.span()); - } - } - - input - } - - pub fn token_value(&self, index: usize) -> &'a str { - &self.source[self.position[index].start..self.position[index].end] - } - - pub fn kind_of(&self, index: usize) -> TokenKind { - if index < self.kind.len() { - self.kind[index] - } else { - TokenKind::EOF - } - } - - pub fn position_of(&self, index: usize) -> Range { - self.position[index].clone() - } - - pub fn size(&self) -> usize { - self.kind.len() - } -} - -#[cfg(test)] -mod tests { - // use std::cmp::min; - - use crate::token_kind::TokenKind; - - use super::Input; - - #[test] - fn test_input() { - let source = r#" - /*a + b == 10*/ - a + 10 - "# - .to_string(); - - let expected_input = Input { - kind: vec![ - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::BlockComment, - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::Identifier, - TokenKind::WhiteSpace, - TokenKind::Add, - TokenKind::WhiteSpace, - TokenKind::Number, - TokenKind::EndLine, - TokenKind::WhiteSpace - ], - source: &source, - position: vec![ - {0..1}, - {1..9}, - {9..24}, - {24..25}, - {25..33}, - {33..34}, - {34..35}, - {35..36}, - {36..37}, - {37..39}, - {39..40}, - {40..44}, - ] - }; - - let input = Input::new(&source); - - assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); - } -} +use std::ops::Range; + +use logos::Lexer; + +use crate::token_kind::TokenKind; + +#[derive(Debug, PartialEq)] +pub struct Input<'a> { + kind: Vec, + source: &'a str, + position: Vec>, +} + +impl<'a> Input<'a> { + pub fn new(source: &'a str) -> Self { + let mut input = Input { + source, + kind: Vec::new(), + position: Vec::new(), + }; + + let mut lex = Lexer::::new(source); + + while let Some(tk) = lex.next() { + if tk == TokenKind::CommentBlockOpen { + let mut closed = false; + let mut join_span = lex.span(); + while let Some(t) = lex.next() { + join_span.end = lex.span().end; + if t == TokenKind::CommentBlockClose { + closed = true; + break; + } + } + + if closed { + input.kind.push(TokenKind::BlockComment); + } else { + input.kind.push(TokenKind::Error); + } + input.position.push(join_span); + } else { + input.kind.push(tk); + input.position.push(lex.span()); + } + } + + input + } + + pub fn token_value(&self, index: usize) -> &'a str { + if index < self.kind.len() { + &self.source[self.position[index].start..self.position[index].end] + } else { + // return error for out of bound index + "" + } + } + + pub fn kind_of(&self, index: usize) -> TokenKind { + if index < self.kind.len() { + self.kind[index] + } else { + TokenKind::EOF + } + } + + pub fn position_of(&self, index: usize) -> Range { + if index < self.kind.len() { + self.position[index].clone() + } else { + // return error for out of bound index + 0..0 + } + + } + + pub fn size(&self) -> usize { + self.kind.len() + } +} + +#[cfg(test)] +mod tests { + use crate::token_kind::TokenKind; + + use super::Input; + + #[test] + fn test_input() { + let source = r#" + /*a + b == 10*/ + a + 10 + "# + .to_string(); + + let expected_input = Input { + kind: vec![ + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::BlockComment, + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::Identifier, + TokenKind::WhiteSpace, + TokenKind::Add, + TokenKind::WhiteSpace, + TokenKind::Number, + TokenKind::EndLine, + TokenKind::WhiteSpace + ], + source: &source, + position: vec![ + {0..1}, + {1..9}, + {9..24}, + {24..25}, + {25..33}, + {33..34}, + {34..35}, + {35..36}, + {36..37}, + {37..39}, + {39..40}, + {40..44}, + ] + }; + + let input = Input::new(&source); + + assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); + + // test size method + let expected_size = input.kind.len(); + let size = input.size(); + assert_eq!(expected_size, size, "size method failed"); + + // test methods with index out of bound + let index = input.kind.len(); + + let expected_token_value = ""; + let token_value = input.token_value(index); + assert_eq!(expected_token_value, token_value, "token_value failed (case: index out of bound)"); + + let expected_kind = TokenKind::EOF; + let kind = input.kind_of(index); + assert_eq!(expected_kind, kind, "kind_of failed (case: index out of bound)"); + + let expected_position = 0..0; + let position = input.position_of(index); + assert_eq!(expected_position, position, "position_of failed (case: index out of bound)"); + + // test methods with index in bound + if input.size() == 0 { + return; + } + + let index = input.size() / 2; // a valid index if input size > 0 + + let expected_token_value = &input.source[input.position[index].clone()]; + let token_value = input.token_value(index); + assert_eq!(expected_token_value, token_value, "token_value failed"); + + let expected_kind = input.kind[index]; + let kind = input.kind_of(index); + assert_eq!(expected_kind, kind, "kind_of failed"); + + let expected_position = input.position[index].clone(); + let position = input.position_of(index); + assert_eq!(expected_position, position, "position_of failed"); + + } +} From 8efa4f70d57a52e24b92ed4c5002ec339ed77095 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 18 Nov 2024 21:30:38 +0700 Subject: [PATCH 04/71] update input test --- crates/parser/src/input.rs | 145 +++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 22 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index bb37613..ebc1b9e 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -72,7 +72,6 @@ impl<'a> Input<'a> { // return error for out of bound index 0..0 } - } pub fn size(&self) -> usize { @@ -87,7 +86,7 @@ mod tests { use super::Input; #[test] - fn test_input() { + fn test_input_1() { let source = r#" /*a + b == 10*/ a + 10 @@ -107,27 +106,121 @@ mod tests { TokenKind::WhiteSpace, TokenKind::Number, TokenKind::EndLine, - TokenKind::WhiteSpace + TokenKind::WhiteSpace, ], source: &source, position: vec![ - {0..1}, - {1..9}, - {9..24}, - {24..25}, - {25..33}, - {33..34}, - {34..35}, - {35..36}, - {36..37}, - {37..39}, - {39..40}, - {40..44}, - ] + { 0..1 }, + { 1..9 }, + { 9..24 }, + { 24..25 }, + { 25..33 }, + { 33..34 }, + { 34..35 }, + { 35..36 }, + { 36..37 }, + { 37..39 }, + { 39..40 }, + { 40..44 }, + ], }; let input = Input::new(&source); + assert_eq!( + expected_input, input, + "Tokens extract from source code are not correct" + ); + + // test size method + let expected_size = input.kind.len(); + let size = input.size(); + assert_eq!(expected_size, size, "size method failed"); + + // test methods with index out of bound + let index = input.kind.len(); + + let expected_token_value = ""; + let token_value = input.token_value(index); + assert_eq!( + expected_token_value, token_value, + "token_value failed (case: index out of bound)" + ); + + let expected_kind = TokenKind::EOF; + let kind = input.kind_of(index); + assert_eq!( + expected_kind, kind, + "kind_of failed (case: index out of bound)" + ); + + let expected_position = 0..0; + let position = input.position_of(index); + assert_eq!( + expected_position, position, + "position_of failed (case: index out of bound)" + ); + + // test methods with index in bound + if input.size() == 0 { + return; + } + + let index = input.size() / 2; // a valid index if input size > 0 + + let expected_token_value = &input.source[input.position[index].clone()]; + let token_value = input.token_value(index); + assert_eq!(expected_token_value, token_value, "token_value failed"); + + let expected_kind = input.kind[index]; + let kind = input.kind_of(index); + assert_eq!(expected_kind, kind, "kind_of failed"); + + let expected_position = input.position[index].clone(); + let position = input.position_of(index); + assert_eq!(expected_position, position, "position_of failed"); + } + + #[test] + fn test_input_2() { + let source = r#" + pragma 2.1.1; + /*a + b == 10* + a + 10 + template + + /* + "# + .to_string(); + + let expected_input = Input { + kind: vec![ + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::Pragma, + TokenKind::WhiteSpace, + TokenKind::Version, + TokenKind::Semicolon, + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::Error, + ], + source: &source, + position: vec![ + 0..1, + 1..9, + 9..15, + 15..16, + 16..21, + 21..22, + 22..23, + 23..31, + 31..94, + ], + }; + + let input = Input::new(&source); + assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); // test size method @@ -140,15 +233,24 @@ mod tests { let expected_token_value = ""; let token_value = input.token_value(index); - assert_eq!(expected_token_value, token_value, "token_value failed (case: index out of bound)"); + assert_eq!( + expected_token_value, token_value, + "token_value failed (case: index out of bound)" + ); let expected_kind = TokenKind::EOF; let kind = input.kind_of(index); - assert_eq!(expected_kind, kind, "kind_of failed (case: index out of bound)"); + assert_eq!( + expected_kind, kind, + "kind_of failed (case: index out of bound)" + ); let expected_position = 0..0; let position = input.position_of(index); - assert_eq!(expected_position, position, "position_of failed (case: index out of bound)"); + assert_eq!( + expected_position, position, + "position_of failed (case: index out of bound)" + ); // test methods with index in bound if input.size() == 0 { @@ -156,7 +258,7 @@ mod tests { } let index = input.size() / 2; // a valid index if input size > 0 - + let expected_token_value = &input.source[input.position[index].clone()]; let token_value = input.token_value(index); assert_eq!(expected_token_value, token_value, "token_value failed"); @@ -164,10 +266,9 @@ mod tests { let expected_kind = input.kind[index]; let kind = input.kind_of(index); assert_eq!(expected_kind, kind, "kind_of failed"); - + let expected_position = input.position[index].clone(); let position = input.position_of(index); assert_eq!(expected_position, position, "position_of failed"); - } } From c78761e2ae8378241608491964f93f81ac160b9b Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 6 Dec 2024 21:25:09 +0700 Subject: [PATCH 05/71] update input test --- crates/parser/src/input.rs | 285 ++++++++++++++++++++++---------- crates/parser/src/token_kind.rs | 3 + crates/syntax/src/syntax.rs | 12 +- 3 files changed, 209 insertions(+), 91 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index ebc1b9e..4b1cc55 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -81,50 +81,11 @@ impl<'a> Input<'a> { #[cfg(test)] mod tests { - use crate::token_kind::TokenKind; + use crate::token_kind::TokenKind::{self, *}; use super::Input; - #[test] - fn test_input_1() { - let source = r#" - /*a + b == 10*/ - a + 10 - "# - .to_string(); - - let expected_input = Input { - kind: vec![ - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::BlockComment, - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::Identifier, - TokenKind::WhiteSpace, - TokenKind::Add, - TokenKind::WhiteSpace, - TokenKind::Number, - TokenKind::EndLine, - TokenKind::WhiteSpace, - ], - source: &source, - position: vec![ - { 0..1 }, - { 1..9 }, - { 9..24 }, - { 24..25 }, - { 25..33 }, - { 33..34 }, - { 34..35 }, - { 35..36 }, - { 36..37 }, - { 37..39 }, - { 39..40 }, - { 40..44 }, - ], - }; - + fn test(source: &str, expected_input: Input) { let input = Input::new(&source); assert_eq!( @@ -182,7 +143,49 @@ mod tests { } #[test] - fn test_input_2() { + fn test_comment_block() { + let source = r#" + /*a + b == 10*/ + a + 10 + "#; + + let expected_input = Input { + kind: vec![ + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::BlockComment, + TokenKind::EndLine, + TokenKind::WhiteSpace, + TokenKind::Identifier, + TokenKind::WhiteSpace, + TokenKind::Add, + TokenKind::WhiteSpace, + TokenKind::Number, + TokenKind::EndLine, + TokenKind::WhiteSpace, + ], + source: &source, + position: vec![ + { 0..1 }, + { 1..9 }, + { 9..24 }, + { 24..25 }, + { 25..33 }, + { 33..34 }, + { 34..35 }, + { 35..36 }, + { 36..37 }, + { 37..39 }, + { 39..40 }, + { 40..44 }, + ], + }; + + test(source, expected_input); + } + + #[test] + fn test_comment_error() { let source = r#" pragma 2.1.1; /*a + b == 10* @@ -190,8 +193,7 @@ mod tests { template /* - "# - .to_string(); + "#; let expected_input = Input { kind: vec![ @@ -219,56 +221,169 @@ mod tests { ], }; - let input = Input::new(&source); + test(source, expected_input); + } - assert_eq!(expected_input, input, "Tokens extract from source code are not correct"); + #[test] + fn test_pragma() { + let source = r#" + /* test pragma token kinds */ - // test size method - let expected_size = input.kind.len(); - let size = input.size(); - assert_eq!(expected_size, size, "size method failed"); + pragma circom 2.0.0; - // test methods with index out of bound - let index = input.kind.len(); + "#; - let expected_token_value = ""; - let token_value = input.token_value(index); - assert_eq!( - expected_token_value, token_value, - "token_value failed (case: index out of bound)" - ); - - let expected_kind = TokenKind::EOF; - let kind = input.kind_of(index); - assert_eq!( - expected_kind, kind, - "kind_of failed (case: index out of bound)" - ); + let expected_input = Input { + kind: vec![ + EndLine, + WhiteSpace, + BlockComment, + EndLine, + EndLine, + WhiteSpace, + Pragma, + WhiteSpace, + Circom, + WhiteSpace, + Version, + Semicolon, + EndLine, + EndLine, + WhiteSpace, + ], + source: &source, + position: vec![ + 0..1, + 1..9, + 9..38, + 38..39, + 39..40, + 40..44, + 44..50, + 50..51, + 51..57, + 57..58, + 58..63, + 63..64, + 64..65, + 65..66, + 66..70, + ], + }; - let expected_position = 0..0; - let position = input.position_of(index); - assert_eq!( - expected_position, position, - "position_of failed (case: index out of bound)" - ); + test(source, expected_input); + } - // test methods with index in bound - if input.size() == 0 { - return; + #[test] + fn test_function() { + let source = r#" + function nbits(a) { + var n = 1; + var r = 0; + while (n-1 0 + let expected_input = Input { + kind: vec![ + EndLine, WhiteSpace, FunctionKw, WhiteSpace, Identifier, LParen, Identifier, + RParen, WhiteSpace, LCurly, EndLine, WhiteSpace, VarKw, WhiteSpace, Identifier, + WhiteSpace, Assign, WhiteSpace, Number, Semicolon, EndLine, WhiteSpace, VarKw, + WhiteSpace, Identifier, WhiteSpace, Assign, WhiteSpace, Number, Semicolon, EndLine, + WhiteSpace, WhileKw, WhiteSpace, LParen, Identifier, Sub, Number, LessThan, + Identifier, RParen, WhiteSpace, LCurly, EndLine, WhiteSpace, Identifier, Add, Add, + Semicolon, EndLine, WhiteSpace, Identifier, WhiteSpace, Mul, Assign, WhiteSpace, + Number, Semicolon, EndLine, WhiteSpace, RCurly, EndLine, WhiteSpace, ReturnKw, + WhiteSpace, Identifier, Semicolon, EndLine, WhiteSpace, RCurly, + ], + source: &source, + position: vec![ + 0..1, + 1..5, + 5..13, + 13..14, + 14..19, + 19..20, + 20..21, + 21..22, + 22..23, + 23..24, + 24..25, + 25..33, + 33..36, + 36..37, + 37..38, + 38..39, + 39..40, + 40..41, + 41..42, + 42..43, + 43..44, + 44..52, + 52..55, + 55..56, + 56..57, + 57..58, + 58..59, + 59..60, + 60..61, + 61..62, + 62..63, + 63..71, + 71..76, + 76..77, + 77..78, + 78..79, + 79..80, + 80..81, + 81..82, + 82..83, + 83..84, + 84..85, + 85..86, + 86..87, + 87..99, + 99..100, + 100..101, + 101..102, + 102..103, + 103..104, + 104..116, + 116..117, + 117..118, + 118..119, + 119..120, + 120..121, + 121..122, + 122..123, + 123..124, + 124..132, + 132..133, + 133..134, + 134..142, + 142..148, + 148..149, + 149..150, + 150..151, + 151..152, + 152..156, + 156..157, + ], + }; - let expected_token_value = &input.source[input.position[index].clone()]; - let token_value = input.token_value(index); - assert_eq!(expected_token_value, token_value, "token_value failed"); + test(source, expected_input); + } - let expected_kind = input.kind[index]; - let kind = input.kind_of(index); - assert_eq!(expected_kind, kind, "kind_of failed"); + // #[test] + // fn test_gen() { + // let source = r#" + // "#; - let expected_position = input.position[index].clone(); - let position = input.position_of(index); - assert_eq!(expected_position, position, "position_of failed"); - } + // let input = Input::new(&source); + // println!("{:?}", input.kind); + // println!("{:?}", input.position); + // } } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 26145bf..779191f 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -229,6 +229,7 @@ impl TokenKind { _ => None, } } + pub fn prefix(self) -> Option { match self { Self::Sub => Some(100), @@ -245,9 +246,11 @@ impl TokenKind { _ => None, } } + pub fn is_declaration_kw(self) -> bool { matches!(self, Self::VarKw | Self::ComponentKw | Self::SignalKw) } + pub fn is_trivial(self) -> bool { matches!( self, diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 3483b61..21b9734 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -126,7 +126,7 @@ mod tests { } #[test] - fn parser_test_1() { + fn syntax_test_1() { let source: &str = test_programs::PARSER_TEST_1; let expected_pragma = "pragma circom 2.0.0;".to_string(); @@ -206,7 +206,7 @@ mod tests { } #[test] - fn parser_test_2() { + fn syntax_test_2() { let source = test_programs::PARSER_TEST_2; let syntax = SyntaxTreeBuilder::syntax_tree(source); @@ -237,7 +237,7 @@ mod tests { } #[test] - fn parser_test_3() { + fn syntax_test_3() { let source = test_programs::PARSER_TEST_3; let syntax = SyntaxTreeBuilder::syntax_tree(source); @@ -254,7 +254,7 @@ mod tests { } #[test] - fn parser_test_4() { + fn syntax_test_4() { let source = test_programs::PARSER_TEST_4; let syntax = SyntaxTreeBuilder::syntax_tree(source); @@ -271,7 +271,7 @@ mod tests { } #[test] - fn parser_test_5() { + fn syntax_test_5() { let source = test_programs::PARSER_TEST_5; let syntax = SyntaxTreeBuilder::syntax_tree(source); @@ -285,7 +285,7 @@ mod tests { } #[test] - fn parser_test_6() { + fn syntax_test_6() { let source = test_programs::PARSER_TEST_6; let syntax = SyntaxTreeBuilder::syntax_tree(source); From bfd1f1519bba52be08a0b9032bdaa28edad5dff5 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 15:38:34 +0700 Subject: [PATCH 06/71] make test programs private --- crates/syntax/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index adeb8b0..d1300bb 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -3,4 +3,4 @@ pub mod syntax_node; pub mod abstract_syntax_tree; -pub mod test_programs; \ No newline at end of file +mod test_programs; \ No newline at end of file From e054b574fa54e0862006da06e0072a11789aa780 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 15:41:47 +0700 Subject: [PATCH 07/71] remove comments in syntax tests --- crates/syntax/src/syntax.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 21b9734..58d7194 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -277,9 +277,8 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - // print_ast_children(&ast); - - println!("{:?}", ast.pragma()); + println!("pragma: {:?}", ast.pragma()); + println!("template list: {:?}", ast.template_list()); // assert!(ast.pragma().is_none(), "No pragma in source code"); } } @@ -294,6 +293,8 @@ mod tests { // print_ast_children(&ast); println!("{:?}", ast.pragma()); + + println!("template list: {:?}", ast.template_list()); // assert!(ast.pragma().is_none(), "No pragma in source code"); } } From 15c9e5f7dfb801952f358f8e2d97036cb7928a67 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 15:45:28 +0700 Subject: [PATCH 08/71] format --- crates/parser/src/grammar.rs | 5 +++-- crates/parser/src/grammar/block.rs | 1 + crates/parser/src/grammar/declaration.rs | 3 +++ crates/parser/src/grammar/expression.rs | 1 + crates/parser/src/grammar/function.rs | 8 +++++--- crates/parser/src/grammar/include.rs | 2 +- crates/parser/src/grammar/list_identity.rs | 1 + crates/parser/src/grammar/main_component.rs | 7 +++++++ crates/parser/src/grammar/template.rs | 2 +- crates/parser/src/output.rs | 1 + crates/parser/src/token_kind.rs | 2 +- crates/syntax/src/syntax.rs | 10 ---------- 12 files changed, 25 insertions(+), 18 deletions(-) diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 98832cc..6b3791a 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -35,14 +35,15 @@ pub mod entry { } pragma::pragma(p); + while !p.eof() { match p.current() { TemplateKw => { template::template(p); - } + }, IncludeKw => { include::include(p); - } + }, ComponentKw => main_component::main_component(p), FunctionKw => function::function_parse(p), _ => { diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index 7b0f89a..5a40865 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -2,6 +2,7 @@ use super::*; pub fn block(p: &mut Parser) { p.inc_rcurly(); + if !p.at(LCurly) { p.advance_with_error("Miss {"); } else { diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 1ebbb70..8022f81 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -3,6 +3,9 @@ use super::{ *, }; +// "signal" --> None +// "signal input" --> Some(true) +// "signal output" --> Some(false) fn signal_header(p: &mut Parser) -> Option { let mut res = None; let m = p.open(); diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 8932828..8c7fad6 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -1,6 +1,7 @@ use crate::parser::Marker; use super::*; + pub(super) fn expression(p: &mut Parser) { let m = p.open(); circom_expression(p); diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index 24b60d3..fad1d44 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -1,12 +1,15 @@ use crate::grammar::*; +// fucntion name() pub fn function_parse(p: &mut Parser) { let m = p.open(); + p.expect(FunctionKw); - let fn_name_marker = p.open(); + let fn_name_marker = p.open(); p.expect(Identifier); p.close(fn_name_marker, FunctionName); + p.expect(LParen); let arg_marker = p.open(); while !p.at(RParen) && !p.eof() { @@ -15,11 +18,10 @@ pub fn function_parse(p: &mut Parser) { p.expect(Comma); } } - p.close(arg_marker, ParameterList); - p.expect(RParen); block::block(p); + p.close(m, FunctionDef); } diff --git a/crates/parser/src/grammar/include.rs b/crates/parser/src/grammar/include.rs index 7269995..d8f0ac7 100644 --- a/crates/parser/src/grammar/include.rs +++ b/crates/parser/src/grammar/include.rs @@ -2,7 +2,7 @@ use super::*; pub(super) fn include(p: &mut Parser) { // assert!(p.at(IncludeKw)); - + let m = p.open(); p.expect(IncludeKw); p.expect(CircomString); diff --git a/crates/parser/src/grammar/list_identity.rs b/crates/parser/src/grammar/list_identity.rs index 6a4effa..73f85c9 100644 --- a/crates/parser/src/grammar/list_identity.rs +++ b/crates/parser/src/grammar/list_identity.rs @@ -1,5 +1,6 @@ use super::*; +// a, b, c, d pub fn parse(p: &mut Parser) { while p.at(Identifier) && !p.eof() { p.expect(Identifier); diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index 538a73b..3f6f862 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -1,13 +1,20 @@ use super::*; +/* +component main {public [signal_list]} = tempid(v1,...,vn); + +{public [signal_list]} is optional +*/ pub fn main_component(p: &mut Parser) { p.expect(ComponentKw); p.expect(MainKw); + p.expect(LCurly); p.expect(PublicKw); p.expect(LBracket); list_identity::parse(p); p.expect(RBracket); + p.expect(Assign); expression::expression(p); } diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 9973366..9249b1f 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -1,7 +1,7 @@ use crate::grammar::*; /** * template Identifier() {content} - * + * template Identifier( param_1, ... , param_n ) { content } */ pub fn template(p: &mut Parser) { // assert!(p.at(TemplateKw)); diff --git a/crates/parser/src/output.rs b/crates/parser/src/output.rs index 0a4e07d..271c2c3 100644 --- a/crates/parser/src/output.rs +++ b/crates/parser/src/output.rs @@ -30,6 +30,7 @@ impl Output { &self.children } } + impl From> for Output { fn from(events: Vec) -> Self { let mut stack = Vec::new(); diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 779191f..9ebba15 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -229,7 +229,7 @@ impl TokenKind { _ => None, } } - + pub fn prefix(self) -> Option { match self { Self::Sub => Some(100), diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 58d7194..f44b88c 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -212,14 +212,11 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - // print_ast_children(&ast); - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); print!("Templates: "); let templates = ast.template_list(); for template in templates.iter() { - // print!("{:?} ", template.name().unwrap().name().unwrap().syntax().text()); print!("{:?} ", template.name().unwrap().syntax().text()); // leading whitespaces // print!("{:?} ", template.syntax().text()); // leading whitespaces } @@ -243,8 +240,6 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - // print_ast_children(&ast); - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); println!( "Pragma version: {:?}", @@ -260,8 +255,6 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - // print_ast_children(&ast); - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); println!( "Pragma version: {:?}", @@ -290,10 +283,7 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - // print_ast_children(&ast); - println!("{:?}", ast.pragma()); - println!("template list: {:?}", ast.template_list()); // assert!(ast.pragma().is_none(), "No pragma in source code"); } From c76246b5251954ffb6e31f34294754eb5efcd327 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 16:04:32 +0700 Subject: [PATCH 09/71] make Pragma optional, remove ROOT --- crates/parser/src/grammar.rs | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 6b3791a..a0c9f53 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -34,21 +34,14 @@ pub mod entry { p.skip(); } - pragma::pragma(p); - while !p.eof() { match p.current() { - TemplateKw => { - template::template(p); - }, - IncludeKw => { - include::include(p); - }, + Pragma => pragma::pragma(p), + TemplateKw => template::template(p), + IncludeKw => include::include(p), ComponentKw => main_component::main_component(p), FunctionKw => function::function_parse(p), - _ => { - p.advance_with_error("invalid token"); - } + _ => p.advance_with_error("invalid token"), } } p.close(m, CircomProgram); @@ -64,20 +57,10 @@ pub mod entry { impl Scope { pub fn parse(self, p: &mut Parser) { match self { - Self::Block => { - let m = p.open(); - block::block(p); - p.close(m, ROOT); - } + Self::Block => block::block(p), Self::CircomProgram => circom_program(p), - Self::Pragma => { - let m = p.open(); - pragma::pragma(p); - p.close(m, ROOT); - } - Self::Template => { - template::template(p); - } + Self::Pragma => pragma::pragma(p), + Self::Template => template::template(p), } } } From cd125abe3dee9663b84f010eeeff6775c10b08a9 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 16:07:16 +0700 Subject: [PATCH 10/71] rename close() params, use advance() in eat(), fix typo scope --- crates/parser/src/parser.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 23c4dde..a4f0efe 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -52,8 +52,8 @@ impl<'a> Parser<'a> { } } - pub fn close(&mut self, marker_close: Marker, kind: TokenKind) -> Marker { - match marker_close { + pub fn close(&mut self, marker_open: Marker, kind: TokenKind) -> Marker { + match marker_open { Marker::Open(index) => { self.events[index] = Event::Open { kind }; self.events.push(Event::Close); @@ -159,8 +159,7 @@ impl<'a> Parser<'a> { pub fn eat(&mut self, kind: TokenKind) -> bool { if self.at(kind) { - self.events.push(Event::TokenPosition(self.pos)); - self.skip(); + self.advance(); return true; } false @@ -193,7 +192,7 @@ impl<'a> Parser<'a> { } impl Parser<'_> { - pub fn parsing_with_scrope(input: &Input, scope: Scope) -> Output { + pub fn parsing_with_scope(input: &Input, scope: Scope) -> Output { let mut p = Parser::new(input); scope.parse(&mut p); Output::from(p.events) @@ -201,6 +200,6 @@ impl Parser<'_> { pub fn parsing(input: &Input) -> Output { let c = Scope::CircomProgram; - Parser::parsing_with_scrope(input, c) + Parser::parsing_with_scope(input, c) } } From 15470b1035bf20a855ae0be0d83f74ed275e2311 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 8 Dec 2024 16:08:12 +0700 Subject: [PATCH 11/71] parse params using list_identity --- crates/parser/src/grammar/function.rs | 7 +------ crates/parser/src/grammar/template.rs | 12 +++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index fad1d44..bca7018 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -12,12 +12,7 @@ pub fn function_parse(p: &mut Parser) { p.expect(LParen); let arg_marker = p.open(); - while !p.at(RParen) && !p.eof() { - p.expect(Identifier); - if p.at(Comma) { - p.expect(Comma); - } - } + list_identity::parse(p); p.close(arg_marker, ParameterList); p.expect(RParen); diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 9249b1f..be5f17e 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -6,23 +6,21 @@ use crate::grammar::*; pub fn template(p: &mut Parser) { // assert!(p.at(TemplateKw)); let m = p.open(); + p.expect(TemplateKw); + let name_marker = p.open(); p.expect(Identifier); p.close(name_marker, TemplateName); p.expect(LParen); let arg_marker = p.open(); - while !p.at(RParen) && !p.eof() { - p.expect(Identifier); - if p.at(Comma) { - p.expect(Comma); - } - } - + list_identity::parse(p); p.close(arg_marker, ParameterList); p.expect(RParen); + block::block(p); + p.close(m, TemplateDef); } From 6dbb51a333ccc075c49a609895bce1a32b5c7041 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 10 Dec 2024 22:40:00 +0700 Subject: [PATCH 12/71] return Option in token_value() and position_of() --- crates/parser/src/input.rs | 22 +++++++++++----------- crates/syntax/src/syntax.rs | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index 4b1cc55..8ddf602 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -48,12 +48,12 @@ impl<'a> Input<'a> { input } - pub fn token_value(&self, index: usize) -> &'a str { + pub fn token_value(&self, index: usize) -> Option<&'a str> { if index < self.kind.len() { - &self.source[self.position[index].start..self.position[index].end] + Some(&self.source[self.position[index].start..self.position[index].end]) } else { - // return error for out of bound index - "" + // return None for out of bound index + None } } @@ -65,12 +65,12 @@ impl<'a> Input<'a> { } } - pub fn position_of(&self, index: usize) -> Range { + pub fn position_of(&self, index: usize) -> Option> { if index < self.kind.len() { - self.position[index].clone() + Some(self.position[index].clone()) } else { // return error for out of bound index - 0..0 + None } } @@ -101,7 +101,7 @@ mod tests { // test methods with index out of bound let index = input.kind.len(); - let expected_token_value = ""; + let expected_token_value = None; let token_value = input.token_value(index); assert_eq!( expected_token_value, token_value, @@ -115,7 +115,7 @@ mod tests { "kind_of failed (case: index out of bound)" ); - let expected_position = 0..0; + let expected_position = None; let position = input.position_of(index); assert_eq!( expected_position, position, @@ -130,7 +130,7 @@ mod tests { let index = input.size() / 2; // a valid index if input size > 0 let expected_token_value = &input.source[input.position[index].clone()]; - let token_value = input.token_value(index); + let token_value = input.token_value(index).unwrap(); assert_eq!(expected_token_value, token_value, "token_value failed"); let expected_kind = input.kind[index]; @@ -138,7 +138,7 @@ mod tests { assert_eq!(expected_kind, kind, "kind_of failed"); let expected_position = input.position[index].clone(); - let position = input.position_of(index); + let position = input.position_of(index).unwrap(); assert_eq!(expected_position, position, "position_of failed"); } diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index f44b88c..32a273b 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -23,7 +23,8 @@ impl<'a> SyntaxTreeBuilder<'a> { match child { Child::Token(token_id) => { let token_kind = self.input.kind_of(*token_id); - let token_value = self.input.token_value(*token_id); + // TODO: return Error to replace .unwrap() + let token_value = self.input.token_value(*token_id).unwrap(); self.builder.start_node(token_kind.into()); self.builder.token(token_kind.into(), token_value); self.builder.finish_node(); From 6d5f0c6d44d8d8d15e8bfa66b68659dc4644552a Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 10 Dec 2024 22:51:11 +0700 Subject: [PATCH 13/71] do not allow <--, <== in var declaration --- crates/parser/src/grammar/declaration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 8022f81..c37630c 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -38,7 +38,7 @@ pub(super) fn var_declaration(p: &mut Parser) { if p.at(LParen) { tuple(p); - if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { + if p.at(Assign) { tuple_init(p); } } else { From fbdc5b9857cd6944c9b0df9cb892d44c00ece8dc Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 10 Dec 2024 22:54:53 +0700 Subject: [PATCH 14/71] make public signal optional in main component --- crates/parser/src/grammar/main_component.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index 3f6f862..d9c176d 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -9,11 +9,13 @@ pub fn main_component(p: &mut Parser) { p.expect(ComponentKw); p.expect(MainKw); - p.expect(LCurly); - p.expect(PublicKw); - p.expect(LBracket); - list_identity::parse(p); - p.expect(RBracket); + if p.at(LCurly) { + p.expect(LCurly); + p.expect(PublicKw); + p.expect(LBracket); + list_identity::parse(p); + p.expect(RBracket); + } p.expect(Assign); expression::expression(p); From 07c4171540a9fbb51df57caa9e2f09671b12b9f6 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 13 Dec 2024 14:32:06 +0700 Subject: [PATCH 15/71] fix format before merge --- crates/parser/src/grammar/block.rs | 2 +- crates/parser/src/grammar/function.rs | 2 +- crates/parser/src/grammar/include.rs | 2 +- crates/parser/src/grammar/main_component.rs | 2 +- crates/parser/src/grammar/template.rs | 2 +- crates/syntax/src/lib.rs | 5 ++--- crates/syntax/src/syntax.rs | 3 +-- crates/syntax/src/test_programs.rs | 1 - 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index 5a40865..03f7ed2 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -2,7 +2,7 @@ use super::*; pub fn block(p: &mut Parser) { p.inc_rcurly(); - + if !p.at(LCurly) { p.advance_with_error("Miss {"); } else { diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index bca7018..4da6276 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -3,7 +3,7 @@ use crate::grammar::*; // fucntion name() pub fn function_parse(p: &mut Parser) { let m = p.open(); - + p.expect(FunctionKw); let fn_name_marker = p.open(); diff --git a/crates/parser/src/grammar/include.rs b/crates/parser/src/grammar/include.rs index d8f0ac7..7269995 100644 --- a/crates/parser/src/grammar/include.rs +++ b/crates/parser/src/grammar/include.rs @@ -2,7 +2,7 @@ use super::*; pub(super) fn include(p: &mut Parser) { // assert!(p.at(IncludeKw)); - + let m = p.open(); p.expect(IncludeKw); p.expect(CircomString); diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index d9c176d..5129310 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -8,7 +8,7 @@ component main {public [signal_list]} = tempid(v1,...,vn); pub fn main_component(p: &mut Parser) { p.expect(ComponentKw); p.expect(MainKw); - + if p.at(LCurly) { p.expect(LCurly); p.expect(PublicKw); diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index be5f17e..693fe68 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -8,7 +8,7 @@ pub fn template(p: &mut Parser) { let m = p.open(); p.expect(TemplateKw); - + let name_marker = p.open(); p.expect(Identifier); p.close(name_marker, TemplateName); diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index d1300bb..7f4b53c 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -1,6 +1,5 @@ +pub mod abstract_syntax_tree; pub mod syntax; pub mod syntax_node; -pub mod abstract_syntax_tree; - -mod test_programs; \ No newline at end of file +mod test_programs; diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 32a273b..9b9202f 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -164,8 +164,7 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); - - if let Some(ast) = AstCircomProgram::cast(syntax) { + if let Some(ast) = AstCircomProgram::cast(syntax) { check_ast_children(&ast, &expected_kinds, &expected_ranges); // check pragma diff --git a/crates/syntax/src/test_programs.rs b/crates/syntax/src/test_programs.rs index 0879679..655222f 100644 --- a/crates/syntax/src/test_programs.rs +++ b/crates/syntax/src/test_programs.rs @@ -132,4 +132,3 @@ pub const PARSER_TEST_6: &str = r#" /* T _ T */ template Multiplier2 () {} "#; - \ No newline at end of file From 0bf3a04a0f476adf43cda2d39136b01592ab9bf1 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 17 Dec 2024 15:59:27 +0700 Subject: [PATCH 16/71] remove empty test --- crates/parser/src/grammar/declaration.rs | 8 +---- crates/parser/src/grammar/expression.rs | 24 +------------ crates/parser/src/grammar/pragma.rs | 23 ------------ crates/parser/src/grammar/statement.rs | 46 ++++++++++++++---------- crates/parser/src/grammar/template.rs | 41 +-------------------- 5 files changed, 31 insertions(+), 111 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index c37630c..27471b3 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -127,10 +127,4 @@ pub(super) fn declaration(p: &mut Parser) { ComponentKw => component_declaration(p), _ => unreachable!(), } -} - -#[cfg(test)] -mod declar_tests { - #[test] - fn signal_with_tag() {} -} +} \ No newline at end of file diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 8c7fad6..96c85e0 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -155,26 +155,4 @@ fn circom_expression(p: &mut Parser) { p.close(m, TenaryConditional); } } -} -// #[cfg(test)] -// mod tests { - -// use rowan::SyntaxNode; - -// use crate::{syntax_node::CircomLang}; - -// use super::{entry::Scope, Parser}; - -// #[test] -// fn test_expression() { -// let source = r#" -// { -// a.tmp <== 100; -// b[1].c <== 10; -// } -// "#; -// let green = Parser::parse_scope(source, Scope::Block); -// let node = SyntaxNode::::new_root(green); -// println!("{:#?}", node); -// } -// } +} \ No newline at end of file diff --git a/crates/parser/src/grammar/pragma.rs b/crates/parser/src/grammar/pragma.rs index bacf839..9ce3eaf 100644 --- a/crates/parser/src/grammar/pragma.rs +++ b/crates/parser/src/grammar/pragma.rs @@ -14,26 +14,3 @@ pub fn pragma(p: &mut Parser) { p.expect(Semicolon); p.close(m, Pragma); } - -// #[cfg(test)] -// mod tests { -// #[test] -// fn pragam_test() { -// use crate::{ -// ast::{AstNode, AstPragma}, -// syntax_node::SyntaxNode, -// token_kind::TokenKind, -// }; - -// use super::{entry::Scope, Parser}; - -// let source: String = r#"pragma circom 2.0.1;"#.to_string(); - -// let green_node = Parser::parse_scope(&source, Scope::Pragma); -// let node = SyntaxNode::new_root(green_node); - -// let pragma = AstPragma::cast(node.last_child().unwrap()).unwrap(); - -// assert!(pragma.version().unwrap().syntax().kind() == TokenKind::Version); -// } -// } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index a4ee698..d8b75fa 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -9,6 +9,12 @@ pub(super) fn statement(p: &mut Parser) { p.close(m, Statement); } +/* +if (expr) + +else + +*/ fn if_statement(p: &mut Parser) { let m = p.open(); p.expect(IfKw); @@ -25,6 +31,7 @@ fn if_statement(p: &mut Parser) { /** * no if condition here. + * for/while/return/assert... */ fn statement_no_condition(p: &mut Parser) { match p.current() { @@ -50,6 +57,10 @@ fn statement_no_condition(p: &mut Parser) { } } +/* +for (/; ; ) + +*/ fn for_statement(p: &mut Parser) { let m = p.open(); p.expect(ForKw); @@ -70,6 +81,10 @@ fn for_statement(p: &mut Parser) { p.close(m, ForLoop); } +/* +while () + +*/ fn while_statement(p: &mut Parser) { p.expect(WhileKw); p.expect(LParen); @@ -78,6 +93,9 @@ fn while_statement(p: &mut Parser) { statement(p); } +/* +assert() +*/ fn assert_statement(p: &mut Parser) { let m = p.open(); p.expect(AssertKw); @@ -87,6 +105,9 @@ fn assert_statement(p: &mut Parser) { p.close(m, AssertKw); } +/* +log() +*/ fn log_statement(p: &mut Parser) { let m = p.open(); p.expect(LogKw); @@ -109,6 +130,9 @@ fn log_statement(p: &mut Parser) { p.close(m, LogKw); } +/* +return +*/ fn return_statement(p: &mut Parser) { let m = p.open(); p.expect(ReturnKw); @@ -116,6 +140,9 @@ fn return_statement(p: &mut Parser) { p.close(m, ReturnKw); } +/* + +*/ fn assignment_statement(p: &mut Parser) { let m = p.open(); @@ -154,21 +181,4 @@ fn assignment_statement(p: &mut Parser) { } else { p.close(m, Error); } -} - -#[cfg(test)] -mod tests { - - #[test] - fn if_statement_test() { - let _source = r#" - assert(1 == 2); - "#; - // let mut parser = Parser::new(source); - - // statement(&mut parser); - // let cst = parser.build_tree().ok().unwrap(); - - // println!("{:?}", cst); - } -} +} \ No newline at end of file diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 693fe68..359d774 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -22,43 +22,4 @@ pub fn template(p: &mut Parser) { block::block(p); p.close(m, TemplateDef); -} - -// #[cfg(test)] -// mod tests { -// use crate::ast::AstTemplateDef; - -// #[test] -// fn template_parse_test() { -// use crate::{ast::AstNode, syntax_node::SyntaxNode}; - -// use super::{entry::Scope, Parser}; - -// let source: String = r#" -// template Multiplier2 (a, b, c) { - -// // Declaration of signals. -// signal input a; -// signal input b; -// signal output c; - -// // Constraints. -// c <== a * b; -// } - -// "# -// .to_string(); - -// let green_node = ::parse_scope(&source, Scope::Template); -// let node = SyntaxNode::new_root(green_node); - -// let ast_template = AstTemplateDef::cast(node); - -// if let Some(ast_internal) = ast_template { -// println!( -// "name {:?}", -// ast_internal.template_name().unwrap().syntax().text() -// ); -// } -// } -// } +} \ No newline at end of file From f1b0c3967be3941287c76bb69b90a9290d9db586 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 17 Dec 2024 16:00:07 +0700 Subject: [PATCH 17/71] replace expect by eat in block --- crates/parser/src/grammar/block.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index 03f7ed2..f01b515 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -1,5 +1,13 @@ use super::*; +/* +{ + / + / + .... + / +} +*/ pub fn block(p: &mut Parser) { p.inc_rcurly(); @@ -30,7 +38,7 @@ pub fn block(p: &mut Parser) { p.close(stmt_marker, StatementList); - p.expect(RCurly); + p.eat(RCurly); p.close(m, Block); From a10be252a1d9661aa5183883546fd5ccc6a531b4 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 17 Dec 2024 16:00:36 +0700 Subject: [PATCH 18/71] add scope parsing test --- crates/parser/Cargo.toml | 1 - crates/syntax/src/syntax.rs | 213 ++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 5021d30..1ce7c59 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -12,6 +12,5 @@ rowan = "0.15.15" num-traits = "0.2" num-derive = "0.2" - [profile.dev] debug = 2 \ No newline at end of file diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 9b9202f..6cde0b1 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -289,3 +289,216 @@ mod tests { } } } + +#[cfg(test)] +mod grammar_tests { + use parser::{grammar::entry::Scope, input::Input, parser::Parser, token_kind::TokenKind}; + use rowan::ast::AstNode; + + use crate::{ + abstract_syntax_tree::{AstBlock, AstPragma, AstTemplateDef}, + syntax::SyntaxTreeBuilder, + syntax_node::SyntaxNode, + }; + + #[test] + fn pragma_happy_test() { + // parse source (string) into output tree + let version = r#"2.0.1"#; + let source = format!(r#"pragma circom {};"#, version); + let input = Input::new(&source); + let output = Parser::parsing_with_scope(&input, Scope::Pragma); + + // output is a tree whose node is index of token, no content of token + // convert output into green node + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + + // then cast green node into syntax node + let syntax = SyntaxNode::new_root(green); + + // cast syntax node into ast node to retrieve more information + let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); + + // finally, assert with expect value + assert!(pragma.version().unwrap().syntax().kind() == TokenKind::Version); + assert!(pragma.version().unwrap().syntax().text() == version); + } + + #[test] + fn template_happy_test() { + // SOURCE & EXPECTED RESULT + const SOURCE: &str = r#"template MultiplierN (N, P, QQ) { + //Declaration of signals and components. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + + // ... some more code (see below) + + }"#; + let expected_statements: Vec<&str> = vec![ + "signal input in[N];", + "signal output out;", + "component comp[N-1];", + "for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + }", + ]; + let expected_name = "MultiplierN"; + let expected_first_param = "N"; + let expected_last_param = "QQ"; + + // parse source (string) into output tree + let input = Input::new(&SOURCE); + let output = Parser::parsing_with_scope(&input, Scope::Template); + + // output is a tree whose node is index of token, no content of token + // convert output into green node + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + + // then cast green node into syntax node + let syntax = SyntaxNode::new_root(green); + + // cast syntax node into ast node to retrieve more information + let template = + AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); + + // finally, assert with expect value + + // name + let name = template + .name() + .expect("Can not extract template name") + .syntax() + .text(); + assert_eq!(expected_name, name); + + // parameter list + let first_param = template + .parameter_list() + .expect("Can not detect parameter list") + .syntax() + .first_child() + .unwrap() + .text(); + assert_eq!(expected_first_param, first_param); + let last_param = template + .parameter_list() + .expect("Can not detect parameter list") + .syntax() + .last_child() + .unwrap() + .text(); + assert_eq!(expected_last_param, last_param); + + // statements + let statements = template.statements().unwrap().statement_list(); + let statements: Vec = statements + .into_iter() + .map(|statement| statement.syntax().text().to_string()) + .collect(); + assert_eq!( + expected_statements.len(), + statements.len(), + "Number of statements is not match" + ); + + for id in 0..statements.len() { + assert_eq!(expected_statements[id].to_string(), statements[id]); + } + + // // input signal + // println!("find_input_signal: {:?}", template.find_input_signal()); + + // // output signal + // println!("find_output_signal: {:?}", template.find_output_signal()); + + // // internal signal + // println!("find_internal_signal: {:?}", template.find_internal_signal()); + + // // component + // println!("find_component: {:?}", template.find_component()); + } + + #[test] + fn block_happy_test() { + // SOURCE & EXPECTED RESULT + let source = r#"{ + //Declaration of signals. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + comp[0].in1 <== in[0]; + comp[0].in2 <== in[1]; + for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + } + out <== comp[N-2].out; +}"#; + let expected_statements = vec![ + "signal input in[N];", + "signal output out;", + "component comp[N-1];", + "for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + }", + "comp[0].in1 <== in[0];", + "comp[0].in2 <== in[1];", + "for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + }", + "out <== comp[N-2].out;", + ]; + + + // parse source (string) into output tree + let input = Input::new(&source); + let output = Parser::parsing_with_scope(&input, Scope::Block); + + // output is a tree whose node is index of token, no content of token + // convert output into green node + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + + // then cast green node into syntax node + let syntax = SyntaxNode::new_root(green); + + // cast syntax node into ast node to retrieve more information + let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); + + // finally, assert with expect statements + let statements = block.statement_list().unwrap().statement_list(); + let statements: Vec = statements + .into_iter() + .map(|statement| statement.syntax().text().to_string()) + .collect(); + assert_eq!( + expected_statements.len(), + statements.len(), + "Number of statements is not match" + ); + + for id in 0..statements.len() { + assert_eq!(expected_statements[id].to_string(), statements[id]); + } + } +} From 47df964daedb4bca28ccead785dc348614fe9e88 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 17 Dec 2024 16:04:50 +0700 Subject: [PATCH 19/71] fix space in scope parsing test --- crates/syntax/src/syntax.rs | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 6cde0b1..defc696 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -348,8 +348,8 @@ mod grammar_tests { "signal output out;", "component comp[N-1];", "for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - }", + comp[i] = Multiplier2(); + }", ]; let expected_name = "MultiplierN"; let expected_first_param = "N"; @@ -433,42 +433,41 @@ mod grammar_tests { fn block_happy_test() { // SOURCE & EXPECTED RESULT let source = r#"{ - //Declaration of signals. - signal input in[N]; - signal output out; - component comp[N-1]; - - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - comp[0].in1 <== in[0]; - comp[0].in2 <== in[1]; - for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; + //Declaration of signals. + signal input in[N]; + signal output out; + component comp[N-1]; - } - out <== comp[N-2].out; -}"#; + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + comp[0].in1 <== in[0]; + comp[0].in2 <== in[1]; + for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + } + out <== comp[N-2].out; + }"#; let expected_statements = vec![ "signal input in[N];", "signal output out;", "component comp[N-1];", "for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - }", + comp[i] = Multiplier2(); + }", "comp[0].in1 <== in[0];", "comp[0].in2 <== in[1];", "for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; - }", + }", "out <== comp[N-2].out;", ]; - // parse source (string) into output tree let input = Input::new(&source); let output = Parser::parsing_with_scope(&input, Scope::Block); From 5c6cb56fe53f636b4ea1e82d4d0d1a52badb74af Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 19 Dec 2024 18:10:15 +0700 Subject: [PATCH 20/71] update snapshot test for syntax --- Cargo.toml | 1 + crates/parser/Cargo.toml | 1 + crates/parser/src/token_kind.rs | 3 +- crates/syntax/Cargo.toml | 10 +- ...ar_tests__block_happy_test_statements.snap | 12 + ...tests__template_happy_test_statements.snap | 8 + ...syntax__tests__syntax_test_1_children.snap | 17 ++ ...yntax__tests__syntax_test_2_functions.snap | 5 + ...yntax__tests__syntax_test_2_templates.snap | 5 + ...yntax__tests__syntax_test_5_templates.snap | 5 + ...yntax__tests__syntax_test_6_templates.snap | 5 + crates/syntax/src/syntax.rs | 252 +++++++----------- 12 files changed, 163 insertions(+), 161 deletions(-) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap diff --git a/Cargo.toml b/Cargo.toml index 5dc248b..bfbc8e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,6 @@ syntax = {path = './crates/syntax', version = "0.1.0"} circom-lsp = {path = './crates/lsp', version = "*"} common = { path = './crates/common', version = "*"} database = {path = "./crates/database", version = "*"} + [workspace.package] rust-version = "1.71" diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 1ce7c59..9070855 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -11,6 +11,7 @@ lsp-types = {version = "0.94.1", features = ["proposed"]} rowan = "0.15.15" num-traits = "0.2" num-derive = "0.2" +serde = "1.0.216" [profile.dev] debug = 2 \ No newline at end of file diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 9ebba15..9eba89c 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -1,6 +1,7 @@ use logos::Logos; +use serde::Serialize; -#[derive(Logos, Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash)] +#[derive(Logos, Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash, Serialize)] #[allow(non_camel_case_types)] #[repr(u16)] pub enum TokenKind { diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index d6a3b47..795f0b1 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml @@ -9,5 +9,13 @@ rust-version.workspace = true [dependencies] rowan = "0.15.13" parser.workspace = true - lsp-types = {version = "0.94.1", features = ["proposed"]} + +[dev-dependencies] +# for snapshot testing, yaml format +insta = { version = "1.41.1", features = ["yaml"] } + +[profile.dev.package] +# compile slightly slower once, but use less memory, have faster diffs +insta.opt-level = 3 +similar.opt-level = 3 \ No newline at end of file diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap new file mode 100644 index 0000000..5db6859 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap @@ -0,0 +1,12 @@ +--- +source: crates/syntax/src/syntax.rs +expression: statements +--- +- "signal input in[N];" +- "signal output out;" +- "component comp[N-1];" +- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" +- "comp[0].in1 <== in[0];" +- "comp[0].in2 <== in[1];" +- "for(var i = 0; i < N-2; i++){\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" +- "out <== comp[N-2].out;" \ No newline at end of file diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap new file mode 100644 index 0000000..74cf89f --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap @@ -0,0 +1,8 @@ +--- +source: crates/syntax/src/syntax.rs +expression: statements +--- +- "signal input in[N];" +- "signal output out;" +- "component comp[N-1];" +- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap new file mode 100644 index 0000000..b1feddb --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap @@ -0,0 +1,17 @@ +--- +source: crates/syntax/src/syntax.rs +expression: children_string +--- +- pragma circom 2.0.0; +- "\n" +- "\n" +- " " +- "\n" +- " " +- "template Multiplier2 () {}" +- "\n" +- " " +- "template Multiplier2 () {}" +- " " +- "\n" +- " " diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap new file mode 100644 index 0000000..49ea709 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: function_names +--- +- "nbits" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap new file mode 100644 index 0000000..03a1b69 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: template_names +--- +- "BinSum" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap new file mode 100644 index 0000000..53cde17 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: template_names +--- +- "Multiplier2" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap new file mode 100644 index 0000000..53cde17 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: template_names +--- +- "Multiplier2" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index defc696..dcb98d0 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -58,118 +58,37 @@ impl<'a> SyntaxTreeBuilder<'a> { #[cfg(test)] mod tests { - use parser::token_kind::TokenKind::{self, *}; use std::hash::{DefaultHasher, Hash, Hasher}; - use rowan::{ast::AstNode, TextRange}; + use rowan::ast::AstNode; use crate::{abstract_syntax_tree::AstCircomProgram, test_programs}; use super::SyntaxTreeBuilder; - fn generate_expected_token_kind(ast: &AstCircomProgram) { - let children = ast - .syntax() - .first_child() - .unwrap() - .siblings(rowan::Direction::Next); - - println!("vec!["); - for child in children { - println!("{:?},", child.kind()); - } - println!("];"); - } - - fn generate_expected_token_range(ast: &AstCircomProgram) { - let children = ast - .syntax() - .first_child() - .unwrap() - .siblings(rowan::Direction::Next); - - println!("vec!["); - for child in children { - println!( - "TextRange::new({:?}.into(), {:?}.into()), ", - child.text_range().start(), - child.text_range().end() - ); - } - println!("];"); - } - - fn check_ast_children( - ast: &AstCircomProgram, - expected_kinds: &Vec, - expected_ranges: &Vec, - ) { - let children = ast - .syntax() - .first_child() - .unwrap() - .siblings(rowan::Direction::Next); - - let mut kind_iterator = expected_kinds.iter(); - let mut range_iterator = expected_ranges.iter(); - - for child in children { - if let (Some(expected_kind), Some(expected_range)) = - (kind_iterator.next(), range_iterator.next()) - { - assert_eq!(child.kind(), *expected_kind); - assert_eq!(child.text_range(), *expected_range); - } else { - panic!("Mismatched number of children and expected values"); - } - } - println!(); - } - #[test] fn syntax_test_1() { let source: &str = test_programs::PARSER_TEST_1; - let expected_pragma = "pragma circom 2.0.0;".to_string(); - let expected_kinds = vec![ - Pragma, - EndLine, - EndLine, - WhiteSpace, - EndLine, - WhiteSpace, - TemplateDef, - EndLine, - WhiteSpace, - TemplateDef, - WhiteSpace, - EndLine, - WhiteSpace, - ]; - let expected_ranges = vec![ - TextRange::new(0.into(), 20.into()), - TextRange::new(20.into(), 21.into()), - TextRange::new(21.into(), 22.into()), - TextRange::new(22.into(), 26.into()), - TextRange::new(26.into(), 27.into()), - TextRange::new(27.into(), 31.into()), - TextRange::new(31.into(), 57.into()), - TextRange::new(57.into(), 58.into()), - TextRange::new(58.into(), 62.into()), - TextRange::new(62.into(), 88.into()), - TextRange::new(88.into(), 89.into()), - TextRange::new(89.into(), 90.into()), - TextRange::new(90.into(), 94.into()), - ]; - let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - check_ast_children(&ast, &expected_kinds, &expected_ranges); + // check_ast_children + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next); + let mut children_string = Vec::new(); + + for child in children.into_iter() { + children_string.push(child.text().to_string()); + } + insta::assert_yaml_snapshot!("syntax_test_1_children", children_string); // check pragma let pragma = ast.pragma().unwrap().syntax().text().to_string(); - assert_eq!(pragma, expected_pragma, "Pragma is not correct!"); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); // check ast hash let mut hasher = DefaultHasher::default(); @@ -212,24 +131,29 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); + let pragma = ast.pragma().unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - print!("Templates: "); let templates = ast.template_list(); + let mut template_names = Vec::new(); for template in templates.iter() { - print!("{:?} ", template.name().unwrap().syntax().text()); // leading whitespaces - // print!("{:?} ", template.syntax().text()); // leading whitespaces + let template_name = template.name().unwrap().syntax().text().to_string(); + template_names.push(template_name); } - println!(); + insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); - print!("Functions: "); let functions = ast.function_list(); + let mut function_names = Vec::new(); for function in functions.iter() { - print!("{:?} ", function.function_name().unwrap().syntax().text()); - // leading whitespaces - // print!("{:?} ", function.syntax().text()); // leading whitespaces + let function_name = function + .function_name() + .unwrap() + .syntax() + .text() + .to_string(); + function_names.push(function_name); } - println!(); + insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); } } @@ -240,11 +164,18 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); - println!( - "Pragma version: {:?}", - ast.pragma().unwrap().version().unwrap().syntax().text() - ); + let pragma = ast.pragma().unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + let pragma_version = ast + .pragma() + .unwrap() + .version() + .unwrap() + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); } } @@ -255,11 +186,18 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - println!("Pragma: {:?}", ast.pragma().unwrap().syntax().text()); - println!( - "Pragma version: {:?}", - ast.pragma().unwrap().version().unwrap().syntax().text() - ); + let pragma = ast.pragma().unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + let pragma_version = ast + .pragma() + .unwrap() + .version() + .unwrap() + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); } } @@ -270,9 +208,16 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - println!("pragma: {:?}", ast.pragma()); - println!("template list: {:?}", ast.template_list()); - // assert!(ast.pragma().is_none(), "No pragma in source code"); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); + + let templates = ast.template_list(); + let mut template_names = Vec::new(); + for template in templates.iter() { + let template_name = template.name().unwrap().syntax().text().to_string(); + template_names.push(template_name); + } + insta::assert_yaml_snapshot!("syntax_test_5_templates", template_names); } } @@ -283,16 +228,23 @@ mod tests { let syntax = SyntaxTreeBuilder::syntax_tree(source); if let Some(ast) = AstCircomProgram::cast(syntax) { - println!("{:?}", ast.pragma()); - println!("template list: {:?}", ast.template_list()); - // assert!(ast.pragma().is_none(), "No pragma in source code"); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); + + let templates = ast.template_list(); + let mut template_names = Vec::new(); + for template in templates.iter() { + let template_name = template.name().unwrap().syntax().text().to_string(); + template_names.push(template_name); + } + insta::assert_yaml_snapshot!("syntax_test_6_templates", template_names); } } } #[cfg(test)] mod grammar_tests { - use parser::{grammar::entry::Scope, input::Input, parser::Parser, token_kind::TokenKind}; + use parser::{grammar::entry::Scope, input::Input, parser::Parser}; use rowan::ast::AstNode; use crate::{ @@ -322,8 +274,11 @@ mod grammar_tests { let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); // finally, assert with expect value - assert!(pragma.version().unwrap().syntax().kind() == TokenKind::Version); - assert!(pragma.version().unwrap().syntax().text() == version); + let pragma_versison_kind = pragma.version().unwrap().syntax().kind(); + insta::assert_yaml_snapshot!(pragma_versison_kind, @"Version"); + + let pragma_versison_text = pragma.version().unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(pragma_versison_text, @"2.0.1"); } #[test] @@ -343,17 +298,6 @@ mod grammar_tests { // ... some more code (see below) }"#; - let expected_statements: Vec<&str> = vec![ - "signal input in[N];", - "signal output out;", - "component comp[N-1];", - "for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - }", - ]; - let expected_name = "MultiplierN"; - let expected_first_param = "N"; - let expected_last_param = "QQ"; // parse source (string) into output tree let input = Input::new(&SOURCE); @@ -379,8 +323,9 @@ mod grammar_tests { .name() .expect("Can not extract template name") .syntax() - .text(); - assert_eq!(expected_name, name); + .text() + .to_string(); + insta::assert_yaml_snapshot!(name, @"MultiplierN"); // parameter list let first_param = template @@ -389,16 +334,19 @@ mod grammar_tests { .syntax() .first_child() .unwrap() - .text(); - assert_eq!(expected_first_param, first_param); + .text() + .to_string(); + insta::assert_yaml_snapshot!(first_param, @"N"); + let last_param = template .parameter_list() .expect("Can not detect parameter list") .syntax() .last_child() .unwrap() - .text(); - assert_eq!(expected_last_param, last_param); + .text() + .to_string(); + insta::assert_yaml_snapshot!(last_param, @"QQ"); // statements let statements = template.statements().unwrap().statement_list(); @@ -406,15 +354,7 @@ mod grammar_tests { .into_iter() .map(|statement| statement.syntax().text().to_string()) .collect(); - assert_eq!( - expected_statements.len(), - statements.len(), - "Number of statements is not match" - ); - - for id in 0..statements.len() { - assert_eq!(expected_statements[id].to_string(), statements[id]); - } + insta::assert_yaml_snapshot!("template_happy_test_statements", statements); // // input signal // println!("find_input_signal: {:?}", template.find_input_signal()); @@ -451,6 +391,7 @@ mod grammar_tests { } out <== comp[N-2].out; }"#; + /* let expected_statements = vec![ "signal input in[N];", "signal output out;", @@ -467,6 +408,7 @@ mod grammar_tests { }", "out <== comp[N-2].out;", ]; + */ // parse source (string) into output tree let input = Input::new(&source); @@ -490,14 +432,6 @@ mod grammar_tests { .into_iter() .map(|statement| statement.syntax().text().to_string()) .collect(); - assert_eq!( - expected_statements.len(), - statements.len(), - "Number of statements is not match" - ); - - for id in 0..statements.len() { - assert_eq!(expected_statements[id].to_string(), statements[id]); - } + insta::assert_yaml_snapshot!("block_happy_test_statements", statements); } } From 372efd3d6a6510b100305b9d8c9d751f2d21c723 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 19 Dec 2024 18:39:51 +0700 Subject: [PATCH 21/71] refactor syntax test --- .gitignore | 4 +- crates/syntax/src/syntax.rs | 331 +++++++++++++++--------------------- 2 files changed, 144 insertions(+), 191 deletions(-) diff --git a/.gitignore b/.gitignore index 6f429f5..165e8e1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ node_modules .vscode-test /target Cargo.lock -assets \ No newline at end of file +assets +*.new +*.pending-snap \ No newline at end of file diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index dcb98d0..0c1d1b8 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -66,198 +66,178 @@ mod tests { use super::SyntaxTreeBuilder; - #[test] - fn syntax_test_1() { - let source: &str = test_programs::PARSER_TEST_1; - + fn ast_from_source(source: &str) -> AstCircomProgram { let syntax = SyntaxTreeBuilder::syntax_tree(source); + AstCircomProgram::cast(syntax).unwrap() + } - if let Some(ast) = AstCircomProgram::cast(syntax) { - // check_ast_children - let children = ast - .syntax() - .first_child() - .unwrap() - .siblings(rowan::Direction::Next); - let mut children_string = Vec::new(); - - for child in children.into_iter() { - children_string.push(child.text().to_string()); - } - insta::assert_yaml_snapshot!("syntax_test_1_children", children_string); - - // check pragma - let pragma = ast.pragma().unwrap().syntax().text().to_string(); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - // check ast hash - let mut hasher = DefaultHasher::default(); - ast.syntax().hash(&mut hasher); - let _ast_hash = hasher.finish(); - - // check template hash - let mut h1 = DefaultHasher::default(); - let mut h2 = DefaultHasher::default(); - - let template = ast.template_list(); - - template[0].syntax().hash(&mut h1); - template[1].syntax().hash(&mut h2); - - assert_ne!( - h1.finish(), - h2.finish(), - "Templates with same syntax should have different hashes!" - ); - - // check template syntax (text & green node) - assert_eq!( - template[0].syntax().text(), - template[1].syntax().text(), - "The syntax (as text) of template 1 and 2 must be the same!" - ); - assert_eq!( - template[0].syntax().green(), - template[1].syntax().green(), - "The syntax (as green node) of template 1 and 2 must be the same!!" - ); - } + fn children_from_ast(ast: &AstCircomProgram) -> Vec { + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next) + .into_iter() + .map(|child| child.text().to_string()) + .collect(); + + children } - #[test] - fn syntax_test_2() { - let source = test_programs::PARSER_TEST_2; + fn pragma_string_from_ast(ast: &AstCircomProgram) -> String { + ast.pragma().unwrap().syntax().text().to_string() + } - let syntax = SyntaxTreeBuilder::syntax_tree(source); + fn pragma_version_from_ast(ast: &AstCircomProgram) -> String { + ast.pragma() + .unwrap() + .version() + .unwrap() + .syntax() + .text() + .to_string() + } - if let Some(ast) = AstCircomProgram::cast(syntax) { - let pragma = ast.pragma().unwrap().syntax().text().to_string(); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + fn template_names_from_ast(ast: &AstCircomProgram) -> Vec { + let templates = ast + .template_list() + .iter() + .map(|template| template.name().unwrap().syntax().text().to_string()) + .collect(); - let templates = ast.template_list(); - let mut template_names = Vec::new(); - for template in templates.iter() { - let template_name = template.name().unwrap().syntax().text().to_string(); - template_names.push(template_name); - } - insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); + templates + } - let functions = ast.function_list(); - let mut function_names = Vec::new(); - for function in functions.iter() { - let function_name = function + fn function_names_from_ast(ast: &AstCircomProgram) -> Vec { + let functions = ast + .function_list() + .iter() + .map(|function| { + function .function_name() .unwrap() .syntax() .text() - .to_string(); - function_names.push(function_name); - } - insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); - } + .to_string() + }) + .collect(); + + functions } #[test] - fn syntax_test_3() { - let source = test_programs::PARSER_TEST_3; - - let syntax = SyntaxTreeBuilder::syntax_tree(source); - - if let Some(ast) = AstCircomProgram::cast(syntax) { - let pragma = ast.pragma().unwrap().syntax().text().to_string(); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - let pragma_version = ast - .pragma() - .unwrap() - .version() - .unwrap() - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); - } + fn syntax_test_1() { + let ast = ast_from_source(test_programs::PARSER_TEST_1); + + // check_ast_children + let children = children_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_1_children", children); + + // check pragma + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + // check ast hash + let mut hasher = DefaultHasher::default(); + ast.syntax().hash(&mut hasher); + let _ast_hash = hasher.finish(); + + // check template hash + let mut h1 = DefaultHasher::default(); + let mut h2 = DefaultHasher::default(); + + let template = ast.template_list(); + + template[0].syntax().hash(&mut h1); + template[1].syntax().hash(&mut h2); + + assert_ne!( + h1.finish(), + h2.finish(), + "Templates with same syntax should have different hashes!" + ); + + // check template syntax (text & green node) + assert_eq!( + template[0].syntax().text(), + template[1].syntax().text(), + "The syntax (as text) of template 1 and 2 must be the same!" + ); + assert_eq!( + template[0].syntax().green(), + template[1].syntax().green(), + "The syntax (as green node) of template 1 and 2 must be the same!!" + ); } #[test] - fn syntax_test_4() { - let source = test_programs::PARSER_TEST_4; + fn syntax_test_2() { + let ast = ast_from_source(test_programs::PARSER_TEST_2); - let syntax = SyntaxTreeBuilder::syntax_tree(source); + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - if let Some(ast) = AstCircomProgram::cast(syntax) { - let pragma = ast.pragma().unwrap().syntax().text().to_string(); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - let pragma_version = ast - .pragma() - .unwrap() - .version() - .unwrap() - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); - } + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); + + let function_names = function_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); } #[test] - fn syntax_test_5() { - let source = test_programs::PARSER_TEST_5; + fn syntax_test_3() { + let ast = ast_from_source(test_programs::PARSER_TEST_3); + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - let syntax = SyntaxTreeBuilder::syntax_tree(source); + let pragma_version = pragma_version_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); + } - if let Some(ast) = AstCircomProgram::cast(syntax) { - let pragma = ast.pragma().is_none(); - insta::assert_yaml_snapshot!(pragma, @"true"); + #[test] + fn syntax_test_4() { + let ast = ast_from_source(test_programs::PARSER_TEST_4); + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - let templates = ast.template_list(); - let mut template_names = Vec::new(); - for template in templates.iter() { - let template_name = template.name().unwrap().syntax().text().to_string(); - template_names.push(template_name); - } - insta::assert_yaml_snapshot!("syntax_test_5_templates", template_names); - } + let pragma_version = pragma_version_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); } #[test] - fn syntax_test_6() { - let source = test_programs::PARSER_TEST_6; + fn syntax_test_5() { + let ast = ast_from_source(test_programs::PARSER_TEST_5); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); - let syntax = SyntaxTreeBuilder::syntax_tree(source); + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_5_templates", template_names); + } - if let Some(ast) = AstCircomProgram::cast(syntax) { - let pragma = ast.pragma().is_none(); - insta::assert_yaml_snapshot!(pragma, @"true"); + #[test] + fn syntax_test_6() { + let ast = ast_from_source(test_programs::PARSER_TEST_6); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); - let templates = ast.template_list(); - let mut template_names = Vec::new(); - for template in templates.iter() { - let template_name = template.name().unwrap().syntax().text().to_string(); - template_names.push(template_name); - } - insta::assert_yaml_snapshot!("syntax_test_6_templates", template_names); - } + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_6_templates", template_names); } } #[cfg(test)] mod grammar_tests { + use parser::{grammar::entry::Scope, input::Input, parser::Parser}; - use rowan::ast::AstNode; + use rowan::{ast::AstNode, SyntaxNode}; use crate::{ abstract_syntax_tree::{AstBlock, AstPragma, AstTemplateDef}, syntax::SyntaxTreeBuilder, - syntax_node::SyntaxNode, + syntax_node::CircomLanguage, }; - #[test] - fn pragma_happy_test() { - // parse source (string) into output tree - let version = r#"2.0.1"#; - let source = format!(r#"pragma circom {};"#, version); + fn syntax_node_from_source(source: &str) -> SyntaxNode { let input = Input::new(&source); let output = Parser::parsing_with_scope(&input, Scope::Pragma); @@ -270,6 +250,17 @@ mod grammar_tests { // then cast green node into syntax node let syntax = SyntaxNode::new_root(green); + syntax + } + + #[test] + fn pragma_happy_test() { + // parse source (string) into output tree + let version = r#"2.0.1"#; + let source = format!(r#"pragma circom {};"#, version); + + let syntax = syntax_node_from_source(&source); + // cast syntax node into ast node to retrieve more information let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); @@ -299,18 +290,7 @@ mod grammar_tests { }"#; - // parse source (string) into output tree - let input = Input::new(&SOURCE); - let output = Parser::parsing_with_scope(&input, Scope::Template); - - // output is a tree whose node is index of token, no content of token - // convert output into green node - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - - // then cast green node into syntax node - let syntax = SyntaxNode::new_root(green); + let syntax = syntax_node_from_source(&SOURCE); // cast syntax node into ast node to retrieve more information let template = @@ -391,37 +371,8 @@ mod grammar_tests { } out <== comp[N-2].out; }"#; - /* - let expected_statements = vec![ - "signal input in[N];", - "signal output out;", - "component comp[N-1];", - "for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - }", - "comp[0].in1 <== in[0];", - "comp[0].in2 <== in[1];", - "for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; - }", - "out <== comp[N-2].out;", - ]; - */ - - // parse source (string) into output tree - let input = Input::new(&source); - let output = Parser::parsing_with_scope(&input, Scope::Block); - - // output is a tree whose node is index of token, no content of token - // convert output into green node - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - - // then cast green node into syntax node - let syntax = SyntaxNode::new_root(green); + let syntax = syntax_node_from_source(&source); // cast syntax node into ast node to retrieve more information let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); From 46929c2d65db1c28ddf66117c815285af4ca8fca Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 20 Dec 2024 12:34:32 +0700 Subject: [PATCH 22/71] update input tests with snapshot --- crates/parser/Cargo.toml | 11 +- crates/parser/src/input.rs | 265 +----------------- ...ser__input__tests__test_comment_block.snap | 43 +++ ...ser__input__tests__test_comment_error.snap | 34 +++ .../parser__input__tests__test_function.snap | 217 ++++++++++++++ .../parser__input__tests__test_pragma.snap | 52 ++++ 6 files changed, 364 insertions(+), 258 deletions(-) create mode 100644 crates/parser/src/snapshots/parser__input__tests__test_comment_block.snap create mode 100644 crates/parser/src/snapshots/parser__input__tests__test_comment_error.snap create mode 100644 crates/parser/src/snapshots/parser__input__tests__test_function.snap create mode 100644 crates/parser/src/snapshots/parser__input__tests__test_pragma.snap diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 9070855..0173d54 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -14,4 +14,13 @@ num-derive = "0.2" serde = "1.0.216" [profile.dev] -debug = 2 \ No newline at end of file +debug = 2 + +[dev-dependencies] +# for snapshot testing, yaml format +insta = { version = "1.41.1", features = ["yaml"] } + +[profile.dev.package] +# compile slightly slower once, but use less memory, have faster diffs +insta.opt-level = 3 +similar.opt-level = 3 \ No newline at end of file diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index 8ddf602..a37579e 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -1,10 +1,11 @@ use std::ops::Range; use logos::Lexer; +use serde::Serialize; use crate::token_kind::TokenKind; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Serialize)] pub struct Input<'a> { kind: Vec, source: &'a str, @@ -81,65 +82,12 @@ impl<'a> Input<'a> { #[cfg(test)] mod tests { - use crate::token_kind::TokenKind::{self, *}; - use super::Input; - fn test(source: &str, expected_input: Input) { + fn test(source: &str, snapshot_name: &str) { let input = Input::new(&source); - assert_eq!( - expected_input, input, - "Tokens extract from source code are not correct" - ); - - // test size method - let expected_size = input.kind.len(); - let size = input.size(); - assert_eq!(expected_size, size, "size method failed"); - - // test methods with index out of bound - let index = input.kind.len(); - - let expected_token_value = None; - let token_value = input.token_value(index); - assert_eq!( - expected_token_value, token_value, - "token_value failed (case: index out of bound)" - ); - - let expected_kind = TokenKind::EOF; - let kind = input.kind_of(index); - assert_eq!( - expected_kind, kind, - "kind_of failed (case: index out of bound)" - ); - - let expected_position = None; - let position = input.position_of(index); - assert_eq!( - expected_position, position, - "position_of failed (case: index out of bound)" - ); - - // test methods with index in bound - if input.size() == 0 { - return; - } - - let index = input.size() / 2; // a valid index if input size > 0 - - let expected_token_value = &input.source[input.position[index].clone()]; - let token_value = input.token_value(index).unwrap(); - assert_eq!(expected_token_value, token_value, "token_value failed"); - - let expected_kind = input.kind[index]; - let kind = input.kind_of(index); - assert_eq!(expected_kind, kind, "kind_of failed"); - - let expected_position = input.position[index].clone(); - let position = input.position_of(index).unwrap(); - assert_eq!(expected_position, position, "position_of failed"); + insta::assert_yaml_snapshot!(snapshot_name, input); } #[test] @@ -148,40 +96,7 @@ mod tests { /*a + b == 10*/ a + 10 "#; - - let expected_input = Input { - kind: vec![ - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::BlockComment, - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::Identifier, - TokenKind::WhiteSpace, - TokenKind::Add, - TokenKind::WhiteSpace, - TokenKind::Number, - TokenKind::EndLine, - TokenKind::WhiteSpace, - ], - source: &source, - position: vec![ - { 0..1 }, - { 1..9 }, - { 9..24 }, - { 24..25 }, - { 25..33 }, - { 33..34 }, - { 34..35 }, - { 35..36 }, - { 36..37 }, - { 37..39 }, - { 39..40 }, - { 40..44 }, - ], - }; - - test(source, expected_input); + test(source, "test_comment_block"); } #[test] @@ -194,34 +109,7 @@ mod tests { /* "#; - - let expected_input = Input { - kind: vec![ - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::Pragma, - TokenKind::WhiteSpace, - TokenKind::Version, - TokenKind::Semicolon, - TokenKind::EndLine, - TokenKind::WhiteSpace, - TokenKind::Error, - ], - source: &source, - position: vec![ - 0..1, - 1..9, - 9..15, - 15..16, - 16..21, - 21..22, - 22..23, - 23..31, - 31..94, - ], - }; - - test(source, expected_input); + test(source, "test_comment_error"); } #[test] @@ -232,46 +120,7 @@ mod tests { pragma circom 2.0.0; "#; - - let expected_input = Input { - kind: vec![ - EndLine, - WhiteSpace, - BlockComment, - EndLine, - EndLine, - WhiteSpace, - Pragma, - WhiteSpace, - Circom, - WhiteSpace, - Version, - Semicolon, - EndLine, - EndLine, - WhiteSpace, - ], - source: &source, - position: vec![ - 0..1, - 1..9, - 9..38, - 38..39, - 39..40, - 40..44, - 44..50, - 50..51, - 51..57, - 57..58, - 58..63, - 63..64, - 64..65, - 65..66, - 66..70, - ], - }; - - test(source, expected_input); + test(source, "test_pragma"); } #[test] @@ -286,104 +135,6 @@ mod tests { } return r; }"#; - - let expected_input = Input { - kind: vec![ - EndLine, WhiteSpace, FunctionKw, WhiteSpace, Identifier, LParen, Identifier, - RParen, WhiteSpace, LCurly, EndLine, WhiteSpace, VarKw, WhiteSpace, Identifier, - WhiteSpace, Assign, WhiteSpace, Number, Semicolon, EndLine, WhiteSpace, VarKw, - WhiteSpace, Identifier, WhiteSpace, Assign, WhiteSpace, Number, Semicolon, EndLine, - WhiteSpace, WhileKw, WhiteSpace, LParen, Identifier, Sub, Number, LessThan, - Identifier, RParen, WhiteSpace, LCurly, EndLine, WhiteSpace, Identifier, Add, Add, - Semicolon, EndLine, WhiteSpace, Identifier, WhiteSpace, Mul, Assign, WhiteSpace, - Number, Semicolon, EndLine, WhiteSpace, RCurly, EndLine, WhiteSpace, ReturnKw, - WhiteSpace, Identifier, Semicolon, EndLine, WhiteSpace, RCurly, - ], - source: &source, - position: vec![ - 0..1, - 1..5, - 5..13, - 13..14, - 14..19, - 19..20, - 20..21, - 21..22, - 22..23, - 23..24, - 24..25, - 25..33, - 33..36, - 36..37, - 37..38, - 38..39, - 39..40, - 40..41, - 41..42, - 42..43, - 43..44, - 44..52, - 52..55, - 55..56, - 56..57, - 57..58, - 58..59, - 59..60, - 60..61, - 61..62, - 62..63, - 63..71, - 71..76, - 76..77, - 77..78, - 78..79, - 79..80, - 80..81, - 81..82, - 82..83, - 83..84, - 84..85, - 85..86, - 86..87, - 87..99, - 99..100, - 100..101, - 101..102, - 102..103, - 103..104, - 104..116, - 116..117, - 117..118, - 118..119, - 119..120, - 120..121, - 121..122, - 122..123, - 123..124, - 124..132, - 132..133, - 133..134, - 134..142, - 142..148, - 148..149, - 149..150, - 150..151, - 151..152, - 152..156, - 156..157, - ], - }; - - test(source, expected_input); + test(source, "test_function"); } - - // #[test] - // fn test_gen() { - // let source = r#" - // "#; - - // let input = Input::new(&source); - // println!("{:?}", input.kind); - // println!("{:?}", input.position); - // } } diff --git a/crates/parser/src/snapshots/parser__input__tests__test_comment_block.snap b/crates/parser/src/snapshots/parser__input__tests__test_comment_block.snap new file mode 100644 index 0000000..f6bdb27 --- /dev/null +++ b/crates/parser/src/snapshots/parser__input__tests__test_comment_block.snap @@ -0,0 +1,43 @@ +--- +source: crates/parser/src/input.rs +expression: input +--- +kind: + - EndLine + - WhiteSpace + - BlockComment + - EndLine + - WhiteSpace + - Identifier + - WhiteSpace + - Add + - WhiteSpace + - Number + - EndLine + - WhiteSpace +source: "\n /*a + b == 10*/\n a + 10\n " +position: + - start: 0 + end: 1 + - start: 1 + end: 9 + - start: 9 + end: 24 + - start: 24 + end: 25 + - start: 25 + end: 33 + - start: 33 + end: 34 + - start: 34 + end: 35 + - start: 35 + end: 36 + - start: 36 + end: 37 + - start: 37 + end: 39 + - start: 39 + end: 40 + - start: 40 + end: 44 diff --git a/crates/parser/src/snapshots/parser__input__tests__test_comment_error.snap b/crates/parser/src/snapshots/parser__input__tests__test_comment_error.snap new file mode 100644 index 0000000..f8307a5 --- /dev/null +++ b/crates/parser/src/snapshots/parser__input__tests__test_comment_error.snap @@ -0,0 +1,34 @@ +--- +source: crates/parser/src/input.rs +expression: input +--- +kind: + - EndLine + - WhiteSpace + - Pragma + - WhiteSpace + - Version + - Semicolon + - EndLine + - WhiteSpace + - Error +source: "\n pragma 2.1.1;\n /*a + b == 10*\n a + 10\n template\n\n /*\n " +position: + - start: 0 + end: 1 + - start: 1 + end: 9 + - start: 9 + end: 15 + - start: 15 + end: 16 + - start: 16 + end: 21 + - start: 21 + end: 22 + - start: 22 + end: 23 + - start: 23 + end: 31 + - start: 31 + end: 94 diff --git a/crates/parser/src/snapshots/parser__input__tests__test_function.snap b/crates/parser/src/snapshots/parser__input__tests__test_function.snap new file mode 100644 index 0000000..dd235e2 --- /dev/null +++ b/crates/parser/src/snapshots/parser__input__tests__test_function.snap @@ -0,0 +1,217 @@ +--- +source: crates/parser/src/input.rs +expression: input +--- +kind: + - EndLine + - WhiteSpace + - FunctionKw + - WhiteSpace + - Identifier + - LParen + - Identifier + - RParen + - WhiteSpace + - LCurly + - EndLine + - WhiteSpace + - VarKw + - WhiteSpace + - Identifier + - WhiteSpace + - Assign + - WhiteSpace + - Number + - Semicolon + - EndLine + - WhiteSpace + - VarKw + - WhiteSpace + - Identifier + - WhiteSpace + - Assign + - WhiteSpace + - Number + - Semicolon + - EndLine + - WhiteSpace + - WhileKw + - WhiteSpace + - LParen + - Identifier + - Sub + - Number + - LessThan + - Identifier + - RParen + - WhiteSpace + - LCurly + - EndLine + - WhiteSpace + - Identifier + - Add + - Add + - Semicolon + - EndLine + - WhiteSpace + - Identifier + - WhiteSpace + - Mul + - Assign + - WhiteSpace + - Number + - Semicolon + - EndLine + - WhiteSpace + - RCurly + - EndLine + - WhiteSpace + - ReturnKw + - WhiteSpace + - Identifier + - Semicolon + - EndLine + - WhiteSpace + - RCurly +source: "\n function nbits(a) {\n var n = 1;\n var r = 0;\n while (n-1 Date: Wed, 25 Dec 2024 12:17:10 +0700 Subject: [PATCH 23/71] change param type in find signal into str --- crates/parser/src/parser.rs | 4 ++-- .../src/abstract_syntax_tree/template.rs | 13 ++++++------- crates/syntax/src/syntax.rs | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index a4f0efe..2fbe667 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -181,8 +181,8 @@ impl<'a> Parser<'a> { if self.at(kind) { self.advance(); } else { - // error report - // println!("expect {:?} but got {:?}", kind, current); + // TODO + // advance_with_error: ("expect {:?} but got {:?}", kind, current); } } diff --git a/crates/syntax/src/abstract_syntax_tree/template.rs b/crates/syntax/src/abstract_syntax_tree/template.rs index ab2f354..7253b12 100644 --- a/crates/syntax/src/abstract_syntax_tree/template.rs +++ b/crates/syntax/src/abstract_syntax_tree/template.rs @@ -1,5 +1,4 @@ use parser::token_kind::TokenKind::*; -use rowan::SyntaxText; use crate::syntax_node::CircomLanguage; use crate::syntax_node::SyntaxNode; @@ -45,11 +44,11 @@ impl AstTemplateDef { None } - pub fn find_input_signal(&self, name: &SyntaxText) -> Option { + pub fn find_input_signal(&self, name: &str) -> Option { if let Some(statements) = self.statements() { for input_signal in statements.find_children::() { if let Some(signal_name) = input_signal.name() { - if signal_name.equal(name) { + if signal_name.syntax().text() == name { return Some(input_signal); } } @@ -58,11 +57,11 @@ impl AstTemplateDef { None } - pub fn find_output_signal(&self, name: &SyntaxText) -> Option { + pub fn find_output_signal(&self, name: &str) -> Option { if let Some(statements) = self.statements() { for input_signal in statements.find_children::() { if let Some(signal_name) = input_signal.name() { - if signal_name.equal(name) { + if signal_name.syntax().text() == name { return Some(input_signal); } } @@ -71,11 +70,11 @@ impl AstTemplateDef { None } - pub fn find_internal_signal(&self, name: &SyntaxText) -> Option { + pub fn find_internal_signal(&self, name: &str) -> Option { if let Some(statements) = self.statements() { for signal in statements.find_children::() { if let Some(signal_name) = signal.name() { - if signal_name.equal(name) { + if signal_name.syntax().text() == name { return Some(signal); } } diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 0c1d1b8..a2fe669 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -230,16 +230,15 @@ mod grammar_tests { use parser::{grammar::entry::Scope, input::Input, parser::Parser}; use rowan::{ast::AstNode, SyntaxNode}; - use crate::{ - abstract_syntax_tree::{AstBlock, AstPragma, AstTemplateDef}, + abstract_syntax_tree::{AstBlock, AstOutputSignalDecl, AstPragma, AstTemplateDef}, syntax::SyntaxTreeBuilder, syntax_node::CircomLanguage, }; - fn syntax_node_from_source(source: &str) -> SyntaxNode { + fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { let input = Input::new(&source); - let output = Parser::parsing_with_scope(&input, Scope::Pragma); + let output = Parser::parsing_with_scope(&input, scope); // output is a tree whose node is index of token, no content of token // convert output into green node @@ -259,7 +258,7 @@ mod grammar_tests { let version = r#"2.0.1"#; let source = format!(r#"pragma circom {};"#, version); - let syntax = syntax_node_from_source(&source); + let syntax = syntax_node_from_source(&source, Scope::Pragma); // cast syntax node into ast node to retrieve more information let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); @@ -290,7 +289,7 @@ mod grammar_tests { }"#; - let syntax = syntax_node_from_source(&SOURCE); + let syntax = syntax_node_from_source(&SOURCE, Scope::Template); // cast syntax node into ast node to retrieve more information let template = @@ -329,8 +328,12 @@ mod grammar_tests { insta::assert_yaml_snapshot!(last_param, @"QQ"); // statements - let statements = template.statements().unwrap().statement_list(); + let statements = template.statements().unwrap(); + let output_signal = statements.find_children::(); + println!("{:?}", output_signal); + let statements: Vec = statements + .statement_list() .into_iter() .map(|statement| statement.syntax().text().to_string()) .collect(); @@ -372,7 +375,7 @@ mod grammar_tests { out <== comp[N-2].out; }"#; - let syntax = syntax_node_from_source(&source); + let syntax = syntax_node_from_source(&source, Scope::Block); // cast syntax node into ast node to retrieve more information let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); From cafff028e7e9528b4d07ce64f9f5d8f2455d8b8e Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 27 Dec 2024 21:03:15 +0700 Subject: [PATCH 24/71] add snapshot guild --- SNAPSHOT_TEST.md | 11 +++++++++++ crates/syntax/src/syntax.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 SNAPSHOT_TEST.md diff --git a/SNAPSHOT_TEST.md b/SNAPSHOT_TEST.md new file mode 100644 index 0000000..304166f --- /dev/null +++ b/SNAPSHOT_TEST.md @@ -0,0 +1,11 @@ +# Snapshot Test + +* Run all tests: + ``` + cargo test + ``` + +* Review snapshot changes + ``` + cargo insta review + ``` \ No newline at end of file diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index a2fe669..8e194e0 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -304,7 +304,7 @@ mod grammar_tests { .syntax() .text() .to_string(); - insta::assert_yaml_snapshot!(name, @"MultiplierN"); + insta::assert_yaml_snapshot!(name, @r###"" MultiplierN""###); // parameter list let first_param = template From 03da99a9dcd3c24258d3929ef329ca5365b4f4d6 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 27 Dec 2024 23:23:54 +0700 Subject: [PATCH 25/71] add some combine arithmetic operators --- crates/parser/src/token_kind.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 9eba89c..62b28bb 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -67,6 +67,26 @@ pub enum TokenKind { Semicolon, #[token(",")] Comma, + // TODO: review + #[token("++")] + UnitInc, + #[token("--")] + UnitDec, + #[token("+=")] + AddAssign, + #[token("-=")] + SubAssign, + #[token("/=")] + DivAssign, + #[token(r"\=")] + IntDivAssign, + #[token("%=")] + ModAssign, + #[token("*=")] + MulAssign, + #[token("**=")] + PowerAssign, + // end review #[token("=")] Assign, #[token("===")] @@ -227,12 +247,18 @@ impl TokenKind { Self::Add | Self::Sub => Some((92, 93)), Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), Self::Power => Some((96, 97)), + // TODO: review + Self::AddAssign | Self::SubAssign => Some((98,99)), + Self::MulAssign | Self::DivAssign | Self::IntDivAssign | Self::ModAssign => Some((100,101)), + Self::PowerAssign => Some((102,103)), _ => None, } } pub fn prefix(self) -> Option { match self { + // TODO: review UnitDec, UnitInc + Self::UnitDec | Self::UnitInc => Some(101), Self::Sub => Some(100), Self::Not => Some(99), Self::BitNot => Some(98), @@ -242,6 +268,8 @@ impl TokenKind { pub fn postfix(self) -> Option { match self { + // TODO: review UnitDec, UnitInc + Self::UnitDec | Self::UnitInc => Some(202), Self::Dot => Some(200), Self::LBracket => Some(201), _ => None, From 7792a96c5d0a556a9b57ee638afe42267a0d92fe Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 27 Dec 2024 23:25:34 +0700 Subject: [PATCH 26/71] error report in expect and expect_any --- crates/parser/src/event.rs | 3 ++- crates/parser/src/output.rs | 8 ++++++++ crates/parser/src/parser.rs | 19 +++++++++++++------ crates/syntax/src/syntax.rs | 27 ++++++++++++++++++++------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/crates/parser/src/event.rs b/crates/parser/src/event.rs index 16996b9..bd9c2cc 100644 --- a/crates/parser/src/event.rs +++ b/crates/parser/src/event.rs @@ -1,8 +1,9 @@ use crate::token_kind::TokenKind; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub enum Event { Open { kind: TokenKind }, Close, TokenPosition(usize), + ErrorReport(String), } diff --git a/crates/parser/src/output.rs b/crates/parser/src/output.rs index 271c2c3..b594a3e 100644 --- a/crates/parser/src/output.rs +++ b/crates/parser/src/output.rs @@ -3,6 +3,7 @@ use crate::{event::Event, token_kind::TokenKind}; #[derive(Debug)] pub enum Child { Token(usize), // position of token, + Error(String), Tree(Tree), } @@ -58,6 +59,13 @@ impl From> for Output { .children .push(Child::Token(*token)); } + Event::ErrorReport(error) => { + stack + .last_mut() + .unwrap() + .children + .push(Child::Error(error.clone())); + } } } } diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 2fbe667..b121669 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -88,6 +88,15 @@ impl<'a> Parser<'a> { } self.close(m, TokenKind::Error); } + + pub fn error_report(&mut self, error: String) { + let m = self.open(); + + let token = Event::ErrorReport(error); + self.events.push(token); + + self.close(m, TokenKind::Error); + } } impl<'a> Parser<'a> { @@ -170,19 +179,17 @@ impl<'a> Parser<'a> { if kinds.contains(&kind) { self.advance(); } else { - // error report - // println!("expect {:?} but got {:?}", kinds, kind); + let error = format!("expect {:?} but got {:?}", kinds, kind); + self.error_report(error); } } pub fn expect(&mut self, kind: TokenKind) { - let _current = self.current(); - if self.at(kind) { self.advance(); } else { - // TODO - // advance_with_error: ("expect {:?} but got {:?}", kind, current); + let error = format!("expect {:?} but got {:?}", kind, self.current()); + self.error_report(error); } } diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 8e194e0..1d65867 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -1,6 +1,7 @@ use parser::input::Input; use parser::output::{Child, Output}; use parser::parser::Parser; +use parser::token_kind::TokenKind; use rowan::{GreenNode, GreenNodeBuilder}; use crate::syntax_node::SyntaxNode; @@ -30,6 +31,14 @@ impl<'a> SyntaxTreeBuilder<'a> { self.builder.finish_node(); } Child::Tree(child_tree) => self.build_rec(child_tree), + Child::Error(error) => { + let token_kind = TokenKind::Error; + let token_value = error.as_str(); + + self.builder.start_node(token_kind.into()); + self.builder.token(token_kind.into(), token_value); + self.builder.finish_node(); + } } } @@ -113,6 +122,10 @@ mod tests { .function_list() .iter() .map(|function| { + println!( + "function body:\n{:?}", + function.body().unwrap().syntax().text().to_string() + ); function .function_name() .unwrap() @@ -177,11 +190,11 @@ mod tests { let pragma = pragma_string_from_ast(&ast); insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - let template_names = template_names_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); - let function_names = function_names_from_ast(&ast); insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); + + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); } #[test] @@ -228,13 +241,13 @@ mod tests { #[cfg(test)] mod grammar_tests { - use parser::{grammar::entry::Scope, input::Input, parser::Parser}; - use rowan::{ast::AstNode, SyntaxNode}; use crate::{ abstract_syntax_tree::{AstBlock, AstOutputSignalDecl, AstPragma, AstTemplateDef}, syntax::SyntaxTreeBuilder, syntax_node::CircomLanguage, }; + use parser::{grammar::entry::Scope, input::Input, parser::Parser}; + use rowan::{ast::AstNode, SyntaxNode}; fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { let input = Input::new(&source); @@ -304,7 +317,7 @@ mod grammar_tests { .syntax() .text() .to_string(); - insta::assert_yaml_snapshot!(name, @r###"" MultiplierN""###); + insta::assert_yaml_snapshot!(name, @"MultiplierN"); // parameter list let first_param = template @@ -331,7 +344,7 @@ mod grammar_tests { let statements = template.statements().unwrap(); let output_signal = statements.find_children::(); println!("{:?}", output_signal); - + let statements: Vec = statements .statement_list() .into_iter() From 6ac9ac990ef9317eafc6cee33e44fa3c72513808 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Fri, 27 Dec 2024 23:30:44 +0700 Subject: [PATCH 27/71] update snapshot for combine operators --- .../snapshots/parser__input__tests__test_function.snap | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/parser/src/snapshots/parser__input__tests__test_function.snap b/crates/parser/src/snapshots/parser__input__tests__test_function.snap index dd235e2..39cbb10 100644 --- a/crates/parser/src/snapshots/parser__input__tests__test_function.snap +++ b/crates/parser/src/snapshots/parser__input__tests__test_function.snap @@ -49,15 +49,13 @@ kind: - EndLine - WhiteSpace - Identifier - - Add - - Add + - UnitInc - Semicolon - EndLine - WhiteSpace - Identifier - WhiteSpace - - Mul - - Assign + - MulAssign - WhiteSpace - Number - Semicolon @@ -168,8 +166,6 @@ position: - start: 99 end: 100 - start: 100 - end: 101 - - start: 101 end: 102 - start: 102 end: 103 @@ -182,8 +178,6 @@ position: - start: 117 end: 118 - start: 118 - end: 119 - - start: 119 end: 120 - start: 120 end: 121 From ec73df88356ef33167bc043ad7f2c91fc0ee7962 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sat, 28 Dec 2024 14:31:30 +0700 Subject: [PATCH 28/71] update snapshot test --- .../syntax__syntax__tests__syntax_test_2_functions.snap | 2 +- .../syntax__syntax__tests__syntax_test_2_templates.snap | 2 +- .../syntax__syntax__tests__syntax_test_5_templates.snap | 2 +- .../syntax__syntax__tests__syntax_test_6_templates.snap | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap index 49ea709..0913804 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: function_names --- -- "nbits" +- nbits diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap index 03a1b69..db61c87 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: template_names --- -- "BinSum" +- BinSum diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap index 53cde17..8050901 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: template_names --- -- "Multiplier2" +- Multiplier2 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap index 53cde17..8050901 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: template_names --- -- "Multiplier2" +- Multiplier2 From 5bdda2fad69a2c84500f1b7da838ebc0fd917018 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sat, 28 Dec 2024 14:35:14 +0700 Subject: [PATCH 29/71] fix wrap trivial tokens before open a tree --- crates/parser/src/parser.rs | 37 ++++++++++++++++++++++++------------- crates/syntax/src/syntax.rs | 4 ---- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index b121669..34a2f64 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -28,7 +28,29 @@ pub enum ParserError { } impl<'a> Parser<'a> { + pub fn wrap_trivial_tokens(&mut self) -> TokenKind { + loop { + let kind = self.input.kind_of(self.pos); + + if kind.is_trivial() == false { + return kind; + } + + self.events.push(Event::Open { kind }); + + self.fuel.set(256); + self.events.push(Event::TokenPosition(self.pos)); + self.skip(); + + self.events.push(Event::Close); + } + } + pub fn open(&mut self) -> Marker { + if self.events.len() > 0 { + self.wrap_trivial_tokens(); + } + let marker = Marker::Open(self.events.len()); self.events.push(Event::Open { kind: TokenKind::Error, @@ -119,19 +141,7 @@ impl<'a> Parser<'a> { } pub fn current(&mut self) -> TokenKind { - let mut kind: TokenKind; - loop { - kind = self.input.kind_of(self.pos); - if !kind.is_trivial() { - break; - } - - let m = self.open(); - self.advance(); - self.close(m, kind); - } - - kind + self.wrap_trivial_tokens() } pub fn next(&mut self) -> TokenKind { @@ -171,6 +181,7 @@ impl<'a> Parser<'a> { self.advance(); return true; } + false } diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 1d65867..054f39d 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -122,10 +122,6 @@ mod tests { .function_list() .iter() .map(|function| { - println!( - "function body:\n{:?}", - function.body().unwrap().syntax().text().to_string() - ); function .function_name() .unwrap() From 8e4853de21093dc348708f3ff50dc36d1e725214 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sat, 28 Dec 2024 15:13:14 +0700 Subject: [PATCH 30/71] update template happy test --- crates/syntax/src/syntax.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 054f39d..a2f9f39 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -348,17 +348,21 @@ mod grammar_tests { .collect(); insta::assert_yaml_snapshot!("template_happy_test_statements", statements); - // // input signal - // println!("find_input_signal: {:?}", template.find_input_signal()); + // input signal + let input_signal = template.find_input_signal("in").unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); - // // output signal - // println!("find_output_signal: {:?}", template.find_output_signal()); + // output signal + let output_signal = template.find_output_signal("out").unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); - // // internal signal - // println!("find_internal_signal: {:?}", template.find_internal_signal()); + // internal signal + let internal_signal = template.find_internal_signal("in").is_none(); + insta::assert_yaml_snapshot!(internal_signal, @"true"); - // // component - // println!("find_component: {:?}", template.find_component()); + // component + let component = template.find_component("comp").unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); } #[test] From bb95297c47d898881305384c17c76362e678367d Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sat, 28 Dec 2024 17:43:19 +0700 Subject: [PATCH 31/71] add operators into token kinds --- crates/lsp/src/handler/goto_definition.rs | 2 +- crates/parser/src/token_kind.rs | 180 +++++++++++++--------- 2 files changed, 105 insertions(+), 77 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 4cba681..10ef0ed 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -228,7 +228,7 @@ template Y() { let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - + if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { for template in program_ast.template_list() { println!("{template:?}"); diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 62b28bb..1265324 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -5,24 +5,29 @@ use serde::Serialize; #[allow(non_camel_case_types)] #[repr(u16)] pub enum TokenKind { + // Error #[error] Error = 0, + // Comments #[regex(r"//[^\n]*")] CommentLine, #[token("/*")] CommentBlockOpen, #[token("*/")] CommentBlockClose, + // Trivial #[regex("[ \t]+")] WhiteSpace, #[regex("[\n]")] EndLine, + // Circom #[token("pragma")] Pragma, #[token("circom")] Circom, #[regex("2.[0-9].[0-9]")] Version, + // Literals #[regex("[0-9]+")] Number, #[regex("[$_]*[a-zA-Z][a-zA-Z0-9_$]*")] @@ -31,26 +36,7 @@ pub enum TokenKind { CircomString, #[token("template")] TemplateKw, - #[token("function")] - FunctionKw, - #[token("component")] - ComponentKw, - #[token("main")] - MainKw, - #[token("public")] - PublicKw, - #[token("signal")] - SignalKw, - #[token("var")] - VarKw, - #[token("include")] - IncludeKw, - #[token("input")] - InputKw, - #[token("output")] - OutputKw, - #[token("log")] - LogKw, + // Brackets #[token("(")] LParen, #[token(")")] @@ -63,30 +49,94 @@ pub enum TokenKind { LBracket, #[token("]")] RBracket, + // Punctuation #[token(";")] Semicolon, #[token(",")] Comma, - // TODO: review - #[token("++")] - UnitInc, - #[token("--")] - UnitDec, + #[token(".")] + Dot, + // Boolean operators + #[token("&&")] + BoolAnd, + #[token("||")] + BoolOr, + #[token("!")] + Not, + // Relational operators + #[token("==")] + Equal, + #[token("!=")] + NotEqual, + #[token("<")] + LessThan, + #[token(">")] + GreaterThan, + #[token("<=")] + LessThanAndEqual, + #[token(">=")] + GreaterThanAndEqual, + // Arithmetic operators + #[token("+")] + Add, + #[token("-")] + Sub, + #[token("*")] + Mul, + #[token("**")] + Power, + #[token("/")] + Div, + #[token("\\")] + IntDiv, + #[token("%")] + Mod, + // Combined arithmetic assignment #[token("+=")] AddAssign, #[token("-=")] SubAssign, + #[token("*=")] + MulAssign, + #[token("**=")] + PowerAssign, #[token("/=")] DivAssign, #[token(r"\=")] IntDivAssign, #[token("%=")] ModAssign, - #[token("*=")] - MulAssign, - #[token("**=")] - PowerAssign, - // end review + #[token("++")] + UnitInc, + #[token("--")] + UnitDec, + // Bitwise operators + #[token("&")] + BitAnd, + #[token("|")] + BitOr, + #[token("~")] + BitNot, + #[token("^")] + BitXor, + #[token(">>")] + ShiftR, + #[token("<<")] + ShiftL, + // Combined bitwise assignments + #[token("&=")] + BitAndAssign, + #[token("|=")] + BitOrAssign, + #[token("~=")] + BitNotAssign, + #[token("^=")] + BitXorAssign, + #[token(">>=")] + ShiftRAssign, + #[token("<<=")] + ShiftLAssign, + // Assign #[token("=")] Assign, #[token("===")] @@ -99,56 +149,33 @@ pub enum TokenKind { RAssignSignal, #[token("<==")] RAssignConstraintSignal, - #[token("+")] - Add, - #[token("-")] - Sub, - #[token("/")] - Div, - #[token("*")] - Mul, - #[token("!")] - Not, - #[token("~")] - BitNot, - #[token("**")] - Power, - #[token("\\")] - IntDiv, - #[token("%")] - Mod, - #[token("<<")] - ShiftL, - #[token(">>")] - ShiftR, - #[token("&")] - BitAnd, - #[token("|")] - BitOr, - #[token("^")] - BitXor, - #[token("==")] - Equal, - #[token("!=")] - NotEqual, - #[token("<")] - LessThan, - #[token(">")] - GreaterThan, - #[token("<=")] - LessThanAndEqual, - #[token(">=")] - GreaterThanAndEqual, - #[token("&&")] - BoolAnd, - #[token("||")] - BoolOr, + // Conditional expressions #[token("?")] MarkQuestion, #[token(":")] Colon, - #[token(".")] - Dot, + // Keywords + #[token("function")] + FunctionKw, + #[token("component")] + ComponentKw, + #[token("main")] + MainKw, + #[token("public")] + PublicKw, + #[token("signal")] + SignalKw, + #[token("var")] + VarKw, + #[token("include")] + IncludeKw, + #[token("input")] + InputKw, + #[token("output")] + OutputKw, + #[token("log")] + LogKw, + // Statement keywords #[token("if")] IfKw, #[token("else")] @@ -161,6 +188,7 @@ pub enum TokenKind { ReturnKw, #[token("assert")] AssertKw, + // Complex token kind ForLoop, AssignStatement, CircomProgram, From 97bb6899c806c5996525ec82b20092884ce5fdab Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 10:59:12 +0700 Subject: [PATCH 32/71] add operators test --- crates/parser/src/input.rs | 30 ++ .../parser__input__tests__test_operators.snap | 391 ++++++++++++++++++ crates/parser/src/token_kind.rs | 4 +- 3 files changed, 423 insertions(+), 2 deletions(-) create mode 100644 crates/parser/src/snapshots/parser__input__tests__test_operators.snap diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index c57648e..0289561 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -138,4 +138,34 @@ mod tests { }"#; test(source, "test_function"); } + + #[test] + fn test_operators() { + let source = r#" + ({[]}) + ;.,: + && & + || | + != ! + === == = + --> ==> + <-- <== + <= < + >= > + ++ += + + -- -= - + **= ** + * *= + / /= + \ \= + % %= + ^ ^= + ~ ~= + >> >>= + << <<= + & &= + | |= + }"#; + test(source, "test_operators"); + } } diff --git a/crates/parser/src/snapshots/parser__input__tests__test_operators.snap b/crates/parser/src/snapshots/parser__input__tests__test_operators.snap new file mode 100644 index 0000000..1366b66 --- /dev/null +++ b/crates/parser/src/snapshots/parser__input__tests__test_operators.snap @@ -0,0 +1,391 @@ +--- +source: crates/parser/src/input.rs +expression: input +--- +kind: + - EndLine + - WhiteSpace + - LParen + - LCurly + - LBracket + - RBracket + - RCurly + - RParen + - EndLine + - WhiteSpace + - Semicolon + - Dot + - Comma + - Colon + - EndLine + - WhiteSpace + - BoolAnd + - WhiteSpace + - BitAnd + - EndLine + - WhiteSpace + - BoolOr + - WhiteSpace + - BitOr + - EndLine + - WhiteSpace + - NotEqual + - WhiteSpace + - Not + - EndLine + - WhiteSpace + - EqualSignal + - WhiteSpace + - Equal + - WhiteSpace + - Assign + - EndLine + - WhiteSpace + - LAssignSignal + - WhiteSpace + - LAssignContraintSignal + - EndLine + - WhiteSpace + - RAssignSignal + - WhiteSpace + - RAssignConstraintSignal + - EndLine + - WhiteSpace + - LessThanAndEqual + - WhiteSpace + - LessThan + - EndLine + - WhiteSpace + - GreaterThanAndEqual + - WhiteSpace + - GreaterThan + - EndLine + - WhiteSpace + - UnitInc + - WhiteSpace + - AddAssign + - WhiteSpace + - Add + - EndLine + - WhiteSpace + - UnitDec + - WhiteSpace + - SubAssign + - WhiteSpace + - Sub + - EndLine + - WhiteSpace + - PowerAssign + - WhiteSpace + - Power + - EndLine + - WhiteSpace + - Mul + - WhiteSpace + - MulAssign + - EndLine + - WhiteSpace + - Div + - WhiteSpace + - DivAssign + - EndLine + - WhiteSpace + - IntDiv + - WhiteSpace + - IntDivAssign + - EndLine + - WhiteSpace + - Mod + - WhiteSpace + - ModAssign + - EndLine + - WhiteSpace + - BitXor + - WhiteSpace + - BitXorAssign + - EndLine + - WhiteSpace + - BitNot + - WhiteSpace + - BitNotAssign + - EndLine + - WhiteSpace + - ShiftR + - WhiteSpace + - ShiftRAssign + - EndLine + - WhiteSpace + - ShiftL + - WhiteSpace + - ShiftLAssign + - EndLine + - WhiteSpace + - BitAnd + - WhiteSpace + - BitAndAssign + - EndLine + - WhiteSpace + - BitOr + - WhiteSpace + - BitOrAssign + - EndLine + - WhiteSpace + - RCurly +source: "\n ({[]})\n ;.,:\n && &\n || |\n != !\n === == =\n --> ==>\n <-- <==\n <= <\n >= >\n ++ += +\n -- -= -\n **= **\n * *=\n / /=\n \\ \\=\n % %=\n ^ ^=\n ~ ~=\n >> >>=\n << <<=\n & &=\n | |=\n }" +position: + - start: 0 + end: 1 + - start: 1 + end: 9 + - start: 9 + end: 10 + - start: 10 + end: 11 + - start: 11 + end: 12 + - start: 12 + end: 13 + - start: 13 + end: 14 + - start: 14 + end: 15 + - start: 15 + end: 16 + - start: 16 + end: 24 + - start: 24 + end: 25 + - start: 25 + end: 26 + - start: 26 + end: 27 + - start: 27 + end: 28 + - start: 28 + end: 29 + - start: 29 + end: 37 + - start: 37 + end: 39 + - start: 39 + end: 40 + - start: 40 + end: 41 + - start: 41 + end: 42 + - start: 42 + end: 50 + - start: 50 + end: 52 + - start: 52 + end: 53 + - start: 53 + end: 54 + - start: 54 + end: 55 + - start: 55 + end: 63 + - start: 63 + end: 65 + - start: 65 + end: 66 + - start: 66 + end: 67 + - start: 67 + end: 68 + - start: 68 + end: 76 + - start: 76 + end: 79 + - start: 79 + end: 80 + - start: 80 + end: 82 + - start: 82 + end: 83 + - start: 83 + end: 84 + - start: 84 + end: 85 + - start: 85 + end: 93 + - start: 93 + end: 96 + - start: 96 + end: 97 + - start: 97 + end: 100 + - start: 100 + end: 101 + - start: 101 + end: 109 + - start: 109 + end: 112 + - start: 112 + end: 113 + - start: 113 + end: 116 + - start: 116 + end: 117 + - start: 117 + end: 125 + - start: 125 + end: 127 + - start: 127 + end: 128 + - start: 128 + end: 129 + - start: 129 + end: 130 + - start: 130 + end: 138 + - start: 138 + end: 140 + - start: 140 + end: 141 + - start: 141 + end: 142 + - start: 142 + end: 143 + - start: 143 + end: 151 + - start: 151 + end: 153 + - start: 153 + end: 154 + - start: 154 + end: 156 + - start: 156 + end: 157 + - start: 157 + end: 158 + - start: 158 + end: 159 + - start: 159 + end: 167 + - start: 167 + end: 169 + - start: 169 + end: 170 + - start: 170 + end: 172 + - start: 172 + end: 173 + - start: 173 + end: 174 + - start: 174 + end: 175 + - start: 175 + end: 183 + - start: 183 + end: 186 + - start: 186 + end: 187 + - start: 187 + end: 189 + - start: 189 + end: 190 + - start: 190 + end: 198 + - start: 198 + end: 199 + - start: 199 + end: 200 + - start: 200 + end: 202 + - start: 202 + end: 203 + - start: 203 + end: 211 + - start: 211 + end: 212 + - start: 212 + end: 213 + - start: 213 + end: 215 + - start: 215 + end: 216 + - start: 216 + end: 224 + - start: 224 + end: 225 + - start: 225 + end: 226 + - start: 226 + end: 228 + - start: 228 + end: 229 + - start: 229 + end: 237 + - start: 237 + end: 238 + - start: 238 + end: 239 + - start: 239 + end: 241 + - start: 241 + end: 242 + - start: 242 + end: 250 + - start: 250 + end: 251 + - start: 251 + end: 252 + - start: 252 + end: 254 + - start: 254 + end: 255 + - start: 255 + end: 263 + - start: 263 + end: 264 + - start: 264 + end: 265 + - start: 265 + end: 267 + - start: 267 + end: 268 + - start: 268 + end: 276 + - start: 276 + end: 278 + - start: 278 + end: 279 + - start: 279 + end: 282 + - start: 282 + end: 283 + - start: 283 + end: 291 + - start: 291 + end: 293 + - start: 293 + end: 294 + - start: 294 + end: 297 + - start: 297 + end: 298 + - start: 298 + end: 306 + - start: 306 + end: 307 + - start: 307 + end: 308 + - start: 308 + end: 310 + - start: 310 + end: 311 + - start: 311 + end: 319 + - start: 319 + end: 320 + - start: 320 + end: 321 + - start: 321 + end: 323 + - start: 323 + end: 324 + - start: 324 + end: 328 + - start: 328 + end: 329 diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 1265324..9f1e3cb 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -34,8 +34,6 @@ pub enum TokenKind { Identifier, #[regex(r#""[^"]*""#)] CircomString, - #[token("template")] - TemplateKw, // Brackets #[token("(")] LParen, @@ -155,6 +153,8 @@ pub enum TokenKind { #[token(":")] Colon, // Keywords + #[token("template")] + TemplateKw, #[token("function")] FunctionKw, #[token("component")] From 179f6bc77c7fa9ec3246c3852b311bb10c5bd55b Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 12:37:07 +0700 Subject: [PATCH 33/71] re-priority token kinds --- crates/parser/src/token_kind.rs | 98 +++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 9f1e3cb..21d3625 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -47,7 +47,7 @@ pub enum TokenKind { LBracket, #[token("]")] RBracket, - // Punctuation + // Punctuation #[token(";")] Semicolon, #[token(",")] @@ -121,7 +121,7 @@ pub enum TokenKind { ShiftR, #[token("<<")] ShiftL, - // Combined bitwise assignments + // Combined bitwise assignments #[token("&=")] BitAndAssign, #[token("|=")] @@ -254,52 +254,94 @@ impl From for rowan::SyntaxKind { } impl TokenKind { + // a + 10 --> a and 10 are literals pub fn is_literal(self) -> bool { matches!(self, Self::Number | Self::Identifier) } + // these tokens have the lowest priority + // infix_operator + // eg: a + b --> + is an infix token pub fn infix(self) -> Option<(u16, u16)> { match self { - Self::BoolOr => Some((78, 79)), - Self::BoolAnd => Some((80, 81)), - Self::Equal - | Self::NotEqual - | Self::LessThan + // arithmetic operators + Self::Power => Some((99, 100)), + Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), + Self::Add | Self::Sub => Some((89, 90)), + + // shift bitwise operators + Self::ShiftL | Self::ShiftR => Some((84, 85)), + + // relational operators + Self::LessThan | Self::GreaterThan | Self::LessThanAndEqual - | Self::GreaterThanAndEqual => Some((82, 83)), - Self::BitOr => Some((84, 85)), - Self::BitXor => Some((86, 87)), - Self::BitAnd => Some((88, 89)), - Self::ShiftL | Self::ShiftR => Some((90, 91)), - Self::Add | Self::Sub => Some((92, 93)), - Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), - Self::Power => Some((96, 97)), - // TODO: review - Self::AddAssign | Self::SubAssign => Some((98,99)), - Self::MulAssign | Self::DivAssign | Self::IntDivAssign | Self::ModAssign => Some((100,101)), - Self::PowerAssign => Some((102,103)), + | Self::GreaterThanAndEqual => Some((79, 80)), + Self::Equal + | Self::NotEqual => Some((74, 75)), + + // other bitwise operators + Self::BitAnd => Some((69, 70)), + Self::BitXor => Some((64, 65)), // exclusive or + Self::BitOr => Some((59, 60)), + + // boolean operators + Self::BoolAnd => Some((54, 55)), + Self::BoolOr => Some((49, 50)), + + // TODO: how about conditional operation ( ? : ) + // associativity: right to left [ a ? b : c --> ??? ] + + // associativity: right to left [ a = b = c --> a = (b = c) ] + // assignment operators + Self::Assign + // bitwise asignment operators + | Self::BitOrAssign + | Self::BitXorAssign + | Self::BitAndAssign + | Self::ShiftLAssign + | Self::ShiftRAssign + // arithmetic asignament operators + | Self::AddAssign + | Self::SubAssign + | Self::MulAssign + | Self::DivAssign + | Self::IntDivAssign + | Self::ModAssign + | Self::PowerAssign => Some((44, 45)), + + // TODO: how about comma (expression separator) + Self::Comma => Some((39, 40)), + + // not an infix operator _ => None, } } + // priority: post > pre > in + // associativity: right to left [ --!a --> --(!a) ] + // prefix_operator + // eg: -10, !a, ++a, --a pub fn prefix(self) -> Option { match self { - // TODO: review UnitDec, UnitInc - Self::UnitDec | Self::UnitInc => Some(101), - Self::Sub => Some(100), - Self::Not => Some(99), - Self::BitNot => Some(98), + Self::UnitDec | Self::UnitInc + | Self::Sub | Self::Add + | Self::Not | Self::BitNot => Some(200), + _ => None, } } + // these tokens have the highest priority + // postfix_operator + // eg: a[10], b++, c.att1 pub fn postfix(self) -> Option { match self { - // TODO: review UnitDec, UnitInc - Self::UnitDec | Self::UnitInc => Some(202), - Self::Dot => Some(200), - Self::LBracket => Some(201), + Self::LParen // function call + | Self::LBracket // array subscript + | Self::Dot // attribute access + | Self::UnitDec | Self::UnitInc => Some(300), + _ => None, } } From 40268bf3bdc2894b36ffc23b0599a8bfabb891d6 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 12:54:30 +0700 Subject: [PATCH 34/71] fix clippy check --- crates/lsp/src/handler/goto_definition.rs | 2 +- crates/parser/src/grammar/declaration.rs | 2 +- crates/parser/src/grammar/expression.rs | 2 +- crates/parser/src/grammar/statement.rs | 8 ++++---- crates/parser/src/grammar/template.rs | 2 +- crates/parser/src/input.rs | 2 +- crates/parser/src/token_kind.rs | 12 +++++++----- crates/syntax/src/syntax.rs | 23 +++++++++++++++++++---- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 10ef0ed..4cba681 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -228,7 +228,7 @@ template Y() { let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - + if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { for template in program_ast.template_list() { println!("{template:?}"); diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 27471b3..c5dd125 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -127,4 +127,4 @@ pub(super) fn declaration(p: &mut Parser) { ComponentKw => component_declaration(p), _ => unreachable!(), } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 96c85e0..4604da4 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -155,4 +155,4 @@ fn circom_expression(p: &mut Parser) { p.close(m, TenaryConditional); } } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index d8b75fa..84ca0a6 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -12,7 +12,7 @@ pub(super) fn statement(p: &mut Parser) { /* if (expr) -else +else */ fn if_statement(p: &mut Parser) { @@ -81,7 +81,7 @@ fn for_statement(p: &mut Parser) { p.close(m, ForLoop); } -/* +/* while () */ @@ -93,7 +93,7 @@ fn while_statement(p: &mut Parser) { statement(p); } -/* +/* assert() */ fn assert_statement(p: &mut Parser) { @@ -181,4 +181,4 @@ fn assignment_statement(p: &mut Parser) { } else { p.close(m, Error); } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 359d774..a502365 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -22,4 +22,4 @@ pub fn template(p: &mut Parser) { block::block(p); p.close(m, TemplateDef); -} \ No newline at end of file +} diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index c57648e..fc555cf 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -136,6 +136,6 @@ mod tests { } return r; }"#; - test(source, "test_function"); + test(source, "test_function"); } } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 1265324..2b2cade 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -49,7 +49,7 @@ pub enum TokenKind { LBracket, #[token("]")] RBracket, - // Punctuation + // Punctuation #[token(";")] Semicolon, #[token(",")] @@ -123,7 +123,7 @@ pub enum TokenKind { ShiftR, #[token("<<")] ShiftL, - // Combined bitwise assignments + // Combined bitwise assignments #[token("&=")] BitAndAssign, #[token("|=")] @@ -276,9 +276,11 @@ impl TokenKind { Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), Self::Power => Some((96, 97)), // TODO: review - Self::AddAssign | Self::SubAssign => Some((98,99)), - Self::MulAssign | Self::DivAssign | Self::IntDivAssign | Self::ModAssign => Some((100,101)), - Self::PowerAssign => Some((102,103)), + Self::AddAssign | Self::SubAssign => Some((98, 99)), + Self::MulAssign | Self::DivAssign | Self::IntDivAssign | Self::ModAssign => { + Some((100, 101)) + } + Self::PowerAssign => Some((102, 103)), _ => None, } } diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 56816dc..ded3cc3 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -299,7 +299,7 @@ mod grammar_tests { }"#; let syntax = syntax_node_from_source(&SOURCE, Scope::Template); - + // cast syntax node into ast node to retrieve more information let template = AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); @@ -349,11 +349,21 @@ mod grammar_tests { insta::assert_yaml_snapshot!("template_happy_test_statements", statements); // input signal - let input_signal = template.find_input_signal("in").unwrap().syntax().text().to_string(); + let input_signal = template + .find_input_signal("in") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); // output signal - let output_signal = template.find_output_signal("out").unwrap().syntax().text().to_string(); + let output_signal = template + .find_output_signal("out") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); // internal signal @@ -361,7 +371,12 @@ mod grammar_tests { insta::assert_yaml_snapshot!(internal_signal, @"true"); // component - let component = template.find_component("comp").unwrap().syntax().text().to_string(); + let component = template + .find_component("comp") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); } From 156b8729a85a14ffa0be70bf77e6020191472317 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 12:54:30 +0700 Subject: [PATCH 35/71] fix clippy check --- crates/lsp/src/handler/goto_definition.rs | 2 +- crates/parser/src/grammar/declaration.rs | 2 +- crates/parser/src/grammar/expression.rs | 2 +- crates/parser/src/grammar/statement.rs | 8 ++++---- crates/parser/src/grammar/template.rs | 2 +- crates/parser/src/input.rs | 2 +- crates/syntax/src/syntax.rs | 23 +++++++++++++++++++---- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 10ef0ed..4cba681 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -228,7 +228,7 @@ template Y() { let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - + if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { for template in program_ast.template_list() { println!("{template:?}"); diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 27471b3..c5dd125 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -127,4 +127,4 @@ pub(super) fn declaration(p: &mut Parser) { ComponentKw => component_declaration(p), _ => unreachable!(), } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 96c85e0..4604da4 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -155,4 +155,4 @@ fn circom_expression(p: &mut Parser) { p.close(m, TenaryConditional); } } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index d8b75fa..84ca0a6 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -12,7 +12,7 @@ pub(super) fn statement(p: &mut Parser) { /* if (expr) -else +else */ fn if_statement(p: &mut Parser) { @@ -81,7 +81,7 @@ fn for_statement(p: &mut Parser) { p.close(m, ForLoop); } -/* +/* while () */ @@ -93,7 +93,7 @@ fn while_statement(p: &mut Parser) { statement(p); } -/* +/* assert() */ fn assert_statement(p: &mut Parser) { @@ -181,4 +181,4 @@ fn assignment_statement(p: &mut Parser) { } else { p.close(m, Error); } -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 359d774..a502365 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -22,4 +22,4 @@ pub fn template(p: &mut Parser) { block::block(p); p.close(m, TemplateDef); -} \ No newline at end of file +} diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index 0289561..f22d611 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -136,7 +136,7 @@ mod tests { } return r; }"#; - test(source, "test_function"); + test(source, "test_function"); } #[test] diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 56816dc..ded3cc3 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -299,7 +299,7 @@ mod grammar_tests { }"#; let syntax = syntax_node_from_source(&SOURCE, Scope::Template); - + // cast syntax node into ast node to retrieve more information let template = AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); @@ -349,11 +349,21 @@ mod grammar_tests { insta::assert_yaml_snapshot!("template_happy_test_statements", statements); // input signal - let input_signal = template.find_input_signal("in").unwrap().syntax().text().to_string(); + let input_signal = template + .find_input_signal("in") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); // output signal - let output_signal = template.find_output_signal("out").unwrap().syntax().text().to_string(); + let output_signal = template + .find_output_signal("out") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); // internal signal @@ -361,7 +371,12 @@ mod grammar_tests { insta::assert_yaml_snapshot!(internal_signal, @"true"); // component - let component = template.find_component("comp").unwrap().syntax().text().to_string(); + let component = template + .find_component("comp") + .unwrap() + .syntax() + .text() + .to_string(); insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); } From d18fba0921772711bf835e41c06fa2882464e14b Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 13:06:44 +0700 Subject: [PATCH 36/71] rebase add-token-kinds --- crates/lsp/src/handler/goto_definition.rs | 526 +++++------ crates/parser/src/grammar/declaration.rs | 260 +++--- crates/parser/src/grammar/expression.rs | 316 +++---- crates/parser/src/grammar/statement.rs | 368 ++++---- crates/parser/src/grammar/template.rs | 50 +- .../parser__input__tests__test_operators.snap | 782 ++++++++-------- crates/parser/src/token_kind.rs | 718 +++++++-------- crates/syntax/src/syntax.rs | 838 +++++++++--------- 8 files changed, 1929 insertions(+), 1929 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 4cba681..b02121b 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -1,263 +1,263 @@ -use lsp_types::Location; -use lsp_types::Position; -use lsp_types::Range; -use lsp_types::Url; -use parser::token_kind::TokenKind; -use rowan::ast::AstNode; -use rowan::SyntaxText; - -use syntax::abstract_syntax_tree::AstComponentCall; -use syntax::abstract_syntax_tree::AstInclude; -use syntax::abstract_syntax_tree::AstTemplateDef; -use syntax::abstract_syntax_tree::AstTemplateName; -use syntax::abstract_syntax_tree::{AstCircomProgram, AstComponentDecl}; -use syntax::syntax_node::SyntaxNode; -use syntax::syntax_node::SyntaxToken; - -use crate::database::{FileDB, SemanticData, TokenId}; - -pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Option { - let mut p = token.parent(); - while let Some(t) = p { - if t.kind() == ast_type { - return Some(t); - } - p = t.parent(); - } - None -} - -pub fn lookup_token_at_postion( - file: &FileDB, - ast: &AstCircomProgram, - position: Position, -) -> Option { - let off_set = file.off_set(position); - ast.syntax().token_at_offset(off_set).find_map(|token| { - let kind = token.kind(); - - if kind == TokenKind::Identifier { - return Some(token); - } - - if kind == TokenKind::CircomString { - return Some(token); - } - None - }) -} - -pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option { - if let Some(statements) = template.statements() { - for component in statements.find_children::() { - if let Some(iden) = component.component_identifier() { - if iden.name().unwrap().syntax().text() == text { - return component.template(); - } - } - } - } - None -} - -pub fn jump_to_lib(file: &FileDB, token: &SyntaxToken) -> Vec { - if let Some(include_lib) = lookup_node_wrap_token(TokenKind::IncludeKw, token) { - if let Some(ast_include) = AstInclude::cast(include_lib) { - if let Some(abs_lib_ans) = ast_include.lib() { - let lib_path = file - .get_path() - .parent() - .unwrap() - .join(abs_lib_ans.value()) - .clone(); - let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); - return vec![Location::new(lib_url, Range::default())]; - } - } - } - - Vec::new() -} - -pub fn lookup_definition( - file: &FileDB, - ast: &AstCircomProgram, - semantic_data: &SemanticData, - token: &SyntaxToken, -) -> Vec { - let template_list = ast.template_list(); - - let mut res = Vec::new(); - - if token.kind() == TokenKind::CircomString { - return jump_to_lib(file, token); - } - - let mut signal_outside = false; - - if let Some(component_call) = lookup_node_wrap_token(TokenKind::ComponentCall, token) { - // find template called. - if let Some(ast_component_call) = AstComponentCall::cast(component_call) { - if let Some(signal) = ast_component_call.signal() { - if signal.syntax().text() == token.text() { - signal_outside = true; - // lookup template of componenet - if let Some(current_template) = - lookup_node_wrap_token(TokenKind::TemplateDef, token) - { - if let Some(ast_template_name) = lookup_component( - &AstTemplateDef::cast(current_template).unwrap(), - ast_component_call.component_name().unwrap().syntax().text(), - ) { - if let Some(other_template) = - ast.get_template_by_name(&ast_template_name) - { - let template_id = other_template.syntax().token_id(); - if let Some(semantic) = - semantic_data.template_data_semantic.get(&template_id) - { - if let Some(tmp) = - semantic.signal.0.get(&signal.syntax().token_id()) - { - res.extend(tmp) - } - } - } - } - } - } - } - } - } - - if !signal_outside { - for template in template_list { - let template_name = template.name().unwrap(); - if template_name.name().unwrap().syntax().text() == token.text() { - let range = file.range(template.syntax()); - res.push(range); - } - - if !template - .syntax() - .text_range() - .contains_range(token.text_range()) - { - continue; - } - - let template_id = template.syntax().token_id(); - - if let Some(data) = semantic_data.lookup_signal(template_id, token) { - res.extend(data); - } - - if let Some(data) = semantic_data.lookup_variable(template_id, token) { - res.extend(data); - } - - if let Some(component_decl) = semantic_data.lookup_component(template_id, token) { - res.extend(component_decl); - } - } - } - - res.into_iter() - .map(|range| Location::new(file.file_path.clone(), range)) - .collect() -} - -#[cfg(test)] -mod tests { - use std::path::Path; - - use lsp_types::Url; - use parser::token_kind::TokenKind; - use rowan::ast::AstNode; - use syntax::{ - abstract_syntax_tree::{AstCircomProgram, AstInputSignalDecl}, - syntax::SyntaxTreeBuilder, - }; - - use crate::{database::FileDB, handler::goto_definition::lookup_node_wrap_token}; - - use super::lookup_token_at_postion; - - #[test] - fn goto_decl_test() { - let source = r#" - pragma circom 2.0.0; - - template X() { - signal x = 10; - signal input x = 10; - component x = Multiplier2(); - component y = X(); - component y = Multiplier2(); - component z = Multiplier2(); - - } -template M() { - component h = X(); - component k = Multiplier2(); - test - } -template Multiplier2 () { - template m = M(); - // hello world - signal input a; - signal input b; - signal output c; - component y = X(); - - mintlkrekerjke; - component e = Y(); - component z = Y(); - component h = Y(); - signal output d; - c <== a * b; - } -template Y() { - component y = X(); - component a = X(); - - } - "# - .to_string(); - - let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); - - let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - - if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { - for template in program_ast.template_list() { - println!("{template:?}"); - } - - let inputs = program_ast.template_list()[0] - .func_body() - .unwrap() - .statement_list() - .unwrap() - .find_children::(); - let signal_name = inputs[0].name().unwrap(); - - let tmp = signal_name.syntax().text_range().start(); - - if let Some(token) = lookup_token_at_postion(&file, &program_ast, file.position(tmp)) { - println!( - "{:#?}", - lookup_node_wrap_token(TokenKind::TemplateDef, &token) - ); - } - } - } - - #[test] - fn url_test() { - let url = Url::from_file_path(Path::new("/hello/abc.tx")); - let binding = url.unwrap(); - let p = binding.path(); - println!("{:?}", Path::new(p).parent()); - } -} +use lsp_types::Location; +use lsp_types::Position; +use lsp_types::Range; +use lsp_types::Url; +use parser::token_kind::TokenKind; +use rowan::ast::AstNode; +use rowan::SyntaxText; + +use syntax::abstract_syntax_tree::AstComponentCall; +use syntax::abstract_syntax_tree::AstInclude; +use syntax::abstract_syntax_tree::AstTemplateDef; +use syntax::abstract_syntax_tree::AstTemplateName; +use syntax::abstract_syntax_tree::{AstCircomProgram, AstComponentDecl}; +use syntax::syntax_node::SyntaxNode; +use syntax::syntax_node::SyntaxToken; + +use crate::database::{FileDB, SemanticData, TokenId}; + +pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Option { + let mut p = token.parent(); + while let Some(t) = p { + if t.kind() == ast_type { + return Some(t); + } + p = t.parent(); + } + None +} + +pub fn lookup_token_at_postion( + file: &FileDB, + ast: &AstCircomProgram, + position: Position, +) -> Option { + let off_set = file.off_set(position); + ast.syntax().token_at_offset(off_set).find_map(|token| { + let kind = token.kind(); + + if kind == TokenKind::Identifier { + return Some(token); + } + + if kind == TokenKind::CircomString { + return Some(token); + } + None + }) +} + +pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option { + if let Some(statements) = template.statements() { + for component in statements.find_children::() { + if let Some(iden) = component.component_identifier() { + if iden.name().unwrap().syntax().text() == text { + return component.template(); + } + } + } + } + None +} + +pub fn jump_to_lib(file: &FileDB, token: &SyntaxToken) -> Vec { + if let Some(include_lib) = lookup_node_wrap_token(TokenKind::IncludeKw, token) { + if let Some(ast_include) = AstInclude::cast(include_lib) { + if let Some(abs_lib_ans) = ast_include.lib() { + let lib_path = file + .get_path() + .parent() + .unwrap() + .join(abs_lib_ans.value()) + .clone(); + let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); + return vec![Location::new(lib_url, Range::default())]; + } + } + } + + Vec::new() +} + +pub fn lookup_definition( + file: &FileDB, + ast: &AstCircomProgram, + semantic_data: &SemanticData, + token: &SyntaxToken, +) -> Vec { + let template_list = ast.template_list(); + + let mut res = Vec::new(); + + if token.kind() == TokenKind::CircomString { + return jump_to_lib(file, token); + } + + let mut signal_outside = false; + + if let Some(component_call) = lookup_node_wrap_token(TokenKind::ComponentCall, token) { + // find template called. + if let Some(ast_component_call) = AstComponentCall::cast(component_call) { + if let Some(signal) = ast_component_call.signal() { + if signal.syntax().text() == token.text() { + signal_outside = true; + // lookup template of componenet + if let Some(current_template) = + lookup_node_wrap_token(TokenKind::TemplateDef, token) + { + if let Some(ast_template_name) = lookup_component( + &AstTemplateDef::cast(current_template).unwrap(), + ast_component_call.component_name().unwrap().syntax().text(), + ) { + if let Some(other_template) = + ast.get_template_by_name(&ast_template_name) + { + let template_id = other_template.syntax().token_id(); + if let Some(semantic) = + semantic_data.template_data_semantic.get(&template_id) + { + if let Some(tmp) = + semantic.signal.0.get(&signal.syntax().token_id()) + { + res.extend(tmp) + } + } + } + } + } + } + } + } + } + + if !signal_outside { + for template in template_list { + let template_name = template.name().unwrap(); + if template_name.name().unwrap().syntax().text() == token.text() { + let range = file.range(template.syntax()); + res.push(range); + } + + if !template + .syntax() + .text_range() + .contains_range(token.text_range()) + { + continue; + } + + let template_id = template.syntax().token_id(); + + if let Some(data) = semantic_data.lookup_signal(template_id, token) { + res.extend(data); + } + + if let Some(data) = semantic_data.lookup_variable(template_id, token) { + res.extend(data); + } + + if let Some(component_decl) = semantic_data.lookup_component(template_id, token) { + res.extend(component_decl); + } + } + } + + res.into_iter() + .map(|range| Location::new(file.file_path.clone(), range)) + .collect() +} + +#[cfg(test)] +mod tests { + use std::path::Path; + + use lsp_types::Url; + use parser::token_kind::TokenKind; + use rowan::ast::AstNode; + use syntax::{ + abstract_syntax_tree::{AstCircomProgram, AstInputSignalDecl}, + syntax::SyntaxTreeBuilder, + }; + + use crate::{database::FileDB, handler::goto_definition::lookup_node_wrap_token}; + + use super::lookup_token_at_postion; + + #[test] + fn goto_decl_test() { + let source = r#" + pragma circom 2.0.0; + + template X() { + signal x = 10; + signal input x = 10; + component x = Multiplier2(); + component y = X(); + component y = Multiplier2(); + component z = Multiplier2(); + + } +template M() { + component h = X(); + component k = Multiplier2(); + test + } +template Multiplier2 () { + template m = M(); + // hello world + signal input a; + signal input b; + signal output c; + component y = X(); + + mintlkrekerjke; + component e = Y(); + component z = Y(); + component h = Y(); + signal output d; + c <== a * b; + } +template Y() { + component y = X(); + component a = X(); + + } + "# + .to_string(); + + let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); + + let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); + + if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { + for template in program_ast.template_list() { + println!("{template:?}"); + } + + let inputs = program_ast.template_list()[0] + .func_body() + .unwrap() + .statement_list() + .unwrap() + .find_children::(); + let signal_name = inputs[0].name().unwrap(); + + let tmp = signal_name.syntax().text_range().start(); + + if let Some(token) = lookup_token_at_postion(&file, &program_ast, file.position(tmp)) { + println!( + "{:#?}", + lookup_node_wrap_token(TokenKind::TemplateDef, &token) + ); + } + } + } + + #[test] + fn url_test() { + let url = Url::from_file_path(Path::new("/hello/abc.tx")); + let binding = url.unwrap(); + let p = binding.path(); + println!("{:?}", Path::new(p).parent()); + } +} diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index c5dd125..36fd7e0 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,130 +1,130 @@ -use super::{ - expression::{tuple, tuple_init}, - *, -}; - -// "signal" --> None -// "signal input" --> Some(true) -// "signal output" --> Some(false) -fn signal_header(p: &mut Parser) -> Option { - let mut res = None; - let m = p.open(); - p.expect(SignalKw); - if p.at_any(&[InputKw, OutputKw]) { - if p.at(InputKw) { - res = Some(true); - } else { - res = Some(false); - } - p.advance(); - - if p.at(LCurly) { - p.expect(Identifier); - p.expect(RCurly); - } - } - p.close(m, SignalHeader); - res -} - -/** - * Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization | - * - * - */ -pub(super) fn var_declaration(p: &mut Parser) { - let m = p.open(); - p.expect(VarKw); - - if p.at(LParen) { - tuple(p); - if p.at(Assign) { - tuple_init(p); - } - } else { - p.expect(Identifier); - if p.at(Assign) { - p.expect(Assign); - expression::expression(p); - } - // list of var - while p.at(Comma) && !p.eof() { - p.expect(Comma); - p.expect(Identifier); - if p.at(Assign) { - p.expect(Assign); - expression::expression(p); - } - } - } - p.close(m, VarDecl); -} - -pub(super) fn signal_declaration(p: &mut Parser) { - if !p.at(SignalKw) { - p.advance_with_error("Signal error"); - return; - } - - let m = p.open(); - let io_signal = signal_header(p); - - if p.at(LParen) { - tuple(p); - if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { - tuple_init(p); - } - } else { - p.expect(Identifier); - // list of var - while p.at(Comma) && !p.eof() { - p.skip(); - p.expect(Identifier); - } - } - - if let Some(is_input) = io_signal { - if is_input { - p.close(m, InputSignalDecl); - } else { - p.close(m, OutputSignalDecl); - } - } else { - p.close(m, SignalDecl); - } -} - -pub(super) fn component_declaration(p: &mut Parser) { - let m = p.open(); - p.expect(ComponentKw); - let m_c = p.open(); - p.expect(Identifier); - p.close(m_c, ComponentIdentifier); - - p.expect(Assign); - let m_c = p.open(); - p.expect(Identifier); - p.close(m_c, TemplateName); - p.expect(LParen); - - if p.at(Identifier) { - expression::expression(p); - while !p.at(RParen) && !p.eof() { - p.expect(Comma); - expression::expression(p); - } - } - - p.expect(RParen); - - p.close(m, ComponentDecl); -} - -pub(super) fn declaration(p: &mut Parser) { - match p.current() { - SignalKw => signal_declaration(p), - VarKw => var_declaration(p), - ComponentKw => component_declaration(p), - _ => unreachable!(), - } -} +use super::{ + expression::{tuple, tuple_init}, + *, +}; + +// "signal" --> None +// "signal input" --> Some(true) +// "signal output" --> Some(false) +fn signal_header(p: &mut Parser) -> Option { + let mut res = None; + let m = p.open(); + p.expect(SignalKw); + if p.at_any(&[InputKw, OutputKw]) { + if p.at(InputKw) { + res = Some(true); + } else { + res = Some(false); + } + p.advance(); + + if p.at(LCurly) { + p.expect(Identifier); + p.expect(RCurly); + } + } + p.close(m, SignalHeader); + res +} + +/** + * Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization | + * + * + */ +pub(super) fn var_declaration(p: &mut Parser) { + let m = p.open(); + p.expect(VarKw); + + if p.at(LParen) { + tuple(p); + if p.at(Assign) { + tuple_init(p); + } + } else { + p.expect(Identifier); + if p.at(Assign) { + p.expect(Assign); + expression::expression(p); + } + // list of var + while p.at(Comma) && !p.eof() { + p.expect(Comma); + p.expect(Identifier); + if p.at(Assign) { + p.expect(Assign); + expression::expression(p); + } + } + } + p.close(m, VarDecl); +} + +pub(super) fn signal_declaration(p: &mut Parser) { + if !p.at(SignalKw) { + p.advance_with_error("Signal error"); + return; + } + + let m = p.open(); + let io_signal = signal_header(p); + + if p.at(LParen) { + tuple(p); + if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { + tuple_init(p); + } + } else { + p.expect(Identifier); + // list of var + while p.at(Comma) && !p.eof() { + p.skip(); + p.expect(Identifier); + } + } + + if let Some(is_input) = io_signal { + if is_input { + p.close(m, InputSignalDecl); + } else { + p.close(m, OutputSignalDecl); + } + } else { + p.close(m, SignalDecl); + } +} + +pub(super) fn component_declaration(p: &mut Parser) { + let m = p.open(); + p.expect(ComponentKw); + let m_c = p.open(); + p.expect(Identifier); + p.close(m_c, ComponentIdentifier); + + p.expect(Assign); + let m_c = p.open(); + p.expect(Identifier); + p.close(m_c, TemplateName); + p.expect(LParen); + + if p.at(Identifier) { + expression::expression(p); + while !p.at(RParen) && !p.eof() { + p.expect(Comma); + expression::expression(p); + } + } + + p.expect(RParen); + + p.close(m, ComponentDecl); +} + +pub(super) fn declaration(p: &mut Parser) { + match p.current() { + SignalKw => signal_declaration(p), + VarKw => var_declaration(p), + ComponentKw => component_declaration(p), + _ => unreachable!(), + } +} diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 4604da4..1074631 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -1,158 +1,158 @@ -use crate::parser::Marker; - -use super::*; - -pub(super) fn expression(p: &mut Parser) { - let m = p.open(); - circom_expression(p); - p.close(m, Expression); -} - -/** - * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" - */ -pub(super) fn tuple(p: &mut Parser) { - let m = p.open(); - p.expect(LParen); - p.expect(Identifier); - while p.at(Comma) && !p.eof() { - p.expect(Comma); - p.expect(Identifier); - } - p.expect(RParen); - p.close(m, Tuple); -} - -/** - * grammar: - * "= | <== | <--" expression - */ -pub(super) fn tuple_init(p: &mut Parser) { - let m = p.open(); - p.expect_any(&[Assign, RAssignSignal, RAssignConstraintSignal]); - expression(p); - p.close(m, TupleInit); -} - -fn expression_atom(p: &mut Parser) -> Option { - let m_close: Marker; - match p.current() { - Number => { - let m = p.open(); - p.advance(); - m_close = p.close(m, Number); - Some(m_close) - } - Identifier => { - let m = p.open(); - p.advance(); - m_close = p.close(m, Identifier); - Some(m_close) - } - LParen => { - let m = p.open(); - p.expect(LParen); - expression_rec(p, 0); - p.expect(RParen); - m_close = p.close(m, Tuple); - Some(m_close) - } - _ => { - p.advance_with_error("Invalid Token"); - None - } - } -} - -/** - * return marker which bound the expression - */ -pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { - let parse_able: Option = if let Some(pp) = p.current().prefix() { - let kind = p.current(); - let m = p.open(); - p.advance(); - expression_rec(p, pp); - Some(p.close(m, kind)) - } else { - expression_atom(p) - }; - - parse_able?; - - let mut lhs = parse_able.unwrap(); - - // TODO: function call - if p.at(LParen) { - let m = p.open_before(lhs); - tuple(p); - lhs = p.close(m, Call); - } - - while !p.eof() { - let current_kind = p.current(); - if let Some((lp, rp)) = current_kind.infix() { - if rp <= pb { - return None; - } - - let m = p.open_before(lhs); - p.advance(); - expression_rec(p, lp); - lhs = p.close(m, current_kind); - - continue; - } - if let Some(pp) = current_kind.postfix() { - if pp <= pb { - return None; - } - let m = p.open_before(lhs); - p.advance(); - if matches!(current_kind, LBracket) { - expression_rec(p, 0); - p.expect(RBracket); - } else { - p.expect(Identifier); - } - lhs = if matches!(current_kind, Dot) { - p.close(m, ComponentCall) - } else { - p.close(m, ArrayQuery) - }; - - continue; - } - break; - } - Some(lhs) -} - -/** - * circom_expression = expr ? expr: expr | - * expr - */ -fn circom_expression(p: &mut Parser) { - if let Some(mut lhs) = expression_rec(p, 0) { - let current_kind = p.current(); - if matches!(current_kind, MarkQuestion) { - let m = p.open_before(lhs); - lhs = p.close(m, Condition); - - let m = p.open_before(lhs); - p.advance(); - - let first_expression = p.open(); - expression_rec(p, 0); - p.close(first_expression, Expression); - - p.expect(Colon); - - let last_expression = p.open(); - expression_rec(p, 0); - p.close(last_expression, Expression); - - p.close(m, TenaryConditional); - } - } -} +use crate::parser::Marker; + +use super::*; + +pub(super) fn expression(p: &mut Parser) { + let m = p.open(); + circom_expression(p); + p.close(m, Expression); +} + +/** + * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" + */ +pub(super) fn tuple(p: &mut Parser) { + let m = p.open(); + p.expect(LParen); + p.expect(Identifier); + while p.at(Comma) && !p.eof() { + p.expect(Comma); + p.expect(Identifier); + } + p.expect(RParen); + p.close(m, Tuple); +} + +/** + * grammar: + * "= | <== | <--" expression + */ +pub(super) fn tuple_init(p: &mut Parser) { + let m = p.open(); + p.expect_any(&[Assign, RAssignSignal, RAssignConstraintSignal]); + expression(p); + p.close(m, TupleInit); +} + +fn expression_atom(p: &mut Parser) -> Option { + let m_close: Marker; + match p.current() { + Number => { + let m = p.open(); + p.advance(); + m_close = p.close(m, Number); + Some(m_close) + } + Identifier => { + let m = p.open(); + p.advance(); + m_close = p.close(m, Identifier); + Some(m_close) + } + LParen => { + let m = p.open(); + p.expect(LParen); + expression_rec(p, 0); + p.expect(RParen); + m_close = p.close(m, Tuple); + Some(m_close) + } + _ => { + p.advance_with_error("Invalid Token"); + None + } + } +} + +/** + * return marker which bound the expression + */ +pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { + let parse_able: Option = if let Some(pp) = p.current().prefix() { + let kind = p.current(); + let m = p.open(); + p.advance(); + expression_rec(p, pp); + Some(p.close(m, kind)) + } else { + expression_atom(p) + }; + + parse_able?; + + let mut lhs = parse_able.unwrap(); + + // TODO: function call + if p.at(LParen) { + let m = p.open_before(lhs); + tuple(p); + lhs = p.close(m, Call); + } + + while !p.eof() { + let current_kind = p.current(); + if let Some((lp, rp)) = current_kind.infix() { + if rp <= pb { + return None; + } + + let m = p.open_before(lhs); + p.advance(); + expression_rec(p, lp); + lhs = p.close(m, current_kind); + + continue; + } + if let Some(pp) = current_kind.postfix() { + if pp <= pb { + return None; + } + let m = p.open_before(lhs); + p.advance(); + if matches!(current_kind, LBracket) { + expression_rec(p, 0); + p.expect(RBracket); + } else { + p.expect(Identifier); + } + lhs = if matches!(current_kind, Dot) { + p.close(m, ComponentCall) + } else { + p.close(m, ArrayQuery) + }; + + continue; + } + break; + } + Some(lhs) +} + +/** + * circom_expression = expr ? expr: expr | + * expr + */ +fn circom_expression(p: &mut Parser) { + if let Some(mut lhs) = expression_rec(p, 0) { + let current_kind = p.current(); + if matches!(current_kind, MarkQuestion) { + let m = p.open_before(lhs); + lhs = p.close(m, Condition); + + let m = p.open_before(lhs); + p.advance(); + + let first_expression = p.open(); + expression_rec(p, 0); + p.close(first_expression, Expression); + + p.expect(Colon); + + let last_expression = p.open(); + expression_rec(p, 0); + p.close(last_expression, Expression); + + p.close(m, TenaryConditional); + } + } +} diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index 84ca0a6..2828f3c 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,184 +1,184 @@ -use super::{block::block, expression::expression, *}; - -pub(super) fn statement(p: &mut Parser) { - let m = p.open(); - match p.current() { - IfKw => if_statement(p), - _ => statement_no_condition(p), - } - p.close(m, Statement); -} - -/* -if (expr) - -else - -*/ -fn if_statement(p: &mut Parser) { - let m = p.open(); - p.expect(IfKw); - p.expect(LParen); - expression::expression(p); - p.expect(RParen); - statement(p); - if p.at(ElseKw) { - p.expect(ElseKw); - statement(p); - } - p.close(m, IfKw); -} - -/** - * no if condition here. - * for/while/return/assert... - */ -fn statement_no_condition(p: &mut Parser) { - match p.current() { - ForKw => for_statement(p), - WhileKw => while_statement(p), - ReturnKw => { - return_statement(p); - p.expect(Semicolon); - } - LCurly => block(p), - LogKw => { - log_statement(p); - p.expect(Semicolon); - } - AssertKw => { - assert_statement(p); - p.expect(Semicolon); - } - _ => { - assignment_statement(p); - p.expect(Semicolon); - } - } -} - -/* -for (/; ; ) - -*/ -fn for_statement(p: &mut Parser) { - let m = p.open(); - p.expect(ForKw); - p.expect(LParen); - if p.current().is_declaration_kw() { - declaration::declaration(p); - } else { - assignment_statement(p); - } - p.expect(Semicolon); - expression::expression(p); - p.expect(Semicolon); - - assignment_statement(p); - p.expect(RParen); - - statement_no_condition(p); - p.close(m, ForLoop); -} - -/* -while () - -*/ -fn while_statement(p: &mut Parser) { - p.expect(WhileKw); - p.expect(LParen); - expression(p); - p.expect(RParen); - statement(p); -} - -/* -assert() -*/ -fn assert_statement(p: &mut Parser) { - let m = p.open(); - p.expect(AssertKw); - p.expect(LParen); - expression(p); - p.expect(RParen); - p.close(m, AssertKw); -} - -/* -log() -*/ -fn log_statement(p: &mut Parser) { - let m = p.open(); - p.expect(LogKw); - p.expect(LParen); - while !p.eof() { - if p.at(RParen) { - break; - } - match p.current() { - CircomString => p.advance(), - _ => expression(p), - } - if !p.at(Comma) { - break; - } else { - p.advance(); - } - } - p.expect(RParen); - p.close(m, LogKw); -} - -/* -return -*/ -fn return_statement(p: &mut Parser) { - let m = p.open(); - p.expect(ReturnKw); - expression(p); - p.close(m, ReturnKw); -} - -/* - -*/ -fn assignment_statement(p: &mut Parser) { - let m = p.open(); - - if p.at(Identifier) { - let m_id = p.open(); - let m_name = p.open(); - p.expect(Identifier); - p.close(m_name, ComponentIdentifier); - if p.at(LBracket) { - p.expect(LBracket); - expression(p); - p.expect(RBracket); - } - if p.at(Dot) { - p.expect(Dot); - p.expect(Identifier); - p.close(m_id, ComponentCall); - } else { - p.close(m_id, Expression); - } - } else { - expression(p); - } - - if p.at_any(&[ - Assign, - RAssignSignal, - RAssignConstraintSignal, - LAssignContraintSignal, - LAssignSignal, - EqualSignal, - ]) { - p.advance(); - expression(p); - p.close(m, AssignStatement); - } else { - p.close(m, Error); - } -} +use super::{block::block, expression::expression, *}; + +pub(super) fn statement(p: &mut Parser) { + let m = p.open(); + match p.current() { + IfKw => if_statement(p), + _ => statement_no_condition(p), + } + p.close(m, Statement); +} + +/* +if (expr) + +else + +*/ +fn if_statement(p: &mut Parser) { + let m = p.open(); + p.expect(IfKw); + p.expect(LParen); + expression::expression(p); + p.expect(RParen); + statement(p); + if p.at(ElseKw) { + p.expect(ElseKw); + statement(p); + } + p.close(m, IfKw); +} + +/** + * no if condition here. + * for/while/return/assert... + */ +fn statement_no_condition(p: &mut Parser) { + match p.current() { + ForKw => for_statement(p), + WhileKw => while_statement(p), + ReturnKw => { + return_statement(p); + p.expect(Semicolon); + } + LCurly => block(p), + LogKw => { + log_statement(p); + p.expect(Semicolon); + } + AssertKw => { + assert_statement(p); + p.expect(Semicolon); + } + _ => { + assignment_statement(p); + p.expect(Semicolon); + } + } +} + +/* +for (/; ; ) + +*/ +fn for_statement(p: &mut Parser) { + let m = p.open(); + p.expect(ForKw); + p.expect(LParen); + if p.current().is_declaration_kw() { + declaration::declaration(p); + } else { + assignment_statement(p); + } + p.expect(Semicolon); + expression::expression(p); + p.expect(Semicolon); + + assignment_statement(p); + p.expect(RParen); + + statement_no_condition(p); + p.close(m, ForLoop); +} + +/* +while () + +*/ +fn while_statement(p: &mut Parser) { + p.expect(WhileKw); + p.expect(LParen); + expression(p); + p.expect(RParen); + statement(p); +} + +/* +assert() +*/ +fn assert_statement(p: &mut Parser) { + let m = p.open(); + p.expect(AssertKw); + p.expect(LParen); + expression(p); + p.expect(RParen); + p.close(m, AssertKw); +} + +/* +log() +*/ +fn log_statement(p: &mut Parser) { + let m = p.open(); + p.expect(LogKw); + p.expect(LParen); + while !p.eof() { + if p.at(RParen) { + break; + } + match p.current() { + CircomString => p.advance(), + _ => expression(p), + } + if !p.at(Comma) { + break; + } else { + p.advance(); + } + } + p.expect(RParen); + p.close(m, LogKw); +} + +/* +return +*/ +fn return_statement(p: &mut Parser) { + let m = p.open(); + p.expect(ReturnKw); + expression(p); + p.close(m, ReturnKw); +} + +/* + +*/ +fn assignment_statement(p: &mut Parser) { + let m = p.open(); + + if p.at(Identifier) { + let m_id = p.open(); + let m_name = p.open(); + p.expect(Identifier); + p.close(m_name, ComponentIdentifier); + if p.at(LBracket) { + p.expect(LBracket); + expression(p); + p.expect(RBracket); + } + if p.at(Dot) { + p.expect(Dot); + p.expect(Identifier); + p.close(m_id, ComponentCall); + } else { + p.close(m_id, Expression); + } + } else { + expression(p); + } + + if p.at_any(&[ + Assign, + RAssignSignal, + RAssignConstraintSignal, + LAssignContraintSignal, + LAssignSignal, + EqualSignal, + ]) { + p.advance(); + expression(p); + p.close(m, AssignStatement); + } else { + p.close(m, Error); + } +} diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index a502365..9cfa7cb 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -1,25 +1,25 @@ -use crate::grammar::*; -/** - * template Identifier() {content} - * template Identifier( param_1, ... , param_n ) { content } - */ -pub fn template(p: &mut Parser) { - // assert!(p.at(TemplateKw)); - let m = p.open(); - - p.expect(TemplateKw); - - let name_marker = p.open(); - p.expect(Identifier); - p.close(name_marker, TemplateName); - - p.expect(LParen); - let arg_marker = p.open(); - list_identity::parse(p); - p.close(arg_marker, ParameterList); - p.expect(RParen); - - block::block(p); - - p.close(m, TemplateDef); -} +use crate::grammar::*; +/** + * template Identifier() {content} + * template Identifier( param_1, ... , param_n ) { content } + */ +pub fn template(p: &mut Parser) { + // assert!(p.at(TemplateKw)); + let m = p.open(); + + p.expect(TemplateKw); + + let name_marker = p.open(); + p.expect(Identifier); + p.close(name_marker, TemplateName); + + p.expect(LParen); + let arg_marker = p.open(); + list_identity::parse(p); + p.close(arg_marker, ParameterList); + p.expect(RParen); + + block::block(p); + + p.close(m, TemplateDef); +} diff --git a/crates/parser/src/snapshots/parser__input__tests__test_operators.snap b/crates/parser/src/snapshots/parser__input__tests__test_operators.snap index 1366b66..a7a3155 100644 --- a/crates/parser/src/snapshots/parser__input__tests__test_operators.snap +++ b/crates/parser/src/snapshots/parser__input__tests__test_operators.snap @@ -1,391 +1,391 @@ ---- -source: crates/parser/src/input.rs -expression: input ---- -kind: - - EndLine - - WhiteSpace - - LParen - - LCurly - - LBracket - - RBracket - - RCurly - - RParen - - EndLine - - WhiteSpace - - Semicolon - - Dot - - Comma - - Colon - - EndLine - - WhiteSpace - - BoolAnd - - WhiteSpace - - BitAnd - - EndLine - - WhiteSpace - - BoolOr - - WhiteSpace - - BitOr - - EndLine - - WhiteSpace - - NotEqual - - WhiteSpace - - Not - - EndLine - - WhiteSpace - - EqualSignal - - WhiteSpace - - Equal - - WhiteSpace - - Assign - - EndLine - - WhiteSpace - - LAssignSignal - - WhiteSpace - - LAssignContraintSignal - - EndLine - - WhiteSpace - - RAssignSignal - - WhiteSpace - - RAssignConstraintSignal - - EndLine - - WhiteSpace - - LessThanAndEqual - - WhiteSpace - - LessThan - - EndLine - - WhiteSpace - - GreaterThanAndEqual - - WhiteSpace - - GreaterThan - - EndLine - - WhiteSpace - - UnitInc - - WhiteSpace - - AddAssign - - WhiteSpace - - Add - - EndLine - - WhiteSpace - - UnitDec - - WhiteSpace - - SubAssign - - WhiteSpace - - Sub - - EndLine - - WhiteSpace - - PowerAssign - - WhiteSpace - - Power - - EndLine - - WhiteSpace - - Mul - - WhiteSpace - - MulAssign - - EndLine - - WhiteSpace - - Div - - WhiteSpace - - DivAssign - - EndLine - - WhiteSpace - - IntDiv - - WhiteSpace - - IntDivAssign - - EndLine - - WhiteSpace - - Mod - - WhiteSpace - - ModAssign - - EndLine - - WhiteSpace - - BitXor - - WhiteSpace - - BitXorAssign - - EndLine - - WhiteSpace - - BitNot - - WhiteSpace - - BitNotAssign - - EndLine - - WhiteSpace - - ShiftR - - WhiteSpace - - ShiftRAssign - - EndLine - - WhiteSpace - - ShiftL - - WhiteSpace - - ShiftLAssign - - EndLine - - WhiteSpace - - BitAnd - - WhiteSpace - - BitAndAssign - - EndLine - - WhiteSpace - - BitOr - - WhiteSpace - - BitOrAssign - - EndLine - - WhiteSpace - - RCurly -source: "\n ({[]})\n ;.,:\n && &\n || |\n != !\n === == =\n --> ==>\n <-- <==\n <= <\n >= >\n ++ += +\n -- -= -\n **= **\n * *=\n / /=\n \\ \\=\n % %=\n ^ ^=\n ~ ~=\n >> >>=\n << <<=\n & &=\n | |=\n }" -position: - - start: 0 - end: 1 - - start: 1 - end: 9 - - start: 9 - end: 10 - - start: 10 - end: 11 - - start: 11 - end: 12 - - start: 12 - end: 13 - - start: 13 - end: 14 - - start: 14 - end: 15 - - start: 15 - end: 16 - - start: 16 - end: 24 - - start: 24 - end: 25 - - start: 25 - end: 26 - - start: 26 - end: 27 - - start: 27 - end: 28 - - start: 28 - end: 29 - - start: 29 - end: 37 - - start: 37 - end: 39 - - start: 39 - end: 40 - - start: 40 - end: 41 - - start: 41 - end: 42 - - start: 42 - end: 50 - - start: 50 - end: 52 - - start: 52 - end: 53 - - start: 53 - end: 54 - - start: 54 - end: 55 - - start: 55 - end: 63 - - start: 63 - end: 65 - - start: 65 - end: 66 - - start: 66 - end: 67 - - start: 67 - end: 68 - - start: 68 - end: 76 - - start: 76 - end: 79 - - start: 79 - end: 80 - - start: 80 - end: 82 - - start: 82 - end: 83 - - start: 83 - end: 84 - - start: 84 - end: 85 - - start: 85 - end: 93 - - start: 93 - end: 96 - - start: 96 - end: 97 - - start: 97 - end: 100 - - start: 100 - end: 101 - - start: 101 - end: 109 - - start: 109 - end: 112 - - start: 112 - end: 113 - - start: 113 - end: 116 - - start: 116 - end: 117 - - start: 117 - end: 125 - - start: 125 - end: 127 - - start: 127 - end: 128 - - start: 128 - end: 129 - - start: 129 - end: 130 - - start: 130 - end: 138 - - start: 138 - end: 140 - - start: 140 - end: 141 - - start: 141 - end: 142 - - start: 142 - end: 143 - - start: 143 - end: 151 - - start: 151 - end: 153 - - start: 153 - end: 154 - - start: 154 - end: 156 - - start: 156 - end: 157 - - start: 157 - end: 158 - - start: 158 - end: 159 - - start: 159 - end: 167 - - start: 167 - end: 169 - - start: 169 - end: 170 - - start: 170 - end: 172 - - start: 172 - end: 173 - - start: 173 - end: 174 - - start: 174 - end: 175 - - start: 175 - end: 183 - - start: 183 - end: 186 - - start: 186 - end: 187 - - start: 187 - end: 189 - - start: 189 - end: 190 - - start: 190 - end: 198 - - start: 198 - end: 199 - - start: 199 - end: 200 - - start: 200 - end: 202 - - start: 202 - end: 203 - - start: 203 - end: 211 - - start: 211 - end: 212 - - start: 212 - end: 213 - - start: 213 - end: 215 - - start: 215 - end: 216 - - start: 216 - end: 224 - - start: 224 - end: 225 - - start: 225 - end: 226 - - start: 226 - end: 228 - - start: 228 - end: 229 - - start: 229 - end: 237 - - start: 237 - end: 238 - - start: 238 - end: 239 - - start: 239 - end: 241 - - start: 241 - end: 242 - - start: 242 - end: 250 - - start: 250 - end: 251 - - start: 251 - end: 252 - - start: 252 - end: 254 - - start: 254 - end: 255 - - start: 255 - end: 263 - - start: 263 - end: 264 - - start: 264 - end: 265 - - start: 265 - end: 267 - - start: 267 - end: 268 - - start: 268 - end: 276 - - start: 276 - end: 278 - - start: 278 - end: 279 - - start: 279 - end: 282 - - start: 282 - end: 283 - - start: 283 - end: 291 - - start: 291 - end: 293 - - start: 293 - end: 294 - - start: 294 - end: 297 - - start: 297 - end: 298 - - start: 298 - end: 306 - - start: 306 - end: 307 - - start: 307 - end: 308 - - start: 308 - end: 310 - - start: 310 - end: 311 - - start: 311 - end: 319 - - start: 319 - end: 320 - - start: 320 - end: 321 - - start: 321 - end: 323 - - start: 323 - end: 324 - - start: 324 - end: 328 - - start: 328 - end: 329 +--- +source: crates/parser/src/input.rs +expression: input +--- +kind: + - EndLine + - WhiteSpace + - LParen + - LCurly + - LBracket + - RBracket + - RCurly + - RParen + - EndLine + - WhiteSpace + - Semicolon + - Dot + - Comma + - Colon + - EndLine + - WhiteSpace + - BoolAnd + - WhiteSpace + - BitAnd + - EndLine + - WhiteSpace + - BoolOr + - WhiteSpace + - BitOr + - EndLine + - WhiteSpace + - NotEqual + - WhiteSpace + - Not + - EndLine + - WhiteSpace + - EqualSignal + - WhiteSpace + - Equal + - WhiteSpace + - Assign + - EndLine + - WhiteSpace + - LAssignSignal + - WhiteSpace + - LAssignContraintSignal + - EndLine + - WhiteSpace + - RAssignSignal + - WhiteSpace + - RAssignConstraintSignal + - EndLine + - WhiteSpace + - LessThanAndEqual + - WhiteSpace + - LessThan + - EndLine + - WhiteSpace + - GreaterThanAndEqual + - WhiteSpace + - GreaterThan + - EndLine + - WhiteSpace + - UnitInc + - WhiteSpace + - AddAssign + - WhiteSpace + - Add + - EndLine + - WhiteSpace + - UnitDec + - WhiteSpace + - SubAssign + - WhiteSpace + - Sub + - EndLine + - WhiteSpace + - PowerAssign + - WhiteSpace + - Power + - EndLine + - WhiteSpace + - Mul + - WhiteSpace + - MulAssign + - EndLine + - WhiteSpace + - Div + - WhiteSpace + - DivAssign + - EndLine + - WhiteSpace + - IntDiv + - WhiteSpace + - IntDivAssign + - EndLine + - WhiteSpace + - Mod + - WhiteSpace + - ModAssign + - EndLine + - WhiteSpace + - BitXor + - WhiteSpace + - BitXorAssign + - EndLine + - WhiteSpace + - BitNot + - WhiteSpace + - BitNotAssign + - EndLine + - WhiteSpace + - ShiftR + - WhiteSpace + - ShiftRAssign + - EndLine + - WhiteSpace + - ShiftL + - WhiteSpace + - ShiftLAssign + - EndLine + - WhiteSpace + - BitAnd + - WhiteSpace + - BitAndAssign + - EndLine + - WhiteSpace + - BitOr + - WhiteSpace + - BitOrAssign + - EndLine + - WhiteSpace + - RCurly +source: "\n ({[]})\n ;.,:\n && &\n || |\n != !\n === == =\n --> ==>\n <-- <==\n <= <\n >= >\n ++ += +\n -- -= -\n **= **\n * *=\n / /=\n \\ \\=\n % %=\n ^ ^=\n ~ ~=\n >> >>=\n << <<=\n & &=\n | |=\n }" +position: + - start: 0 + end: 1 + - start: 1 + end: 9 + - start: 9 + end: 10 + - start: 10 + end: 11 + - start: 11 + end: 12 + - start: 12 + end: 13 + - start: 13 + end: 14 + - start: 14 + end: 15 + - start: 15 + end: 16 + - start: 16 + end: 24 + - start: 24 + end: 25 + - start: 25 + end: 26 + - start: 26 + end: 27 + - start: 27 + end: 28 + - start: 28 + end: 29 + - start: 29 + end: 37 + - start: 37 + end: 39 + - start: 39 + end: 40 + - start: 40 + end: 41 + - start: 41 + end: 42 + - start: 42 + end: 50 + - start: 50 + end: 52 + - start: 52 + end: 53 + - start: 53 + end: 54 + - start: 54 + end: 55 + - start: 55 + end: 63 + - start: 63 + end: 65 + - start: 65 + end: 66 + - start: 66 + end: 67 + - start: 67 + end: 68 + - start: 68 + end: 76 + - start: 76 + end: 79 + - start: 79 + end: 80 + - start: 80 + end: 82 + - start: 82 + end: 83 + - start: 83 + end: 84 + - start: 84 + end: 85 + - start: 85 + end: 93 + - start: 93 + end: 96 + - start: 96 + end: 97 + - start: 97 + end: 100 + - start: 100 + end: 101 + - start: 101 + end: 109 + - start: 109 + end: 112 + - start: 112 + end: 113 + - start: 113 + end: 116 + - start: 116 + end: 117 + - start: 117 + end: 125 + - start: 125 + end: 127 + - start: 127 + end: 128 + - start: 128 + end: 129 + - start: 129 + end: 130 + - start: 130 + end: 138 + - start: 138 + end: 140 + - start: 140 + end: 141 + - start: 141 + end: 142 + - start: 142 + end: 143 + - start: 143 + end: 151 + - start: 151 + end: 153 + - start: 153 + end: 154 + - start: 154 + end: 156 + - start: 156 + end: 157 + - start: 157 + end: 158 + - start: 158 + end: 159 + - start: 159 + end: 167 + - start: 167 + end: 169 + - start: 169 + end: 170 + - start: 170 + end: 172 + - start: 172 + end: 173 + - start: 173 + end: 174 + - start: 174 + end: 175 + - start: 175 + end: 183 + - start: 183 + end: 186 + - start: 186 + end: 187 + - start: 187 + end: 189 + - start: 189 + end: 190 + - start: 190 + end: 198 + - start: 198 + end: 199 + - start: 199 + end: 200 + - start: 200 + end: 202 + - start: 202 + end: 203 + - start: 203 + end: 211 + - start: 211 + end: 212 + - start: 212 + end: 213 + - start: 213 + end: 215 + - start: 215 + end: 216 + - start: 216 + end: 224 + - start: 224 + end: 225 + - start: 225 + end: 226 + - start: 226 + end: 228 + - start: 228 + end: 229 + - start: 229 + end: 237 + - start: 237 + end: 238 + - start: 238 + end: 239 + - start: 239 + end: 241 + - start: 241 + end: 242 + - start: 242 + end: 250 + - start: 250 + end: 251 + - start: 251 + end: 252 + - start: 252 + end: 254 + - start: 254 + end: 255 + - start: 255 + end: 263 + - start: 263 + end: 264 + - start: 264 + end: 265 + - start: 265 + end: 267 + - start: 267 + end: 268 + - start: 268 + end: 276 + - start: 276 + end: 278 + - start: 278 + end: 279 + - start: 279 + end: 282 + - start: 282 + end: 283 + - start: 283 + end: 291 + - start: 291 + end: 293 + - start: 293 + end: 294 + - start: 294 + end: 297 + - start: 297 + end: 298 + - start: 298 + end: 306 + - start: 306 + end: 307 + - start: 307 + end: 308 + - start: 308 + end: 310 + - start: 310 + end: 311 + - start: 311 + end: 319 + - start: 319 + end: 320 + - start: 320 + end: 321 + - start: 321 + end: 323 + - start: 323 + end: 324 + - start: 324 + end: 328 + - start: 328 + end: 329 diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 21d3625..98ef766 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -1,359 +1,359 @@ -use logos::Logos; -use serde::Serialize; - -#[derive(Logos, Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash, Serialize)] -#[allow(non_camel_case_types)] -#[repr(u16)] -pub enum TokenKind { - // Error - #[error] - Error = 0, - // Comments - #[regex(r"//[^\n]*")] - CommentLine, - #[token("/*")] - CommentBlockOpen, - #[token("*/")] - CommentBlockClose, - // Trivial - #[regex("[ \t]+")] - WhiteSpace, - #[regex("[\n]")] - EndLine, - // Circom - #[token("pragma")] - Pragma, - #[token("circom")] - Circom, - #[regex("2.[0-9].[0-9]")] - Version, - // Literals - #[regex("[0-9]+")] - Number, - #[regex("[$_]*[a-zA-Z][a-zA-Z0-9_$]*")] - Identifier, - #[regex(r#""[^"]*""#)] - CircomString, - // Brackets - #[token("(")] - LParen, - #[token(")")] - RParen, - #[token("{")] - LCurly, - #[token("}")] - RCurly, - #[token("[")] - LBracket, - #[token("]")] - RBracket, - // Punctuation - #[token(";")] - Semicolon, - #[token(",")] - Comma, - #[token(".")] - Dot, - // Boolean operators - #[token("&&")] - BoolAnd, - #[token("||")] - BoolOr, - #[token("!")] - Not, - // Relational operators - #[token("==")] - Equal, - #[token("!=")] - NotEqual, - #[token("<")] - LessThan, - #[token(">")] - GreaterThan, - #[token("<=")] - LessThanAndEqual, - #[token(">=")] - GreaterThanAndEqual, - // Arithmetic operators - #[token("+")] - Add, - #[token("-")] - Sub, - #[token("*")] - Mul, - #[token("**")] - Power, - #[token("/")] - Div, - #[token("\\")] - IntDiv, - #[token("%")] - Mod, - // Combined arithmetic assignment - #[token("+=")] - AddAssign, - #[token("-=")] - SubAssign, - #[token("*=")] - MulAssign, - #[token("**=")] - PowerAssign, - #[token("/=")] - DivAssign, - #[token(r"\=")] - IntDivAssign, - #[token("%=")] - ModAssign, - #[token("++")] - UnitInc, - #[token("--")] - UnitDec, - // Bitwise operators - #[token("&")] - BitAnd, - #[token("|")] - BitOr, - #[token("~")] - BitNot, - #[token("^")] - BitXor, - #[token(">>")] - ShiftR, - #[token("<<")] - ShiftL, - // Combined bitwise assignments - #[token("&=")] - BitAndAssign, - #[token("|=")] - BitOrAssign, - #[token("~=")] - BitNotAssign, - #[token("^=")] - BitXorAssign, - #[token(">>=")] - ShiftRAssign, - #[token("<<=")] - ShiftLAssign, - // Assign - #[token("=")] - Assign, - #[token("===")] - EqualSignal, - #[token("-->")] - LAssignSignal, - #[token("==>")] - LAssignContraintSignal, - #[token("<--")] - RAssignSignal, - #[token("<==")] - RAssignConstraintSignal, - // Conditional expressions - #[token("?")] - MarkQuestion, - #[token(":")] - Colon, - // Keywords - #[token("template")] - TemplateKw, - #[token("function")] - FunctionKw, - #[token("component")] - ComponentKw, - #[token("main")] - MainKw, - #[token("public")] - PublicKw, - #[token("signal")] - SignalKw, - #[token("var")] - VarKw, - #[token("include")] - IncludeKw, - #[token("input")] - InputKw, - #[token("output")] - OutputKw, - #[token("log")] - LogKw, - // Statement keywords - #[token("if")] - IfKw, - #[token("else")] - ElseKw, - #[token("for")] - ForKw, - #[token("while")] - WhileKw, - #[token("return")] - ReturnKw, - #[token("assert")] - AssertKw, - // Complex token kind - ForLoop, - AssignStatement, - CircomProgram, - SignalOfComponent, - SignalHeader, - Block, - Tuple, - TupleInit, - Call, - TenaryConditional, - Condition, - Expression, - FunctionDef, - Statement, - StatementList, - ComponentDecl, - TemplateDef, - TemplateName, - FunctionName, - ParameterList, - SignalDecl, - VarDecl, - InputSignalDecl, - OutputSignalDecl, - ComponentCall, - ComponentIdentifier, - SignalIdentifier, - ArrayQuery, - ParserError, - BlockComment, - EOF, - ROOT, - __LAST, -} - -impl From for TokenKind { - #[inline] - fn from(d: u16) -> TokenKind { - assert!(d <= (TokenKind::__LAST as u16)); - unsafe { std::mem::transmute::(d) } - } -} - -impl From for TokenKind { - fn from(value: rowan::SyntaxKind) -> Self { - match value { - rowan::SyntaxKind(id) => TokenKind::from(id), - } - } -} - -impl From for u16 { - #[inline] - fn from(k: TokenKind) -> u16 { - k as u16 - } -} - -impl From for rowan::SyntaxKind { - fn from(kind: TokenKind) -> Self { - Self(kind as u16) - } -} - -impl TokenKind { - // a + 10 --> a and 10 are literals - pub fn is_literal(self) -> bool { - matches!(self, Self::Number | Self::Identifier) - } - - // these tokens have the lowest priority - // infix_operator - // eg: a + b --> + is an infix token - pub fn infix(self) -> Option<(u16, u16)> { - match self { - // arithmetic operators - Self::Power => Some((99, 100)), - Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), - Self::Add | Self::Sub => Some((89, 90)), - - // shift bitwise operators - Self::ShiftL | Self::ShiftR => Some((84, 85)), - - // relational operators - Self::LessThan - | Self::GreaterThan - | Self::LessThanAndEqual - | Self::GreaterThanAndEqual => Some((79, 80)), - Self::Equal - | Self::NotEqual => Some((74, 75)), - - // other bitwise operators - Self::BitAnd => Some((69, 70)), - Self::BitXor => Some((64, 65)), // exclusive or - Self::BitOr => Some((59, 60)), - - // boolean operators - Self::BoolAnd => Some((54, 55)), - Self::BoolOr => Some((49, 50)), - - // TODO: how about conditional operation ( ? : ) - // associativity: right to left [ a ? b : c --> ??? ] - - // associativity: right to left [ a = b = c --> a = (b = c) ] - // assignment operators - Self::Assign - // bitwise asignment operators - | Self::BitOrAssign - | Self::BitXorAssign - | Self::BitAndAssign - | Self::ShiftLAssign - | Self::ShiftRAssign - // arithmetic asignament operators - | Self::AddAssign - | Self::SubAssign - | Self::MulAssign - | Self::DivAssign - | Self::IntDivAssign - | Self::ModAssign - | Self::PowerAssign => Some((44, 45)), - - // TODO: how about comma (expression separator) - Self::Comma => Some((39, 40)), - - // not an infix operator - _ => None, - } - } - - // priority: post > pre > in - // associativity: right to left [ --!a --> --(!a) ] - // prefix_operator - // eg: -10, !a, ++a, --a - pub fn prefix(self) -> Option { - match self { - Self::UnitDec | Self::UnitInc - | Self::Sub | Self::Add - | Self::Not | Self::BitNot => Some(200), - - _ => None, - } - } - - // these tokens have the highest priority - // postfix_operator - // eg: a[10], b++, c.att1 - pub fn postfix(self) -> Option { - match self { - Self::LParen // function call - | Self::LBracket // array subscript - | Self::Dot // attribute access - | Self::UnitDec | Self::UnitInc => Some(300), - - _ => None, - } - } - - pub fn is_declaration_kw(self) -> bool { - matches!(self, Self::VarKw | Self::ComponentKw | Self::SignalKw) - } - - pub fn is_trivial(self) -> bool { - matches!( - self, - Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error - ) - } -} +use logos::Logos; +use serde::Serialize; + +#[derive(Logos, Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord, Hash, Serialize)] +#[allow(non_camel_case_types)] +#[repr(u16)] +pub enum TokenKind { + // Error + #[error] + Error = 0, + // Comments + #[regex(r"//[^\n]*")] + CommentLine, + #[token("/*")] + CommentBlockOpen, + #[token("*/")] + CommentBlockClose, + // Trivial + #[regex("[ \t]+")] + WhiteSpace, + #[regex("[\n]")] + EndLine, + // Circom + #[token("pragma")] + Pragma, + #[token("circom")] + Circom, + #[regex("2.[0-9].[0-9]")] + Version, + // Literals + #[regex("[0-9]+")] + Number, + #[regex("[$_]*[a-zA-Z][a-zA-Z0-9_$]*")] + Identifier, + #[regex(r#""[^"]*""#)] + CircomString, + // Brackets + #[token("(")] + LParen, + #[token(")")] + RParen, + #[token("{")] + LCurly, + #[token("}")] + RCurly, + #[token("[")] + LBracket, + #[token("]")] + RBracket, + // Punctuation + #[token(";")] + Semicolon, + #[token(",")] + Comma, + #[token(".")] + Dot, + // Boolean operators + #[token("&&")] + BoolAnd, + #[token("||")] + BoolOr, + #[token("!")] + Not, + // Relational operators + #[token("==")] + Equal, + #[token("!=")] + NotEqual, + #[token("<")] + LessThan, + #[token(">")] + GreaterThan, + #[token("<=")] + LessThanAndEqual, + #[token(">=")] + GreaterThanAndEqual, + // Arithmetic operators + #[token("+")] + Add, + #[token("-")] + Sub, + #[token("*")] + Mul, + #[token("**")] + Power, + #[token("/")] + Div, + #[token("\\")] + IntDiv, + #[token("%")] + Mod, + // Combined arithmetic assignment + #[token("+=")] + AddAssign, + #[token("-=")] + SubAssign, + #[token("*=")] + MulAssign, + #[token("**=")] + PowerAssign, + #[token("/=")] + DivAssign, + #[token(r"\=")] + IntDivAssign, + #[token("%=")] + ModAssign, + #[token("++")] + UnitInc, + #[token("--")] + UnitDec, + // Bitwise operators + #[token("&")] + BitAnd, + #[token("|")] + BitOr, + #[token("~")] + BitNot, + #[token("^")] + BitXor, + #[token(">>")] + ShiftR, + #[token("<<")] + ShiftL, + // Combined bitwise assignments + #[token("&=")] + BitAndAssign, + #[token("|=")] + BitOrAssign, + #[token("~=")] + BitNotAssign, + #[token("^=")] + BitXorAssign, + #[token(">>=")] + ShiftRAssign, + #[token("<<=")] + ShiftLAssign, + // Assign + #[token("=")] + Assign, + #[token("===")] + EqualSignal, + #[token("-->")] + LAssignSignal, + #[token("==>")] + LAssignContraintSignal, + #[token("<--")] + RAssignSignal, + #[token("<==")] + RAssignConstraintSignal, + // Conditional expressions + #[token("?")] + MarkQuestion, + #[token(":")] + Colon, + // Keywords + #[token("template")] + TemplateKw, + #[token("function")] + FunctionKw, + #[token("component")] + ComponentKw, + #[token("main")] + MainKw, + #[token("public")] + PublicKw, + #[token("signal")] + SignalKw, + #[token("var")] + VarKw, + #[token("include")] + IncludeKw, + #[token("input")] + InputKw, + #[token("output")] + OutputKw, + #[token("log")] + LogKw, + // Statement keywords + #[token("if")] + IfKw, + #[token("else")] + ElseKw, + #[token("for")] + ForKw, + #[token("while")] + WhileKw, + #[token("return")] + ReturnKw, + #[token("assert")] + AssertKw, + // Complex token kind + ForLoop, + AssignStatement, + CircomProgram, + SignalOfComponent, + SignalHeader, + Block, + Tuple, + TupleInit, + Call, + TenaryConditional, + Condition, + Expression, + FunctionDef, + Statement, + StatementList, + ComponentDecl, + TemplateDef, + TemplateName, + FunctionName, + ParameterList, + SignalDecl, + VarDecl, + InputSignalDecl, + OutputSignalDecl, + ComponentCall, + ComponentIdentifier, + SignalIdentifier, + ArrayQuery, + ParserError, + BlockComment, + EOF, + ROOT, + __LAST, +} + +impl From for TokenKind { + #[inline] + fn from(d: u16) -> TokenKind { + assert!(d <= (TokenKind::__LAST as u16)); + unsafe { std::mem::transmute::(d) } + } +} + +impl From for TokenKind { + fn from(value: rowan::SyntaxKind) -> Self { + match value { + rowan::SyntaxKind(id) => TokenKind::from(id), + } + } +} + +impl From for u16 { + #[inline] + fn from(k: TokenKind) -> u16 { + k as u16 + } +} + +impl From for rowan::SyntaxKind { + fn from(kind: TokenKind) -> Self { + Self(kind as u16) + } +} + +impl TokenKind { + // a + 10 --> a and 10 are literals + pub fn is_literal(self) -> bool { + matches!(self, Self::Number | Self::Identifier) + } + + // these tokens have the lowest priority + // infix_operator + // eg: a + b --> + is an infix token + pub fn infix(self) -> Option<(u16, u16)> { + match self { + // arithmetic operators + Self::Power => Some((99, 100)), + Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), + Self::Add | Self::Sub => Some((89, 90)), + + // shift bitwise operators + Self::ShiftL | Self::ShiftR => Some((84, 85)), + + // relational operators + Self::LessThan + | Self::GreaterThan + | Self::LessThanAndEqual + | Self::GreaterThanAndEqual => Some((79, 80)), + Self::Equal + | Self::NotEqual => Some((74, 75)), + + // other bitwise operators + Self::BitAnd => Some((69, 70)), + Self::BitXor => Some((64, 65)), // exclusive or + Self::BitOr => Some((59, 60)), + + // boolean operators + Self::BoolAnd => Some((54, 55)), + Self::BoolOr => Some((49, 50)), + + // TODO: how about conditional operation ( ? : ) + // associativity: right to left [ a ? b : c --> ??? ] + + // associativity: right to left [ a = b = c --> a = (b = c) ] + // assignment operators + Self::Assign + // bitwise asignment operators + | Self::BitOrAssign + | Self::BitXorAssign + | Self::BitAndAssign + | Self::ShiftLAssign + | Self::ShiftRAssign + // arithmetic asignament operators + | Self::AddAssign + | Self::SubAssign + | Self::MulAssign + | Self::DivAssign + | Self::IntDivAssign + | Self::ModAssign + | Self::PowerAssign => Some((44, 45)), + + // TODO: how about comma (expression separator) + Self::Comma => Some((39, 40)), + + // not an infix operator + _ => None, + } + } + + // priority: post > pre > in + // associativity: right to left [ --!a --> --(!a) ] + // prefix_operator + // eg: -10, !a, ++a, --a + pub fn prefix(self) -> Option { + match self { + Self::UnitDec | Self::UnitInc + | Self::Sub | Self::Add + | Self::Not | Self::BitNot => Some(200), + + _ => None, + } + } + + // these tokens have the highest priority + // postfix_operator + // eg: a[10], b++, c.att1 + pub fn postfix(self) -> Option { + match self { + Self::LParen // function call + | Self::LBracket // array subscript + | Self::Dot // attribute access + | Self::UnitDec | Self::UnitInc => Some(300), + + _ => None, + } + } + + pub fn is_declaration_kw(self) -> bool { + matches!(self, Self::VarKw | Self::ComponentKw | Self::SignalKw) + } + + pub fn is_trivial(self) -> bool { + matches!( + self, + Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error + ) + } +} diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index ded3cc3..1cea829 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -1,419 +1,419 @@ -use parser::input::Input; -use parser::output::{Child, Output}; -use parser::parser::Parser; -use parser::token_kind::TokenKind; -use rowan::{GreenNode, GreenNodeBuilder}; - -use crate::syntax_node::SyntaxNode; - -pub struct SyntaxTreeBuilder<'a> { - builder: GreenNodeBuilder<'static>, - input: &'a Input<'a>, -} - -impl<'a> SyntaxTreeBuilder<'a> { - pub fn new(input: &'a Input) -> Self { - Self { - builder: GreenNodeBuilder::new(), - input, - } - } - pub fn build_rec(&mut self, tree: &Output) { - self.builder.start_node(tree.kind().into()); - for child in tree.children() { - match child { - Child::Token(token_id) => { - let token_kind = self.input.kind_of(*token_id); - // TODO: return Error to replace .unwrap() - let token_value = self.input.token_value(*token_id).unwrap(); - self.builder.start_node(token_kind.into()); - self.builder.token(token_kind.into(), token_value); - self.builder.finish_node(); - } - Child::Tree(child_tree) => self.build_rec(child_tree), - Child::Error(error) => { - let token_kind = TokenKind::Error; - let token_value = error.as_str(); - - self.builder.start_node(token_kind.into()); - self.builder.token(token_kind.into(), token_value); - self.builder.finish_node(); - } - } - } - - self.builder.finish_node(); - } - - pub fn build(&mut self, tree: Output) { - self.build_rec(&tree); - } - - pub fn finish(self) -> GreenNode { - self.builder.finish() - } - - pub fn syntax_tree(source: &str) -> SyntaxNode { - let input = Input::new(source); - - let output = Parser::parsing(&input); - - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - SyntaxNode::new_root(green) - } -} - -#[cfg(test)] -mod tests { - use std::hash::{DefaultHasher, Hash, Hasher}; - - use rowan::ast::AstNode; - - use crate::{abstract_syntax_tree::AstCircomProgram, test_programs}; - - use super::SyntaxTreeBuilder; - - fn ast_from_source(source: &str) -> AstCircomProgram { - let syntax = SyntaxTreeBuilder::syntax_tree(source); - AstCircomProgram::cast(syntax).unwrap() - } - - fn children_from_ast(ast: &AstCircomProgram) -> Vec { - let children = ast - .syntax() - .first_child() - .unwrap() - .siblings(rowan::Direction::Next) - .into_iter() - .map(|child| child.text().to_string()) - .collect(); - - children - } - - fn pragma_string_from_ast(ast: &AstCircomProgram) -> String { - ast.pragma().unwrap().syntax().text().to_string() - } - - fn pragma_version_from_ast(ast: &AstCircomProgram) -> String { - ast.pragma() - .unwrap() - .version() - .unwrap() - .syntax() - .text() - .to_string() - } - - fn template_names_from_ast(ast: &AstCircomProgram) -> Vec { - let templates = ast - .template_list() - .iter() - .map(|template| template.name().unwrap().syntax().text().to_string()) - .collect(); - - templates - } - - fn function_names_from_ast(ast: &AstCircomProgram) -> Vec { - let functions = ast - .function_list() - .iter() - .map(|function| { - function - .function_name() - .unwrap() - .syntax() - .text() - .to_string() - }) - .collect(); - - functions - } - - #[test] - fn syntax_test_1() { - let ast = ast_from_source(test_programs::PARSER_TEST_1); - - // check_ast_children - let children = children_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_1_children", children); - - // check pragma - let pragma = pragma_string_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - // check ast hash - let mut hasher = DefaultHasher::default(); - ast.syntax().hash(&mut hasher); - let _ast_hash = hasher.finish(); - - // check template hash - let mut h1 = DefaultHasher::default(); - let mut h2 = DefaultHasher::default(); - - let template = ast.template_list(); - - template[0].syntax().hash(&mut h1); - template[1].syntax().hash(&mut h2); - - assert_ne!( - h1.finish(), - h2.finish(), - "Templates with same syntax should have different hashes!" - ); - - // check template syntax (text & green node) - assert_eq!( - template[0].syntax().text(), - template[1].syntax().text(), - "The syntax (as text) of template 1 and 2 must be the same!" - ); - assert_eq!( - template[0].syntax().green(), - template[1].syntax().green(), - "The syntax (as green node) of template 1 and 2 must be the same!!" - ); - } - - #[test] - fn syntax_test_2() { - let ast = ast_from_source(test_programs::PARSER_TEST_2); - - let pragma = pragma_string_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - let function_names = function_names_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); - - let template_names = template_names_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); - } - - #[test] - fn syntax_test_3() { - let ast = ast_from_source(test_programs::PARSER_TEST_3); - let pragma = pragma_string_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - let pragma_version = pragma_version_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); - } - - #[test] - fn syntax_test_4() { - let ast = ast_from_source(test_programs::PARSER_TEST_4); - let pragma = pragma_string_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); - - let pragma_version = pragma_version_from_ast(&ast); - insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); - } - - #[test] - fn syntax_test_5() { - let ast = ast_from_source(test_programs::PARSER_TEST_5); - let pragma = ast.pragma().is_none(); - insta::assert_yaml_snapshot!(pragma, @"true"); - - let template_names = template_names_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_5_templates", template_names); - } - - #[test] - fn syntax_test_6() { - let ast = ast_from_source(test_programs::PARSER_TEST_6); - let pragma = ast.pragma().is_none(); - insta::assert_yaml_snapshot!(pragma, @"true"); - - let template_names = template_names_from_ast(&ast); - insta::assert_yaml_snapshot!("syntax_test_6_templates", template_names); - } -} - -#[cfg(test)] -mod grammar_tests { - - use crate::{ - abstract_syntax_tree::{AstBlock, AstOutputSignalDecl, AstPragma, AstTemplateDef}, - syntax::SyntaxTreeBuilder, - syntax_node::CircomLanguage, - }; - use parser::{grammar::entry::Scope, input::Input, parser::Parser}; - use rowan::{ast::AstNode, SyntaxNode}; - - fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { - let input = Input::new(&source); - let output = Parser::parsing_with_scope(&input, scope); - - // output is a tree whose node is index of token, no content of token - // convert output into green node - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - - // then cast green node into syntax node - let syntax = SyntaxNode::new_root(green); - - syntax - } - - #[test] - fn pragma_happy_test() { - // parse source (string) into output tree - let version = r#"2.0.1"#; - let source = format!(r#"pragma circom {};"#, version); - - let syntax = syntax_node_from_source(&source, Scope::Pragma); - - // cast syntax node into ast node to retrieve more information - let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); - - // finally, assert with expect value - let pragma_versison_kind = pragma.version().unwrap().syntax().kind(); - insta::assert_yaml_snapshot!(pragma_versison_kind, @"Version"); - - let pragma_versison_text = pragma.version().unwrap().syntax().text().to_string(); - insta::assert_yaml_snapshot!(pragma_versison_text, @"2.0.1"); - } - - #[test] - fn template_happy_test() { - // SOURCE & EXPECTED RESULT - const SOURCE: &str = r#"template MultiplierN (N, P, QQ) { - //Declaration of signals and components. - signal input in[N]; - signal output out; - component comp[N-1]; - - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - - // ... some more code (see below) - - }"#; - - let syntax = syntax_node_from_source(&SOURCE, Scope::Template); - - // cast syntax node into ast node to retrieve more information - let template = - AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); - - // finally, assert with expect value - - // name - let name = template - .name() - .expect("Can not extract template name") - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(name, @"MultiplierN"); - - // parameter list - let first_param = template - .parameter_list() - .expect("Can not detect parameter list") - .syntax() - .first_child() - .unwrap() - .text() - .to_string(); - insta::assert_yaml_snapshot!(first_param, @"N"); - - let last_param = template - .parameter_list() - .expect("Can not detect parameter list") - .syntax() - .last_child() - .unwrap() - .text() - .to_string(); - insta::assert_yaml_snapshot!(last_param, @"QQ"); - - // statements - let statements = template.statements().unwrap(); - let output_signal = statements.find_children::(); - println!("{:?}", output_signal); - - let statements: Vec = statements - .statement_list() - .into_iter() - .map(|statement| statement.syntax().text().to_string()) - .collect(); - insta::assert_yaml_snapshot!("template_happy_test_statements", statements); - - // input signal - let input_signal = template - .find_input_signal("in") - .unwrap() - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); - - // output signal - let output_signal = template - .find_output_signal("out") - .unwrap() - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); - - // internal signal - let internal_signal = template.find_internal_signal("in").is_none(); - insta::assert_yaml_snapshot!(internal_signal, @"true"); - - // component - let component = template - .find_component("comp") - .unwrap() - .syntax() - .text() - .to_string(); - insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); - } - - #[test] - fn block_happy_test() { - // SOURCE & EXPECTED RESULT - let source = r#"{ - //Declaration of signals. - signal input in[N]; - signal output out; - component comp[N-1]; - - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - comp[0].in1 <== in[0]; - comp[0].in2 <== in[1]; - for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; - - } - out <== comp[N-2].out; - }"#; - - let syntax = syntax_node_from_source(&source, Scope::Block); - - // cast syntax node into ast node to retrieve more information - let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); - - // finally, assert with expect statements - let statements = block.statement_list().unwrap().statement_list(); - let statements: Vec = statements - .into_iter() - .map(|statement| statement.syntax().text().to_string()) - .collect(); - insta::assert_yaml_snapshot!("block_happy_test_statements", statements); - } -} +use parser::input::Input; +use parser::output::{Child, Output}; +use parser::parser::Parser; +use parser::token_kind::TokenKind; +use rowan::{GreenNode, GreenNodeBuilder}; + +use crate::syntax_node::SyntaxNode; + +pub struct SyntaxTreeBuilder<'a> { + builder: GreenNodeBuilder<'static>, + input: &'a Input<'a>, +} + +impl<'a> SyntaxTreeBuilder<'a> { + pub fn new(input: &'a Input) -> Self { + Self { + builder: GreenNodeBuilder::new(), + input, + } + } + pub fn build_rec(&mut self, tree: &Output) { + self.builder.start_node(tree.kind().into()); + for child in tree.children() { + match child { + Child::Token(token_id) => { + let token_kind = self.input.kind_of(*token_id); + // TODO: return Error to replace .unwrap() + let token_value = self.input.token_value(*token_id).unwrap(); + self.builder.start_node(token_kind.into()); + self.builder.token(token_kind.into(), token_value); + self.builder.finish_node(); + } + Child::Tree(child_tree) => self.build_rec(child_tree), + Child::Error(error) => { + let token_kind = TokenKind::Error; + let token_value = error.as_str(); + + self.builder.start_node(token_kind.into()); + self.builder.token(token_kind.into(), token_value); + self.builder.finish_node(); + } + } + } + + self.builder.finish_node(); + } + + pub fn build(&mut self, tree: Output) { + self.build_rec(&tree); + } + + pub fn finish(self) -> GreenNode { + self.builder.finish() + } + + pub fn syntax_tree(source: &str) -> SyntaxNode { + let input = Input::new(source); + + let output = Parser::parsing(&input); + + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + SyntaxNode::new_root(green) + } +} + +#[cfg(test)] +mod tests { + use std::hash::{DefaultHasher, Hash, Hasher}; + + use rowan::ast::AstNode; + + use crate::{abstract_syntax_tree::AstCircomProgram, test_programs}; + + use super::SyntaxTreeBuilder; + + fn ast_from_source(source: &str) -> AstCircomProgram { + let syntax = SyntaxTreeBuilder::syntax_tree(source); + AstCircomProgram::cast(syntax).unwrap() + } + + fn children_from_ast(ast: &AstCircomProgram) -> Vec { + let children = ast + .syntax() + .first_child() + .unwrap() + .siblings(rowan::Direction::Next) + .into_iter() + .map(|child| child.text().to_string()) + .collect(); + + children + } + + fn pragma_string_from_ast(ast: &AstCircomProgram) -> String { + ast.pragma().unwrap().syntax().text().to_string() + } + + fn pragma_version_from_ast(ast: &AstCircomProgram) -> String { + ast.pragma() + .unwrap() + .version() + .unwrap() + .syntax() + .text() + .to_string() + } + + fn template_names_from_ast(ast: &AstCircomProgram) -> Vec { + let templates = ast + .template_list() + .iter() + .map(|template| template.name().unwrap().syntax().text().to_string()) + .collect(); + + templates + } + + fn function_names_from_ast(ast: &AstCircomProgram) -> Vec { + let functions = ast + .function_list() + .iter() + .map(|function| { + function + .function_name() + .unwrap() + .syntax() + .text() + .to_string() + }) + .collect(); + + functions + } + + #[test] + fn syntax_test_1() { + let ast = ast_from_source(test_programs::PARSER_TEST_1); + + // check_ast_children + let children = children_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_1_children", children); + + // check pragma + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + // check ast hash + let mut hasher = DefaultHasher::default(); + ast.syntax().hash(&mut hasher); + let _ast_hash = hasher.finish(); + + // check template hash + let mut h1 = DefaultHasher::default(); + let mut h2 = DefaultHasher::default(); + + let template = ast.template_list(); + + template[0].syntax().hash(&mut h1); + template[1].syntax().hash(&mut h2); + + assert_ne!( + h1.finish(), + h2.finish(), + "Templates with same syntax should have different hashes!" + ); + + // check template syntax (text & green node) + assert_eq!( + template[0].syntax().text(), + template[1].syntax().text(), + "The syntax (as text) of template 1 and 2 must be the same!" + ); + assert_eq!( + template[0].syntax().green(), + template[1].syntax().green(), + "The syntax (as green node) of template 1 and 2 must be the same!!" + ); + } + + #[test] + fn syntax_test_2() { + let ast = ast_from_source(test_programs::PARSER_TEST_2); + + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + let function_names = function_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_2_functions", function_names); + + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_2_templates", template_names); + } + + #[test] + fn syntax_test_3() { + let ast = ast_from_source(test_programs::PARSER_TEST_3); + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + let pragma_version = pragma_version_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); + } + + #[test] + fn syntax_test_4() { + let ast = ast_from_source(test_programs::PARSER_TEST_4); + let pragma = pragma_string_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma, @"pragma circom 2.0.0;"); + + let pragma_version = pragma_version_from_ast(&ast); + insta::assert_yaml_snapshot!(pragma_version, @"2.0.0"); + } + + #[test] + fn syntax_test_5() { + let ast = ast_from_source(test_programs::PARSER_TEST_5); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); + + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_5_templates", template_names); + } + + #[test] + fn syntax_test_6() { + let ast = ast_from_source(test_programs::PARSER_TEST_6); + let pragma = ast.pragma().is_none(); + insta::assert_yaml_snapshot!(pragma, @"true"); + + let template_names = template_names_from_ast(&ast); + insta::assert_yaml_snapshot!("syntax_test_6_templates", template_names); + } +} + +#[cfg(test)] +mod grammar_tests { + + use crate::{ + abstract_syntax_tree::{AstBlock, AstOutputSignalDecl, AstPragma, AstTemplateDef}, + syntax::SyntaxTreeBuilder, + syntax_node::CircomLanguage, + }; + use parser::{grammar::entry::Scope, input::Input, parser::Parser}; + use rowan::{ast::AstNode, SyntaxNode}; + + fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { + let input = Input::new(&source); + let output = Parser::parsing_with_scope(&input, scope); + + // output is a tree whose node is index of token, no content of token + // convert output into green node + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + + // then cast green node into syntax node + let syntax = SyntaxNode::new_root(green); + + syntax + } + + #[test] + fn pragma_happy_test() { + // parse source (string) into output tree + let version = r#"2.0.1"#; + let source = format!(r#"pragma circom {};"#, version); + + let syntax = syntax_node_from_source(&source, Scope::Pragma); + + // cast syntax node into ast node to retrieve more information + let pragma = AstPragma::cast(syntax).expect("Can not cast syntax node into ast pragma"); + + // finally, assert with expect value + let pragma_versison_kind = pragma.version().unwrap().syntax().kind(); + insta::assert_yaml_snapshot!(pragma_versison_kind, @"Version"); + + let pragma_versison_text = pragma.version().unwrap().syntax().text().to_string(); + insta::assert_yaml_snapshot!(pragma_versison_text, @"2.0.1"); + } + + #[test] + fn template_happy_test() { + // SOURCE & EXPECTED RESULT + const SOURCE: &str = r#"template MultiplierN (N, P, QQ) { + //Declaration of signals and components. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + + // ... some more code (see below) + + }"#; + + let syntax = syntax_node_from_source(&SOURCE, Scope::Template); + + // cast syntax node into ast node to retrieve more information + let template = + AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); + + // finally, assert with expect value + + // name + let name = template + .name() + .expect("Can not extract template name") + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(name, @"MultiplierN"); + + // parameter list + let first_param = template + .parameter_list() + .expect("Can not detect parameter list") + .syntax() + .first_child() + .unwrap() + .text() + .to_string(); + insta::assert_yaml_snapshot!(first_param, @"N"); + + let last_param = template + .parameter_list() + .expect("Can not detect parameter list") + .syntax() + .last_child() + .unwrap() + .text() + .to_string(); + insta::assert_yaml_snapshot!(last_param, @"QQ"); + + // statements + let statements = template.statements().unwrap(); + let output_signal = statements.find_children::(); + println!("{:?}", output_signal); + + let statements: Vec = statements + .statement_list() + .into_iter() + .map(|statement| statement.syntax().text().to_string()) + .collect(); + insta::assert_yaml_snapshot!("template_happy_test_statements", statements); + + // input signal + let input_signal = template + .find_input_signal("in") + .unwrap() + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); + + // output signal + let output_signal = template + .find_output_signal("out") + .unwrap() + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); + + // internal signal + let internal_signal = template.find_internal_signal("in").is_none(); + insta::assert_yaml_snapshot!(internal_signal, @"true"); + + // component + let component = template + .find_component("comp") + .unwrap() + .syntax() + .text() + .to_string(); + insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); + } + + #[test] + fn block_happy_test() { + // SOURCE & EXPECTED RESULT + let source = r#"{ + //Declaration of signals. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + comp[0].in1 <== in[0]; + comp[0].in2 <== in[1]; + for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + } + out <== comp[N-2].out; + }"#; + + let syntax = syntax_node_from_source(&source, Scope::Block); + + // cast syntax node into ast node to retrieve more information + let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); + + // finally, assert with expect statements + let statements = block.statement_list().unwrap().statement_list(); + let statements: Vec = statements + .into_iter() + .map(|statement| statement.syntax().text().to_string()) + .collect(); + insta::assert_yaml_snapshot!("block_happy_test_statements", statements); + } +} From 84e960b229635b28a5ae7c6354c41c5ee09e650f Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 13:12:03 +0700 Subject: [PATCH 37/71] fix clippy check --- crates/parser/src/input.rs | 2 +- crates/parser/src/token_kind.rs | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index f22d611..57e7317 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -166,6 +166,6 @@ mod tests { & &= | |= }"#; - test(source, "test_operators"); + test(source, "test_operators"); } } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 98ef766..974fc8e 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -268,10 +268,8 @@ impl TokenKind { Self::Power => Some((99, 100)), Self::Mul | Self::Div | Self::IntDiv | Self::Mod => Some((94, 95)), Self::Add | Self::Sub => Some((89, 90)), - // shift bitwise operators Self::ShiftL | Self::ShiftR => Some((84, 85)), - // relational operators Self::LessThan | Self::GreaterThan @@ -279,19 +277,17 @@ impl TokenKind { | Self::GreaterThanAndEqual => Some((79, 80)), Self::Equal | Self::NotEqual => Some((74, 75)), - // other bitwise operators Self::BitAnd => Some((69, 70)), Self::BitXor => Some((64, 65)), // exclusive or Self::BitOr => Some((59, 60)), - // boolean operators Self::BoolAnd => Some((54, 55)), Self::BoolOr => Some((49, 50)), - + // ---------- // TODO: how about conditional operation ( ? : ) // associativity: right to left [ a ? b : c --> ??? ] - + // ---------- // associativity: right to left [ a = b = c --> a = (b = c) ] // assignment operators Self::Assign @@ -307,26 +303,24 @@ impl TokenKind { | Self::MulAssign | Self::DivAssign | Self::IntDivAssign - | Self::ModAssign + | Self::ModAssign | Self::PowerAssign => Some((44, 45)), - // TODO: how about comma (expression separator) Self::Comma => Some((39, 40)), - // not an infix operator _ => None, } } // priority: post > pre > in - // associativity: right to left [ --!a --> --(!a) ] + // associativity: right to left [ --!a --> --(!a) ] // prefix_operator // eg: -10, !a, ++a, --a pub fn prefix(self) -> Option { match self { - Self::UnitDec | Self::UnitInc - | Self::Sub | Self::Add - | Self::Not | Self::BitNot => Some(200), + Self::UnitDec | Self::UnitInc | Self::Sub | Self::Add | Self::Not | Self::BitNot => { + Some(200) + } _ => None, } @@ -340,7 +334,7 @@ impl TokenKind { Self::LParen // function call | Self::LBracket // array subscript | Self::Dot // attribute access - | Self::UnitDec | Self::UnitInc => Some(300), + | Self::UnitDec | Self::UnitInc => Some(300), _ => None, } From a1bd25e86d19ae1ced5813b14df1f742dc9e0157 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 13:22:38 +0700 Subject: [PATCH 38/71] fix clippy --- crates/lsp/src/handler/goto_definition.rs | 1 - crates/parser/src/grammar/declaration.rs | 1 - crates/parser/src/grammar/expression.rs | 1 - crates/parser/src/grammar/statement.rs | 3 --- crates/parser/src/grammar/template.rs | 1 - crates/syntax/src/syntax.rs | 1 - 6 files changed, 8 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 4c7e1f0..4cba681 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -229,7 +229,6 @@ template Y() { let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { for template in program_ast.template_list() { println!("{template:?}"); diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 0ee9d61..c5dd125 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -128,4 +128,3 @@ pub(super) fn declaration(p: &mut Parser) { _ => unreachable!(), } } - diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 9beee8f..4604da4 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -156,4 +156,3 @@ fn circom_expression(p: &mut Parser) { } } } - diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index fca6007..626600d 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -82,7 +82,6 @@ fn for_statement(p: &mut Parser) { p.close(m, ForLoop); } -/* /* while () @@ -95,7 +94,6 @@ fn while_statement(p: &mut Parser) { statement(p); } -/* /* assert() */ @@ -185,4 +183,3 @@ fn assignment_statement(p: &mut Parser) { p.close(m, Error); } } - diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index bb599b6..a502365 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -23,4 +23,3 @@ pub fn template(p: &mut Parser) { p.close(m, TemplateDef); } - diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 5edce00..2b303a7 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -300,7 +300,6 @@ mod grammar_tests { let syntax = syntax_node_from_source(&SOURCE, Scope::Template); - // cast syntax node into ast node to retrieve more information let template = AstTemplateDef::cast(syntax).expect("Can not cast syntax node into ast template"); From 3a0879787083551a974fc6b75a26c2aee894c0ba Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 15:06:42 +0700 Subject: [PATCH 39/71] remove duplicate declaration in grammar tests --- crates/syntax/src/syntax.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 2b303a7..ded3cc3 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -349,12 +349,6 @@ mod grammar_tests { insta::assert_yaml_snapshot!("template_happy_test_statements", statements); // input signal - let input_signal = template - .find_input_signal("in") - .unwrap() - .syntax() - .text() - .to_string(); let input_signal = template .find_input_signal("in") .unwrap() @@ -364,12 +358,6 @@ mod grammar_tests { insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); // output signal - let output_signal = template - .find_output_signal("out") - .unwrap() - .syntax() - .text() - .to_string(); let output_signal = template .find_output_signal("out") .unwrap() @@ -383,12 +371,6 @@ mod grammar_tests { insta::assert_yaml_snapshot!(internal_signal, @"true"); // component - let component = template - .find_component("comp") - .unwrap() - .syntax() - .text() - .to_string(); let component = template .find_component("comp") .unwrap() From 39f1e12d515dea3101c7e9851fdab8042561ac91 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 17:06:25 +0700 Subject: [PATCH 40/71] add missing signal assign tokens --- crates/parser/src/token_kind.rs | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 2101ef9..aa89ac0 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -293,6 +293,12 @@ impl TokenKind { // associativity: right to left [ a = b = c --> a = (b = c) ] // assignment operators Self::Assign + // signal assigment operators + | Self::EqualSignal + | Self::LAssignSignal + | Self::LAssignContraintSignal + | Self::RAssignSignal + | Self::RAssignConstraintSignal // bitwise asignment operators | Self::BitOrAssign | Self::BitXorAssign @@ -346,6 +352,36 @@ impl TokenKind { matches!(self, Self::VarKw | Self::ComponentKw | Self::SignalKw) } + pub fn is_assign_token(self) -> bool { + matches!( + self, + Self::Assign + // signal assigment operators + | Self::EqualSignal + | Self::LAssignSignal + | Self::LAssignContraintSignal + | Self::RAssignSignal + | Self::RAssignConstraintSignal + // bitwise asignment operators + | Self::BitOrAssign + | Self::BitXorAssign + | Self::BitAndAssign + | Self::ShiftLAssign + | Self::ShiftRAssign + // arithmetic asignament operators + | Self::AddAssign + | Self::SubAssign + | Self::MulAssign + | Self::DivAssign + | Self::IntDivAssign + | Self::ModAssign + | Self::PowerAssign + // unit inc/dec + | Self::UnitInc + | Self::UnitDec + ) + } + pub fn is_trivial(self) -> bool { matches!( self, From f4db959acaaadb061c63f7e495499068d63492d4 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 17:06:55 +0700 Subject: [PATCH 41/71] fix grammar of for statement --- crates/parser/src/grammar/block.rs | 1 + crates/parser/src/grammar/expression.rs | 12 +++++-- crates/parser/src/grammar/statement.rs | 36 +++++++++++++------ crates/parser/src/parser.rs | 5 +++ ...mmar_tests__for_happy_test_statements.snap | 9 +++++ crates/syntax/src/syntax.rs | 30 ++++++++++++++++ 6 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index f01b515..645632d 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -11,6 +11,7 @@ use super::*; pub fn block(p: &mut Parser) { p.inc_rcurly(); + // TODO: why do not use expect for { and } if !p.at(LCurly) { p.advance_with_error("Miss {"); } else { diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 4604da4..e0a2d7a 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -10,15 +10,21 @@ pub(super) fn expression(p: &mut Parser) { /** * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" + * can be an empty tuple (for function cal: Mul()) */ pub(super) fn tuple(p: &mut Parser) { let m = p.open(); p.expect(LParen); - p.expect(Identifier); - while p.at(Comma) && !p.eof() { - p.expect(Comma); + + if p.at(Identifier) { p.expect(Identifier); + + while p.at(Comma) && !p.eof() { + p.expect(Comma); + p.expect(Identifier); + } } + p.expect(RParen); p.close(m, Tuple); } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index 626600d..27de3c6 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,3 +1,5 @@ +use crate::token_kind::TokenKind; + use super::{block::block, expression::expression, *}; pub(super) fn statement(p: &mut Parser) { @@ -64,21 +66,31 @@ for (/; ; ) */ fn for_statement(p: &mut Parser) { let m = p.open(); + + // for ( p.expect(ForKw); p.expect(LParen); + if p.current().is_declaration_kw() { + // for (var i = 1 declaration::declaration(p); } else { + // for (i = 1 assignment_statement(p); } p.expect(Semicolon); + + // for (i = 1; i < N; expression::expression(p); p.expect(Semicolon); + // for (i = 1; i < N; i++) assignment_statement(p); p.expect(RParen); - statement_no_condition(p); + // for (i = 1; i < N; i++) { } + statement(p); + // statement_no_condition(p); p.close(m, ForLoop); } @@ -149,35 +161,39 @@ fn assignment_statement(p: &mut Parser) { if p.at(Identifier) { let m_id = p.open(); + // abc let m_name = p.open(); p.expect(Identifier); p.close(m_name, ComponentIdentifier); + + // abc[N - 1] if p.at(LBracket) { p.expect(LBracket); expression(p); p.expect(RBracket); } + if p.at(Dot) { + // abc[N - 1].def OR abc.def --> component call p.expect(Dot); p.expect(Identifier); p.close(m_id, ComponentCall); } else { + // abc[N - 1] OR abc --> expression p.close(m_id, Expression); } } else { + // assignment without identifier expression(p); } - if p.at_any(&[ - Assign, - RAssignSignal, - RAssignConstraintSignal, - LAssignContraintSignal, - LAssignSignal, - EqualSignal, - ]) { + // assign part + if p.at_assign_token() { + let is_self_assign = p.at_any(&[TokenKind::UnitDec, TokenKind::UnitInc]); p.advance(); - expression(p); + if is_self_assign == false { + expression(p); + } p.close(m, AssignStatement); } else { p.close(m, Error); diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 34a2f64..9188176 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -166,6 +166,11 @@ impl<'a> Parser<'a> { kinds.contains(¤t_kind) } + pub fn at_assign_token(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_assign_token() + } + pub fn skip(&mut self) { self.next(); } diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap new file mode 100644 index 0000000..ee362e6 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap @@ -0,0 +1,9 @@ +--- +source: crates/syntax/src/syntax.rs +expression: statements +--- +- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" +- "comp[0].in1 <== in[0];" +- "comp[0].in2 <== in[1];" +- "for(var i = 0; i < N-2; i++){\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" +- "out <== comp[N-2].out;" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index ded3cc3..b4ae9d4 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -416,4 +416,34 @@ mod grammar_tests { .collect(); insta::assert_yaml_snapshot!("block_happy_test_statements", statements); } + + #[test] + fn for_happy_test() { + let source = r#"{ + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + comp[0].in1 <== in[0]; + comp[0].in2 <== in[1]; + for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + } + out <== comp[N-2].out; + }"#; + + let syntax = syntax_node_from_source(&source, Scope::Block); + + // cast syntax node into ast node to retrieve more information + let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); + + let statements = block.statement_list().unwrap().statement_list(); + let statements: Vec = statements + .into_iter() + .map(|statement| statement.syntax().text().to_string()) + .collect(); + insta::assert_yaml_snapshot!("for_happy_test_statements", statements); + } } From a9edb76067baa38ce56eb5933fb54bea9ff57f76 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 17:18:37 +0700 Subject: [PATCH 42/71] add statements test --- crates/parser/src/grammar/statement.rs | 1 - ...ests__statement_happy_test_statements.snap | 14 +++++++++++++ crates/syntax/src/syntax.rs | 21 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__statement_happy_test_statements.snap diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index 27de3c6..39f8894 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -14,7 +14,6 @@ pub(super) fn statement(p: &mut Parser) { /* if (expr) -else else */ diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__statement_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__statement_happy_test_statements.snap new file mode 100644 index 0000000..176aeed --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__statement_happy_test_statements.snap @@ -0,0 +1,14 @@ +--- +source: crates/syntax/src/syntax.rs +expression: statements +--- +- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" +- "comp[0].in1 <== in[0];" +- "comp[0].in2 <== in[1];" +- "for(var i = 0; i < N-2; i++){\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" +- "out <== comp[N-2].out;" +- "while (out) {\n for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }\n }" +- assert(comp); +- "log(\"Print something...\", out);" +- "if (1 < 2) {\n log(\"Match...\", 1 < 2);\n } else {\n log(\"Does not match...\", 1 < 2);\n }" +- return out + comp; diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index b4ae9d4..568fbbb 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -418,7 +418,7 @@ mod grammar_tests { } #[test] - fn for_happy_test() { + fn statement_happy_test() { let source = r#"{ //Statements. for(var i = 0; i < N-1; i++){ @@ -432,6 +432,23 @@ mod grammar_tests { } out <== comp[N-2].out; + + // just for testing statement + while (out) { + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + } + assert(comp); + log("Print something...", out); + + if (1 < 2) { + log("Match...", 1 < 2); + } else { + log("Does not match...", 1 < 2); + } + + return out + comp; }"#; let syntax = syntax_node_from_source(&source, Scope::Block); @@ -444,6 +461,6 @@ mod grammar_tests { .into_iter() .map(|statement| statement.syntax().text().to_string()) .collect(); - insta::assert_yaml_snapshot!("for_happy_test_statements", statements); + insta::assert_yaml_snapshot!("statement_happy_test_statements", statements); } } From c5a17c3a9598d8a2bf79d7a1f6f748a30e1cf8e4 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 19:04:46 +0700 Subject: [PATCH 43/71] fix declaration, support matrix --- crates/lsp/src/handler/goto_definition.rs | 6 +- crates/parser/src/grammar/declaration.rs | 55 ++++++++++++------- .../src/abstract_syntax_tree/template.rs | 4 +- ...ar_tests__block_happy_test_statements.snap | 5 +- ...tests__template_happy_test_statements.snap | 5 +- crates/syntax/src/syntax.rs | 8 ++- 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 4cba681..8609b4c 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -189,7 +189,7 @@ mod tests { pragma circom 2.0.0; template X() { - signal x = 10; + signal x[100]; signal input x = 10; component x = Multiplier2(); component y = X(); @@ -230,9 +230,7 @@ template Y() { let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { - for template in program_ast.template_list() { - println!("{template:?}"); - } + println!("program: {}", program_ast.syntax().text().to_string()); let inputs = program_ast.template_list()[0] .func_body() diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index c5dd125..1d01c90 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,5 +1,5 @@ use super::{ - expression::{tuple, tuple_init}, + expression::{expression, tuple, tuple_init}, *, }; @@ -45,7 +45,7 @@ pub(super) fn var_declaration(p: &mut Parser) { p.expect(Identifier); if p.at(Assign) { p.expect(Assign); - expression::expression(p); + expression(p); } // list of var while p.at(Comma) && !p.eof() { @@ -53,13 +53,30 @@ pub(super) fn var_declaration(p: &mut Parser) { p.expect(Identifier); if p.at(Assign) { p.expect(Assign); - expression::expression(p); + expression(p); } } } p.close(m, VarDecl); } +pub(crate) fn signal_init(p: &mut Parser) { + // let m_c = p.open(); + p.expect(Identifier); + // p.close(m_c, SignalIdentifier); + + while p.at(LBracket) { + p.expect(LBracket); + expression(p); + p.expect(RBracket); + } + + if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { + p.advance(); + expression(p); + } +} + pub(super) fn signal_declaration(p: &mut Parser) { if !p.at(SignalKw) { p.advance_with_error("Signal error"); @@ -69,17 +86,18 @@ pub(super) fn signal_declaration(p: &mut Parser) { let m = p.open(); let io_signal = signal_header(p); + // tuple of signal if p.at(LParen) { tuple(p); if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { tuple_init(p); } } else { - p.expect(Identifier); - // list of var + // list of signal + signal_init(p); while p.at(Comma) && !p.eof() { p.skip(); - p.expect(Identifier); + signal_init(p); } } @@ -100,22 +118,19 @@ pub(super) fn component_declaration(p: &mut Parser) { let m_c = p.open(); p.expect(Identifier); p.close(m_c, ComponentIdentifier); - - p.expect(Assign); - let m_c = p.open(); - p.expect(Identifier); - p.close(m_c, TemplateName); - p.expect(LParen); - - if p.at(Identifier) { - expression::expression(p); - while !p.at(RParen) && !p.eof() { - p.expect(Comma); - expression::expression(p); - } + while p.at(LBracket) { + p.expect(LBracket); + expression(p); + p.expect(RBracket); } - p.expect(RParen); + if p.at(Assign) { + p.expect(Assign); + let m_c = p.open(); + p.expect(Identifier); + p.close(m_c, TemplateName); + tuple(p); + } p.close(m, ComponentDecl); } diff --git a/crates/syntax/src/abstract_syntax_tree/template.rs b/crates/syntax/src/abstract_syntax_tree/template.rs index 7253b12..e5db4ca 100644 --- a/crates/syntax/src/abstract_syntax_tree/template.rs +++ b/crates/syntax/src/abstract_syntax_tree/template.rs @@ -86,8 +86,8 @@ impl AstTemplateDef { pub fn find_component(&self, name: &str) -> Option { if let Some(statements) = self.statements() { for component in statements.find_children::() { - if let Some(signal_name) = component.component_identifier() { - if let Some(component_name) = signal_name.name() { + if let Some(component_identifier) = component.component_identifier() { + if let Some(component_name) = component_identifier.name() { if component_name.syntax().text() == name { return Some(component); } diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap index 5db6859..ee362e6 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap @@ -2,11 +2,8 @@ source: crates/syntax/src/syntax.rs expression: statements --- -- "signal input in[N];" -- "signal output out;" -- "component comp[N-1];" - "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" - "comp[0].in1 <== in[0];" - "comp[0].in2 <== in[1];" - "for(var i = 0; i < N-2; i++){\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" -- "out <== comp[N-2].out;" \ No newline at end of file +- "out <== comp[N-2].out;" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap index 74cf89f..a84d4cc 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap @@ -2,7 +2,4 @@ source: crates/syntax/src/syntax.rs expression: statements --- -- "signal input in[N];" -- "signal output out;" -- "component comp[N-1];" -- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" +- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 568fbbb..2484c0a 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -355,7 +355,7 @@ mod grammar_tests { .syntax() .text() .to_string(); - insta::assert_yaml_snapshot!(input_signal, @"signal input in[N];"); + insta::assert_yaml_snapshot!(input_signal, @r###""signal input in[N]""###); // output signal let output_signal = template @@ -364,7 +364,7 @@ mod grammar_tests { .syntax() .text() .to_string(); - insta::assert_yaml_snapshot!(output_signal, @"signal output out;"); + insta::assert_yaml_snapshot!(output_signal, @"signal output out"); // internal signal let internal_signal = template.find_internal_signal("in").is_none(); @@ -377,7 +377,7 @@ mod grammar_tests { .syntax() .text() .to_string(); - insta::assert_yaml_snapshot!(component, @"component comp[N-1];"); + insta::assert_yaml_snapshot!(component, @r###""component comp[N-1]""###); } #[test] @@ -408,6 +408,8 @@ mod grammar_tests { // cast syntax node into ast node to retrieve more information let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); + println!("block: {}", block.syntax().text().to_string()); + // finally, assert with expect statements let statements = block.statement_list().unwrap().statement_list(); let statements: Vec = statements From 605c16b2dc15c7c8335c09da18fb406dc06c0998 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 30 Dec 2024 19:06:19 +0700 Subject: [PATCH 44/71] fix format --- crates/parser/src/grammar/expression.rs | 4 ++-- crates/parser/src/grammar/statement.rs | 2 +- crates/syntax/src/syntax.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index e0a2d7a..bfc9ab0 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -18,13 +18,13 @@ pub(super) fn tuple(p: &mut Parser) { if p.at(Identifier) { p.expect(Identifier); - + while p.at(Comma) && !p.eof() { p.expect(Comma); p.expect(Identifier); } } - + p.expect(RParen); p.close(m, Tuple); } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index 39f8894..ee7d430 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -164,7 +164,7 @@ fn assignment_statement(p: &mut Parser) { let m_name = p.open(); p.expect(Identifier); p.close(m_name, ComponentIdentifier); - + // abc[N - 1] if p.at(LBracket) { p.expect(LBracket); diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 2484c0a..e233d7a 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -409,7 +409,7 @@ mod grammar_tests { let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); println!("block: {}", block.syntax().text().to_string()); - + // finally, assert with expect statements let statements = block.statement_list().unwrap().statement_list(); let statements: Vec = statements From c9d93f7cce3f70fe689aeda65345921dd8ed4312 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 31 Dec 2024 11:33:33 +0700 Subject: [PATCH 45/71] refactor declaration --- crates/parser/src/grammar/declaration.rs | 182 +++++++++++++++-------- crates/parser/src/parser.rs | 10 ++ crates/parser/src/token_kind.rs | 11 ++ 3 files changed, 138 insertions(+), 65 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 1d01c90..7e56504 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -3,81 +3,119 @@ use super::{ *, }; -// "signal" --> None -// "signal input" --> Some(true) -// "signal output" --> Some(false) +// [N][M-1] +fn array(p: &mut Parser) -> bool { + let is_array = p.at(LBracket); + + while p.at(LBracket) { + p.expect(LBracket); + expression(p); + p.expect(RBracket); + } + + is_array +} + +/* +"signal" --> None +"signal input" --> Some(true) +"signal output" --> Some(false) +*/ fn signal_header(p: &mut Parser) -> Option { - let mut res = None; let m = p.open(); p.expect(SignalKw); - if p.at_any(&[InputKw, OutputKw]) { - if p.at(InputKw) { - res = Some(true); - } else { - res = Some(false); - } + + let res = if p.at(InputKw) { + Some(true) + } else if p.at(OutputKw) { + Some(false) + } else { + None + }; + + if res.is_some() { p.advance(); + } - if p.at(LCurly) { - p.expect(Identifier); - p.expect(RCurly); - } + // signal tags + // {tag1, tag2, tag2} + // TODO: support list of tags + if p.at(LCurly) { + p.expect(Identifier); + p.expect(RCurly); } + p.close(m, SignalHeader); res } +pub(crate) fn var_init(p: &mut Parser) { + // name of variable + p.expect(Identifier); + + // eg: [N - 1][M] + array(p); + + // assign for variable + // eg: = 10 + if p.at_var_assign() { + p.advance(); + expression(p); + } +} + +// eg: in[N - 1] <== c.in; +pub(crate) fn signal_init(p: &mut Parser, assign_able: bool) { + // name of signal + p.expect(Identifier); + + // eg: [N][M-1] + array(p); + + // assign for intermediate and outputs signals + // eg: <== Multiplier2().out + if assign_able && p.at_inline_assign_signal() { + p.advance(); + expression(p); + } +} + /** * Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization | - * - * + * "var" iden1 = init1, iden2 = init2, iden3 */ pub(super) fn var_declaration(p: &mut Parser) { let m = p.open(); p.expect(VarKw); + // tuple of variables + // eg: var (in1, in2, in3) = (1, 2, 3); if p.at(LParen) { tuple(p); - if p.at(Assign) { + if p.at_var_assign() { tuple_init(p); } } else { - p.expect(Identifier); - if p.at(Assign) { - p.expect(Assign); - expression(p); - } - // list of var + // list of variables + // var in1[N], in2 = 5; + var_init(p); while p.at(Comma) && !p.eof() { - p.expect(Comma); - p.expect(Identifier); - if p.at(Assign) { - p.expect(Assign); - expression(p); - } + p.skip(); + var_init(p); } } - p.close(m, VarDecl); -} - -pub(crate) fn signal_init(p: &mut Parser) { - // let m_c = p.open(); - p.expect(Identifier); - // p.close(m_c, SignalIdentifier); - - while p.at(LBracket) { - p.expect(LBracket); - expression(p); - p.expect(RBracket); - } - if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { - p.advance(); - expression(p); - } + p.close(m, VarDecl); } +/* +* signal are immutable (can not modify after init value) +* can not initialize value for input signal +* since circom 2.0.4, it is also allowed to initialize +intermediate and outputs signals right after their declaration +*/ pub(super) fn signal_declaration(p: &mut Parser) { + // TODO: can we remove that? if !p.at(SignalKw) { p.advance_with_error("Signal error"); return; @@ -85,50 +123,64 @@ pub(super) fn signal_declaration(p: &mut Parser) { let m = p.open(); let io_signal = signal_header(p); + let assign_able = io_signal != Some(true); // tuple of signal + // eg: signal (in1, in2, in3) <== tuple_value; if p.at(LParen) { tuple(p); - if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) { + // can not assign for input signal + if assign_able && p.at_inline_assign_signal() { tuple_init(p); } } else { - // list of signal - signal_init(p); + // list of signals + // signal in1[N], in2 <== signal_value; + signal_init(p, assign_able); while p.at(Comma) && !p.eof() { p.skip(); - signal_init(p); + signal_init(p, assign_able); } } - if let Some(is_input) = io_signal { - if is_input { - p.close(m, InputSignalDecl); - } else { - p.close(m, OutputSignalDecl); - } - } else { - p.close(m, SignalDecl); - } + let close_kind = match io_signal { + Some(true) => InputSignalDecl, + Some(false) => OutputSignalDecl, + None => SignalDecl, + }; + + p.close(m, close_kind); } +/* +* initialization in the definition of arrays of components is not allowed +*/ pub(super) fn component_declaration(p: &mut Parser) { let m = p.open(); p.expect(ComponentKw); + + // TODO: why do we need `ComponentIdentifier` kind here? let m_c = p.open(); p.expect(Identifier); p.close(m_c, ComponentIdentifier); - while p.at(LBracket) { - p.expect(LBracket); - expression(p); - p.expect(RBracket); - } - if p.at(Assign) { + // support array component + // eg: comp[N - 1][10] + let is_array = array(p); + + // do not assign for array components + if !is_array && p.at(Assign) { p.expect(Assign); + + // TODO: support `parallel` tag + // eg: component comp = parallel NameTemplate(...){...} + + // template name let m_c = p.open(); p.expect(Identifier); p.close(m_c, TemplateName); + + // template params tuple(p); } diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 9188176..3ab99ac 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -171,6 +171,16 @@ impl<'a> Parser<'a> { current_kind.is_assign_token() } + pub fn at_inline_assign_signal(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_inline_assign_signal() + } + + pub fn at_var_assign(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_var_assign() + } + pub fn skip(&mut self) { self.next(); } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index aa89ac0..8a72aa8 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -382,6 +382,17 @@ impl TokenKind { ) } + pub fn is_inline_assign_signal(self) -> bool { + matches!( + self, + Self::Assign | Self::RAssignSignal | Self::RAssignConstraintSignal + ) + } + + pub fn is_var_assign(self) -> bool { + matches!(self, Self::Assign) + } + pub fn is_trivial(self) -> bool { matches!( self, From 8e92b832cc193e94bb5c35d4b3eb94a2d6b03870 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 31 Dec 2024 11:50:30 +0700 Subject: [PATCH 46/71] use list identity parser in tuple --- crates/parser/src/grammar/block.rs | 6 +++--- crates/parser/src/grammar/expression.rs | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index 645632d..52e4137 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -16,7 +16,8 @@ pub fn block(p: &mut Parser) { p.advance_with_error("Miss {"); } else { let m = p.open(); - p.eat(LCurly); + p.expect(LCurly); + let stmt_marker = p.open(); while !p.at(RCurly) && !p.eof() { let kind = p.current(); @@ -39,8 +40,7 @@ pub fn block(p: &mut Parser) { p.close(stmt_marker, StatementList); - p.eat(RCurly); - + p.expect(RCurly); p.close(m, Block); p.dec_rcurly(); diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index bfc9ab0..641e2f3 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -16,14 +16,8 @@ pub(super) fn tuple(p: &mut Parser) { let m = p.open(); p.expect(LParen); - if p.at(Identifier) { - p.expect(Identifier); - - while p.at(Comma) && !p.eof() { - p.expect(Comma); - p.expect(Identifier); - } - } + // iden1, iden2, iden3 + list_identity::parse(p); p.expect(RParen); p.close(m, Tuple); From 6f6d67881f493421a15fec8c60c907956a145bd7 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 31 Dec 2024 11:52:51 +0700 Subject: [PATCH 47/71] fix right curly count in block --- crates/parser/src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 3ab99ac..0225bd9 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -137,7 +137,7 @@ impl<'a> Parser<'a> { } pub fn dec_rcurly(&mut self) { - self.context.r_curly_count += 1; + self.context.r_curly_count -= 1; } pub fn current(&mut self) -> TokenKind { From df3113dfff493d0663df496087ce5e31eab9a867 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 31 Dec 2024 12:38:16 +0700 Subject: [PATCH 48/71] extract function params --- crates/parser/src/grammar/expression.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 641e2f3..bf7d89f 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -8,6 +8,28 @@ pub(super) fn expression(p: &mut Parser) { p.close(m, Expression); } +/** + * grammar: "(param1, param2,..., paramn)" + * can be an empty () + */ +pub(super) fn function_params(p: &mut Parser) { + let m = p.open(); + p.expect(LParen); + + while !p.at(RParen) && !p.eof() { + expression(p); + if p.at(Comma) { + p.expect(Comma) + } else { + break; + } + } + + p.expect(RParen); + // TODO: what kind of it? + p.close(m, Tuple); +} + /** * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" * can be an empty tuple (for function cal: Mul()) @@ -85,7 +107,8 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { // TODO: function call if p.at(LParen) { let m = p.open_before(lhs); - tuple(p); + // tuple(p); + function_params(p); lhs = p.close(m, Call); } From f68d36ad558d16be5ffc2af0479ed39b18a62e3b Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Tue, 31 Dec 2024 12:38:30 +0700 Subject: [PATCH 49/71] add declaration test --- ..._tests__declaration_happy_test_source.snap | 5 ++ crates/syntax/src/syntax.rs | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap new file mode 100644 index 0000000..8327f7c --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: string_syntax +--- +"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index e233d7a..5f235be 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -465,4 +465,55 @@ mod grammar_tests { .collect(); insta::assert_yaml_snapshot!("statement_happy_test_statements", statements); } + + #[test] + fn declaration_happy_test() { + // [scope: block] source must start with { + let source = r#"{ + var nout = nbits((2**n -1)*ops); + signal input in[ops][n]; + signal output out[nout]; + + var lin = 0; + var lout = 0; + + var k; + var j; + + var e2; + + e2 = 1; + for (k=0; k> k) & 1; + + // Ensure out is binary + out[k] * (out[k] - 1) === 0; + + lout += out[k] * e2; + + e2 = e2+e2; + } + + // Ensure the sum; + + lin === lout; + } + }"#; + + + let syntax = syntax_node_from_source(&source, Scope::Block); + + // cast syntax node into ast node to retrieve more information + let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); + + let string_syntax = block.syntax().text().to_string(); + insta::assert_yaml_snapshot!("declaration_happy_test_source", string_syntax); + } } From ccc72260875533a0f1a6b9a0fed0b780995ab31f Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 2 Jan 2025 09:31:37 +0700 Subject: [PATCH 50/71] comment statement in declaration test --- ...x__syntax__grammar_tests__declaration_happy_test_source.snap | 2 +- crates/syntax/src/syntax.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap index 8327f7c..ef054ab 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: string_syntax --- -"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" +"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n // out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 5f235be..03008b7 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -494,7 +494,7 @@ mod grammar_tests { out[k] <-- (lin >> k) & 1; // Ensure out is binary - out[k] * (out[k] - 1) === 0; + // out[k] * (out[k] - 1) === 0; lout += out[k] * e2; From 9a17705e48c2fc085706e1e346a2631bb6f12222 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 2 Jan 2025 09:34:47 +0700 Subject: [PATCH 51/71] fix format --- crates/syntax/src/syntax.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 03008b7..90e304e 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -506,13 +506,12 @@ mod grammar_tests { lin === lout; } }"#; - - + let syntax = syntax_node_from_source(&source, Scope::Block); // cast syntax node into ast node to retrieve more information let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); - + let string_syntax = block.syntax().text().to_string(); insta::assert_yaml_snapshot!("declaration_happy_test_source", string_syntax); } From 09bb4facccb5c5468dafd7eefe39fa0998047fe5 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 2 Jan 2025 11:00:26 +0700 Subject: [PATCH 52/71] add function parse test --- crates/parser/src/input.rs | 1 - ...mar_tests__function_happy_test_source.snap | 5 ++++ crates/syntax/src/syntax.rs | 25 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap diff --git a/crates/parser/src/input.rs b/crates/parser/src/input.rs index 6278fd8..57e7317 100644 --- a/crates/parser/src/input.rs +++ b/crates/parser/src/input.rs @@ -137,7 +137,6 @@ mod tests { return r; }"#; test(source, "test_function"); - test(source, "test_function"); } #[test] diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap new file mode 100644 index 0000000..d8f21fc --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap @@ -0,0 +1,5 @@ +--- +source: crates/syntax/src/syntax.rs +expression: string_function +--- +"function nbits(a) {\n var n = 1;\n var r = 0;\n while (n-1 Date: Mon, 6 Jan 2025 10:03:09 +0700 Subject: [PATCH 53/71] add comments --- crates/lsp/src/global_state.rs | 28 ++++++++++++++++++- crates/lsp/src/handler/goto_definition.rs | 17 ++++++++++- crates/syntax/src/abstract_syntax_tree/ast.rs | 3 ++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/lsp/src/global_state.rs b/crates/lsp/src/global_state.rs index 40ecb64..9752284 100644 --- a/crates/lsp/src/global_state.rs +++ b/crates/lsp/src/global_state.rs @@ -44,9 +44,15 @@ impl From for TextDocument { } } +/// state of all (circom) source file pub struct GlobalState { + /// file id - ast from that file content pub ast_map: DashMap, + + /// file id - file content (+ end lines) pub file_map: DashMap, + + /// file id - database (template in4, function in4...) pub db: SemanticDB, } @@ -71,6 +77,7 @@ impl GlobalState { ast: &AstCircomProgram, token: &SyntaxToken, ) -> Vec { + // look up token in current file let semantic_data = self.db.semantic.get(&root.file_id).unwrap(); let mut result = lookup_definition(root, ast, semantic_data, token); @@ -78,6 +85,10 @@ impl GlobalState { return result; } + + // if can not find that token in current file, + // and if token in a component call / declaration + // continue looking up in libs let p = root.get_path(); if lookup_node_wrap_token(TokenKind::ComponentDecl, token).is_some() @@ -98,17 +109,27 @@ impl GlobalState { } } } + result } pub fn goto_definition_handler(&self, id: RequestId, params: GotoDefinitionParams) -> Response { + eprint!("-------------------"); + // path to the element we want to get definition + // TODO eg: file/line/start column..end column let uri = params.text_document_position_params.text_document.uri; - + + // abtract syntax tree for the element from that uri + // TODO eg: let ast = self.ast_map.get(&uri.to_string()).unwrap(); + // the file contains the element from that uri + // TODO eg: let file = self.file_map.get(&uri.to_string()).unwrap(); let mut locations = Vec::new(); + // extract token from ast at position (file, params position) + // TODO eg: if let Some(token) = lookup_token_at_postion(&file, &ast, params.text_document_position_params.position) { @@ -126,6 +147,11 @@ impl GlobalState { } } + /// update a file of (circom) source code + /// parse new code --> syntax tree + /// remove old data of that file in semantic database + /// add new data (circom_program_semantic) + related libs into database + /// update corresponding file-map and ast-map in global-state pub fn handle_update(&mut self, text_document: &TextDocument) -> Result<()> { let text = &text_document.text; let url = &text_document.uri.to_string(); diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 8609b4c..5a286c0 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -16,6 +16,7 @@ use syntax::syntax_node::SyntaxToken; use crate::database::{FileDB, SemanticData, TokenId}; +// find the first ancestor with given kind of a syntax token pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Option { let mut p = token.parent(); while let Some(t) = p { @@ -27,6 +28,7 @@ pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Optio None } +// return an Identifier/CircomString token at a position pub fn lookup_token_at_postion( file: &FileDB, ast: &AstCircomProgram, @@ -47,6 +49,7 @@ pub fn lookup_token_at_postion( }) } +// find all template name (in component declaration) which are used inside a template pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option { if let Some(statements) = template.statements() { for component in statements.find_children::() { @@ -60,6 +63,8 @@ pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option Vec { if let Some(include_lib) = lookup_node_wrap_token(TokenKind::IncludeKw, token) { if let Some(ast_include) = AstInclude::cast(include_lib) { @@ -86,6 +91,7 @@ pub fn lookup_definition( token: &SyntaxToken, ) -> Vec { let template_list = ast.template_list(); + // TODO: extract function list let mut res = Vec::new(); @@ -93,15 +99,19 @@ pub fn lookup_definition( return jump_to_lib(file, token); } + // signal from other template + // eg: in1, in2 from component call mul(in1, in2) let mut signal_outside = false; if let Some(component_call) = lookup_node_wrap_token(TokenKind::ComponentCall, token) { // find template called. if let Some(ast_component_call) = AstComponentCall::cast(component_call) { if let Some(signal) = ast_component_call.signal() { + // if target token is the parameter of a component call + // TODO: go to params in template!!! (failed) if signal.syntax().text() == token.text() { signal_outside = true; - // lookup template of componenet + // lookup template of component if let Some(current_template) = lookup_node_wrap_token(TokenKind::TemplateDef, token) { @@ -131,6 +141,8 @@ pub fn lookup_definition( } if !signal_outside { + // look up token in template information + // (template name, signal/variable/component in template) for template in template_list { let template_name = template.name().unwrap(); if template_name.name().unwrap().syntax().text() == token.text() { @@ -160,6 +172,9 @@ pub fn lookup_definition( res.extend(component_decl); } } + + // TODO: look up token in function information + // (function name, signal/variable/component in function) } res.into_iter() diff --git a/crates/syntax/src/abstract_syntax_tree/ast.rs b/crates/syntax/src/abstract_syntax_tree/ast.rs index 9d8c282..e105b64 100644 --- a/crates/syntax/src/abstract_syntax_tree/ast.rs +++ b/crates/syntax/src/abstract_syntax_tree/ast.rs @@ -48,6 +48,9 @@ impl AstVarDecl { ast_node!(AstComponentDecl, ComponentDecl); +// component hash = Poseidon(2); +// template --> Poseidon +// component_identifier --> hash impl AstComponentDecl { pub fn template(&self) -> Option { support::child(self.syntax()) From a12d3bbc6aee39bc803f46ccffb6ae95dc1cd1a8 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 11:20:56 +0700 Subject: [PATCH 54/71] refactor expression --- crates/parser/src/grammar/expression.rs | 97 ++++++++++++------- crates/parser/src/grammar/statement.rs | 41 ++------ crates/parser/src/token_kind.rs | 10 +- ..._tests__declaration_happy_test_source.snap | 2 +- crates/syntax/src/syntax.rs | 6 +- 5 files changed, 80 insertions(+), 76 deletions(-) diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index bf7d89f..3e07b20 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -32,7 +32,6 @@ pub(super) fn function_params(p: &mut Parser) { /** * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" - * can be an empty tuple (for function cal: Mul()) */ pub(super) fn tuple(p: &mut Parser) { let m = p.open(); @@ -70,6 +69,7 @@ fn expression_atom(p: &mut Parser) -> Option { p.advance(); m_close = p.close(m, Identifier); Some(m_close) + // identifier(p) } LParen => { let m = p.open(); @@ -90,64 +90,91 @@ fn expression_atom(p: &mut Parser) -> Option { * return marker which bound the expression */ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { - let parse_able: Option = if let Some(pp) = p.current().prefix() { - let kind = p.current(); - let m = p.open(); - p.advance(); - expression_rec(p, pp); - Some(p.close(m, kind)) - } else { - expression_atom(p) + // consume all first prefix tokens (++a, --a, -a, +a, !a) + // next, consume first atom (identifier/number/tuple) + let parse_able: Option = { + if let Some(pp) = p.current().prefix() { + println!("Prefix..."); + let kind = p.current(); + let m = p.open(); + // consume prefix token (++, --, -, +, !) + p.advance(); + // continue with the next tokens + expression_rec(p, pp); + Some(p.close(m, kind)) + } else { + expression_atom(p) + } }; parse_able?; let mut lhs = parse_able.unwrap(); - // TODO: function call - if p.at(LParen) { - let m = p.open_before(lhs); - // tuple(p); - function_params(p); - lhs = p.close(m, Call); - } - while !p.eof() { let current_kind = p.current(); + if let Some((lp, rp)) = current_kind.infix() { + // TODO: what does it mean??? if rp <= pb { return None; } let m = p.open_before(lhs); + // consume the infix token p.advance(); + + // extract the second parameter + // eg: + --> extract expression_rec(p, lp); lhs = p.close(m, current_kind); - continue; - } - if let Some(pp) = current_kind.postfix() { + } else if let Some(pp) = current_kind.postfix() { + println!("Postfix..."); if pp <= pb { return None; } - let m = p.open_before(lhs); - p.advance(); - if matches!(current_kind, LBracket) { - expression_rec(p, 0); - p.expect(RBracket); - } else { - p.expect(Identifier); - } - lhs = if matches!(current_kind, Dot) { - p.close(m, ComponentCall) - } else { - p.close(m, ArrayQuery) - }; - continue; + match current_kind { + LParen => { + // function call + let m = p.open_before(lhs); + function_params(p); + lhs = p.close(m, Call); + } + LBracket => { + // array subscript: abc[N - 1] + let m = p.open_before(lhs); + p.expect(LBracket); + expression(p); + p.expect(RBracket); + p.close(m, ArrayQuery); + } + Dot => { + // attribute access + // abc[N - 1].def OR abc.def --> component call + let m = p.open_before(lhs); + p.expect(Dot); + p.expect(Identifier); + p.close(m, ComponentCall); + } + UnitDec | UnitInc => { + let m = p.open_before(lhs); + // consume token and do nothing + p.advance(); + p.close(m, Expression); + } + _ => { + // not a postfix token + p.advance_with_error(&format!("Expect a postfix token, but found {:?}", current_kind)); + } + }; + } + else { + break; } - break; } + Some(lhs) } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index ee7d430..af36eb7 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -158,43 +158,16 @@ fn return_statement(p: &mut Parser) { fn assignment_statement(p: &mut Parser) { let m = p.open(); - if p.at(Identifier) { - let m_id = p.open(); - // abc - let m_name = p.open(); - p.expect(Identifier); - p.close(m_name, ComponentIdentifier); - - // abc[N - 1] - if p.at(LBracket) { - p.expect(LBracket); - expression(p); - p.expect(RBracket); - } - - if p.at(Dot) { - // abc[N - 1].def OR abc.def --> component call - p.expect(Dot); - p.expect(Identifier); - p.close(m_id, ComponentCall); - } else { - // abc[N - 1] OR abc --> expression - p.close(m_id, Expression); - } - } else { - // assignment without identifier - expression(p); - } + // left expression + expression(p); // assign part if p.at_assign_token() { - let is_self_assign = p.at_any(&[TokenKind::UnitDec, TokenKind::UnitInc]); p.advance(); - if is_self_assign == false { - expression(p); - } - p.close(m, AssignStatement); - } else { - p.close(m, Error); + + // right expression + expression(p); } + + p.close(m, AssignStatement); } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 8a72aa8..92f9a92 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -289,8 +289,11 @@ impl TokenKind { // ---------- // TODO: how about conditional operation ( ? : ) // associativity: right to left [ a ? b : c --> ??? ] + // ---------- // associativity: right to left [ a = b = c --> a = (b = c) ] + // DO NOT CONSIDER ASSIGMENT OPERATORS AS INFIX TOKENS + /* // assignment operators Self::Assign // signal assigment operators @@ -313,6 +316,7 @@ impl TokenKind { | Self::IntDivAssign | Self::ModAssign | Self::PowerAssign => Some((44, 45)), + */ // TODO: how about comma (expression separator) Self::Comma => Some((39, 40)), // not an infix operator @@ -377,8 +381,8 @@ impl TokenKind { | Self::ModAssign | Self::PowerAssign // unit inc/dec - | Self::UnitInc - | Self::UnitDec + // | Self::UnitInc + // | Self::UnitDec ) } @@ -399,4 +403,4 @@ impl TokenKind { Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error ) } -} +} \ No newline at end of file diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap index ef054ab..de98905 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap @@ -2,4 +2,4 @@ source: crates/syntax/src/syntax.rs expression: string_syntax --- -"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n // out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" +"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index bd89e7b..46db801 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -483,18 +483,18 @@ mod grammar_tests { var e2; e2 = 1; - for (k=0; k> k) & 1; // Ensure out is binary - // out[k] * (out[k] - 1) === 0; + out[k] * (out[k] - 1) === 0; lout += out[k] * e2; From e78ab17f2ae9d8dd33597104051286213c412e38 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 11:52:16 +0700 Subject: [PATCH 55/71] extract parameter list, identifier list --- crates/parser/src/grammar/declaration.rs | 18 +++++------ crates/parser/src/grammar/expression.rs | 37 +++++++++++----------- crates/parser/src/grammar/list_identity.rs | 5 ++- crates/parser/src/token_kind.rs | 1 + 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 7e56504..7238bac 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,7 +1,5 @@ -use super::{ - expression::{expression, tuple, tuple_init}, - *, -}; +use super::expression::{expression, identifier_list, parameter_list}; +use crate::{parser::Parser, token_kind::TokenKind::*}; // [N][M-1] fn array(p: &mut Parser) -> bool { @@ -91,9 +89,10 @@ pub(super) fn var_declaration(p: &mut Parser) { // tuple of variables // eg: var (in1, in2, in3) = (1, 2, 3); if p.at(LParen) { - tuple(p); + identifier_list(p); if p.at_var_assign() { - tuple_init(p); + p.advance(); + expression(p); } } else { // list of variables @@ -128,10 +127,11 @@ pub(super) fn signal_declaration(p: &mut Parser) { // tuple of signal // eg: signal (in1, in2, in3) <== tuple_value; if p.at(LParen) { - tuple(p); + identifier_list(p); // can not assign for input signal if assign_able && p.at_inline_assign_signal() { - tuple_init(p); + p.advance(); + expression(p); } } else { // list of signals @@ -181,7 +181,7 @@ pub(super) fn component_declaration(p: &mut Parser) { p.close(m_c, TemplateName); // template params - tuple(p); + parameter_list(p); } p.close(m, ComponentDecl); diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 3e07b20..6ff7886 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -12,28 +12,30 @@ pub(super) fn expression(p: &mut Parser) { * grammar: "(param1, param2,..., paramn)" * can be an empty () */ -pub(super) fn function_params(p: &mut Parser) { +pub(super) fn parameter_list(p: &mut Parser) { let m = p.open(); p.expect(LParen); while !p.at(RParen) && !p.eof() { + // each parameter can be an expression expression(p); - if p.at(Comma) { - p.expect(Comma) - } else { + + // there are no parameters remaining + if p.eat(Comma) == false { break; } } p.expect(RParen); - // TODO: what kind of it? - p.close(m, Tuple); + + p.close(m, ParameterList); } /** - * grammar: "(Symbol_1, Symbol_2,..., Symbol_n)" + * grammar: "(iden1, iden2,..., idenn)" + * can be an empty () */ -pub(super) fn tuple(p: &mut Parser) { +pub(super) fn identifier_list(p: &mut Parser) { let m = p.open(); p.expect(LParen); @@ -41,19 +43,19 @@ pub(super) fn tuple(p: &mut Parser) { list_identity::parse(p); p.expect(RParen); - p.close(m, Tuple); + p.close(m, IdentifierList); } /** * grammar: * "= | <== | <--" expression */ -pub(super) fn tuple_init(p: &mut Parser) { - let m = p.open(); - p.expect_any(&[Assign, RAssignSignal, RAssignConstraintSignal]); - expression(p); - p.close(m, TupleInit); -} +// pub(super) fn tuple_init(p: &mut Parser) { +// let m = p.open(); +// p.expect_any(&[Assign, RAssignSignal, RAssignConstraintSignal]); +// expression(p); +// p.close(m, TupleInit); +// } fn expression_atom(p: &mut Parser) -> Option { let m_close: Marker; @@ -69,7 +71,6 @@ fn expression_atom(p: &mut Parser) -> Option { p.advance(); m_close = p.close(m, Identifier); Some(m_close) - // identifier(p) } LParen => { let m = p.open(); @@ -139,7 +140,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { LParen => { // function call let m = p.open_before(lhs); - function_params(p); + parameter_list(p); lhs = p.close(m, Call); } LBracket => { @@ -174,7 +175,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { break; } } - + Some(lhs) } diff --git a/crates/parser/src/grammar/list_identity.rs b/crates/parser/src/grammar/list_identity.rs index 73f85c9..26cfda1 100644 --- a/crates/parser/src/grammar/list_identity.rs +++ b/crates/parser/src/grammar/list_identity.rs @@ -4,9 +4,8 @@ use super::*; pub fn parse(p: &mut Parser) { while p.at(Identifier) && !p.eof() { p.expect(Identifier); - if p.at(Comma) { - p.expect(Comma) - } else { + + if p.eat(Comma) == false { break; } } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 92f9a92..42467be 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -211,6 +211,7 @@ pub enum TokenKind { TemplateName, FunctionName, ParameterList, + IdentifierList, SignalDecl, VarDecl, InputSignalDecl, From c516b18c4c51dc9b012292d2e76d658ebde1c95d Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 16:24:58 +0700 Subject: [PATCH 56/71] fix statement kind --- crates/parser/src/grammar/statement.rs | 67 +++++++++++++++----------- crates/parser/src/parser.rs | 4 +- crates/parser/src/token_kind.rs | 10 +++- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index af36eb7..fb058d4 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,14 +1,12 @@ -use crate::token_kind::TokenKind; - use super::{block::block, expression::expression, *}; pub(super) fn statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); match p.current() { IfKw => if_statement(p), _ => statement_no_condition(p), } - p.close(m, Statement); + p.close(open_marker, Statement); } /* @@ -18,17 +16,22 @@ else */ fn if_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); + + // if () p.expect(IfKw); p.expect(LParen); - expression::expression(p); + expression(p); p.expect(RParen); statement(p); + + // else if p.at(ElseKw) { p.expect(ElseKw); statement(p); } - p.close(m, IfKw); + + p.close(open_marker, IfStatement); } /** @@ -64,7 +67,7 @@ for (/; ; ) */ fn for_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); // for ( p.expect(ForKw); @@ -89,8 +92,8 @@ fn for_statement(p: &mut Parser) { // for (i = 1; i < N; i++) { } statement(p); - // statement_no_condition(p); - p.close(m, ForLoop); + + p.close(open_marker, ForLoop); } /* @@ -98,65 +101,75 @@ while () */ fn while_statement(p: &mut Parser) { + let open_marker = p.open(); + p.expect(WhileKw); p.expect(LParen); expression(p); p.expect(RParen); statement(p); + + p.close(open_marker, WhileLoop); } /* assert() */ fn assert_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); + p.expect(AssertKw); p.expect(LParen); expression(p); p.expect(RParen); - p.close(m, AssertKw); + + p.close(open_marker, AssertStatement); } /* -log() +log(, , ... ) */ fn log_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); + p.expect(LogKw); p.expect(LParen); + + // list circom string/expression while !p.eof() { - if p.at(RParen) { - break; - } match p.current() { + RParen => break, CircomString => p.advance(), _ => expression(p), } - if !p.at(Comma) { + + if p.eat(Comma) == false { break; - } else { - p.advance(); } } + p.expect(RParen); - p.close(m, LogKw); + + p.close(open_marker, LogStatement); } /* return */ fn return_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); p.expect(ReturnKw); expression(p); - p.close(m, ReturnKw); + p.close(open_marker, ReturnStatement); } /* - + +optional: +eg: out[1] <== in[0] + in[2] */ fn assignment_statement(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); // left expression expression(p); @@ -168,6 +181,6 @@ fn assignment_statement(p: &mut Parser) { // right expression expression(p); } - - p.close(m, AssignStatement); + + p.close(open_marker, AssignStatement); } diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 0225bd9..7f43eae 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -74,8 +74,8 @@ impl<'a> Parser<'a> { } } - pub fn close(&mut self, marker_open: Marker, kind: TokenKind) -> Marker { - match marker_open { + pub fn close(&mut self, open_marker: Marker, kind: TokenKind) -> Marker { + match open_marker { Marker::Open(index) => { self.events[index] = Event::Open { kind }; self.events.push(Event::Close); diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 42467be..2773632 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -190,9 +190,15 @@ pub enum TokenKind { ReturnKw, #[token("assert")] AssertKw, - // Complex token kind - ForLoop, + // Statements + IfStatement, + AssertStatement, + LogStatement, + ReturnStatement, AssignStatement, + ForLoop, + WhileLoop, + // Complex token kind CircomProgram, SignalOfComponent, SignalHeader, From 49c4ac211e22355f09c8cc39ee5056531796d979 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 18:05:25 +0700 Subject: [PATCH 57/71] rearrange token kind --- crates/parser/src/token_kind.rs | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 2773632..1ff27aa 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -198,33 +198,36 @@ pub enum TokenKind { AssignStatement, ForLoop, WhileLoop, - // Complex token kind + // Program CircomProgram, - SignalOfComponent, - SignalHeader, - Block, - Tuple, - TupleInit, - Call, - TenaryConditional, - Condition, - Expression, + // Function FunctionDef, - Statement, - StatementList, - ComponentDecl, + FunctionName, + // Template TemplateDef, TemplateName, - FunctionName, - ParameterList, - IdentifierList, + // Signal SignalDecl, - VarDecl, InputSignalDecl, OutputSignalDecl, + SignalHeader, + SignalIdentifier, + // Variable + VarDecl, + // Component + ComponentDecl, ComponentCall, ComponentIdentifier, - SignalIdentifier, + SignalOfComponent, + // Complex token kind + Block, + ParameterList, + Call, + TenaryConditional, + Condition, + Expression, + Statement, + StatementList, ArrayQuery, ParserError, BlockComment, From ce223c8efedd62e7ae00b292ed1c53fd474cd8c1 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 18:07:00 +0700 Subject: [PATCH 58/71] extract list and tuple --- crates/parser/src/grammar.rs | 2 +- crates/parser/src/grammar/declaration.rs | 12 +- crates/parser/src/grammar/expression.rs | 202 ++++++++---------- crates/parser/src/grammar/function.rs | 12 +- crates/parser/src/grammar/list.rs | 69 ++++++ crates/parser/src/grammar/list_identity.rs | 12 -- crates/parser/src/grammar/main_component.rs | 4 +- crates/parser/src/grammar/template.rs | 10 +- crates/syntax/src/abstract_syntax_tree/ast.rs | 9 + crates/syntax/src/syntax.rs | 17 +- 10 files changed, 199 insertions(+), 150 deletions(-) create mode 100644 crates/parser/src/grammar/list.rs delete mode 100644 crates/parser/src/grammar/list_identity.rs diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index a0c9f53..c8e886f 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -6,7 +6,7 @@ mod declaration; mod expression; mod function; mod include; -mod list_identity; +mod list; mod main_component; mod pragma; mod statement; diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 7238bac..c23223d 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,4 +1,4 @@ -use super::expression::{expression, identifier_list, parameter_list}; +use super::{expression::expression, list::{expression_tuple, identifier_tuple}}; use crate::{parser::Parser, token_kind::TokenKind::*}; // [N][M-1] @@ -6,9 +6,11 @@ fn array(p: &mut Parser) -> bool { let is_array = p.at(LBracket); while p.at(LBracket) { + let array_marker = p.open(); p.expect(LBracket); expression(p); p.expect(RBracket); + p.close(array_marker, ArrayQuery); } is_array @@ -89,7 +91,7 @@ pub(super) fn var_declaration(p: &mut Parser) { // tuple of variables // eg: var (in1, in2, in3) = (1, 2, 3); if p.at(LParen) { - identifier_list(p); + identifier_tuple(p); if p.at_var_assign() { p.advance(); expression(p); @@ -127,7 +129,7 @@ pub(super) fn signal_declaration(p: &mut Parser) { // tuple of signal // eg: signal (in1, in2, in3) <== tuple_value; if p.at(LParen) { - identifier_list(p); + identifier_tuple(p); // can not assign for input signal if assign_able && p.at_inline_assign_signal() { p.advance(); @@ -181,7 +183,9 @@ pub(super) fn component_declaration(p: &mut Parser) { p.close(m_c, TemplateName); // template params - parameter_list(p); + let parameter_marker = p.open(); + expression_tuple(p); + p.close(parameter_marker, Call); } p.close(m, ComponentDecl); diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 6ff7886..2d34bef 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -1,90 +1,59 @@ +use list::expression_tuple; + use crate::parser::Marker; use super::*; pub(super) fn expression(p: &mut Parser) { - let m = p.open(); + let open_marker = p.open(); circom_expression(p); - p.close(m, Expression); + p.close(open_marker, Expression); } /** - * grammar: "(param1, param2,..., paramn)" - * can be an empty () + * TODO: why parse a stament inside expression module??? + * manage 2 cases: normal expression (a++, a-b,...), tenary_conditional_statement (a ? b : c) + * circom_expression = expr ? expr: expr | + * expr */ -pub(super) fn parameter_list(p: &mut Parser) { - let m = p.open(); - p.expect(LParen); - - while !p.at(RParen) && !p.eof() { - // each parameter can be an expression - expression(p); +fn circom_expression(p: &mut Parser) { + if let Some(lhs) = expression_rec(p, 0) { + let current_kind = p.current(); - // there are no parameters remaining - if p.eat(Comma) == false { - break; + if matches!(current_kind, MarkQuestion) { + tenary_conditional_statement(p, lhs); } } - - p.expect(RParen); - - p.close(m, ParameterList); } /** - * grammar: "(iden1, iden2,..., idenn)" - * can be an empty () - */ -pub(super) fn identifier_list(p: &mut Parser) { - let m = p.open(); - p.expect(LParen); - - // iden1, iden2, iden3 - list_identity::parse(p); + * grammar: ? : +* is also an expression, +* whose open and close events are already in the Parser event list +* lhs is that open event +*/ +pub fn tenary_conditional_statement(p: &mut Parser, lhs: Marker) { + // + let open_marker = p.open_before(lhs); + p.close(open_marker, Condition); + + // ? + p.expect(MarkQuestion); + + // ? + let first_expression = p.open(); + expression_rec(p, 0); + p.close(first_expression, Expression); + + // ? : + p.expect(Colon); + + // ? : + let last_expression = p.open(); + expression_rec(p, 0); + p.close(last_expression, Expression); - p.expect(RParen); - p.close(m, IdentifierList); -} - -/** - * grammar: - * "= | <== | <--" expression - */ -// pub(super) fn tuple_init(p: &mut Parser) { -// let m = p.open(); -// p.expect_any(&[Assign, RAssignSignal, RAssignConstraintSignal]); -// expression(p); -// p.close(m, TupleInit); -// } - -fn expression_atom(p: &mut Parser) -> Option { - let m_close: Marker; - match p.current() { - Number => { - let m = p.open(); - p.advance(); - m_close = p.close(m, Number); - Some(m_close) - } - Identifier => { - let m = p.open(); - p.advance(); - m_close = p.close(m, Identifier); - Some(m_close) - } - LParen => { - let m = p.open(); - p.expect(LParen); - expression_rec(p, 0); - p.expect(RParen); - m_close = p.close(m, Tuple); - Some(m_close) - } - _ => { - p.advance_with_error("Invalid Token"); - None - } - } + p.close(open_marker, TenaryConditional); } /** @@ -95,14 +64,13 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { // next, consume first atom (identifier/number/tuple) let parse_able: Option = { if let Some(pp) = p.current().prefix() { - println!("Prefix..."); let kind = p.current(); - let m = p.open(); + let open_marker = p.open(); // consume prefix token (++, --, -, +, !) p.advance(); // continue with the next tokens expression_rec(p, pp); - Some(p.close(m, kind)) + Some(p.close(open_marker, kind)) } else { expression_atom(p) } @@ -113,61 +81,66 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { let mut lhs = parse_able.unwrap(); while !p.eof() { - let current_kind = p.current(); + let kind = p.current(); + + if let Some((lp, rp)) = kind.infix() { + // infix case: + + // is already consume in parse_able - if let Some((lp, rp)) = current_kind.infix() { // TODO: what does it mean??? if rp <= pb { return None; } - let m = p.open_before(lhs); + // open event that wrap the first parameter () + let open_marker = p.open_before(lhs); + // consume the infix token p.advance(); // extract the second parameter - // eg: + --> extract expression_rec(p, lp); - lhs = p.close(m, current_kind); - } else if let Some(pp) = current_kind.postfix() { - println!("Postfix..."); + lhs = p.close(open_marker, kind); + + } else if let Some(pp) = kind.postfix() { if pp <= pb { return None; } - match current_kind { + match kind { LParen => { // function call - let m = p.open_before(lhs); - parameter_list(p); - lhs = p.close(m, Call); + let open_marker = p.open_before(lhs); + expression_tuple(p); + lhs = p.close(open_marker, Call); } LBracket => { // array subscript: abc[N - 1] - let m = p.open_before(lhs); + let open_marker = p.open_before(lhs); p.expect(LBracket); expression(p); p.expect(RBracket); - p.close(m, ArrayQuery); + p.close(open_marker, ArrayQuery); } Dot => { // attribute access // abc[N - 1].def OR abc.def --> component call - let m = p.open_before(lhs); + let open_marker = p.open_before(lhs); p.expect(Dot); p.expect(Identifier); - p.close(m, ComponentCall); + p.close(open_marker, ComponentCall); } UnitDec | UnitInc => { - let m = p.open_before(lhs); - // consume token and do nothing + let open_marker = p.open_before(lhs); + // consume token ++/-- and do nothing p.advance(); - p.close(m, Expression); + p.close(open_marker, Expression); } _ => { // not a postfix token - p.advance_with_error(&format!("Expect a postfix token, but found {:?}", current_kind)); + p.advance_with_error(&format!("Expect a postfix token, but found {:?}", kind)); + break; } }; } @@ -176,34 +149,37 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { } } + // return the outer open marker Some(lhs) } /** - * circom_expression = expr ? expr: expr | - * expr + * the unit element in expression + * eg: a, b, 5, 100, () */ -fn circom_expression(p: &mut Parser) { - if let Some(mut lhs) = expression_rec(p, 0) { - let current_kind = p.current(); - if matches!(current_kind, MarkQuestion) { - let m = p.open_before(lhs); - lhs = p.close(m, Condition); - - let m = p.open_before(lhs); +fn expression_atom(p: &mut Parser) -> Option { + let kind = p.current(); + + match kind { + Number | Identifier => { + let open_marker = p.open(); p.advance(); - - let first_expression = p.open(); - expression_rec(p, 0); - p.close(first_expression, Expression); - - p.expect(Colon); - - let last_expression = p.open(); + let m_close = p.close(open_marker, kind); + Some(m_close) + }, + LParen => { + // () + let open_marker = p.open(); + p.expect(LParen); expression_rec(p, 0); - p.close(last_expression, Expression); - - p.close(m, TenaryConditional); + p.expect(RParen); + let m_close = p.close(open_marker, Expression); + Some(m_close) + }, + _ => { + p.advance_with_error("Invalid Token"); + None } } } + diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index 4da6276..283f622 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -1,3 +1,5 @@ +use list::identifier_tuple; + use crate::grammar::*; // fucntion name() @@ -10,12 +12,10 @@ pub fn function_parse(p: &mut Parser) { p.expect(Identifier); p.close(fn_name_marker, FunctionName); - p.expect(LParen); - let arg_marker = p.open(); - list_identity::parse(p); - p.close(arg_marker, ParameterList); - p.expect(RParen); - + let parameter_marker = p.open(); + identifier_tuple(p); + p.close(parameter_marker, ParameterList); + block::block(p); p.close(m, FunctionDef); diff --git a/crates/parser/src/grammar/list.rs b/crates/parser/src/grammar/list.rs new file mode 100644 index 0000000..83e58d4 --- /dev/null +++ b/crates/parser/src/grammar/list.rs @@ -0,0 +1,69 @@ +use crate::grammar::{ + *, + expression::expression +}; + +/** + * grammar: "(expression-1, expression-2,..., expression-n)" + * can be an empty () + */ +pub(super) fn expression_tuple(p: &mut Parser) { + // let m = p.open(); + p.expect(LParen); + + // expression-1, expression-2,..., expression-n) + while !p.at(RParen) && !p.eof() { + expression(p); + + // there are no expressions remaining + if p.eat(Comma) == false { + break; + } + } + + p.expect(RParen); + + // p.close(m, ExpressionList); +} + +/** + * grammar: "(iden1, iden2,..., idenn)" + * can be an empty () + */ +pub(super) fn identifier_tuple(p: &mut Parser) { + // let m = p.open(); + p.expect(LParen); + + // iden1, iden2, iden3 + while p.at(Identifier) && !p.eof() { + p.expect(Identifier); + + if p.eat(Comma) == false { + break; + } + } + + p.expect(RParen); + // p.close(m, IdentifierList); +} + +/** + * grammar: "[iden1, iden2,..., idenn]" + * can be an empty () + */ +pub(super) fn identifier_list(p: &mut Parser) { + // let m = p.open(); + p.expect(LBracket); + + // iden1, iden2, iden3 + while p.at(Identifier) && !p.eof() { + p.expect(Identifier); + + if p.eat(Comma) == false { + break; + } + } + + p.expect(RBracket); + // p.close(m, IdentifierList); +} \ No newline at end of file diff --git a/crates/parser/src/grammar/list_identity.rs b/crates/parser/src/grammar/list_identity.rs deleted file mode 100644 index 26cfda1..0000000 --- a/crates/parser/src/grammar/list_identity.rs +++ /dev/null @@ -1,12 +0,0 @@ -use super::*; - -// a, b, c, d -pub fn parse(p: &mut Parser) { - while p.at(Identifier) && !p.eof() { - p.expect(Identifier); - - if p.eat(Comma) == false { - break; - } - } -} diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index 5129310..7efdea8 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -1,3 +1,5 @@ +use list::identifier_list; + use super::*; /* @@ -13,7 +15,7 @@ pub fn main_component(p: &mut Parser) { p.expect(LCurly); p.expect(PublicKw); p.expect(LBracket); - list_identity::parse(p); + identifier_list(p); p.expect(RBracket); } diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index a502365..1c70156 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -1,3 +1,5 @@ +use list::identifier_tuple; + use crate::grammar::*; /** * template Identifier() {content} @@ -13,11 +15,9 @@ pub fn template(p: &mut Parser) { p.expect(Identifier); p.close(name_marker, TemplateName); - p.expect(LParen); - let arg_marker = p.open(); - list_identity::parse(p); - p.close(arg_marker, ParameterList); - p.expect(RParen); + let parameter_marker = p.open(); + identifier_tuple(p); + p.close(parameter_marker, ParameterList); block::block(p); diff --git a/crates/syntax/src/abstract_syntax_tree/ast.rs b/crates/syntax/src/abstract_syntax_tree/ast.rs index e105b64..3508dd2 100644 --- a/crates/syntax/src/abstract_syntax_tree/ast.rs +++ b/crates/syntax/src/abstract_syntax_tree/ast.rs @@ -91,6 +91,15 @@ impl AstPragma { } ast_node!(AstParameterList, TokenKind::ParameterList); +impl AstParameterList { + pub fn parameters(&self) -> Vec { + self.syntax() + .children() + .filter_map(AstIdentifier::cast) + .collect() + } +} + ast_node!(AstIdentifier, Identifier); impl AstIdentifier { diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 46db801..036473d 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -316,22 +316,23 @@ mod grammar_tests { insta::assert_yaml_snapshot!(name, @"MultiplierN"); // parameter list - let first_param = template + let paramater_list = template .parameter_list() .expect("Can not detect parameter list") + .parameters(); + + let first_param = paramater_list + .get(0) + .expect("Can not detect first parameter") .syntax() - .first_child() - .unwrap() .text() .to_string(); insta::assert_yaml_snapshot!(first_param, @"N"); - let last_param = template - .parameter_list() - .expect("Can not detect parameter list") + let last_param = paramater_list + .last() + .expect("Can not detect last parameter") .syntax() - .last_child() - .unwrap() .text() .to_string(); insta::assert_yaml_snapshot!(last_param, @"QQ"); From e5a8c453c866dde178f6b695ebadd30bf9d134bd Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 18:09:55 +0700 Subject: [PATCH 59/71] rename tuple and list --- crates/parser/src/grammar/declaration.rs | 8 ++++---- crates/parser/src/grammar/expression.rs | 4 ++-- crates/parser/src/grammar/function.rs | 4 ++-- crates/parser/src/grammar/list.rs | 6 +++--- crates/parser/src/grammar/main_component.rs | 4 ++-- crates/parser/src/grammar/template.rs | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index c23223d..d3459af 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,4 +1,4 @@ -use super::{expression::expression, list::{expression_tuple, identifier_tuple}}; +use super::{expression::expression, list::{tuple_expression, tuple_identifier}}; use crate::{parser::Parser, token_kind::TokenKind::*}; // [N][M-1] @@ -91,7 +91,7 @@ pub(super) fn var_declaration(p: &mut Parser) { // tuple of variables // eg: var (in1, in2, in3) = (1, 2, 3); if p.at(LParen) { - identifier_tuple(p); + tuple_identifier(p); if p.at_var_assign() { p.advance(); expression(p); @@ -129,7 +129,7 @@ pub(super) fn signal_declaration(p: &mut Parser) { // tuple of signal // eg: signal (in1, in2, in3) <== tuple_value; if p.at(LParen) { - identifier_tuple(p); + tuple_identifier(p); // can not assign for input signal if assign_able && p.at_inline_assign_signal() { p.advance(); @@ -184,7 +184,7 @@ pub(super) fn component_declaration(p: &mut Parser) { // template params let parameter_marker = p.open(); - expression_tuple(p); + tuple_expression(p); p.close(parameter_marker, Call); } diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 2d34bef..b7105ec 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -1,4 +1,4 @@ -use list::expression_tuple; +use list::tuple_expression; use crate::parser::Marker; @@ -112,7 +112,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { LParen => { // function call let open_marker = p.open_before(lhs); - expression_tuple(p); + tuple_expression(p); lhs = p.close(open_marker, Call); } LBracket => { diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index 283f622..431df8a 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -1,4 +1,4 @@ -use list::identifier_tuple; +use list::tuple_identifier; use crate::grammar::*; @@ -13,7 +13,7 @@ pub fn function_parse(p: &mut Parser) { p.close(fn_name_marker, FunctionName); let parameter_marker = p.open(); - identifier_tuple(p); + tuple_identifier(p); p.close(parameter_marker, ParameterList); block::block(p); diff --git a/crates/parser/src/grammar/list.rs b/crates/parser/src/grammar/list.rs index 83e58d4..6d76cb8 100644 --- a/crates/parser/src/grammar/list.rs +++ b/crates/parser/src/grammar/list.rs @@ -7,7 +7,7 @@ use crate::grammar::{ * grammar: "(expression-1, expression-2,..., expression-n)" * can be an empty () */ -pub(super) fn expression_tuple(p: &mut Parser) { +pub(super) fn tuple_expression(p: &mut Parser) { // let m = p.open(); p.expect(LParen); @@ -30,7 +30,7 @@ pub(super) fn expression_tuple(p: &mut Parser) { * grammar: "(iden1, iden2,..., idenn)" * can be an empty () */ -pub(super) fn identifier_tuple(p: &mut Parser) { +pub(super) fn tuple_identifier(p: &mut Parser) { // let m = p.open(); p.expect(LParen); @@ -51,7 +51,7 @@ pub(super) fn identifier_tuple(p: &mut Parser) { * grammar: "[iden1, iden2,..., idenn]" * can be an empty () */ -pub(super) fn identifier_list(p: &mut Parser) { +pub(super) fn list_identifier(p: &mut Parser) { // let m = p.open(); p.expect(LBracket); diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index 7efdea8..b61fbac 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -1,4 +1,4 @@ -use list::identifier_list; +use list::list_identifier; use super::*; @@ -15,7 +15,7 @@ pub fn main_component(p: &mut Parser) { p.expect(LCurly); p.expect(PublicKw); p.expect(LBracket); - identifier_list(p); + list_identifier(p); p.expect(RBracket); } diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 1c70156..3686ead 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -1,4 +1,4 @@ -use list::identifier_tuple; +use list::tuple_identifier; use crate::grammar::*; /** @@ -16,7 +16,7 @@ pub fn template(p: &mut Parser) { p.close(name_marker, TemplateName); let parameter_marker = p.open(); - identifier_tuple(p); + tuple_identifier(p); p.close(parameter_marker, ParameterList); block::block(p); From b081735119663a6191bb7f3dd05f95833d3611f6 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 6 Jan 2025 18:11:55 +0700 Subject: [PATCH 60/71] format --- crates/lsp/src/global_state.rs | 5 ++--- crates/lsp/src/handler/goto_definition.rs | 6 +++--- crates/parser/src/grammar/declaration.rs | 5 ++++- crates/parser/src/grammar/expression.rs | 21 +++++++++------------ crates/parser/src/grammar/function.rs | 2 +- crates/parser/src/grammar/list.rs | 13 +++++-------- crates/parser/src/grammar/statement.rs | 2 +- crates/parser/src/token_kind.rs | 18 ++++++++---------- crates/syntax/src/syntax.rs | 7 +++++-- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/crates/lsp/src/global_state.rs b/crates/lsp/src/global_state.rs index 9752284..8811566 100644 --- a/crates/lsp/src/global_state.rs +++ b/crates/lsp/src/global_state.rs @@ -85,7 +85,6 @@ impl GlobalState { return result; } - // if can not find that token in current file, // and if token in a component call / declaration // continue looking up in libs @@ -118,7 +117,7 @@ impl GlobalState { // path to the element we want to get definition // TODO eg: file/line/start column..end column let uri = params.text_document_position_params.text_document.uri; - + // abtract syntax tree for the element from that uri // TODO eg: let ast = self.ast_map.get(&uri.to_string()).unwrap(); @@ -129,7 +128,7 @@ impl GlobalState { let mut locations = Vec::new(); // extract token from ast at position (file, params position) - // TODO eg: + // TODO eg: if let Some(token) = lookup_token_at_postion(&file, &ast, params.text_document_position_params.position) { diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index 5a286c0..a23a933 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -99,7 +99,7 @@ pub fn lookup_definition( return jump_to_lib(file, token); } - // signal from other template + // signal from other template // eg: in1, in2 from component call mul(in1, in2) let mut signal_outside = false; @@ -141,7 +141,7 @@ pub fn lookup_definition( } if !signal_outside { - // look up token in template information + // look up token in template information // (template name, signal/variable/component in template) for template in template_list { let template_name = template.name().unwrap(); @@ -173,7 +173,7 @@ pub fn lookup_definition( } } - // TODO: look up token in function information + // TODO: look up token in function information // (function name, signal/variable/component in function) } diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index d3459af..e010983 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,4 +1,7 @@ -use super::{expression::expression, list::{tuple_expression, tuple_identifier}}; +use super::{ + expression::expression, + list::{tuple_expression, tuple_identifier}, +}; use crate::{parser::Parser, token_kind::TokenKind::*}; // [N][M-1] diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index b7105ec..5423c18 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -28,7 +28,7 @@ fn circom_expression(p: &mut Parser) { /** * grammar: ? : -* is also an expression, +* is also an expression, * whose open and close events are already in the Parser event list * lhs is that open event */ @@ -36,18 +36,18 @@ pub fn tenary_conditional_statement(p: &mut Parser, lhs: Marker) { // let open_marker = p.open_before(lhs); p.close(open_marker, Condition); - + // ? p.expect(MarkQuestion); - + // ? let first_expression = p.open(); expression_rec(p, 0); p.close(first_expression, Expression); - + // ? : p.expect(Colon); - + // ? : let last_expression = p.open(); expression_rec(p, 0); @@ -102,7 +102,6 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { expression_rec(p, lp); lhs = p.close(open_marker, kind); - } else if let Some(pp) = kind.postfix() { if pp <= pb { return None; @@ -143,8 +142,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { break; } }; - } - else { + } else { break; } } @@ -159,14 +157,14 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { */ fn expression_atom(p: &mut Parser) -> Option { let kind = p.current(); - + match kind { Number | Identifier => { let open_marker = p.open(); p.advance(); let m_close = p.close(open_marker, kind); Some(m_close) - }, + } LParen => { // () let open_marker = p.open(); @@ -175,11 +173,10 @@ fn expression_atom(p: &mut Parser) -> Option { p.expect(RParen); let m_close = p.close(open_marker, Expression); Some(m_close) - }, + } _ => { p.advance_with_error("Invalid Token"); None } } } - diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index 431df8a..7dc25ad 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -15,7 +15,7 @@ pub fn function_parse(p: &mut Parser) { let parameter_marker = p.open(); tuple_identifier(p); p.close(parameter_marker, ParameterList); - + block::block(p); p.close(m, FunctionDef); diff --git a/crates/parser/src/grammar/list.rs b/crates/parser/src/grammar/list.rs index 6d76cb8..fe66cd9 100644 --- a/crates/parser/src/grammar/list.rs +++ b/crates/parser/src/grammar/list.rs @@ -1,7 +1,4 @@ -use crate::grammar::{ - *, - expression::expression -}; +use crate::grammar::{expression::expression, *}; /** * grammar: "(expression-1, expression-2,..., expression-n)" @@ -22,7 +19,7 @@ pub(super) fn tuple_expression(p: &mut Parser) { } p.expect(RParen); - + // p.close(m, ExpressionList); } @@ -37,7 +34,7 @@ pub(super) fn tuple_identifier(p: &mut Parser) { // iden1, iden2, iden3 while p.at(Identifier) && !p.eof() { p.expect(Identifier); - + if p.eat(Comma) == false { break; } @@ -58,7 +55,7 @@ pub(super) fn list_identifier(p: &mut Parser) { // iden1, iden2, iden3 while p.at(Identifier) && !p.eof() { p.expect(Identifier); - + if p.eat(Comma) == false { break; } @@ -66,4 +63,4 @@ pub(super) fn list_identifier(p: &mut Parser) { p.expect(RBracket); // p.close(m, IdentifierList); -} \ No newline at end of file +} diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index fb058d4..c6ad18a 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -92,7 +92,7 @@ fn for_statement(p: &mut Parser) { // for (i = 1; i < N; i++) { } statement(p); - + p.close(open_marker, ForLoop); } diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 1ff27aa..18b654c 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -287,8 +287,7 @@ impl TokenKind { | Self::GreaterThan | Self::LessThanAndEqual | Self::GreaterThanAndEqual => Some((79, 80)), - Self::Equal - | Self::NotEqual => Some((74, 75)), + Self::Equal | Self::NotEqual => Some((74, 75)), // other bitwise operators Self::BitAnd => Some((69, 70)), Self::BitXor => Some((64, 65)), // exclusive or @@ -298,10 +297,10 @@ impl TokenKind { Self::BoolOr => Some((49, 50)), // ---------- // TODO: how about conditional operation ( ? : ) - // associativity: right to left [ a ? b : c --> ??? ] - + // associativity: right to left [ a ? b : c --> ??? ] + // ---------- - // associativity: right to left [ a = b = c --> a = (b = c) ] + // associativity: right to left [ a = b = c --> a = (b = c) ] // DO NOT CONSIDER ASSIGMENT OPERATORS AS INFIX TOKENS /* // assignment operators @@ -389,10 +388,9 @@ impl TokenKind { | Self::DivAssign | Self::IntDivAssign | Self::ModAssign - | Self::PowerAssign - // unit inc/dec - // | Self::UnitInc - // | Self::UnitDec + | Self::PowerAssign // unit inc/dec + // | Self::UnitInc + // | Self::UnitDec ) } @@ -413,4 +411,4 @@ impl TokenKind { Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error ) } -} \ No newline at end of file +} diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 036473d..61c2e7c 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -238,7 +238,9 @@ mod tests { mod grammar_tests { use crate::{ - abstract_syntax_tree::{AstBlock, AstCircomProgram, AstOutputSignalDecl, AstPragma, AstTemplateDef}, + abstract_syntax_tree::{ + AstBlock, AstCircomProgram, AstOutputSignalDecl, AstPragma, AstTemplateDef, + }, syntax::SyntaxTreeBuilder, syntax_node::CircomLanguage, }; @@ -533,7 +535,8 @@ mod grammar_tests { let syntax = syntax_node_from_source(&source, Scope::CircomProgram); // cast syntax node into ast node to retrieve more information - let ast_circom = AstCircomProgram::cast(syntax).expect("Can not cast syntax node into ast circom"); + let ast_circom = + AstCircomProgram::cast(syntax).expect("Can not cast syntax node into ast circom"); let function = &ast_circom.function_list()[0]; let string_function = function.syntax().text().to_string(); From 783f2a74ff02ecd9455d0f1697c775bf7dcc949e Mon Sep 17 00:00:00 2001 From: Truc Vy <92658621+NTTVy03@users.noreply.github.com> Date: Sat, 18 Jan 2025 22:16:38 +0700 Subject: [PATCH 61/71] remove eprint in goto_definition_handler Update crates/lsp/src/global_state.rs Co-authored-by: Vu Vo --- crates/lsp/src/global_state.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/lsp/src/global_state.rs b/crates/lsp/src/global_state.rs index 8811566..e3726fc 100644 --- a/crates/lsp/src/global_state.rs +++ b/crates/lsp/src/global_state.rs @@ -113,7 +113,6 @@ impl GlobalState { } pub fn goto_definition_handler(&self, id: RequestId, params: GotoDefinitionParams) -> Response { - eprint!("-------------------"); // path to the element we want to get definition // TODO eg: file/line/start column..end column let uri = params.text_document_position_params.text_document.uri; From 20a2c189ee74df136b8e63aa93034f431f73510c Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 30 Jan 2025 22:37:06 +0700 Subject: [PATCH 62/71] replace if with match for signal header check --- crates/parser/src/grammar/declaration.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index e010983..ddad3d2 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -28,15 +28,13 @@ fn signal_header(p: &mut Parser) -> Option { let m = p.open(); p.expect(SignalKw); - let res = if p.at(InputKw) { - Some(true) - } else if p.at(OutputKw) { - Some(false) - } else { - None + let result = match p.current() { + InputKw => Some(true), + OutputKw => Some(false), + _ => None }; - - if res.is_some() { + + if result.is_some() { p.advance(); } @@ -49,7 +47,7 @@ fn signal_header(p: &mut Parser) -> Option { } p.close(m, SignalHeader); - res + result } pub(crate) fn var_init(p: &mut Parser) { From ccc0f8b95f1ebc7d140251e6fcbbab402da11c21 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 30 Jan 2025 22:42:45 +0700 Subject: [PATCH 63/71] format --- crates/parser/src/grammar/declaration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index ddad3d2..f6e22cf 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -31,9 +31,9 @@ fn signal_header(p: &mut Parser) -> Option { let result = match p.current() { InputKw => Some(true), OutputKw => Some(false), - _ => None + _ => None, }; - + if result.is_some() { p.advance(); } From cf96bb7c0e701ddbb79a20da3ff685e316e3dbfe Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 30 Jan 2025 22:48:57 +0700 Subject: [PATCH 64/71] add example for var_init --- crates/parser/src/grammar/declaration.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index f6e22cf..1166273 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -50,6 +50,10 @@ fn signal_header(p: &mut Parser) -> Option { result } +/* +var_init does not include `var` keyword +eg: tmp = 10; +*/ pub(crate) fn var_init(p: &mut Parser) { // name of variable p.expect(Identifier); From 2b19a9b270214b0c6b5d182ee1920033beb90221 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Mon, 3 Feb 2025 16:11:44 +0700 Subject: [PATCH 65/71] remove unuse snapshots --- .vscode/settings.json | 8 +- crates/lsp/src/global_state.rs | 390 +-- crates/lsp/src/handler/goto_definition.rs | 552 ++-- crates/parser/src/grammar.rs | 134 +- crates/parser/src/grammar/block.rs | 96 +- crates/parser/src/grammar/declaration.rs | 412 +-- crates/parser/src/grammar/expression.rs | 364 +-- crates/parser/src/grammar/function.rs | 44 +- crates/parser/src/grammar/list.rs | 132 +- crates/parser/src/grammar/main_component.rs | 48 +- crates/parser/src/grammar/pragma.rs | 32 +- crates/parser/src/grammar/statement.rs | 372 +-- crates/parser/src/grammar/template.rs | 50 +- crates/parser/src/lib.rs | 18 +- crates/parser/src/output.rs | 150 +- crates/parser/src/parser.rs | 476 +-- crates/syntax/src/abstract_syntax_tree/ast.rs | 408 +-- .../src/abstract_syntax_tree/template.rs | 200 +- crates/syntax/src/lib.rs | 10 +- ..._src__test_files__happy__block.circom.snap | 670 ---- ...src__test_files__happy__pragma.circom.snap | 19 - ...c__test_files__happy__template.circom.snap | 358 --- ...sts____src__test_files__pragma.circom.snap | 19 - ...ar_tests__block_happy_test_statements.snap | 18 - ..._tests__declaration_happy_test_source.snap | 5 - ...mmar_tests__for_happy_test_statements.snap | 9 - ...mar_tests__function_happy_test_source.snap | 5 - ...ests__statement_happy_test_statements.snap | 14 - ...tests__template_happy_test_statements.snap | 13 - ..._src__test_files__happy__block.circom.snap | 1313 ++++---- ...st_files__happy__block_comment.circom.snap | 58 +- ...es__happy__full_circom_program.circom.snap | 2758 ++++++++--------- ...est_files__happy__line_comment.circom.snap | 79 +- ...src__test_files__happy__pragma.circom.snap | 2 +- ...c__test_files__happy__template.circom.snap | 606 ++-- ...syntax__tests__syntax_test_1_children.snap | 17 - ...yntax__tests__syntax_test_2_functions.snap | 5 - ...yntax__tests__syntax_test_2_templates.snap | 5 - ...yntax__tests__syntax_test_5_templates.snap | 5 - ...yntax__tests__syntax_test_6_templates.snap | 5 - crates/syntax/src/syntax.rs | 381 +-- .../syntax/src/test_files/happy/block.circom | 36 +- .../src/test_files/happy/block_comment.circom | 10 +- .../happy/full_circom_program.circom | 198 +- .../src/test_files/happy/line_comment.circom | 8 +- .../src/test_files/happy/no_pragma.circom | 2 +- .../syntax/src/test_files/happy/pragma.circom | 2 +- .../src/test_files/happy/template.circom | 24 +- crates/syntax/src/utils.rs | 20 +- crates/syntax/src/view_syntax.rs | 104 +- 50 files changed, 4638 insertions(+), 6026 deletions(-) delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__block.circom.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__pragma.circom.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__template.circom.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__pragma.circom.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__statement_happy_test_statements.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__grammar_tests__template_happy_test_statements.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap delete mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap diff --git a/.vscode/settings.json b/.vscode/settings.json index a9aba9f..92b237a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ -{ - "cSpell.words": [ - "vuvoth" - ] +{ + "cSpell.words": [ + "vuvoth" + ] } \ No newline at end of file diff --git a/crates/lsp/src/global_state.rs b/crates/lsp/src/global_state.rs index e3726fc..84a0ddf 100644 --- a/crates/lsp/src/global_state.rs +++ b/crates/lsp/src/global_state.rs @@ -1,195 +1,195 @@ -use std::{fs, path::PathBuf}; - -use crate::{ - database::{FileDB, SemanticDB}, - handler::goto_definition::lookup_node_wrap_token, -}; -use anyhow::Result; -use dashmap::DashMap; -use lsp_server::{RequestId, Response}; -use lsp_types::{ - DidChangeTextDocumentParams, DidOpenTextDocumentParams, GotoDefinitionParams, - GotoDefinitionResponse, Location, Url, -}; - -use parser::token_kind::TokenKind; -use rowan::ast::AstNode; -use syntax::abstract_syntax_tree::AstCircomProgram; -use syntax::syntax::SyntaxTreeBuilder; -use syntax::syntax_node::SyntaxToken; - -use crate::handler::goto_definition::{lookup_definition, lookup_token_at_postion}; - -#[derive(Debug)] -pub struct TextDocument { - text: String, - uri: Url, -} - -impl From for TextDocument { - fn from(value: DidOpenTextDocumentParams) -> Self { - Self { - text: value.text_document.text, - uri: value.text_document.uri, - } - } -} - -impl From for TextDocument { - fn from(value: DidChangeTextDocumentParams) -> Self { - Self { - text: value.content_changes[0].text.to_string(), - uri: value.text_document.uri, - } - } -} - -/// state of all (circom) source file -pub struct GlobalState { - /// file id - ast from that file content - pub ast_map: DashMap, - - /// file id - file content (+ end lines) - pub file_map: DashMap, - - /// file id - database (template in4, function in4...) - pub db: SemanticDB, -} - -impl Default for GlobalState { - fn default() -> Self { - Self::new() - } -} - -impl GlobalState { - pub fn new() -> Self { - Self { - ast_map: DashMap::new(), - file_map: DashMap::new(), - db: SemanticDB::new(), - } - } - - pub fn lookup_definition( - &self, - root: &FileDB, - ast: &AstCircomProgram, - token: &SyntaxToken, - ) -> Vec { - // look up token in current file - let semantic_data = self.db.semantic.get(&root.file_id).unwrap(); - let mut result = lookup_definition(root, ast, semantic_data, token); - - if token.kind() == TokenKind::CircomString { - return result; - } - - // if can not find that token in current file, - // and if token in a component call / declaration - // continue looking up in libs - let p = root.get_path(); - - if lookup_node_wrap_token(TokenKind::ComponentDecl, token).is_some() - || lookup_node_wrap_token(TokenKind::ComponentCall, token).is_some() - { - for lib in ast.libs() { - let lib_abs_path = PathBuf::from(lib.lib().unwrap().value()); - let lib_path = p.parent().unwrap().join(lib_abs_path).clone(); - let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); - - if let Some(file_lib) = self.file_map.get(&lib_url.to_string()) { - let ast_lib = self.ast_map.get(&lib_url.to_string()).unwrap(); - if let Some(semantic_data_lib) = self.db.semantic.get(&file_lib.file_id) { - let lib_result = - lookup_definition(&file_lib, &ast_lib, semantic_data_lib, token); - result.extend(lib_result); - } - } - } - } - - result - } - - pub fn goto_definition_handler(&self, id: RequestId, params: GotoDefinitionParams) -> Response { - // path to the element we want to get definition - // TODO eg: file/line/start column..end column - let uri = params.text_document_position_params.text_document.uri; - - // abtract syntax tree for the element from that uri - // TODO eg: - let ast = self.ast_map.get(&uri.to_string()).unwrap(); - // the file contains the element from that uri - // TODO eg: - let file = self.file_map.get(&uri.to_string()).unwrap(); - - let mut locations = Vec::new(); - - // extract token from ast at position (file, params position) - // TODO eg: - if let Some(token) = - lookup_token_at_postion(&file, &ast, params.text_document_position_params.position) - { - locations = self.lookup_definition(&file, &ast, &token); - }; - - let result: Option = Some(GotoDefinitionResponse::Array(locations)); - - let result = serde_json::to_value(result).unwrap(); - - Response { - id, - result: Some(result), - error: None, - } - } - - /// update a file of (circom) source code - /// parse new code --> syntax tree - /// remove old data of that file in semantic database - /// add new data (circom_program_semantic) + related libs into database - /// update corresponding file-map and ast-map in global-state - pub fn handle_update(&mut self, text_document: &TextDocument) -> Result<()> { - let text = &text_document.text; - let url = &text_document.uri.to_string(); - - let syntax = SyntaxTreeBuilder::syntax_tree(text); - let file_db = FileDB::create(text, text_document.uri.clone()); - let file_id = file_db.file_id; - - let p: PathBuf = file_db.get_path(); - if let Some(ast) = AstCircomProgram::cast(syntax) { - self.db.semantic.remove(&file_id); - self.db.circom_program_semantic(&file_db, &ast); - - for lib in ast.libs() { - if let Some(lib_abs_path) = lib.lib() { - let lib_path = p.parent().unwrap().join(lib_abs_path.value()).clone(); - let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); - if let Ok(src) = fs::read_to_string(lib_path) { - let text_doc = TextDocument { - text: src, - uri: lib_url.clone(), - }; - let lib_file = FileDB::create(&text_doc.text, lib_url.clone()); - let syntax = SyntaxTreeBuilder::syntax_tree(&text_doc.text); - - if let Some(lib_ast) = AstCircomProgram::cast(syntax) { - self.db.semantic.remove(&lib_file.file_id); - self.db.circom_program_semantic(&lib_file, &lib_ast); - self.ast_map.insert(lib_url.to_string(), lib_ast); - } - - self.file_map.insert(lib_url.to_string(), lib_file); - } - } - } - self.ast_map.insert(url.to_string(), ast); - } - - self.file_map.insert(url.to_string(), file_db); - - Ok(()) - } -} +use std::{fs, path::PathBuf}; + +use crate::{ + database::{FileDB, SemanticDB}, + handler::goto_definition::lookup_node_wrap_token, +}; +use anyhow::Result; +use dashmap::DashMap; +use lsp_server::{RequestId, Response}; +use lsp_types::{ + DidChangeTextDocumentParams, DidOpenTextDocumentParams, GotoDefinitionParams, + GotoDefinitionResponse, Location, Url, +}; + +use parser::token_kind::TokenKind; +use rowan::ast::AstNode; +use syntax::abstract_syntax_tree::AstCircomProgram; +use syntax::syntax::SyntaxTreeBuilder; +use syntax::syntax_node::SyntaxToken; + +use crate::handler::goto_definition::{lookup_definition, lookup_token_at_postion}; + +#[derive(Debug)] +pub struct TextDocument { + text: String, + uri: Url, +} + +impl From for TextDocument { + fn from(value: DidOpenTextDocumentParams) -> Self { + Self { + text: value.text_document.text, + uri: value.text_document.uri, + } + } +} + +impl From for TextDocument { + fn from(value: DidChangeTextDocumentParams) -> Self { + Self { + text: value.content_changes[0].text.to_string(), + uri: value.text_document.uri, + } + } +} + +/// state of all (circom) source file +pub struct GlobalState { + /// file id - ast from that file content + pub ast_map: DashMap, + + /// file id - file content (+ end lines) + pub file_map: DashMap, + + /// file id - database (template in4, function in4...) + pub db: SemanticDB, +} + +impl Default for GlobalState { + fn default() -> Self { + Self::new() + } +} + +impl GlobalState { + pub fn new() -> Self { + Self { + ast_map: DashMap::new(), + file_map: DashMap::new(), + db: SemanticDB::new(), + } + } + + pub fn lookup_definition( + &self, + root: &FileDB, + ast: &AstCircomProgram, + token: &SyntaxToken, + ) -> Vec { + // look up token in current file + let semantic_data = self.db.semantic.get(&root.file_id).unwrap(); + let mut result = lookup_definition(root, ast, semantic_data, token); + + if token.kind() == TokenKind::CircomString { + return result; + } + + // if can not find that token in current file, + // and if token in a component call / declaration + // continue looking up in libs + let p = root.get_path(); + + if lookup_node_wrap_token(TokenKind::ComponentDecl, token).is_some() + || lookup_node_wrap_token(TokenKind::ComponentCall, token).is_some() + { + for lib in ast.libs() { + let lib_abs_path = PathBuf::from(lib.lib().unwrap().value()); + let lib_path = p.parent().unwrap().join(lib_abs_path).clone(); + let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); + + if let Some(file_lib) = self.file_map.get(&lib_url.to_string()) { + let ast_lib = self.ast_map.get(&lib_url.to_string()).unwrap(); + if let Some(semantic_data_lib) = self.db.semantic.get(&file_lib.file_id) { + let lib_result = + lookup_definition(&file_lib, &ast_lib, semantic_data_lib, token); + result.extend(lib_result); + } + } + } + } + + result + } + + pub fn goto_definition_handler(&self, id: RequestId, params: GotoDefinitionParams) -> Response { + // path to the element we want to get definition + // TODO eg: file/line/start column..end column + let uri = params.text_document_position_params.text_document.uri; + + // abtract syntax tree for the element from that uri + // TODO eg: + let ast = self.ast_map.get(&uri.to_string()).unwrap(); + // the file contains the element from that uri + // TODO eg: + let file = self.file_map.get(&uri.to_string()).unwrap(); + + let mut locations = Vec::new(); + + // extract token from ast at position (file, params position) + // TODO eg: + if let Some(token) = + lookup_token_at_postion(&file, &ast, params.text_document_position_params.position) + { + locations = self.lookup_definition(&file, &ast, &token); + }; + + let result: Option = Some(GotoDefinitionResponse::Array(locations)); + + let result = serde_json::to_value(result).unwrap(); + + Response { + id, + result: Some(result), + error: None, + } + } + + /// update a file of (circom) source code + /// parse new code --> syntax tree + /// remove old data of that file in semantic database + /// add new data (circom_program_semantic) + related libs into database + /// update corresponding file-map and ast-map in global-state + pub fn handle_update(&mut self, text_document: &TextDocument) -> Result<()> { + let text = &text_document.text; + let url = &text_document.uri.to_string(); + + let syntax = SyntaxTreeBuilder::syntax_tree(text); + let file_db = FileDB::create(text, text_document.uri.clone()); + let file_id = file_db.file_id; + + let p: PathBuf = file_db.get_path(); + if let Some(ast) = AstCircomProgram::cast(syntax) { + self.db.semantic.remove(&file_id); + self.db.circom_program_semantic(&file_db, &ast); + + for lib in ast.libs() { + if let Some(lib_abs_path) = lib.lib() { + let lib_path = p.parent().unwrap().join(lib_abs_path.value()).clone(); + let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); + if let Ok(src) = fs::read_to_string(lib_path) { + let text_doc = TextDocument { + text: src, + uri: lib_url.clone(), + }; + let lib_file = FileDB::create(&text_doc.text, lib_url.clone()); + let syntax = SyntaxTreeBuilder::syntax_tree(&text_doc.text); + + if let Some(lib_ast) = AstCircomProgram::cast(syntax) { + self.db.semantic.remove(&lib_file.file_id); + self.db.circom_program_semantic(&lib_file, &lib_ast); + self.ast_map.insert(lib_url.to_string(), lib_ast); + } + + self.file_map.insert(lib_url.to_string(), lib_file); + } + } + } + self.ast_map.insert(url.to_string(), ast); + } + + self.file_map.insert(url.to_string(), file_db); + + Ok(()) + } +} diff --git a/crates/lsp/src/handler/goto_definition.rs b/crates/lsp/src/handler/goto_definition.rs index a23a933..0ff6ff1 100644 --- a/crates/lsp/src/handler/goto_definition.rs +++ b/crates/lsp/src/handler/goto_definition.rs @@ -1,276 +1,276 @@ -use lsp_types::Location; -use lsp_types::Position; -use lsp_types::Range; -use lsp_types::Url; -use parser::token_kind::TokenKind; -use rowan::ast::AstNode; -use rowan::SyntaxText; - -use syntax::abstract_syntax_tree::AstComponentCall; -use syntax::abstract_syntax_tree::AstInclude; -use syntax::abstract_syntax_tree::AstTemplateDef; -use syntax::abstract_syntax_tree::AstTemplateName; -use syntax::abstract_syntax_tree::{AstCircomProgram, AstComponentDecl}; -use syntax::syntax_node::SyntaxNode; -use syntax::syntax_node::SyntaxToken; - -use crate::database::{FileDB, SemanticData, TokenId}; - -// find the first ancestor with given kind of a syntax token -pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Option { - let mut p = token.parent(); - while let Some(t) = p { - if t.kind() == ast_type { - return Some(t); - } - p = t.parent(); - } - None -} - -// return an Identifier/CircomString token at a position -pub fn lookup_token_at_postion( - file: &FileDB, - ast: &AstCircomProgram, - position: Position, -) -> Option { - let off_set = file.off_set(position); - ast.syntax().token_at_offset(off_set).find_map(|token| { - let kind = token.kind(); - - if kind == TokenKind::Identifier { - return Some(token); - } - - if kind == TokenKind::CircomString { - return Some(token); - } - None - }) -} - -// find all template name (in component declaration) which are used inside a template -pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option { - if let Some(statements) = template.statements() { - for component in statements.find_children::() { - if let Some(iden) = component.component_identifier() { - if iden.name().unwrap().syntax().text() == text { - return component.template(); - } - } - } - } - None -} - -// if token in an include statement -// add lib path (location of source code of that library) into result -pub fn jump_to_lib(file: &FileDB, token: &SyntaxToken) -> Vec { - if let Some(include_lib) = lookup_node_wrap_token(TokenKind::IncludeKw, token) { - if let Some(ast_include) = AstInclude::cast(include_lib) { - if let Some(abs_lib_ans) = ast_include.lib() { - let lib_path = file - .get_path() - .parent() - .unwrap() - .join(abs_lib_ans.value()) - .clone(); - let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); - return vec![Location::new(lib_url, Range::default())]; - } - } - } - - Vec::new() -} - -pub fn lookup_definition( - file: &FileDB, - ast: &AstCircomProgram, - semantic_data: &SemanticData, - token: &SyntaxToken, -) -> Vec { - let template_list = ast.template_list(); - // TODO: extract function list - - let mut res = Vec::new(); - - if token.kind() == TokenKind::CircomString { - return jump_to_lib(file, token); - } - - // signal from other template - // eg: in1, in2 from component call mul(in1, in2) - let mut signal_outside = false; - - if let Some(component_call) = lookup_node_wrap_token(TokenKind::ComponentCall, token) { - // find template called. - if let Some(ast_component_call) = AstComponentCall::cast(component_call) { - if let Some(signal) = ast_component_call.signal() { - // if target token is the parameter of a component call - // TODO: go to params in template!!! (failed) - if signal.syntax().text() == token.text() { - signal_outside = true; - // lookup template of component - if let Some(current_template) = - lookup_node_wrap_token(TokenKind::TemplateDef, token) - { - if let Some(ast_template_name) = lookup_component( - &AstTemplateDef::cast(current_template).unwrap(), - ast_component_call.component_name().unwrap().syntax().text(), - ) { - if let Some(other_template) = - ast.get_template_by_name(&ast_template_name) - { - let template_id = other_template.syntax().token_id(); - if let Some(semantic) = - semantic_data.template_data_semantic.get(&template_id) - { - if let Some(tmp) = - semantic.signal.0.get(&signal.syntax().token_id()) - { - res.extend(tmp) - } - } - } - } - } - } - } - } - } - - if !signal_outside { - // look up token in template information - // (template name, signal/variable/component in template) - for template in template_list { - let template_name = template.name().unwrap(); - if template_name.name().unwrap().syntax().text() == token.text() { - let range = file.range(template.syntax()); - res.push(range); - } - - if !template - .syntax() - .text_range() - .contains_range(token.text_range()) - { - continue; - } - - let template_id = template.syntax().token_id(); - - if let Some(data) = semantic_data.lookup_signal(template_id, token) { - res.extend(data); - } - - if let Some(data) = semantic_data.lookup_variable(template_id, token) { - res.extend(data); - } - - if let Some(component_decl) = semantic_data.lookup_component(template_id, token) { - res.extend(component_decl); - } - } - - // TODO: look up token in function information - // (function name, signal/variable/component in function) - } - - res.into_iter() - .map(|range| Location::new(file.file_path.clone(), range)) - .collect() -} - -#[cfg(test)] -mod tests { - use std::path::Path; - - use lsp_types::Url; - use parser::token_kind::TokenKind; - use rowan::ast::AstNode; - use syntax::{ - abstract_syntax_tree::{AstCircomProgram, AstInputSignalDecl}, - syntax::SyntaxTreeBuilder, - }; - - use crate::{database::FileDB, handler::goto_definition::lookup_node_wrap_token}; - - use super::lookup_token_at_postion; - - #[test] - fn goto_decl_test() { - let source = r#" - pragma circom 2.0.0; - - template X() { - signal x[100]; - signal input x = 10; - component x = Multiplier2(); - component y = X(); - component y = Multiplier2(); - component z = Multiplier2(); - - } -template M() { - component h = X(); - component k = Multiplier2(); - test - } -template Multiplier2 () { - template m = M(); - // hello world - signal input a; - signal input b; - signal output c; - component y = X(); - - mintlkrekerjke; - component e = Y(); - component z = Y(); - component h = Y(); - signal output d; - c <== a * b; - } -template Y() { - component y = X(); - component a = X(); - - } - "# - .to_string(); - - let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); - - let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); - - if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { - println!("program: {}", program_ast.syntax().text().to_string()); - - let inputs = program_ast.template_list()[0] - .func_body() - .unwrap() - .statement_list() - .unwrap() - .find_children::(); - let signal_name = inputs[0].name().unwrap(); - - let tmp = signal_name.syntax().text_range().start(); - - if let Some(token) = lookup_token_at_postion(&file, &program_ast, file.position(tmp)) { - println!( - "{:#?}", - lookup_node_wrap_token(TokenKind::TemplateDef, &token) - ); - } - } - } - - #[test] - fn url_test() { - let url = Url::from_file_path(Path::new("/hello/abc.tx")); - let binding = url.unwrap(); - let p = binding.path(); - println!("{:?}", Path::new(p).parent()); - } -} +use lsp_types::Location; +use lsp_types::Position; +use lsp_types::Range; +use lsp_types::Url; +use parser::token_kind::TokenKind; +use rowan::ast::AstNode; +use rowan::SyntaxText; + +use syntax::abstract_syntax_tree::AstComponentCall; +use syntax::abstract_syntax_tree::AstInclude; +use syntax::abstract_syntax_tree::AstTemplateDef; +use syntax::abstract_syntax_tree::AstTemplateName; +use syntax::abstract_syntax_tree::{AstCircomProgram, AstComponentDecl}; +use syntax::syntax_node::SyntaxNode; +use syntax::syntax_node::SyntaxToken; + +use crate::database::{FileDB, SemanticData, TokenId}; + +// find the first ancestor with given kind of a syntax token +pub fn lookup_node_wrap_token(ast_type: TokenKind, token: &SyntaxToken) -> Option { + let mut p = token.parent(); + while let Some(t) = p { + if t.kind() == ast_type { + return Some(t); + } + p = t.parent(); + } + None +} + +// return an Identifier/CircomString token at a position +pub fn lookup_token_at_postion( + file: &FileDB, + ast: &AstCircomProgram, + position: Position, +) -> Option { + let off_set = file.off_set(position); + ast.syntax().token_at_offset(off_set).find_map(|token| { + let kind = token.kind(); + + if kind == TokenKind::Identifier { + return Some(token); + } + + if kind == TokenKind::CircomString { + return Some(token); + } + None + }) +} + +// find all template name (in component declaration) which are used inside a template +pub fn lookup_component(template: &AstTemplateDef, text: SyntaxText) -> Option { + if let Some(statements) = template.statements() { + for component in statements.find_children::() { + if let Some(iden) = component.component_identifier() { + if iden.name().unwrap().syntax().text() == text { + return component.template(); + } + } + } + } + None +} + +// if token in an include statement +// add lib path (location of source code of that library) into result +pub fn jump_to_lib(file: &FileDB, token: &SyntaxToken) -> Vec { + if let Some(include_lib) = lookup_node_wrap_token(TokenKind::IncludeKw, token) { + if let Some(ast_include) = AstInclude::cast(include_lib) { + if let Some(abs_lib_ans) = ast_include.lib() { + let lib_path = file + .get_path() + .parent() + .unwrap() + .join(abs_lib_ans.value()) + .clone(); + let lib_url = Url::from_file_path(lib_path.clone()).unwrap(); + return vec![Location::new(lib_url, Range::default())]; + } + } + } + + Vec::new() +} + +pub fn lookup_definition( + file: &FileDB, + ast: &AstCircomProgram, + semantic_data: &SemanticData, + token: &SyntaxToken, +) -> Vec { + let template_list = ast.template_list(); + // TODO: extract function list + + let mut res = Vec::new(); + + if token.kind() == TokenKind::CircomString { + return jump_to_lib(file, token); + } + + // signal from other template + // eg: in1, in2 from component call mul(in1, in2) + let mut signal_outside = false; + + if let Some(component_call) = lookup_node_wrap_token(TokenKind::ComponentCall, token) { + // find template called. + if let Some(ast_component_call) = AstComponentCall::cast(component_call) { + if let Some(signal) = ast_component_call.signal() { + // if target token is the parameter of a component call + // TODO: go to params in template!!! (failed) + if signal.syntax().text() == token.text() { + signal_outside = true; + // lookup template of component + if let Some(current_template) = + lookup_node_wrap_token(TokenKind::TemplateDef, token) + { + if let Some(ast_template_name) = lookup_component( + &AstTemplateDef::cast(current_template).unwrap(), + ast_component_call.component_name().unwrap().syntax().text(), + ) { + if let Some(other_template) = + ast.get_template_by_name(&ast_template_name) + { + let template_id = other_template.syntax().token_id(); + if let Some(semantic) = + semantic_data.template_data_semantic.get(&template_id) + { + if let Some(tmp) = + semantic.signal.0.get(&signal.syntax().token_id()) + { + res.extend(tmp) + } + } + } + } + } + } + } + } + } + + if !signal_outside { + // look up token in template information + // (template name, signal/variable/component in template) + for template in template_list { + let template_name = template.name().unwrap(); + if template_name.name().unwrap().syntax().text() == token.text() { + let range = file.range(template.syntax()); + res.push(range); + } + + if !template + .syntax() + .text_range() + .contains_range(token.text_range()) + { + continue; + } + + let template_id = template.syntax().token_id(); + + if let Some(data) = semantic_data.lookup_signal(template_id, token) { + res.extend(data); + } + + if let Some(data) = semantic_data.lookup_variable(template_id, token) { + res.extend(data); + } + + if let Some(component_decl) = semantic_data.lookup_component(template_id, token) { + res.extend(component_decl); + } + } + + // TODO: look up token in function information + // (function name, signal/variable/component in function) + } + + res.into_iter() + .map(|range| Location::new(file.file_path.clone(), range)) + .collect() +} + +#[cfg(test)] +mod tests { + use std::path::Path; + + use lsp_types::Url; + use parser::token_kind::TokenKind; + use rowan::ast::AstNode; + use syntax::{ + abstract_syntax_tree::{AstCircomProgram, AstInputSignalDecl}, + syntax::SyntaxTreeBuilder, + }; + + use crate::{database::FileDB, handler::goto_definition::lookup_node_wrap_token}; + + use super::lookup_token_at_postion; + + #[test] + fn goto_decl_test() { + let source = r#" + pragma circom 2.0.0; + + template X() { + signal x[100]; + signal input x = 10; + component x = Multiplier2(); + component y = X(); + component y = Multiplier2(); + component z = Multiplier2(); + + } +template M() { + component h = X(); + component k = Multiplier2(); + test + } +template Multiplier2 () { + template m = M(); + // hello world + signal input a; + signal input b; + signal output c; + component y = X(); + + mintlkrekerjke; + component e = Y(); + component z = Y(); + component h = Y(); + signal output d; + c <== a * b; + } +template Y() { + component y = X(); + component a = X(); + + } + "# + .to_string(); + + let file = FileDB::create(&source, Url::from_file_path(Path::new("/tmp")).unwrap()); + + let syntax_node = SyntaxTreeBuilder::syntax_tree(&source); + + if let Some(program_ast) = AstCircomProgram::cast(syntax_node) { + println!("program: {}", program_ast.syntax().text().to_string()); + + let inputs = program_ast.template_list()[0] + .func_body() + .unwrap() + .statement_list() + .unwrap() + .find_children::(); + let signal_name = inputs[0].name().unwrap(); + + let tmp = signal_name.syntax().text_range().start(); + + if let Some(token) = lookup_token_at_postion(&file, &program_ast, file.position(tmp)) { + println!( + "{:#?}", + lookup_node_wrap_token(TokenKind::TemplateDef, &token) + ); + } + } + } + + #[test] + fn url_test() { + let url = Url::from_file_path(Path::new("/hello/abc.tx")); + let binding = url.unwrap(); + let p = binding.path(); + println!("{:?}", Path::new(p).parent()); + } +} diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index c8e886f..a986050 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -1,67 +1,67 @@ -use crate::parser::Parser; -use crate::token_kind::TokenKind::*; - -mod block; -mod declaration; -mod expression; -mod function; -mod include; -mod list; -mod main_component; -mod pragma; -mod statement; -mod template; - -/** - * parse circom program - */ - -pub mod entry { - - use crate::token_kind::TokenKind; - - use super::*; - - pub fn circom_program(p: &mut Parser) { - let m = p.open(); - - while p.at_any(&[ - TokenKind::BlockComment, - TokenKind::CommentLine, - TokenKind::EndLine, - TokenKind::WhiteSpace, - ]) { - p.skip(); - } - - while !p.eof() { - match p.current() { - Pragma => pragma::pragma(p), - TemplateKw => template::template(p), - IncludeKw => include::include(p), - ComponentKw => main_component::main_component(p), - FunctionKw => function::function_parse(p), - _ => p.advance_with_error("invalid token"), - } - } - p.close(m, CircomProgram); - } - - pub enum Scope { - Block, - CircomProgram, - Pragma, - Template, - } - - impl Scope { - pub fn parse(self, p: &mut Parser) { - match self { - Self::Block => block::block(p), - Self::CircomProgram => circom_program(p), - Self::Pragma => pragma::pragma(p), - Self::Template => template::template(p), - } - } - } -} +use crate::parser::Parser; +use crate::token_kind::TokenKind::*; + +mod block; +mod declaration; +mod expression; +mod function; +mod include; +mod list; +mod main_component; +mod pragma; +mod statement; +mod template; + +/** + * parse circom program + */ + +pub mod entry { + + use crate::token_kind::TokenKind; + + use super::*; + + pub fn circom_program(p: &mut Parser) { + let m = p.open(); + + while p.at_any(&[ + TokenKind::BlockComment, + TokenKind::CommentLine, + TokenKind::EndLine, + TokenKind::WhiteSpace, + ]) { + p.skip(); + } + + while !p.eof() { + match p.current() { + Pragma => pragma::pragma(p), + TemplateKw => template::template(p), + IncludeKw => include::include(p), + ComponentKw => main_component::main_component(p), + FunctionKw => function::function_parse(p), + _ => p.advance_with_error("invalid token"), + } + } + p.close(m, CircomProgram); + } + + pub enum Scope { + Block, + CircomProgram, + Pragma, + Template, + } + + impl Scope { + pub fn parse(self, p: &mut Parser) { + match self { + Self::Block => block::block(p), + Self::CircomProgram => circom_program(p), + Self::Pragma => pragma::pragma(p), + Self::Template => template::template(p), + } + } + } +} diff --git a/crates/parser/src/grammar/block.rs b/crates/parser/src/grammar/block.rs index 52e4137..5e3d396 100644 --- a/crates/parser/src/grammar/block.rs +++ b/crates/parser/src/grammar/block.rs @@ -1,48 +1,48 @@ -use super::*; - -/* -{ - / - / - .... - / -} -*/ -pub fn block(p: &mut Parser) { - p.inc_rcurly(); - - // TODO: why do not use expect for { and } - if !p.at(LCurly) { - p.advance_with_error("Miss {"); - } else { - let m = p.open(); - p.expect(LCurly); - - let stmt_marker = p.open(); - while !p.at(RCurly) && !p.eof() { - let kind = p.current(); - match kind { - SignalKw => { - declaration::signal_declaration(p); - p.expect(Semicolon); - } - VarKw => { - declaration::var_declaration(p); - p.expect(Semicolon); - } - ComponentKw => { - declaration::component_declaration(p); - p.expect(Semicolon); - } - _ => statement::statement(p), - } - } - - p.close(stmt_marker, StatementList); - - p.expect(RCurly); - p.close(m, Block); - - p.dec_rcurly(); - } -} +use super::*; + +/* +{ + / + / + .... + / +} +*/ +pub fn block(p: &mut Parser) { + p.inc_rcurly(); + + // TODO: why do not use expect for { and } + if !p.at(LCurly) { + p.advance_with_error("Miss {"); + } else { + let m = p.open(); + p.expect(LCurly); + + let stmt_marker = p.open(); + while !p.at(RCurly) && !p.eof() { + let kind = p.current(); + match kind { + SignalKw => { + declaration::signal_declaration(p); + p.expect(Semicolon); + } + VarKw => { + declaration::var_declaration(p); + p.expect(Semicolon); + } + ComponentKw => { + declaration::component_declaration(p); + p.expect(Semicolon); + } + _ => statement::statement(p), + } + } + + p.close(stmt_marker, StatementList); + + p.expect(RCurly); + p.close(m, Block); + + p.dec_rcurly(); + } +} diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 1166273..31a8818 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -1,206 +1,206 @@ -use super::{ - expression::expression, - list::{tuple_expression, tuple_identifier}, -}; -use crate::{parser::Parser, token_kind::TokenKind::*}; - -// [N][M-1] -fn array(p: &mut Parser) -> bool { - let is_array = p.at(LBracket); - - while p.at(LBracket) { - let array_marker = p.open(); - p.expect(LBracket); - expression(p); - p.expect(RBracket); - p.close(array_marker, ArrayQuery); - } - - is_array -} - -/* -"signal" --> None -"signal input" --> Some(true) -"signal output" --> Some(false) -*/ -fn signal_header(p: &mut Parser) -> Option { - let m = p.open(); - p.expect(SignalKw); - - let result = match p.current() { - InputKw => Some(true), - OutputKw => Some(false), - _ => None, - }; - - if result.is_some() { - p.advance(); - } - - // signal tags - // {tag1, tag2, tag2} - // TODO: support list of tags - if p.at(LCurly) { - p.expect(Identifier); - p.expect(RCurly); - } - - p.close(m, SignalHeader); - result -} - -/* -var_init does not include `var` keyword -eg: tmp = 10; -*/ -pub(crate) fn var_init(p: &mut Parser) { - // name of variable - p.expect(Identifier); - - // eg: [N - 1][M] - array(p); - - // assign for variable - // eg: = 10 - if p.at_var_assign() { - p.advance(); - expression(p); - } -} - -// eg: in[N - 1] <== c.in; -pub(crate) fn signal_init(p: &mut Parser, assign_able: bool) { - // name of signal - p.expect(Identifier); - - // eg: [N][M-1] - array(p); - - // assign for intermediate and outputs signals - // eg: <== Multiplier2().out - if assign_able && p.at_inline_assign_signal() { - p.advance(); - expression(p); - } -} - -/** - * Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization | - * "var" iden1 = init1, iden2 = init2, iden3 - */ -pub(super) fn var_declaration(p: &mut Parser) { - let m = p.open(); - p.expect(VarKw); - - // tuple of variables - // eg: var (in1, in2, in3) = (1, 2, 3); - if p.at(LParen) { - tuple_identifier(p); - if p.at_var_assign() { - p.advance(); - expression(p); - } - } else { - // list of variables - // var in1[N], in2 = 5; - var_init(p); - while p.at(Comma) && !p.eof() { - p.skip(); - var_init(p); - } - } - - p.close(m, VarDecl); -} - -/* -* signal are immutable (can not modify after init value) -* can not initialize value for input signal -* since circom 2.0.4, it is also allowed to initialize -intermediate and outputs signals right after their declaration -*/ -pub(super) fn signal_declaration(p: &mut Parser) { - // TODO: can we remove that? - if !p.at(SignalKw) { - p.advance_with_error("Signal error"); - return; - } - - let m = p.open(); - let io_signal = signal_header(p); - let assign_able = io_signal != Some(true); - - // tuple of signal - // eg: signal (in1, in2, in3) <== tuple_value; - if p.at(LParen) { - tuple_identifier(p); - // can not assign for input signal - if assign_able && p.at_inline_assign_signal() { - p.advance(); - expression(p); - } - } else { - // list of signals - // signal in1[N], in2 <== signal_value; - signal_init(p, assign_able); - while p.at(Comma) && !p.eof() { - p.skip(); - signal_init(p, assign_able); - } - } - - let close_kind = match io_signal { - Some(true) => InputSignalDecl, - Some(false) => OutputSignalDecl, - None => SignalDecl, - }; - - p.close(m, close_kind); -} - -/* -* initialization in the definition of arrays of components is not allowed -*/ -pub(super) fn component_declaration(p: &mut Parser) { - let m = p.open(); - p.expect(ComponentKw); - - // TODO: why do we need `ComponentIdentifier` kind here? - let m_c = p.open(); - p.expect(Identifier); - p.close(m_c, ComponentIdentifier); - - // support array component - // eg: comp[N - 1][10] - let is_array = array(p); - - // do not assign for array components - if !is_array && p.at(Assign) { - p.expect(Assign); - - // TODO: support `parallel` tag - // eg: component comp = parallel NameTemplate(...){...} - - // template name - let m_c = p.open(); - p.expect(Identifier); - p.close(m_c, TemplateName); - - // template params - let parameter_marker = p.open(); - tuple_expression(p); - p.close(parameter_marker, Call); - } - - p.close(m, ComponentDecl); -} - -pub(super) fn declaration(p: &mut Parser) { - match p.current() { - SignalKw => signal_declaration(p), - VarKw => var_declaration(p), - ComponentKw => component_declaration(p), - _ => unreachable!(), - } -} +use super::{ + expression::expression, + list::{tuple_expression, tuple_identifier}, +}; +use crate::{parser::Parser, token_kind::TokenKind::*}; + +// [N][M-1] +fn array(p: &mut Parser) -> bool { + let is_array = p.at(LBracket); + + while p.at(LBracket) { + let array_marker = p.open(); + p.expect(LBracket); + expression(p); + p.expect(RBracket); + p.close(array_marker, ArrayQuery); + } + + is_array +} + +/* +"signal" --> None +"signal input" --> Some(true) +"signal output" --> Some(false) +*/ +fn signal_header(p: &mut Parser) -> Option { + let m = p.open(); + p.expect(SignalKw); + + let result = match p.current() { + InputKw => Some(true), + OutputKw => Some(false), + _ => None, + }; + + if result.is_some() { + p.advance(); + } + + // signal tags + // {tag1, tag2, tag2} + // TODO: support list of tags + if p.at(LCurly) { + p.expect(Identifier); + p.expect(RCurly); + } + + p.close(m, SignalHeader); + result +} + +/* +var_init does not include `var` keyword +eg: tmp = 10; +*/ +pub(crate) fn var_init(p: &mut Parser) { + // name of variable + p.expect(Identifier); + + // eg: [N - 1][M] + array(p); + + // assign for variable + // eg: = 10 + if p.at_var_assign() { + p.advance(); + expression(p); + } +} + +// eg: in[N - 1] <== c.in; +pub(crate) fn signal_init(p: &mut Parser, assign_able: bool) { + // name of signal + p.expect(Identifier); + + // eg: [N][M-1] + array(p); + + // assign for intermediate and outputs signals + // eg: <== Multiplier2().out + if assign_able && p.at_inline_assign_signal() { + p.advance(); + expression(p); + } +} + +/** + * Declaration := "var" (SimpleSymbol, ..., SimpleSymbol) TupleInitialization | + * "var" iden1 = init1, iden2 = init2, iden3 + */ +pub(super) fn var_declaration(p: &mut Parser) { + let m = p.open(); + p.expect(VarKw); + + // tuple of variables + // eg: var (in1, in2, in3) = (1, 2, 3); + if p.at(LParen) { + tuple_identifier(p); + if p.at_var_assign() { + p.advance(); + expression(p); + } + } else { + // list of variables + // var in1[N], in2 = 5; + var_init(p); + while p.at(Comma) && !p.eof() { + p.skip(); + var_init(p); + } + } + + p.close(m, VarDecl); +} + +/* +* signal are immutable (can not modify after init value) +* can not initialize value for input signal +* since circom 2.0.4, it is also allowed to initialize +intermediate and outputs signals right after their declaration +*/ +pub(super) fn signal_declaration(p: &mut Parser) { + // TODO: can we remove that? + if !p.at(SignalKw) { + p.advance_with_error("Signal error"); + return; + } + + let m = p.open(); + let io_signal = signal_header(p); + let assign_able = io_signal != Some(true); + + // tuple of signal + // eg: signal (in1, in2, in3) <== tuple_value; + if p.at(LParen) { + tuple_identifier(p); + // can not assign for input signal + if assign_able && p.at_inline_assign_signal() { + p.advance(); + expression(p); + } + } else { + // list of signals + // signal in1[N], in2 <== signal_value; + signal_init(p, assign_able); + while p.at(Comma) && !p.eof() { + p.skip(); + signal_init(p, assign_able); + } + } + + let close_kind = match io_signal { + Some(true) => InputSignalDecl, + Some(false) => OutputSignalDecl, + None => SignalDecl, + }; + + p.close(m, close_kind); +} + +/* +* initialization in the definition of arrays of components is not allowed +*/ +pub(super) fn component_declaration(p: &mut Parser) { + let m = p.open(); + p.expect(ComponentKw); + + // TODO: why do we need `ComponentIdentifier` kind here? + let m_c = p.open(); + p.expect(Identifier); + p.close(m_c, ComponentIdentifier); + + // support array component + // eg: comp[N - 1][10] + let is_array = array(p); + + // do not assign for array components + if !is_array && p.at(Assign) { + p.expect(Assign); + + // TODO: support `parallel` tag + // eg: component comp = parallel NameTemplate(...){...} + + // template name + let m_c = p.open(); + p.expect(Identifier); + p.close(m_c, TemplateName); + + // template params + let parameter_marker = p.open(); + tuple_expression(p); + p.close(parameter_marker, Call); + } + + p.close(m, ComponentDecl); +} + +pub(super) fn declaration(p: &mut Parser) { + match p.current() { + SignalKw => signal_declaration(p), + VarKw => var_declaration(p), + ComponentKw => component_declaration(p), + _ => unreachable!(), + } +} diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 5423c18..5c6e455 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -1,182 +1,182 @@ -use list::tuple_expression; - -use crate::parser::Marker; - -use super::*; - -pub(super) fn expression(p: &mut Parser) { - let open_marker = p.open(); - circom_expression(p); - p.close(open_marker, Expression); -} - -/** - * TODO: why parse a stament inside expression module??? - * manage 2 cases: normal expression (a++, a-b,...), tenary_conditional_statement (a ? b : c) - * circom_expression = expr ? expr: expr | - * expr - */ -fn circom_expression(p: &mut Parser) { - if let Some(lhs) = expression_rec(p, 0) { - let current_kind = p.current(); - - if matches!(current_kind, MarkQuestion) { - tenary_conditional_statement(p, lhs); - } - } -} - -/** - * grammar: ? : -* is also an expression, -* whose open and close events are already in the Parser event list -* lhs is that open event -*/ -pub fn tenary_conditional_statement(p: &mut Parser, lhs: Marker) { - // - let open_marker = p.open_before(lhs); - p.close(open_marker, Condition); - - // ? - p.expect(MarkQuestion); - - // ? - let first_expression = p.open(); - expression_rec(p, 0); - p.close(first_expression, Expression); - - // ? : - p.expect(Colon); - - // ? : - let last_expression = p.open(); - expression_rec(p, 0); - p.close(last_expression, Expression); - - p.close(open_marker, TenaryConditional); -} - -/** - * return marker which bound the expression - */ -pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { - // consume all first prefix tokens (++a, --a, -a, +a, !a) - // next, consume first atom (identifier/number/tuple) - let parse_able: Option = { - if let Some(pp) = p.current().prefix() { - let kind = p.current(); - let open_marker = p.open(); - // consume prefix token (++, --, -, +, !) - p.advance(); - // continue with the next tokens - expression_rec(p, pp); - Some(p.close(open_marker, kind)) - } else { - expression_atom(p) - } - }; - - parse_able?; - - let mut lhs = parse_able.unwrap(); - - while !p.eof() { - let kind = p.current(); - - if let Some((lp, rp)) = kind.infix() { - // infix case: + - // is already consume in parse_able - - // TODO: what does it mean??? - if rp <= pb { - return None; - } - - // open event that wrap the first parameter () - let open_marker = p.open_before(lhs); - - // consume the infix token - p.advance(); - - // extract the second parameter - expression_rec(p, lp); - - lhs = p.close(open_marker, kind); - } else if let Some(pp) = kind.postfix() { - if pp <= pb { - return None; - } - - match kind { - LParen => { - // function call - let open_marker = p.open_before(lhs); - tuple_expression(p); - lhs = p.close(open_marker, Call); - } - LBracket => { - // array subscript: abc[N - 1] - let open_marker = p.open_before(lhs); - p.expect(LBracket); - expression(p); - p.expect(RBracket); - p.close(open_marker, ArrayQuery); - } - Dot => { - // attribute access - // abc[N - 1].def OR abc.def --> component call - let open_marker = p.open_before(lhs); - p.expect(Dot); - p.expect(Identifier); - p.close(open_marker, ComponentCall); - } - UnitDec | UnitInc => { - let open_marker = p.open_before(lhs); - // consume token ++/-- and do nothing - p.advance(); - p.close(open_marker, Expression); - } - _ => { - // not a postfix token - p.advance_with_error(&format!("Expect a postfix token, but found {:?}", kind)); - break; - } - }; - } else { - break; - } - } - - // return the outer open marker - Some(lhs) -} - -/** - * the unit element in expression - * eg: a, b, 5, 100, () - */ -fn expression_atom(p: &mut Parser) -> Option { - let kind = p.current(); - - match kind { - Number | Identifier => { - let open_marker = p.open(); - p.advance(); - let m_close = p.close(open_marker, kind); - Some(m_close) - } - LParen => { - // () - let open_marker = p.open(); - p.expect(LParen); - expression_rec(p, 0); - p.expect(RParen); - let m_close = p.close(open_marker, Expression); - Some(m_close) - } - _ => { - p.advance_with_error("Invalid Token"); - None - } - } -} +use list::tuple_expression; + +use crate::parser::Marker; + +use super::*; + +pub(super) fn expression(p: &mut Parser) { + let open_marker = p.open(); + circom_expression(p); + p.close(open_marker, Expression); +} + +/** + * TODO: why parse a stament inside expression module??? + * manage 2 cases: normal expression (a++, a-b,...), tenary_conditional_statement (a ? b : c) + * circom_expression = expr ? expr: expr | + * expr + */ +fn circom_expression(p: &mut Parser) { + if let Some(lhs) = expression_rec(p, 0) { + let current_kind = p.current(); + + if matches!(current_kind, MarkQuestion) { + tenary_conditional_statement(p, lhs); + } + } +} + +/** + * grammar: ? : +* is also an expression, +* whose open and close events are already in the Parser event list +* lhs is that open event +*/ +pub fn tenary_conditional_statement(p: &mut Parser, lhs: Marker) { + // + let open_marker = p.open_before(lhs); + p.close(open_marker, Condition); + + // ? + p.expect(MarkQuestion); + + // ? + let first_expression = p.open(); + expression_rec(p, 0); + p.close(first_expression, Expression); + + // ? : + p.expect(Colon); + + // ? : + let last_expression = p.open(); + expression_rec(p, 0); + p.close(last_expression, Expression); + + p.close(open_marker, TenaryConditional); +} + +/** + * return marker which bound the expression + */ +pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { + // consume all first prefix tokens (++a, --a, -a, +a, !a) + // next, consume first atom (identifier/number/tuple) + let parse_able: Option = { + if let Some(pp) = p.current().prefix() { + let kind = p.current(); + let open_marker = p.open(); + // consume prefix token (++, --, -, +, !) + p.advance(); + // continue with the next tokens + expression_rec(p, pp); + Some(p.close(open_marker, kind)) + } else { + expression_atom(p) + } + }; + + parse_able?; + + let mut lhs = parse_able.unwrap(); + + while !p.eof() { + let kind = p.current(); + + if let Some((lp, rp)) = kind.infix() { + // infix case: + + // is already consume in parse_able + + // TODO: what does it mean??? + if rp <= pb { + return None; + } + + // open event that wrap the first parameter () + let open_marker = p.open_before(lhs); + + // consume the infix token + p.advance(); + + // extract the second parameter + expression_rec(p, lp); + + lhs = p.close(open_marker, kind); + } else if let Some(pp) = kind.postfix() { + if pp <= pb { + return None; + } + + match kind { + LParen => { + // function call + let open_marker = p.open_before(lhs); + tuple_expression(p); + lhs = p.close(open_marker, Call); + } + LBracket => { + // array subscript: abc[N - 1] + let open_marker = p.open_before(lhs); + p.expect(LBracket); + expression(p); + p.expect(RBracket); + p.close(open_marker, ArrayQuery); + } + Dot => { + // attribute access + // abc[N - 1].def OR abc.def --> component call + let open_marker = p.open_before(lhs); + p.expect(Dot); + p.expect(Identifier); + p.close(open_marker, ComponentCall); + } + UnitDec | UnitInc => { + let open_marker = p.open_before(lhs); + // consume token ++/-- and do nothing + p.advance(); + p.close(open_marker, Expression); + } + _ => { + // not a postfix token + p.advance_with_error(&format!("Expect a postfix token, but found {:?}", kind)); + break; + } + }; + } else { + break; + } + } + + // return the outer open marker + Some(lhs) +} + +/** + * the unit element in expression + * eg: a, b, 5, 100, () + */ +fn expression_atom(p: &mut Parser) -> Option { + let kind = p.current(); + + match kind { + Number | Identifier => { + let open_marker = p.open(); + p.advance(); + let m_close = p.close(open_marker, kind); + Some(m_close) + } + LParen => { + // () + let open_marker = p.open(); + p.expect(LParen); + expression_rec(p, 0); + p.expect(RParen); + let m_close = p.close(open_marker, Expression); + Some(m_close) + } + _ => { + p.advance_with_error("Invalid Token"); + None + } + } +} diff --git a/crates/parser/src/grammar/function.rs b/crates/parser/src/grammar/function.rs index 7dc25ad..1e89e97 100644 --- a/crates/parser/src/grammar/function.rs +++ b/crates/parser/src/grammar/function.rs @@ -1,22 +1,22 @@ -use list::tuple_identifier; - -use crate::grammar::*; - -// fucntion name() -pub fn function_parse(p: &mut Parser) { - let m = p.open(); - - p.expect(FunctionKw); - - let fn_name_marker = p.open(); - p.expect(Identifier); - p.close(fn_name_marker, FunctionName); - - let parameter_marker = p.open(); - tuple_identifier(p); - p.close(parameter_marker, ParameterList); - - block::block(p); - - p.close(m, FunctionDef); -} +use list::tuple_identifier; + +use crate::grammar::*; + +// fucntion name() +pub fn function_parse(p: &mut Parser) { + let m = p.open(); + + p.expect(FunctionKw); + + let fn_name_marker = p.open(); + p.expect(Identifier); + p.close(fn_name_marker, FunctionName); + + let parameter_marker = p.open(); + tuple_identifier(p); + p.close(parameter_marker, ParameterList); + + block::block(p); + + p.close(m, FunctionDef); +} diff --git a/crates/parser/src/grammar/list.rs b/crates/parser/src/grammar/list.rs index fe66cd9..3b8575d 100644 --- a/crates/parser/src/grammar/list.rs +++ b/crates/parser/src/grammar/list.rs @@ -1,66 +1,66 @@ -use crate::grammar::{expression::expression, *}; - -/** - * grammar: "(expression-1, expression-2,..., expression-n)" - * can be an empty () - */ -pub(super) fn tuple_expression(p: &mut Parser) { - // let m = p.open(); - p.expect(LParen); - - // expression-1, expression-2,..., expression-n) - while !p.at(RParen) && !p.eof() { - expression(p); - - // there are no expressions remaining - if p.eat(Comma) == false { - break; - } - } - - p.expect(RParen); - - // p.close(m, ExpressionList); -} - -/** - * grammar: "(iden1, iden2,..., idenn)" - * can be an empty () - */ -pub(super) fn tuple_identifier(p: &mut Parser) { - // let m = p.open(); - p.expect(LParen); - - // iden1, iden2, iden3 - while p.at(Identifier) && !p.eof() { - p.expect(Identifier); - - if p.eat(Comma) == false { - break; - } - } - - p.expect(RParen); - // p.close(m, IdentifierList); -} - -/** - * grammar: "[iden1, iden2,..., idenn]" - * can be an empty () - */ -pub(super) fn list_identifier(p: &mut Parser) { - // let m = p.open(); - p.expect(LBracket); - - // iden1, iden2, iden3 - while p.at(Identifier) && !p.eof() { - p.expect(Identifier); - - if p.eat(Comma) == false { - break; - } - } - - p.expect(RBracket); - // p.close(m, IdentifierList); -} +use crate::grammar::{expression::expression, *}; + +/** + * grammar: "(expression-1, expression-2,..., expression-n)" + * can be an empty () + */ +pub(super) fn tuple_expression(p: &mut Parser) { + // let m = p.open(); + p.expect(LParen); + + // expression-1, expression-2,..., expression-n) + while !p.at(RParen) && !p.eof() { + expression(p); + + // there are no expressions remaining + if p.eat(Comma) == false { + break; + } + } + + p.expect(RParen); + + // p.close(m, ExpressionList); +} + +/** + * grammar: "(iden1, iden2,..., idenn)" + * can be an empty () + */ +pub(super) fn tuple_identifier(p: &mut Parser) { + // let m = p.open(); + p.expect(LParen); + + // iden1, iden2, iden3 + while p.at(Identifier) && !p.eof() { + p.expect(Identifier); + + if p.eat(Comma) == false { + break; + } + } + + p.expect(RParen); + // p.close(m, IdentifierList); +} + +/** + * grammar: "[iden1, iden2,..., idenn]" + * can be an empty () + */ +pub(super) fn list_identifier(p: &mut Parser) { + // let m = p.open(); + p.expect(LBracket); + + // iden1, iden2, iden3 + while p.at(Identifier) && !p.eof() { + p.expect(Identifier); + + if p.eat(Comma) == false { + break; + } + } + + p.expect(RBracket); + // p.close(m, IdentifierList); +} diff --git a/crates/parser/src/grammar/main_component.rs b/crates/parser/src/grammar/main_component.rs index b61fbac..2fd307b 100644 --- a/crates/parser/src/grammar/main_component.rs +++ b/crates/parser/src/grammar/main_component.rs @@ -1,24 +1,24 @@ -use list::list_identifier; - -use super::*; - -/* -component main {public [signal_list]} = tempid(v1,...,vn); - -{public [signal_list]} is optional -*/ -pub fn main_component(p: &mut Parser) { - p.expect(ComponentKw); - p.expect(MainKw); - - if p.at(LCurly) { - p.expect(LCurly); - p.expect(PublicKw); - p.expect(LBracket); - list_identifier(p); - p.expect(RBracket); - } - - p.expect(Assign); - expression::expression(p); -} +use list::list_identifier; + +use super::*; + +/* +component main {public [signal_list]} = tempid(v1,...,vn); + +{public [signal_list]} is optional +*/ +pub fn main_component(p: &mut Parser) { + p.expect(ComponentKw); + p.expect(MainKw); + + if p.at(LCurly) { + p.expect(LCurly); + p.expect(PublicKw); + p.expect(LBracket); + list_identifier(p); + p.expect(RBracket); + } + + p.expect(Assign); + expression::expression(p); +} diff --git a/crates/parser/src/grammar/pragma.rs b/crates/parser/src/grammar/pragma.rs index 9ce3eaf..48301c7 100644 --- a/crates/parser/src/grammar/pragma.rs +++ b/crates/parser/src/grammar/pragma.rs @@ -1,16 +1,16 @@ -use super::*; - -/** - * parse pragma in circom language - * grammar: - * pragma circom ; - */ - -pub fn pragma(p: &mut Parser) { - let m = p.open(); - p.expect(Pragma); - p.expect(Circom); - p.expect(Version); - p.expect(Semicolon); - p.close(m, Pragma); -} +use super::*; + +/** + * parse pragma in circom language + * grammar: + * pragma circom ; + */ + +pub fn pragma(p: &mut Parser) { + let m = p.open(); + p.expect(Pragma); + p.expect(Circom); + p.expect(Version); + p.expect(Semicolon); + p.close(m, Pragma); +} diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index c6ad18a..a2e57f6 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,186 +1,186 @@ -use super::{block::block, expression::expression, *}; - -pub(super) fn statement(p: &mut Parser) { - let open_marker = p.open(); - match p.current() { - IfKw => if_statement(p), - _ => statement_no_condition(p), - } - p.close(open_marker, Statement); -} - -/* -if (expr) - -else - -*/ -fn if_statement(p: &mut Parser) { - let open_marker = p.open(); - - // if () - p.expect(IfKw); - p.expect(LParen); - expression(p); - p.expect(RParen); - statement(p); - - // else - if p.at(ElseKw) { - p.expect(ElseKw); - statement(p); - } - - p.close(open_marker, IfStatement); -} - -/** - * no if condition here. - * for/while/return/assert... - */ -fn statement_no_condition(p: &mut Parser) { - match p.current() { - ForKw => for_statement(p), - WhileKw => while_statement(p), - ReturnKw => { - return_statement(p); - p.expect(Semicolon); - } - LCurly => block(p), - LogKw => { - log_statement(p); - p.expect(Semicolon); - } - AssertKw => { - assert_statement(p); - p.expect(Semicolon); - } - _ => { - assignment_statement(p); - p.expect(Semicolon); - } - } -} - -/* -for (/; ; ) - -*/ -fn for_statement(p: &mut Parser) { - let open_marker = p.open(); - - // for ( - p.expect(ForKw); - p.expect(LParen); - - if p.current().is_declaration_kw() { - // for (var i = 1 - declaration::declaration(p); - } else { - // for (i = 1 - assignment_statement(p); - } - p.expect(Semicolon); - - // for (i = 1; i < N; - expression::expression(p); - p.expect(Semicolon); - - // for (i = 1; i < N; i++) - assignment_statement(p); - p.expect(RParen); - - // for (i = 1; i < N; i++) { } - statement(p); - - p.close(open_marker, ForLoop); -} - -/* -while () - -*/ -fn while_statement(p: &mut Parser) { - let open_marker = p.open(); - - p.expect(WhileKw); - p.expect(LParen); - expression(p); - p.expect(RParen); - statement(p); - - p.close(open_marker, WhileLoop); -} - -/* -assert() -*/ -fn assert_statement(p: &mut Parser) { - let open_marker = p.open(); - - p.expect(AssertKw); - p.expect(LParen); - expression(p); - p.expect(RParen); - - p.close(open_marker, AssertStatement); -} - -/* -log(, , ... ) -*/ -fn log_statement(p: &mut Parser) { - let open_marker = p.open(); - - p.expect(LogKw); - p.expect(LParen); - - // list circom string/expression - while !p.eof() { - match p.current() { - RParen => break, - CircomString => p.advance(), - _ => expression(p), - } - - if p.eat(Comma) == false { - break; - } - } - - p.expect(RParen); - - p.close(open_marker, LogStatement); -} - -/* -return -*/ -fn return_statement(p: &mut Parser) { - let open_marker = p.open(); - p.expect(ReturnKw); - expression(p); - p.close(open_marker, ReturnStatement); -} - -/* - -optional: -eg: out[1] <== in[0] + in[2] -*/ -fn assignment_statement(p: &mut Parser) { - let open_marker = p.open(); - - // left expression - expression(p); - - // assign part - if p.at_assign_token() { - p.advance(); - - // right expression - expression(p); - } - - p.close(open_marker, AssignStatement); -} +use super::{block::block, expression::expression, *}; + +pub(super) fn statement(p: &mut Parser) { + let open_marker = p.open(); + match p.current() { + IfKw => if_statement(p), + _ => statement_no_condition(p), + } + p.close(open_marker, Statement); +} + +/* +if (expr) + +else + +*/ +fn if_statement(p: &mut Parser) { + let open_marker = p.open(); + + // if () + p.expect(IfKw); + p.expect(LParen); + expression(p); + p.expect(RParen); + statement(p); + + // else + if p.at(ElseKw) { + p.expect(ElseKw); + statement(p); + } + + p.close(open_marker, IfStatement); +} + +/** + * no if condition here. + * for/while/return/assert... + */ +fn statement_no_condition(p: &mut Parser) { + match p.current() { + ForKw => for_statement(p), + WhileKw => while_statement(p), + ReturnKw => { + return_statement(p); + p.expect(Semicolon); + } + LCurly => block(p), + LogKw => { + log_statement(p); + p.expect(Semicolon); + } + AssertKw => { + assert_statement(p); + p.expect(Semicolon); + } + _ => { + assignment_statement(p); + p.expect(Semicolon); + } + } +} + +/* +for (/; ; ) + +*/ +fn for_statement(p: &mut Parser) { + let open_marker = p.open(); + + // for ( + p.expect(ForKw); + p.expect(LParen); + + if p.current().is_declaration_kw() { + // for (var i = 1 + declaration::declaration(p); + } else { + // for (i = 1 + assignment_statement(p); + } + p.expect(Semicolon); + + // for (i = 1; i < N; + expression::expression(p); + p.expect(Semicolon); + + // for (i = 1; i < N; i++) + assignment_statement(p); + p.expect(RParen); + + // for (i = 1; i < N; i++) { } + statement(p); + + p.close(open_marker, ForLoop); +} + +/* +while () + +*/ +fn while_statement(p: &mut Parser) { + let open_marker = p.open(); + + p.expect(WhileKw); + p.expect(LParen); + expression(p); + p.expect(RParen); + statement(p); + + p.close(open_marker, WhileLoop); +} + +/* +assert() +*/ +fn assert_statement(p: &mut Parser) { + let open_marker = p.open(); + + p.expect(AssertKw); + p.expect(LParen); + expression(p); + p.expect(RParen); + + p.close(open_marker, AssertStatement); +} + +/* +log(, , ... ) +*/ +fn log_statement(p: &mut Parser) { + let open_marker = p.open(); + + p.expect(LogKw); + p.expect(LParen); + + // list circom string/expression + while !p.eof() { + match p.current() { + RParen => break, + CircomString => p.advance(), + _ => expression(p), + } + + if p.eat(Comma) == false { + break; + } + } + + p.expect(RParen); + + p.close(open_marker, LogStatement); +} + +/* +return +*/ +fn return_statement(p: &mut Parser) { + let open_marker = p.open(); + p.expect(ReturnKw); + expression(p); + p.close(open_marker, ReturnStatement); +} + +/* + +optional: +eg: out[1] <== in[0] + in[2] +*/ +fn assignment_statement(p: &mut Parser) { + let open_marker = p.open(); + + // left expression + expression(p); + + // assign part + if p.at_assign_token() { + p.advance(); + + // right expression + expression(p); + } + + p.close(open_marker, AssignStatement); +} diff --git a/crates/parser/src/grammar/template.rs b/crates/parser/src/grammar/template.rs index 3686ead..b575cf1 100644 --- a/crates/parser/src/grammar/template.rs +++ b/crates/parser/src/grammar/template.rs @@ -1,25 +1,25 @@ -use list::tuple_identifier; - -use crate::grammar::*; -/** - * template Identifier() {content} - * template Identifier( param_1, ... , param_n ) { content } - */ -pub fn template(p: &mut Parser) { - // assert!(p.at(TemplateKw)); - let m = p.open(); - - p.expect(TemplateKw); - - let name_marker = p.open(); - p.expect(Identifier); - p.close(name_marker, TemplateName); - - let parameter_marker = p.open(); - tuple_identifier(p); - p.close(parameter_marker, ParameterList); - - block::block(p); - - p.close(m, TemplateDef); -} +use list::tuple_identifier; + +use crate::grammar::*; +/** + * template Identifier() {content} + * template Identifier( param_1, ... , param_n ) { content } + */ +pub fn template(p: &mut Parser) { + // assert!(p.at(TemplateKw)); + let m = p.open(); + + p.expect(TemplateKw); + + let name_marker = p.open(); + p.expect(Identifier); + p.close(name_marker, TemplateName); + + let parameter_marker = p.open(); + tuple_identifier(p); + p.close(parameter_marker, ParameterList); + + block::block(p); + + p.close(m, TemplateDef); +} diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 53879ac..f279245 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -1,9 +1,9 @@ -pub mod event; -pub mod grammar; -pub mod parser; -pub mod token_kind; - -pub use logos::Lexer; - -pub mod input; -pub mod output; +pub mod event; +pub mod grammar; +pub mod parser; +pub mod token_kind; + +pub use logos::Lexer; + +pub mod input; +pub mod output; diff --git a/crates/parser/src/output.rs b/crates/parser/src/output.rs index b594a3e..43ed428 100644 --- a/crates/parser/src/output.rs +++ b/crates/parser/src/output.rs @@ -1,75 +1,75 @@ -use crate::{event::Event, token_kind::TokenKind}; - -#[derive(Debug)] -pub enum Child { - Token(usize), // position of token, - Error(String), - Tree(Tree), -} - -#[derive(Debug)] -pub struct Tree { - kind: TokenKind, - children: Vec, -} - -pub type Output = Tree; - -impl Output { - fn empty() -> Self { - Tree { - kind: TokenKind::ParserError, - children: Vec::new(), - } - } - - pub fn kind(&self) -> TokenKind { - self.kind - } - - pub fn children(&self) -> &Vec { - &self.children - } -} - -impl From> for Output { - fn from(events: Vec) -> Self { - let mut stack = Vec::new(); - if let Some((last, elements)) = events.split_last() { - if !matches!(*last, Event::Close) { - return Output::empty(); - } - for event in elements { - match event { - Event::Open { kind } => { - stack.push(Tree { - kind: *kind, - children: Vec::new(), - }); - } - Event::Close => { - let tree = stack.pop().unwrap(); - - stack.last_mut().unwrap().children.push(Child::Tree(tree)); - } - Event::TokenPosition(token) => { - stack - .last_mut() - .unwrap() - .children - .push(Child::Token(*token)); - } - Event::ErrorReport(error) => { - stack - .last_mut() - .unwrap() - .children - .push(Child::Error(error.clone())); - } - } - } - } - // TODO: Make it more safe - stack.pop().unwrap() - } -} +use crate::{event::Event, token_kind::TokenKind}; + +#[derive(Debug)] +pub enum Child { + Token(usize), // position of token, + Error(String), + Tree(Tree), +} + +#[derive(Debug)] +pub struct Tree { + kind: TokenKind, + children: Vec, +} + +pub type Output = Tree; + +impl Output { + fn empty() -> Self { + Tree { + kind: TokenKind::ParserError, + children: Vec::new(), + } + } + + pub fn kind(&self) -> TokenKind { + self.kind + } + + pub fn children(&self) -> &Vec { + &self.children + } +} + +impl From> for Output { + fn from(events: Vec) -> Self { + let mut stack = Vec::new(); + if let Some((last, elements)) = events.split_last() { + if !matches!(*last, Event::Close) { + return Output::empty(); + } + for event in elements { + match event { + Event::Open { kind } => { + stack.push(Tree { + kind: *kind, + children: Vec::new(), + }); + } + Event::Close => { + let tree = stack.pop().unwrap(); + + stack.last_mut().unwrap().children.push(Child::Tree(tree)); + } + Event::TokenPosition(token) => { + stack + .last_mut() + .unwrap() + .children + .push(Child::Token(*token)); + } + Event::ErrorReport(error) => { + stack + .last_mut() + .unwrap() + .children + .push(Child::Error(error.clone())); + } + } + } + } + // TODO: Make it more safe + stack.pop().unwrap() + } +} diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 7f43eae..db350cf 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -1,238 +1,238 @@ -use std::cell::Cell; - -use crate::{ - event::Event, grammar::entry::Scope, input::Input, output::Output, token_kind::TokenKind, -}; - -pub struct Context { - pub r_curly_count: i32, -} - -pub struct Parser<'a> { - pub(crate) input: &'a Input<'a>, - pub context: Context, - pos: usize, - fuel: Cell, - pub(crate) events: Vec, -} - -#[derive(Clone, Copy, Debug)] -pub enum Marker { - Open(usize), - Close(usize), -} - -#[derive(Debug)] -pub enum ParserError { - InvalidEvents, -} - -impl<'a> Parser<'a> { - pub fn wrap_trivial_tokens(&mut self) -> TokenKind { - loop { - let kind = self.input.kind_of(self.pos); - - if kind.is_trivial() == false { - return kind; - } - - self.events.push(Event::Open { kind }); - - self.fuel.set(256); - self.events.push(Event::TokenPosition(self.pos)); - self.skip(); - - self.events.push(Event::Close); - } - } - - pub fn open(&mut self) -> Marker { - if self.events.len() > 0 { - self.wrap_trivial_tokens(); - } - - let marker = Marker::Open(self.events.len()); - self.events.push(Event::Open { - kind: TokenKind::Error, - }); - marker - } - - pub fn open_before(&mut self, marker_closed: Marker) -> Marker { - match marker_closed { - Marker::Close(index) => { - let marker_opened = Marker::Open(index); - self.events.insert( - index, - Event::Open { - kind: TokenKind::EOF, - }, - ); - marker_opened - } - _ => unreachable!(), - } - } - - pub fn close(&mut self, open_marker: Marker, kind: TokenKind) -> Marker { - match open_marker { - Marker::Open(index) => { - self.events[index] = Event::Open { kind }; - self.events.push(Event::Close); - Marker::Close(index) - } - _ => unreachable!(), - } - } - - pub fn advance(&mut self) { - // assert!(!self.eof()); - self.fuel.set(256); - let token = Event::TokenPosition(self.pos); - self.events.push(token); - self.skip(); - } - - pub fn advance_with_token(&mut self, index: usize) { - // assert!(token.kind != TokenKind::EOF); - if self.input.kind_of(index) != TokenKind::EOF { - self.fuel.set(256); - let token = Event::TokenPosition(index); - self.events.push(token); - } - } - - pub fn advance_with_error(&mut self, _error: &str) { - let m = self.open(); - // TODO: Error reporting. - if !self.eof() { - self.advance(); - } - self.close(m, TokenKind::Error); - } - - pub fn error_report(&mut self, error: String) { - let m = self.open(); - - let token = Event::ErrorReport(error); - self.events.push(token); - - self.close(m, TokenKind::Error); - } -} - -impl<'a> Parser<'a> { - pub fn new(input: &'a Input) -> Self { - Self { - input, - pos: 0, - context: Context { r_curly_count: 0 }, - fuel: Cell::new(256), - events: Vec::new(), - } - } - - pub fn inc_rcurly(&mut self) { - self.context.r_curly_count += 1; - } - - pub fn dec_rcurly(&mut self) { - self.context.r_curly_count -= 1; - } - - pub fn current(&mut self) -> TokenKind { - self.wrap_trivial_tokens() - } - - pub fn next(&mut self) -> TokenKind { - if self.fuel.get() == 0 { - panic!("parser is stuck"); - } - self.fuel.set(self.fuel.get() - 1); - if self.pos < self.input.size() { - self.pos += 1; - return self.input.kind_of(self.pos); - } - - TokenKind::EOF - } - - pub fn at(&mut self, kind: TokenKind) -> bool { - self.current() == kind - } - - pub fn at_any(&mut self, kinds: &[TokenKind]) -> bool { - let current_kind = self.current(); - kinds.contains(¤t_kind) - } - - pub fn at_assign_token(&mut self) -> bool { - let current_kind = self.current(); - current_kind.is_assign_token() - } - - pub fn at_inline_assign_signal(&mut self) -> bool { - let current_kind = self.current(); - current_kind.is_inline_assign_signal() - } - - pub fn at_var_assign(&mut self) -> bool { - let current_kind = self.current(); - current_kind.is_var_assign() - } - - pub fn skip(&mut self) { - self.next(); - } - - pub fn skip_if(&mut self, kinds: &[TokenKind]) { - if self.at_any(kinds) { - self.skip(); - } - } - - pub fn eat(&mut self, kind: TokenKind) -> bool { - if self.at(kind) { - self.advance(); - return true; - } - - false - } - - pub fn expect_any(&mut self, kinds: &[TokenKind]) { - let kind = self.current(); - if kinds.contains(&kind) { - self.advance(); - } else { - let error = format!("expect {:?} but got {:?}", kinds, kind); - self.error_report(error); - } - } - - pub fn expect(&mut self, kind: TokenKind) { - if self.at(kind) { - self.advance(); - } else { - let error = format!("expect {:?} but got {:?}", kind, self.current()); - self.error_report(error); - } - } - - pub fn eof(&mut self) -> bool { - self.current() == TokenKind::EOF - } -} - -impl Parser<'_> { - pub fn parsing_with_scope(input: &Input, scope: Scope) -> Output { - let mut p = Parser::new(input); - scope.parse(&mut p); - Output::from(p.events) - } - - pub fn parsing(input: &Input) -> Output { - let c = Scope::CircomProgram; - Parser::parsing_with_scope(input, c) - } -} +use std::cell::Cell; + +use crate::{ + event::Event, grammar::entry::Scope, input::Input, output::Output, token_kind::TokenKind, +}; + +pub struct Context { + pub r_curly_count: i32, +} + +pub struct Parser<'a> { + pub(crate) input: &'a Input<'a>, + pub context: Context, + pos: usize, + fuel: Cell, + pub(crate) events: Vec, +} + +#[derive(Clone, Copy, Debug)] +pub enum Marker { + Open(usize), + Close(usize), +} + +#[derive(Debug)] +pub enum ParserError { + InvalidEvents, +} + +impl<'a> Parser<'a> { + pub fn wrap_trivial_tokens(&mut self) -> TokenKind { + loop { + let kind = self.input.kind_of(self.pos); + + if kind.is_trivial() == false { + return kind; + } + + self.events.push(Event::Open { kind }); + + self.fuel.set(256); + self.events.push(Event::TokenPosition(self.pos)); + self.skip(); + + self.events.push(Event::Close); + } + } + + pub fn open(&mut self) -> Marker { + if self.events.len() > 0 { + self.wrap_trivial_tokens(); + } + + let marker = Marker::Open(self.events.len()); + self.events.push(Event::Open { + kind: TokenKind::Error, + }); + marker + } + + pub fn open_before(&mut self, marker_closed: Marker) -> Marker { + match marker_closed { + Marker::Close(index) => { + let marker_opened = Marker::Open(index); + self.events.insert( + index, + Event::Open { + kind: TokenKind::EOF, + }, + ); + marker_opened + } + _ => unreachable!(), + } + } + + pub fn close(&mut self, open_marker: Marker, kind: TokenKind) -> Marker { + match open_marker { + Marker::Open(index) => { + self.events[index] = Event::Open { kind }; + self.events.push(Event::Close); + Marker::Close(index) + } + _ => unreachable!(), + } + } + + pub fn advance(&mut self) { + // assert!(!self.eof()); + self.fuel.set(256); + let token = Event::TokenPosition(self.pos); + self.events.push(token); + self.skip(); + } + + pub fn advance_with_token(&mut self, index: usize) { + // assert!(token.kind != TokenKind::EOF); + if self.input.kind_of(index) != TokenKind::EOF { + self.fuel.set(256); + let token = Event::TokenPosition(index); + self.events.push(token); + } + } + + pub fn advance_with_error(&mut self, _error: &str) { + let m = self.open(); + // TODO: Error reporting. + if !self.eof() { + self.advance(); + } + self.close(m, TokenKind::Error); + } + + pub fn error_report(&mut self, error: String) { + let m = self.open(); + + let token = Event::ErrorReport(error); + self.events.push(token); + + self.close(m, TokenKind::Error); + } +} + +impl<'a> Parser<'a> { + pub fn new(input: &'a Input) -> Self { + Self { + input, + pos: 0, + context: Context { r_curly_count: 0 }, + fuel: Cell::new(256), + events: Vec::new(), + } + } + + pub fn inc_rcurly(&mut self) { + self.context.r_curly_count += 1; + } + + pub fn dec_rcurly(&mut self) { + self.context.r_curly_count -= 1; + } + + pub fn current(&mut self) -> TokenKind { + self.wrap_trivial_tokens() + } + + pub fn next(&mut self) -> TokenKind { + if self.fuel.get() == 0 { + panic!("parser is stuck"); + } + self.fuel.set(self.fuel.get() - 1); + if self.pos < self.input.size() { + self.pos += 1; + return self.input.kind_of(self.pos); + } + + TokenKind::EOF + } + + pub fn at(&mut self, kind: TokenKind) -> bool { + self.current() == kind + } + + pub fn at_any(&mut self, kinds: &[TokenKind]) -> bool { + let current_kind = self.current(); + kinds.contains(¤t_kind) + } + + pub fn at_assign_token(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_assign_token() + } + + pub fn at_inline_assign_signal(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_inline_assign_signal() + } + + pub fn at_var_assign(&mut self) -> bool { + let current_kind = self.current(); + current_kind.is_var_assign() + } + + pub fn skip(&mut self) { + self.next(); + } + + pub fn skip_if(&mut self, kinds: &[TokenKind]) { + if self.at_any(kinds) { + self.skip(); + } + } + + pub fn eat(&mut self, kind: TokenKind) -> bool { + if self.at(kind) { + self.advance(); + return true; + } + + false + } + + pub fn expect_any(&mut self, kinds: &[TokenKind]) { + let kind = self.current(); + if kinds.contains(&kind) { + self.advance(); + } else { + let error = format!("expect {:?} but got {:?}", kinds, kind); + self.error_report(error); + } + } + + pub fn expect(&mut self, kind: TokenKind) { + if self.at(kind) { + self.advance(); + } else { + let error = format!("expect {:?} but got {:?}", kind, self.current()); + self.error_report(error); + } + } + + pub fn eof(&mut self) -> bool { + self.current() == TokenKind::EOF + } +} + +impl Parser<'_> { + pub fn parsing_with_scope(input: &Input, scope: Scope) -> Output { + let mut p = Parser::new(input); + scope.parse(&mut p); + Output::from(p.events) + } + + pub fn parsing(input: &Input) -> Output { + let c = Scope::CircomProgram; + Parser::parsing_with_scope(input, c) + } +} diff --git a/crates/syntax/src/abstract_syntax_tree/ast.rs b/crates/syntax/src/abstract_syntax_tree/ast.rs index 3508dd2..c917222 100644 --- a/crates/syntax/src/abstract_syntax_tree/ast.rs +++ b/crates/syntax/src/abstract_syntax_tree/ast.rs @@ -1,204 +1,204 @@ -use parser::token_kind::TokenKind::*; -use rowan::ast::AstChildren; -use rowan::SyntaxText; - -use crate::syntax_node::CircomLanguage; -use crate::syntax_node::SyntaxNode; -use parser::token_kind::TokenKind; -use rowan::ast::{support, AstNode}; - -use super::template::AstTemplateDef; -use super::template::AstTemplateName; - -ast_node!(AstSignalHeader, SignalHeader); -ast_node!(AstInputSignalDecl, InputSignalDecl); -ast_node!(AstOutputSignalDecl, OutputSignalDecl); -ast_node!(AstSignalDecl, SignalDecl); - -impl AstInputSignalDecl { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } - - pub fn same_name(&self, other: &SyntaxText) -> bool { - if let Some(name) = self.name() { - return name.equal(other); - } - false - } -} - -impl AstOutputSignalDecl { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } -} -impl AstSignalDecl { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } -} -ast_node!(AstVarDecl, VarDecl); - -impl AstVarDecl { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } -} - -ast_node!(AstComponentDecl, ComponentDecl); - -// component hash = Poseidon(2); -// template --> Poseidon -// component_identifier --> hash -impl AstComponentDecl { - pub fn template(&self) -> Option { - support::child(self.syntax()) - } - pub fn component_identifier(&self) -> Option { - support::child(self.syntax()) - } -} - -ast_node!(AstStatement, Statement); - -ast_node!(AstStatementList, StatementList); - -impl AstStatementList { - pub fn statement_list(&self) -> AstChildren { - support::children(self.syntax()) - } - - pub fn find_children>(&self) -> Vec { - self.syntax().children().filter_map(N::cast).collect() - } -} - -ast_node!(AstBlock, Block); -impl AstBlock { - pub fn statement_list(&self) -> Option { - support::child::(self.syntax()) - } -} - -ast_node!(AstVersion, Version); -ast_node!(AstPragma, Pragma); - -impl AstPragma { - pub fn version(&self) -> Option { - support::child(self.syntax()) - } -} -ast_node!(AstParameterList, TokenKind::ParameterList); - -impl AstParameterList { - pub fn parameters(&self) -> Vec { - self.syntax() - .children() - .filter_map(AstIdentifier::cast) - .collect() - } -} - -ast_node!(AstIdentifier, Identifier); - -impl AstIdentifier { - pub fn equal(&self, other: &SyntaxText) -> bool { - self.syntax().text() == *other - } -} - -ast_node!(AstFunctionName, FunctionName); - -ast_node!(AstFunctionDef, FunctionDef); - -impl AstFunctionDef { - pub fn body(&self) -> Option { - self.syntax().children().find_map(AstBlock::cast) - } - - pub fn function_name(&self) -> Option { - self.syntax().children().find_map(AstFunctionName::cast) - } - - pub fn argument_list(&self) -> Option { - self.syntax().children().find_map(AstParameterList::cast) - } -} - -ast_node!(AstCircomProgram, CircomProgram); - -impl AstCircomProgram { - pub fn pragma(&self) -> Option { - self.syntax().children().find_map(AstPragma::cast) - } - pub fn libs(&self) -> Vec { - self.syntax() - .children() - .filter_map(AstInclude::cast) - .collect() - } - - pub fn template_list(&self) -> Vec { - self.syntax() - .children() - .filter_map(AstTemplateDef::cast) - .collect() - } - - pub fn function_list(&self) -> Vec { - self.syntax() - .children() - .filter_map(AstFunctionDef::cast) - .collect() - } - - pub fn get_template_by_name( - &self, - ast_template_name: &AstTemplateName, - ) -> Option { - for template in self.template_list() { - if let Some(template_name) = template.name() { - if template_name.same_name(ast_template_name) { - return Some(template); - } - } - } - None - } -} - -ast_node!(AstComponentCall, ComponentCall); - -impl AstComponentCall { - pub fn component_name(&self) -> Option { - support::child(self.syntax()) - } - pub fn signal(&self) -> Option { - support::child(self.syntax()) - } -} - -ast_node!(AstComponentIdentifier, ComponentIdentifier); - -impl AstComponentIdentifier { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } -} - -ast_node!(AstCircomString, CircomString); -impl AstCircomString { - pub fn value(&self) -> String { - let text = &self.syntax().text().to_string(); - text[1..text.len() - 1].to_string() - } -} - -ast_node!(AstInclude, IncludeKw); - -impl AstInclude { - pub fn lib(&self) -> Option { - support::child(self.syntax()) - } -} +use parser::token_kind::TokenKind::*; +use rowan::ast::AstChildren; +use rowan::SyntaxText; + +use crate::syntax_node::CircomLanguage; +use crate::syntax_node::SyntaxNode; +use parser::token_kind::TokenKind; +use rowan::ast::{support, AstNode}; + +use super::template::AstTemplateDef; +use super::template::AstTemplateName; + +ast_node!(AstSignalHeader, SignalHeader); +ast_node!(AstInputSignalDecl, InputSignalDecl); +ast_node!(AstOutputSignalDecl, OutputSignalDecl); +ast_node!(AstSignalDecl, SignalDecl); + +impl AstInputSignalDecl { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } + + pub fn same_name(&self, other: &SyntaxText) -> bool { + if let Some(name) = self.name() { + return name.equal(other); + } + false + } +} + +impl AstOutputSignalDecl { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } +} +impl AstSignalDecl { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } +} +ast_node!(AstVarDecl, VarDecl); + +impl AstVarDecl { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } +} + +ast_node!(AstComponentDecl, ComponentDecl); + +// component hash = Poseidon(2); +// template --> Poseidon +// component_identifier --> hash +impl AstComponentDecl { + pub fn template(&self) -> Option { + support::child(self.syntax()) + } + pub fn component_identifier(&self) -> Option { + support::child(self.syntax()) + } +} + +ast_node!(AstStatement, Statement); + +ast_node!(AstStatementList, StatementList); + +impl AstStatementList { + pub fn statement_list(&self) -> AstChildren { + support::children(self.syntax()) + } + + pub fn find_children>(&self) -> Vec { + self.syntax().children().filter_map(N::cast).collect() + } +} + +ast_node!(AstBlock, Block); +impl AstBlock { + pub fn statement_list(&self) -> Option { + support::child::(self.syntax()) + } +} + +ast_node!(AstVersion, Version); +ast_node!(AstPragma, Pragma); + +impl AstPragma { + pub fn version(&self) -> Option { + support::child(self.syntax()) + } +} +ast_node!(AstParameterList, TokenKind::ParameterList); + +impl AstParameterList { + pub fn parameters(&self) -> Vec { + self.syntax() + .children() + .filter_map(AstIdentifier::cast) + .collect() + } +} + +ast_node!(AstIdentifier, Identifier); + +impl AstIdentifier { + pub fn equal(&self, other: &SyntaxText) -> bool { + self.syntax().text() == *other + } +} + +ast_node!(AstFunctionName, FunctionName); + +ast_node!(AstFunctionDef, FunctionDef); + +impl AstFunctionDef { + pub fn body(&self) -> Option { + self.syntax().children().find_map(AstBlock::cast) + } + + pub fn function_name(&self) -> Option { + self.syntax().children().find_map(AstFunctionName::cast) + } + + pub fn argument_list(&self) -> Option { + self.syntax().children().find_map(AstParameterList::cast) + } +} + +ast_node!(AstCircomProgram, CircomProgram); + +impl AstCircomProgram { + pub fn pragma(&self) -> Option { + self.syntax().children().find_map(AstPragma::cast) + } + pub fn libs(&self) -> Vec { + self.syntax() + .children() + .filter_map(AstInclude::cast) + .collect() + } + + pub fn template_list(&self) -> Vec { + self.syntax() + .children() + .filter_map(AstTemplateDef::cast) + .collect() + } + + pub fn function_list(&self) -> Vec { + self.syntax() + .children() + .filter_map(AstFunctionDef::cast) + .collect() + } + + pub fn get_template_by_name( + &self, + ast_template_name: &AstTemplateName, + ) -> Option { + for template in self.template_list() { + if let Some(template_name) = template.name() { + if template_name.same_name(ast_template_name) { + return Some(template); + } + } + } + None + } +} + +ast_node!(AstComponentCall, ComponentCall); + +impl AstComponentCall { + pub fn component_name(&self) -> Option { + support::child(self.syntax()) + } + pub fn signal(&self) -> Option { + support::child(self.syntax()) + } +} + +ast_node!(AstComponentIdentifier, ComponentIdentifier); + +impl AstComponentIdentifier { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } +} + +ast_node!(AstCircomString, CircomString); +impl AstCircomString { + pub fn value(&self) -> String { + let text = &self.syntax().text().to_string(); + text[1..text.len() - 1].to_string() + } +} + +ast_node!(AstInclude, IncludeKw); + +impl AstInclude { + pub fn lib(&self) -> Option { + support::child(self.syntax()) + } +} diff --git a/crates/syntax/src/abstract_syntax_tree/template.rs b/crates/syntax/src/abstract_syntax_tree/template.rs index e5db4ca..c4ebd0d 100644 --- a/crates/syntax/src/abstract_syntax_tree/template.rs +++ b/crates/syntax/src/abstract_syntax_tree/template.rs @@ -1,100 +1,100 @@ -use parser::token_kind::TokenKind::*; - -use crate::syntax_node::CircomLanguage; -use crate::syntax_node::SyntaxNode; -use parser::token_kind::TokenKind; -use rowan::ast::AstNode; - -use super::ast::AstBlock; -use super::ast::AstComponentDecl; -use super::ast::AstIdentifier; -use super::ast::AstInputSignalDecl; -use super::ast::AstOutputSignalDecl; -use super::ast::AstParameterList; -use super::ast::AstSignalDecl; -use super::ast::AstStatementList; - -ast_node!(AstTemplateName, TemplateName); - -ast_node!(AstTemplateDef, TemplateDef); - -impl AstTemplateName { - pub fn name(&self) -> Option { - self.syntax().children().find_map(AstIdentifier::cast) - } - pub fn same_name>(&self, other: &M) -> bool { - self.syntax().text() == other.syntax().text() - } -} - -impl AstTemplateDef { - pub fn name(&self) -> Option { - self.syntax.children().find_map(AstTemplateName::cast) - } - pub fn func_body(&self) -> Option { - self.syntax.children().find_map(AstBlock::cast) - } - pub fn parameter_list(&self) -> Option { - self.syntax().children().find_map(AstParameterList::cast) - } - pub fn statements(&self) -> Option { - if let Some(body) = self.func_body() { - return body.statement_list(); - } - None - } - - pub fn find_input_signal(&self, name: &str) -> Option { - if let Some(statements) = self.statements() { - for input_signal in statements.find_children::() { - if let Some(signal_name) = input_signal.name() { - if signal_name.syntax().text() == name { - return Some(input_signal); - } - } - } - } - None - } - - pub fn find_output_signal(&self, name: &str) -> Option { - if let Some(statements) = self.statements() { - for input_signal in statements.find_children::() { - if let Some(signal_name) = input_signal.name() { - if signal_name.syntax().text() == name { - return Some(input_signal); - } - } - } - } - None - } - - pub fn find_internal_signal(&self, name: &str) -> Option { - if let Some(statements) = self.statements() { - for signal in statements.find_children::() { - if let Some(signal_name) = signal.name() { - if signal_name.syntax().text() == name { - return Some(signal); - } - } - } - } - None - } - - pub fn find_component(&self, name: &str) -> Option { - if let Some(statements) = self.statements() { - for component in statements.find_children::() { - if let Some(component_identifier) = component.component_identifier() { - if let Some(component_name) = component_identifier.name() { - if component_name.syntax().text() == name { - return Some(component); - } - } - } - } - } - None - } -} +use parser::token_kind::TokenKind::*; + +use crate::syntax_node::CircomLanguage; +use crate::syntax_node::SyntaxNode; +use parser::token_kind::TokenKind; +use rowan::ast::AstNode; + +use super::ast::AstBlock; +use super::ast::AstComponentDecl; +use super::ast::AstIdentifier; +use super::ast::AstInputSignalDecl; +use super::ast::AstOutputSignalDecl; +use super::ast::AstParameterList; +use super::ast::AstSignalDecl; +use super::ast::AstStatementList; + +ast_node!(AstTemplateName, TemplateName); + +ast_node!(AstTemplateDef, TemplateDef); + +impl AstTemplateName { + pub fn name(&self) -> Option { + self.syntax().children().find_map(AstIdentifier::cast) + } + pub fn same_name>(&self, other: &M) -> bool { + self.syntax().text() == other.syntax().text() + } +} + +impl AstTemplateDef { + pub fn name(&self) -> Option { + self.syntax.children().find_map(AstTemplateName::cast) + } + pub fn func_body(&self) -> Option { + self.syntax.children().find_map(AstBlock::cast) + } + pub fn parameter_list(&self) -> Option { + self.syntax().children().find_map(AstParameterList::cast) + } + pub fn statements(&self) -> Option { + if let Some(body) = self.func_body() { + return body.statement_list(); + } + None + } + + pub fn find_input_signal(&self, name: &str) -> Option { + if let Some(statements) = self.statements() { + for input_signal in statements.find_children::() { + if let Some(signal_name) = input_signal.name() { + if signal_name.syntax().text() == name { + return Some(input_signal); + } + } + } + } + None + } + + pub fn find_output_signal(&self, name: &str) -> Option { + if let Some(statements) = self.statements() { + for input_signal in statements.find_children::() { + if let Some(signal_name) = input_signal.name() { + if signal_name.syntax().text() == name { + return Some(input_signal); + } + } + } + } + None + } + + pub fn find_internal_signal(&self, name: &str) -> Option { + if let Some(statements) = self.statements() { + for signal in statements.find_children::() { + if let Some(signal_name) = signal.name() { + if signal_name.syntax().text() == name { + return Some(signal); + } + } + } + } + None + } + + pub fn find_component(&self, name: &str) -> Option { + if let Some(statements) = self.statements() { + for component in statements.find_children::() { + if let Some(component_identifier) = component.component_identifier() { + if let Some(component_name) = component_identifier.name() { + if component_name.syntax().text() == name { + return Some(component); + } + } + } + } + } + None + } +} diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index e746fe1..81704de 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -1,5 +1,5 @@ -pub mod abstract_syntax_tree; -pub mod syntax; -pub mod syntax_node; -mod utils; -mod view_syntax; +pub mod abstract_syntax_tree; +pub mod syntax; +pub mod syntax_node; +mod utils; +mod view_syntax; diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__block.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__block.circom.snap deleted file mode 100644 index beaf281..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__block.circom.snap +++ /dev/null @@ -1,670 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" ---- - Block 0..1021 -| LCurly 0..1 -| | LCurly 0..1 "{" -| EndLine 1..2 -| | EndLine 1..2 -| | | EndLine 1..2 "\n" -| WhiteSpace 2..3 -| | WhiteSpace 2..3 -| | | WhiteSpace 2..3 " " -| CommentLine 3..28 -| | CommentLine 3..28 -| | | CommentLine 3..28 "//Declaration of signals." -| EndLine 28..29 -| | EndLine 28..29 -| | | EndLine 28..29 "\n" -| WhiteSpace 29..41 -| | WhiteSpace 29..41 -| | | WhiteSpace 29..41 " " -| StatementList 41..1020 -| | InputSignalDecl 41..56 -| | | SignalHeader 41..54 -| | | | SignalKw 41..47 -| | | | | SignalKw 41..47 "signal" -| | | | WhiteSpace 47..48 -| | | | | WhiteSpace 47..48 -| | | | | | WhiteSpace 47..48 " " -| | | | InputKw 48..53 -| | | | | InputKw 48..53 "input" -| | | | WhiteSpace 53..54 -| | | | | WhiteSpace 53..54 -| | | | | | WhiteSpace 53..54 " " -| | | Identifier 54..56 -| | | | Identifier 54..56 "in" -| | Error 56..89 -| | | Error 56..89 -| | | | Error 56..89 "expect Semicolon but got LBracket" -| | Statement 89..125 -| | | Error 89..90 -| | | | Expression 89..90 -| | | | | Error 89..90 -| | | | | | LBracket 89..90 -| | | | | | | LBracket 89..90 "[" -| | | Error 90..125 -| | | | Error 90..125 -| | | | | Error 90..125 "expect Semicolon but got Identifier" -| | Statement 125..159 -| | | Error 125..126 -| | | | Expression 125..126 -| | | | | ComponentIdentifier 125..126 -| | | | | | Identifier 125..126 -| | | | | | | Identifier 125..126 "N" -| | | Error 126..159 -| | | | Error 126..159 -| | | | | Error 126..159 "expect Semicolon but got RBracket" -| | Statement 159..161 -| | | Error 159..160 -| | | | Expression 159..160 -| | | | | Error 159..160 -| | | | | | RBracket 159..160 -| | | | | | | RBracket 159..160 "]" -| | | Semicolon 160..161 -| | | | Semicolon 160..161 ";" -| | EndLine 161..162 -| | | EndLine 161..162 -| | | | EndLine 161..162 "\n" -| | WhiteSpace 162..174 -| | | WhiteSpace 162..174 -| | | | WhiteSpace 162..174 " " -| | OutputSignalDecl 174..191 -| | | SignalHeader 174..188 -| | | | SignalKw 174..180 -| | | | | SignalKw 174..180 "signal" -| | | | WhiteSpace 180..181 -| | | | | WhiteSpace 180..181 -| | | | | | WhiteSpace 180..181 " " -| | | | OutputKw 181..187 -| | | | | OutputKw 181..187 "output" -| | | | WhiteSpace 187..188 -| | | | | WhiteSpace 187..188 -| | | | | | WhiteSpace 187..188 " " -| | | Identifier 188..191 -| | | | Identifier 188..191 "out" -| | Semicolon 191..192 -| | | Semicolon 191..192 ";" -| | EndLine 192..193 -| | | EndLine 192..193 -| | | | EndLine 192..193 "\n" -| | WhiteSpace 193..205 -| | | WhiteSpace 193..205 -| | | | WhiteSpace 193..205 " " -| | ComponentDecl 205..343 -| | | ComponentKw 205..214 -| | | | ComponentKw 205..214 "component" -| | | WhiteSpace 214..215 -| | | | WhiteSpace 214..215 -| | | | | WhiteSpace 214..215 " " -| | | ComponentIdentifier 215..219 -| | | | Identifier 215..219 -| | | | | Identifier 215..219 "comp" -| | | Error 219..249 -| | | | Error 219..249 -| | | | | Error 219..249 "expect Assign but got LBracket" -| | | TemplateName 249..283 -| | | | Error 249..283 -| | | | | Error 249..283 -| | | | | | Error 249..283 "expect Identifier but got LBracket" -| | | Error 283..313 -| | | | Error 283..313 -| | | | | Error 283..313 "expect LParen but got LBracket" -| | | Error 313..343 -| | | | Error 313..343 -| | | | | Error 313..343 "expect RParen but got LBracket" -| | Error 343..376 -| | | Error 343..376 -| | | | Error 343..376 "expect Semicolon but got LBracket" -| | Statement 376..412 -| | | Error 376..377 -| | | | Expression 376..377 -| | | | | Error 376..377 -| | | | | | LBracket 376..377 -| | | | | | | LBracket 376..377 "[" -| | | Error 377..412 -| | | | Error 377..412 -| | | | | Error 377..412 "expect Semicolon but got Identifier" -| | Statement 412..441 -| | | Error 412..413 -| | | | Expression 412..413 -| | | | | ComponentIdentifier 412..413 -| | | | | | Identifier 412..413 -| | | | | | | Identifier 412..413 "N" -| | | Error 413..441 -| | | | Error 413..441 -| | | | | Error 413..441 "expect Semicolon but got Sub" -| | Statement 441..476 -| | | Error 441..443 -| | | | Expression 441..443 -| | | | | Sub 441..443 -| | | | | | Sub 441..442 -| | | | | | | Sub 441..442 "-" -| | | | | | Number 442..443 -| | | | | | | Number 442..443 -| | | | | | | | Number 442..443 "1" -| | | Error 443..476 -| | | | Error 443..476 -| | | | | Error 443..476 "expect Semicolon but got RBracket" -| | Statement 476..478 -| | | Error 476..477 -| | | | Expression 476..477 -| | | | | Error 476..477 -| | | | | | RBracket 476..477 -| | | | | | | RBracket 476..477 "]" -| | | Semicolon 477..478 -| | | | Semicolon 477..478 ";" -| | EndLine 478..479 -| | | EndLine 478..479 -| | | | EndLine 478..479 "\n" -| | EndLine 479..480 -| | | EndLine 479..480 -| | | | EndLine 479..480 "\n" -| | WhiteSpace 480..492 -| | | WhiteSpace 480..492 -| | | | WhiteSpace 480..492 " " -| | CommentLine 492..505 -| | | CommentLine 492..505 -| | | | CommentLine 492..505 "//Statements." -| | EndLine 505..506 -| | | EndLine 505..506 -| | | | EndLine 505..506 "\n" -| | WhiteSpace 506..518 -| | | WhiteSpace 506..518 -| | | | WhiteSpace 506..518 " " -| | Statement 518..606 -| | | ForLoop 518..606 -| | | | ForKw 518..521 -| | | | | ForKw 518..521 "for" -| | | | LParen 521..522 -| | | | | LParen 521..522 "(" -| | | | VarDecl 522..531 -| | | | | VarKw 522..525 -| | | | | | VarKw 522..525 "var" -| | | | | WhiteSpace 525..526 -| | | | | | WhiteSpace 525..526 -| | | | | | | WhiteSpace 525..526 " " -| | | | | Identifier 526..527 -| | | | | | Identifier 526..527 "i" -| | | | | WhiteSpace 527..528 -| | | | | | WhiteSpace 527..528 -| | | | | | | WhiteSpace 527..528 " " -| | | | | Assign 528..529 -| | | | | | Assign 528..529 "=" -| | | | | WhiteSpace 529..530 -| | | | | | WhiteSpace 529..530 -| | | | | | | WhiteSpace 529..530 " " -| | | | | Expression 530..531 -| | | | | | Number 530..531 -| | | | | | | Number 530..531 -| | | | | | | | Number 530..531 "0" -| | | | Semicolon 531..532 -| | | | | Semicolon 531..532 ";" -| | | | WhiteSpace 532..533 -| | | | | WhiteSpace 532..533 -| | | | | | WhiteSpace 532..533 " " -| | | | Expression 533..540 -| | | | | LessThan 533..540 -| | | | | | Identifier 533..534 -| | | | | | | Identifier 533..534 -| | | | | | | | Identifier 533..534 "i" -| | | | | | WhiteSpace 534..535 -| | | | | | | WhiteSpace 534..535 -| | | | | | | | WhiteSpace 534..535 " " -| | | | | | LessThan 535..536 -| | | | | | | LessThan 535..536 "<" -| | | | | | WhiteSpace 536..537 -| | | | | | | WhiteSpace 536..537 -| | | | | | | | WhiteSpace 536..537 " " -| | | | | | Sub 537..540 -| | | | | | | Identifier 537..538 -| | | | | | | | Identifier 537..538 -| | | | | | | | | Identifier 537..538 "N" -| | | | | | | Sub 538..539 -| | | | | | | | Sub 538..539 "-" -| | | | | | | Number 539..540 -| | | | | | | | Number 539..540 -| | | | | | | | | Number 539..540 "1" -| | | | Semicolon 540..541 -| | | | | Semicolon 540..541 ";" -| | | | WhiteSpace 541..542 -| | | | | WhiteSpace 541..542 -| | | | | | WhiteSpace 541..542 " " -| | | | Error 542..543 -| | | | | Expression 542..543 -| | | | | | ComponentIdentifier 542..543 -| | | | | | | Identifier 542..543 -| | | | | | | | Identifier 542..543 "i" -| | | | Error 543..572 -| | | | | Error 543..572 -| | | | | | Error 543..572 "expect RParen but got UnitInc" -| | | | Error 572..575 -| | | | | Expression 572..575 -| | | | | | UnitInc 572..575 -| | | | | | | UnitInc 572..574 -| | | | | | | | UnitInc 572..574 "++" -| | | | | | | Error 574..575 -| | | | | | | | RParen 574..575 -| | | | | | | | | RParen 574..575 ")" -| | | | Error 575..606 -| | | | | Error 575..606 -| | | | | | Error 575..606 "expect Semicolon but got LCurly" -| | Statement 606..694 -| | | Block 606..694 -| | | | LCurly 606..607 -| | | | | LCurly 606..607 "{" -| | | | EndLine 607..608 -| | | | | EndLine 607..608 -| | | | | | EndLine 607..608 "\n" -| | | | WhiteSpace 608..624 -| | | | | WhiteSpace 608..624 -| | | | | | WhiteSpace 608..624 " " -| | | | StatementList 624..693 -| | | | | Statement 624..680 -| | | | | | AssignStatement 624..679 -| | | | | | | Expression 624..632 -| | | | | | | | ComponentIdentifier 624..628 -| | | | | | | | | Identifier 624..628 -| | | | | | | | | | Identifier 624..628 "comp" -| | | | | | | | LBracket 628..629 -| | | | | | | | | LBracket 628..629 "[" -| | | | | | | | Expression 629..630 -| | | | | | | | | Identifier 629..630 -| | | | | | | | | | Identifier 629..630 -| | | | | | | | | | | Identifier 629..630 "i" -| | | | | | | | RBracket 630..631 -| | | | | | | | | RBracket 630..631 "]" -| | | | | | | | WhiteSpace 631..632 -| | | | | | | | | WhiteSpace 631..632 -| | | | | | | | | | WhiteSpace 631..632 " " -| | | | | | | Assign 632..633 -| | | | | | | | Assign 632..633 "=" -| | | | | | | WhiteSpace 633..634 -| | | | | | | | WhiteSpace 633..634 -| | | | | | | | | WhiteSpace 633..634 " " -| | | | | | | Expression 634..679 -| | | | | | | | Call 634..679 -| | | | | | | | | Identifier 634..645 -| | | | | | | | | | Identifier 634..645 -| | | | | | | | | | | Identifier 634..645 "Multiplier2" -| | | | | | | | | Tuple 645..679 -| | | | | | | | | | LParen 645..646 -| | | | | | | | | | | LParen 645..646 "(" -| | | | | | | | | | Error 646..678 -| | | | | | | | | | | Error 646..678 -| | | | | | | | | | | | Error 646..678 "expect Identifier but got RParen" -| | | | | | | | | | RParen 678..679 -| | | | | | | | | | | RParen 678..679 ")" -| | | | | | Semicolon 679..680 -| | | | | | | Semicolon 679..680 ";" -| | | | | EndLine 680..681 -| | | | | | EndLine 680..681 -| | | | | | | EndLine 680..681 "\n" -| | | | | WhiteSpace 681..693 -| | | | | | WhiteSpace 681..693 -| | | | | | | WhiteSpace 681..693 " " -| | | | RCurly 693..694 -| | | | | RCurly 693..694 "}" -| | EndLine 694..695 -| | | EndLine 694..695 -| | | | EndLine 694..695 "\n" -| | WhiteSpace 695..707 -| | | WhiteSpace 695..707 -| | | | WhiteSpace 695..707 " " -| | Statement 707..729 -| | | AssignStatement 707..728 -| | | | ComponentCall 707..718 -| | | | | ComponentIdentifier 707..711 -| | | | | | Identifier 707..711 -| | | | | | | Identifier 707..711 "comp" -| | | | | LBracket 711..712 -| | | | | | LBracket 711..712 "[" -| | | | | Expression 712..713 -| | | | | | Number 712..713 -| | | | | | | Number 712..713 -| | | | | | | | Number 712..713 "0" -| | | | | RBracket 713..714 -| | | | | | RBracket 713..714 "]" -| | | | | Dot 714..715 -| | | | | | Dot 714..715 "." -| | | | | Identifier 715..718 -| | | | | | Identifier 715..718 "in1" -| | | | WhiteSpace 718..719 -| | | | | WhiteSpace 718..719 -| | | | | | WhiteSpace 718..719 " " -| | | | RAssignConstraintSignal 719..722 -| | | | | RAssignConstraintSignal 719..722 "<==" -| | | | WhiteSpace 722..723 -| | | | | WhiteSpace 722..723 -| | | | | | WhiteSpace 722..723 " " -| | | | Expression 723..728 -| | | | | ArrayQuery 723..728 -| | | | | | Identifier 723..725 -| | | | | | | Identifier 723..725 -| | | | | | | | Identifier 723..725 "in" -| | | | | | LBracket 725..726 -| | | | | | | LBracket 725..726 "[" -| | | | | | Number 726..727 -| | | | | | | Number 726..727 -| | | | | | | | Number 726..727 "0" -| | | | | | RBracket 727..728 -| | | | | | | RBracket 727..728 "]" -| | | Semicolon 728..729 -| | | | Semicolon 728..729 ";" -| | EndLine 729..730 -| | | EndLine 729..730 -| | | | EndLine 729..730 "\n" -| | WhiteSpace 730..742 -| | | WhiteSpace 730..742 -| | | | WhiteSpace 730..742 " " -| | Statement 742..764 -| | | AssignStatement 742..763 -| | | | ComponentCall 742..753 -| | | | | ComponentIdentifier 742..746 -| | | | | | Identifier 742..746 -| | | | | | | Identifier 742..746 "comp" -| | | | | LBracket 746..747 -| | | | | | LBracket 746..747 "[" -| | | | | Expression 747..748 -| | | | | | Number 747..748 -| | | | | | | Number 747..748 -| | | | | | | | Number 747..748 "0" -| | | | | RBracket 748..749 -| | | | | | RBracket 748..749 "]" -| | | | | Dot 749..750 -| | | | | | Dot 749..750 "." -| | | | | Identifier 750..753 -| | | | | | Identifier 750..753 "in2" -| | | | WhiteSpace 753..754 -| | | | | WhiteSpace 753..754 -| | | | | | WhiteSpace 753..754 " " -| | | | RAssignConstraintSignal 754..757 -| | | | | RAssignConstraintSignal 754..757 "<==" -| | | | WhiteSpace 757..758 -| | | | | WhiteSpace 757..758 -| | | | | | WhiteSpace 757..758 " " -| | | | Expression 758..763 -| | | | | ArrayQuery 758..763 -| | | | | | Identifier 758..760 -| | | | | | | Identifier 758..760 -| | | | | | | | Identifier 758..760 "in" -| | | | | | LBracket 760..761 -| | | | | | | LBracket 760..761 "[" -| | | | | | Number 761..762 -| | | | | | | Number 761..762 -| | | | | | | | Number 761..762 "1" -| | | | | | RBracket 762..763 -| | | | | | | RBracket 762..763 "]" -| | | Semicolon 763..764 -| | | | Semicolon 763..764 ";" -| | EndLine 764..765 -| | | EndLine 764..765 -| | | | EndLine 764..765 "\n" -| | WhiteSpace 765..777 -| | | WhiteSpace 765..777 -| | | | WhiteSpace 765..777 " " -| | Statement 777..865 -| | | ForLoop 777..865 -| | | | ForKw 777..780 -| | | | | ForKw 777..780 "for" -| | | | LParen 780..781 -| | | | | LParen 780..781 "(" -| | | | VarDecl 781..790 -| | | | | VarKw 781..784 -| | | | | | VarKw 781..784 "var" -| | | | | WhiteSpace 784..785 -| | | | | | WhiteSpace 784..785 -| | | | | | | WhiteSpace 784..785 " " -| | | | | Identifier 785..786 -| | | | | | Identifier 785..786 "i" -| | | | | WhiteSpace 786..787 -| | | | | | WhiteSpace 786..787 -| | | | | | | WhiteSpace 786..787 " " -| | | | | Assign 787..788 -| | | | | | Assign 787..788 "=" -| | | | | WhiteSpace 788..789 -| | | | | | WhiteSpace 788..789 -| | | | | | | WhiteSpace 788..789 " " -| | | | | Expression 789..790 -| | | | | | Number 789..790 -| | | | | | | Number 789..790 -| | | | | | | | Number 789..790 "0" -| | | | Semicolon 790..791 -| | | | | Semicolon 790..791 ";" -| | | | WhiteSpace 791..792 -| | | | | WhiteSpace 791..792 -| | | | | | WhiteSpace 791..792 " " -| | | | Expression 792..799 -| | | | | LessThan 792..799 -| | | | | | Identifier 792..793 -| | | | | | | Identifier 792..793 -| | | | | | | | Identifier 792..793 "i" -| | | | | | WhiteSpace 793..794 -| | | | | | | WhiteSpace 793..794 -| | | | | | | | WhiteSpace 793..794 " " -| | | | | | LessThan 794..795 -| | | | | | | LessThan 794..795 "<" -| | | | | | WhiteSpace 795..796 -| | | | | | | WhiteSpace 795..796 -| | | | | | | | WhiteSpace 795..796 " " -| | | | | | Sub 796..799 -| | | | | | | Identifier 796..797 -| | | | | | | | Identifier 796..797 -| | | | | | | | | Identifier 796..797 "N" -| | | | | | | Sub 797..798 -| | | | | | | | Sub 797..798 "-" -| | | | | | | Number 798..799 -| | | | | | | | Number 798..799 -| | | | | | | | | Number 798..799 "2" -| | | | Semicolon 799..800 -| | | | | Semicolon 799..800 ";" -| | | | WhiteSpace 800..801 -| | | | | WhiteSpace 800..801 -| | | | | | WhiteSpace 800..801 " " -| | | | Error 801..802 -| | | | | Expression 801..802 -| | | | | | ComponentIdentifier 801..802 -| | | | | | | Identifier 801..802 -| | | | | | | | Identifier 801..802 "i" -| | | | Error 802..831 -| | | | | Error 802..831 -| | | | | | Error 802..831 "expect RParen but got UnitInc" -| | | | Error 831..834 -| | | | | Expression 831..834 -| | | | | | UnitInc 831..834 -| | | | | | | UnitInc 831..833 -| | | | | | | | UnitInc 831..833 "++" -| | | | | | | Error 833..834 -| | | | | | | | RParen 833..834 -| | | | | | | | | RParen 833..834 ")" -| | | | Error 834..865 -| | | | | Error 834..865 -| | | | | | Error 834..865 "expect Semicolon but got LCurly" -| | Statement 865..971 -| | | Block 865..971 -| | | | LCurly 865..866 -| | | | | LCurly 865..866 "{" -| | | | EndLine 866..867 -| | | | | EndLine 866..867 -| | | | | | EndLine 866..867 "\n" -| | | | WhiteSpace 867..883 -| | | | | WhiteSpace 867..883 -| | | | | | WhiteSpace 867..883 " " -| | | | StatementList 883..970 -| | | | | Statement 883..913 -| | | | | | AssignStatement 883..912 -| | | | | | | ComponentCall 883..896 -| | | | | | | | ComponentIdentifier 883..887 -| | | | | | | | | Identifier 883..887 -| | | | | | | | | | Identifier 883..887 "comp" -| | | | | | | | LBracket 887..888 -| | | | | | | | | LBracket 887..888 "[" -| | | | | | | | Expression 888..891 -| | | | | | | | | Add 888..891 -| | | | | | | | | | Identifier 888..889 -| | | | | | | | | | | Identifier 888..889 -| | | | | | | | | | | | Identifier 888..889 "i" -| | | | | | | | | | Add 889..890 -| | | | | | | | | | | Add 889..890 "+" -| | | | | | | | | | Number 890..891 -| | | | | | | | | | | Number 890..891 -| | | | | | | | | | | | Number 890..891 "1" -| | | | | | | | RBracket 891..892 -| | | | | | | | | RBracket 891..892 "]" -| | | | | | | | Dot 892..893 -| | | | | | | | | Dot 892..893 "." -| | | | | | | | Identifier 893..896 -| | | | | | | | | Identifier 893..896 "in1" -| | | | | | | WhiteSpace 896..897 -| | | | | | | | WhiteSpace 896..897 -| | | | | | | | | WhiteSpace 896..897 " " -| | | | | | | RAssignConstraintSignal 897..900 -| | | | | | | | RAssignConstraintSignal 897..900 "<==" -| | | | | | | WhiteSpace 900..901 -| | | | | | | | WhiteSpace 900..901 -| | | | | | | | | WhiteSpace 900..901 " " -| | | | | | | Expression 901..912 -| | | | | | | | ComponentCall 901..912 -| | | | | | | | | ArrayQuery 901..908 -| | | | | | | | | | Identifier 901..905 -| | | | | | | | | | | Identifier 901..905 -| | | | | | | | | | | | Identifier 901..905 "comp" -| | | | | | | | | | LBracket 905..906 -| | | | | | | | | | | LBracket 905..906 "[" -| | | | | | | | | | Identifier 906..907 -| | | | | | | | | | | Identifier 906..907 -| | | | | | | | | | | | Identifier 906..907 "i" -| | | | | | | | | | RBracket 907..908 -| | | | | | | | | | | RBracket 907..908 "]" -| | | | | | | | | Dot 908..909 -| | | | | | | | | | Dot 908..909 "." -| | | | | | | | | Identifier 909..912 -| | | | | | | | | | Identifier 909..912 "out" -| | | | | | Semicolon 912..913 -| | | | | | | Semicolon 912..913 ";" -| | | | | EndLine 913..914 -| | | | | | EndLine 913..914 -| | | | | | | EndLine 913..914 "\n" -| | | | | WhiteSpace 914..930 -| | | | | | WhiteSpace 914..930 -| | | | | | | WhiteSpace 914..930 " " -| | | | | Statement 930..956 -| | | | | | AssignStatement 930..955 -| | | | | | | ComponentCall 930..943 -| | | | | | | | ComponentIdentifier 930..934 -| | | | | | | | | Identifier 930..934 -| | | | | | | | | | Identifier 930..934 "comp" -| | | | | | | | LBracket 934..935 -| | | | | | | | | LBracket 934..935 "[" -| | | | | | | | Expression 935..938 -| | | | | | | | | Add 935..938 -| | | | | | | | | | Identifier 935..936 -| | | | | | | | | | | Identifier 935..936 -| | | | | | | | | | | | Identifier 935..936 "i" -| | | | | | | | | | Add 936..937 -| | | | | | | | | | | Add 936..937 "+" -| | | | | | | | | | Number 937..938 -| | | | | | | | | | | Number 937..938 -| | | | | | | | | | | | Number 937..938 "1" -| | | | | | | | RBracket 938..939 -| | | | | | | | | RBracket 938..939 "]" -| | | | | | | | Dot 939..940 -| | | | | | | | | Dot 939..940 "." -| | | | | | | | Identifier 940..943 -| | | | | | | | | Identifier 940..943 "in2" -| | | | | | | WhiteSpace 943..944 -| | | | | | | | WhiteSpace 943..944 -| | | | | | | | | WhiteSpace 943..944 " " -| | | | | | | RAssignConstraintSignal 944..947 -| | | | | | | | RAssignConstraintSignal 944..947 "<==" -| | | | | | | WhiteSpace 947..948 -| | | | | | | | WhiteSpace 947..948 -| | | | | | | | | WhiteSpace 947..948 " " -| | | | | | | Expression 948..955 -| | | | | | | | ArrayQuery 948..955 -| | | | | | | | | Identifier 948..950 -| | | | | | | | | | Identifier 948..950 -| | | | | | | | | | | Identifier 948..950 "in" -| | | | | | | | | LBracket 950..951 -| | | | | | | | | | LBracket 950..951 "[" -| | | | | | | | | Add 951..954 -| | | | | | | | | | Identifier 951..952 -| | | | | | | | | | | Identifier 951..952 -| | | | | | | | | | | | Identifier 951..952 "i" -| | | | | | | | | | Add 952..953 -| | | | | | | | | | | Add 952..953 "+" -| | | | | | | | | | Number 953..954 -| | | | | | | | | | | Number 953..954 -| | | | | | | | | | | | Number 953..954 "2" -| | | | | | | | | RBracket 954..955 -| | | | | | | | | | RBracket 954..955 "]" -| | | | | | Semicolon 955..956 -| | | | | | | Semicolon 955..956 ";" -| | | | | EndLine 956..957 -| | | | | | EndLine 956..957 -| | | | | | | EndLine 956..957 "\n" -| | | | | EndLine 957..958 -| | | | | | EndLine 957..958 -| | | | | | | EndLine 957..958 "\n" -| | | | | WhiteSpace 958..970 -| | | | | | WhiteSpace 958..970 -| | | | | | | WhiteSpace 958..970 " " -| | | | RCurly 970..971 -| | | | | RCurly 970..971 "}" -| | EndLine 971..972 -| | | EndLine 971..972 -| | | | EndLine 971..972 "\n" -| | WhiteSpace 972..984 -| | | WhiteSpace 972..984 -| | | | WhiteSpace 972..984 " " -| | Statement 984..1006 -| | | AssignStatement 984..1005 -| | | | Expression 984..988 -| | | | | ComponentIdentifier 984..987 -| | | | | | Identifier 984..987 -| | | | | | | Identifier 984..987 "out" -| | | | | WhiteSpace 987..988 -| | | | | | WhiteSpace 987..988 -| | | | | | | WhiteSpace 987..988 " " -| | | | RAssignConstraintSignal 988..991 -| | | | | RAssignConstraintSignal 988..991 "<==" -| | | | WhiteSpace 991..992 -| | | | | WhiteSpace 991..992 -| | | | | | WhiteSpace 991..992 " " -| | | | Expression 992..1005 -| | | | | ComponentCall 992..1005 -| | | | | | ArrayQuery 992..1001 -| | | | | | | Identifier 992..996 -| | | | | | | | Identifier 992..996 -| | | | | | | | | Identifier 992..996 "comp" -| | | | | | | LBracket 996..997 -| | | | | | | | LBracket 996..997 "[" -| | | | | | | Sub 997..1000 -| | | | | | | | Identifier 997..998 -| | | | | | | | | Identifier 997..998 -| | | | | | | | | | Identifier 997..998 "N" -| | | | | | | | Sub 998..999 -| | | | | | | | | Sub 998..999 "-" -| | | | | | | | Number 999..1000 -| | | | | | | | | Number 999..1000 -| | | | | | | | | | Number 999..1000 "2" -| | | | | | | RBracket 1000..1001 -| | | | | | | | RBracket 1000..1001 "]" -| | | | | | Dot 1001..1002 -| | | | | | | Dot 1001..1002 "." -| | | | | | Identifier 1002..1005 -| | | | | | | Identifier 1002..1005 "out" -| | | Semicolon 1005..1006 -| | | | Semicolon 1005..1006 ";" -| | WhiteSpace 1006..1007 -| | | WhiteSpace 1006..1007 -| | | | WhiteSpace 1006..1007 " " -| | EndLine 1007..1008 -| | | EndLine 1007..1008 -| | | | EndLine 1007..1008 "\n" -| | WhiteSpace 1008..1020 -| | | WhiteSpace 1008..1020 -| | | | WhiteSpace 1008..1020 " " -| RCurly 1020..1021 -| | RCurly 1020..1021 "}" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__pragma.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__pragma.circom.snap deleted file mode 100644 index f84ef6f..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__pragma.circom.snap +++ /dev/null @@ -1,19 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" ---- - Pragma 0..20 -| Pragma 0..6 -| | Pragma 0..6 "pragma" -| WhiteSpace 6..7 -| | WhiteSpace 6..7 -| | | WhiteSpace 6..7 " " -| Circom 7..13 -| | Circom 7..13 "circom" -| WhiteSpace 13..14 -| | WhiteSpace 13..14 -| | | WhiteSpace 13..14 " " -| Version 14..19 -| | Version 14..19 "2.0.0" -| Semicolon 19..20 -| | Semicolon 19..20 ";" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__template.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__template.circom.snap deleted file mode 100644 index 6d1a073..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__happy__template.circom.snap +++ /dev/null @@ -1,358 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" ---- - TemplateDef 0..784 -| TemplateKw 0..8 -| | TemplateKw 0..8 "template" -| WhiteSpace 8..9 -| | WhiteSpace 8..9 -| | | WhiteSpace 8..9 " " -| TemplateName 9..20 -| | Identifier 9..20 -| | | Identifier 9..20 "MultiplierN" -| WhiteSpace 20..21 -| | WhiteSpace 20..21 -| | | WhiteSpace 20..21 " " -| LParen 21..22 -| | LParen 21..22 "(" -| ParameterList 22..30 -| | Identifier 22..23 -| | | Identifier 22..23 "N" -| | Comma 23..24 -| | | Comma 23..24 "," -| | WhiteSpace 24..25 -| | | WhiteSpace 24..25 -| | | | WhiteSpace 24..25 " " -| | Identifier 25..26 -| | | Identifier 25..26 "P" -| | Comma 26..27 -| | | Comma 26..27 "," -| | WhiteSpace 27..28 -| | | WhiteSpace 27..28 -| | | | WhiteSpace 27..28 " " -| | Identifier 28..30 -| | | Identifier 28..30 "QQ" -| RParen 30..31 -| | RParen 30..31 ")" -| WhiteSpace 31..32 -| | WhiteSpace 31..32 -| | | WhiteSpace 31..32 " " -| Block 32..784 -| | LCurly 32..33 -| | | LCurly 32..33 "{" -| | EndLine 33..34 -| | | EndLine 33..34 -| | | | EndLine 33..34 "\n" -| | WhiteSpace 34..46 -| | | WhiteSpace 34..46 -| | | | WhiteSpace 34..46 " " -| | CommentLine 46..86 -| | | CommentLine 46..86 -| | | | CommentLine 46..86 "//Declaration of signals and components." -| | EndLine 86..87 -| | | EndLine 86..87 -| | | | EndLine 86..87 "\n" -| | WhiteSpace 87..99 -| | | WhiteSpace 87..99 -| | | | WhiteSpace 87..99 " " -| | StatementList 99..783 -| | | InputSignalDecl 99..114 -| | | | SignalHeader 99..112 -| | | | | SignalKw 99..105 -| | | | | | SignalKw 99..105 "signal" -| | | | | WhiteSpace 105..106 -| | | | | | WhiteSpace 105..106 -| | | | | | | WhiteSpace 105..106 " " -| | | | | InputKw 106..111 -| | | | | | InputKw 106..111 "input" -| | | | | WhiteSpace 111..112 -| | | | | | WhiteSpace 111..112 -| | | | | | | WhiteSpace 111..112 " " -| | | | Identifier 112..114 -| | | | | Identifier 112..114 "in" -| | | Error 114..147 -| | | | Error 114..147 -| | | | | Error 114..147 "expect Semicolon but got LBracket" -| | | Statement 147..183 -| | | | Error 147..148 -| | | | | Expression 147..148 -| | | | | | Error 147..148 -| | | | | | | LBracket 147..148 -| | | | | | | | LBracket 147..148 "[" -| | | | Error 148..183 -| | | | | Error 148..183 -| | | | | | Error 148..183 "expect Semicolon but got Identifier" -| | | Statement 183..217 -| | | | Error 183..184 -| | | | | Expression 183..184 -| | | | | | ComponentIdentifier 183..184 -| | | | | | | Identifier 183..184 -| | | | | | | | Identifier 183..184 "N" -| | | | Error 184..217 -| | | | | Error 184..217 -| | | | | | Error 184..217 "expect Semicolon but got RBracket" -| | | Statement 217..219 -| | | | Error 217..218 -| | | | | Expression 217..218 -| | | | | | Error 217..218 -| | | | | | | RBracket 217..218 -| | | | | | | | RBracket 217..218 "]" -| | | | Semicolon 218..219 -| | | | | Semicolon 218..219 ";" -| | | EndLine 219..220 -| | | | EndLine 219..220 -| | | | | EndLine 219..220 "\n" -| | | WhiteSpace 220..232 -| | | | WhiteSpace 220..232 -| | | | | WhiteSpace 220..232 " " -| | | OutputSignalDecl 232..249 -| | | | SignalHeader 232..246 -| | | | | SignalKw 232..238 -| | | | | | SignalKw 232..238 "signal" -| | | | | WhiteSpace 238..239 -| | | | | | WhiteSpace 238..239 -| | | | | | | WhiteSpace 238..239 " " -| | | | | OutputKw 239..245 -| | | | | | OutputKw 239..245 "output" -| | | | | WhiteSpace 245..246 -| | | | | | WhiteSpace 245..246 -| | | | | | | WhiteSpace 245..246 " " -| | | | Identifier 246..249 -| | | | | Identifier 246..249 "out" -| | | Semicolon 249..250 -| | | | Semicolon 249..250 ";" -| | | EndLine 250..251 -| | | | EndLine 250..251 -| | | | | EndLine 250..251 "\n" -| | | WhiteSpace 251..263 -| | | | WhiteSpace 251..263 -| | | | | WhiteSpace 251..263 " " -| | | ComponentDecl 263..401 -| | | | ComponentKw 263..272 -| | | | | ComponentKw 263..272 "component" -| | | | WhiteSpace 272..273 -| | | | | WhiteSpace 272..273 -| | | | | | WhiteSpace 272..273 " " -| | | | ComponentIdentifier 273..277 -| | | | | Identifier 273..277 -| | | | | | Identifier 273..277 "comp" -| | | | Error 277..307 -| | | | | Error 277..307 -| | | | | | Error 277..307 "expect Assign but got LBracket" -| | | | TemplateName 307..341 -| | | | | Error 307..341 -| | | | | | Error 307..341 -| | | | | | | Error 307..341 "expect Identifier but got LBracket" -| | | | Error 341..371 -| | | | | Error 341..371 -| | | | | | Error 341..371 "expect LParen but got LBracket" -| | | | Error 371..401 -| | | | | Error 371..401 -| | | | | | Error 371..401 "expect RParen but got LBracket" -| | | Error 401..434 -| | | | Error 401..434 -| | | | | Error 401..434 "expect Semicolon but got LBracket" -| | | Statement 434..470 -| | | | Error 434..435 -| | | | | Expression 434..435 -| | | | | | Error 434..435 -| | | | | | | LBracket 434..435 -| | | | | | | | LBracket 434..435 "[" -| | | | Error 435..470 -| | | | | Error 435..470 -| | | | | | Error 435..470 "expect Semicolon but got Identifier" -| | | Statement 470..499 -| | | | Error 470..471 -| | | | | Expression 470..471 -| | | | | | ComponentIdentifier 470..471 -| | | | | | | Identifier 470..471 -| | | | | | | | Identifier 470..471 "N" -| | | | Error 471..499 -| | | | | Error 471..499 -| | | | | | Error 471..499 "expect Semicolon but got Sub" -| | | Statement 499..534 -| | | | Error 499..501 -| | | | | Expression 499..501 -| | | | | | Sub 499..501 -| | | | | | | Sub 499..500 -| | | | | | | | Sub 499..500 "-" -| | | | | | | Number 500..501 -| | | | | | | | Number 500..501 -| | | | | | | | | Number 500..501 "1" -| | | | Error 501..534 -| | | | | Error 501..534 -| | | | | | Error 501..534 "expect Semicolon but got RBracket" -| | | Statement 534..536 -| | | | Error 534..535 -| | | | | Expression 534..535 -| | | | | | Error 534..535 -| | | | | | | RBracket 534..535 -| | | | | | | | RBracket 534..535 "]" -| | | | Semicolon 535..536 -| | | | | Semicolon 535..536 ";" -| | | EndLine 536..537 -| | | | EndLine 536..537 -| | | | | EndLine 536..537 "\n" -| | | WhiteSpace 537..550 -| | | | WhiteSpace 537..550 -| | | | | WhiteSpace 537..550 " " -| | | EndLine 550..551 -| | | | EndLine 550..551 -| | | | | EndLine 550..551 "\n" -| | | WhiteSpace 551..563 -| | | | WhiteSpace 551..563 -| | | | | WhiteSpace 551..563 " " -| | | CommentLine 563..576 -| | | | CommentLine 563..576 -| | | | | CommentLine 563..576 "//Statements." -| | | EndLine 576..577 -| | | | EndLine 576..577 -| | | | | EndLine 576..577 "\n" -| | | WhiteSpace 577..589 -| | | | WhiteSpace 577..589 -| | | | | WhiteSpace 577..589 " " -| | | Statement 589..677 -| | | | ForLoop 589..677 -| | | | | ForKw 589..592 -| | | | | | ForKw 589..592 "for" -| | | | | LParen 592..593 -| | | | | | LParen 592..593 "(" -| | | | | VarDecl 593..602 -| | | | | | VarKw 593..596 -| | | | | | | VarKw 593..596 "var" -| | | | | | WhiteSpace 596..597 -| | | | | | | WhiteSpace 596..597 -| | | | | | | | WhiteSpace 596..597 " " -| | | | | | Identifier 597..598 -| | | | | | | Identifier 597..598 "i" -| | | | | | WhiteSpace 598..599 -| | | | | | | WhiteSpace 598..599 -| | | | | | | | WhiteSpace 598..599 " " -| | | | | | Assign 599..600 -| | | | | | | Assign 599..600 "=" -| | | | | | WhiteSpace 600..601 -| | | | | | | WhiteSpace 600..601 -| | | | | | | | WhiteSpace 600..601 " " -| | | | | | Expression 601..602 -| | | | | | | Number 601..602 -| | | | | | | | Number 601..602 -| | | | | | | | | Number 601..602 "0" -| | | | | Semicolon 602..603 -| | | | | | Semicolon 602..603 ";" -| | | | | WhiteSpace 603..604 -| | | | | | WhiteSpace 603..604 -| | | | | | | WhiteSpace 603..604 " " -| | | | | Expression 604..611 -| | | | | | LessThan 604..611 -| | | | | | | Identifier 604..605 -| | | | | | | | Identifier 604..605 -| | | | | | | | | Identifier 604..605 "i" -| | | | | | | WhiteSpace 605..606 -| | | | | | | | WhiteSpace 605..606 -| | | | | | | | | WhiteSpace 605..606 " " -| | | | | | | LessThan 606..607 -| | | | | | | | LessThan 606..607 "<" -| | | | | | | WhiteSpace 607..608 -| | | | | | | | WhiteSpace 607..608 -| | | | | | | | | WhiteSpace 607..608 " " -| | | | | | | Sub 608..611 -| | | | | | | | Identifier 608..609 -| | | | | | | | | Identifier 608..609 -| | | | | | | | | | Identifier 608..609 "N" -| | | | | | | | Sub 609..610 -| | | | | | | | | Sub 609..610 "-" -| | | | | | | | Number 610..611 -| | | | | | | | | Number 610..611 -| | | | | | | | | | Number 610..611 "1" -| | | | | Semicolon 611..612 -| | | | | | Semicolon 611..612 ";" -| | | | | WhiteSpace 612..613 -| | | | | | WhiteSpace 612..613 -| | | | | | | WhiteSpace 612..613 " " -| | | | | Error 613..614 -| | | | | | Expression 613..614 -| | | | | | | ComponentIdentifier 613..614 -| | | | | | | | Identifier 613..614 -| | | | | | | | | Identifier 613..614 "i" -| | | | | Error 614..643 -| | | | | | Error 614..643 -| | | | | | | Error 614..643 "expect RParen but got UnitInc" -| | | | | Error 643..646 -| | | | | | Expression 643..646 -| | | | | | | UnitInc 643..646 -| | | | | | | | UnitInc 643..645 -| | | | | | | | | UnitInc 643..645 "++" -| | | | | | | | Error 645..646 -| | | | | | | | | RParen 645..646 -| | | | | | | | | | RParen 645..646 ")" -| | | | | Error 646..677 -| | | | | | Error 646..677 -| | | | | | | Error 646..677 "expect Semicolon but got LCurly" -| | | Statement 677..765 -| | | | Block 677..765 -| | | | | LCurly 677..678 -| | | | | | LCurly 677..678 "{" -| | | | | EndLine 678..679 -| | | | | | EndLine 678..679 -| | | | | | | EndLine 678..679 "\n" -| | | | | WhiteSpace 679..695 -| | | | | | WhiteSpace 679..695 -| | | | | | | WhiteSpace 679..695 " " -| | | | | StatementList 695..764 -| | | | | | Statement 695..751 -| | | | | | | AssignStatement 695..750 -| | | | | | | | Expression 695..703 -| | | | | | | | | ComponentIdentifier 695..699 -| | | | | | | | | | Identifier 695..699 -| | | | | | | | | | | Identifier 695..699 "comp" -| | | | | | | | | LBracket 699..700 -| | | | | | | | | | LBracket 699..700 "[" -| | | | | | | | | Expression 700..701 -| | | | | | | | | | Identifier 700..701 -| | | | | | | | | | | Identifier 700..701 -| | | | | | | | | | | | Identifier 700..701 "i" -| | | | | | | | | RBracket 701..702 -| | | | | | | | | | RBracket 701..702 "]" -| | | | | | | | | WhiteSpace 702..703 -| | | | | | | | | | WhiteSpace 702..703 -| | | | | | | | | | | WhiteSpace 702..703 " " -| | | | | | | | Assign 703..704 -| | | | | | | | | Assign 703..704 "=" -| | | | | | | | WhiteSpace 704..705 -| | | | | | | | | WhiteSpace 704..705 -| | | | | | | | | | WhiteSpace 704..705 " " -| | | | | | | | Expression 705..750 -| | | | | | | | | Call 705..750 -| | | | | | | | | | Identifier 705..716 -| | | | | | | | | | | Identifier 705..716 -| | | | | | | | | | | | Identifier 705..716 "Multiplier2" -| | | | | | | | | | Tuple 716..750 -| | | | | | | | | | | LParen 716..717 -| | | | | | | | | | | | LParen 716..717 "(" -| | | | | | | | | | | Error 717..749 -| | | | | | | | | | | | Error 717..749 -| | | | | | | | | | | | | Error 717..749 "expect Identifier but got RParen" -| | | | | | | | | | | RParen 749..750 -| | | | | | | | | | | | RParen 749..750 ")" -| | | | | | | Semicolon 750..751 -| | | | | | | | Semicolon 750..751 ";" -| | | | | | EndLine 751..752 -| | | | | | | EndLine 751..752 -| | | | | | | | EndLine 751..752 "\n" -| | | | | | WhiteSpace 752..764 -| | | | | | | WhiteSpace 752..764 -| | | | | | | | WhiteSpace 752..764 " " -| | | | | RCurly 764..765 -| | | | | | RCurly 764..765 "}" -| | | EndLine 765..766 -| | | | EndLine 765..766 -| | | | | EndLine 765..766 "\n" -| | | WhiteSpace 766..782 -| | | | WhiteSpace 766..782 -| | | | | WhiteSpace 766..782 " " -| | | EndLine 782..783 -| | | | EndLine 782..783 -| | | | | EndLine 782..783 "\n" -| | RCurly 783..784 -| | | RCurly 783..784 "}" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__pragma.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__pragma.circom.snap deleted file mode 100644 index f84ef6f..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests____src__test_files__pragma.circom.snap +++ /dev/null @@ -1,19 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" ---- - Pragma 0..20 -| Pragma 0..6 -| | Pragma 0..6 "pragma" -| WhiteSpace 6..7 -| | WhiteSpace 6..7 -| | | WhiteSpace 6..7 " " -| Circom 7..13 -| | Circom 7..13 "circom" -| WhiteSpace 13..14 -| | WhiteSpace 13..14 -| | | WhiteSpace 13..14 " " -| Version 14..19 -| | Version 14..19 "2.0.0" -| Semicolon 19..20 -| | Semicolon 19..20 ";" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap deleted file mode 100644 index a0e6f49..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__block_happy_test_statements.snap +++ /dev/null @@ -1,18 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: statements ---- -- "[expect Semicolon but got Identifier" -- Nexpect Semicolon but got RBracket -- "];" -- "[expect Semicolon but got Identifier" -- Nexpect Semicolon but got Sub -- "-1expect Semicolon but got RBracket" -- "];" -- for(var i = 0; i < N-1; iexpect RParen but got UnitInc++)expect Semicolon but got LCurly -- "{\n comp[i] = Multiplier2(expect Identifier but got RParen);\n }" -- "comp[0].in1 <== in[0];" -- "comp[0].in2 <== in[1];" -- for(var i = 0; i < N-2; iexpect RParen but got UnitInc++)expect Semicolon but got LCurly -- "{\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" -- "out <== comp[N-2].out;" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap deleted file mode 100644 index de98905..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__declaration_happy_test_source.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: string_syntax ---- -"{\n var nout = nbits((2**n -1)*ops);\n signal input in[ops][n];\n signal output out[nout];\n \n var lin = 0;\n var lout = 0;\n \n var k;\n var j;\n \n var e2;\n \n e2 = 1;\n for (k=0; k> k) & 1;\n \n // Ensure out is binary\n out[k] * (out[k] - 1) === 0;\n \n lout += out[k] * e2;\n \n e2 = e2+e2;\n }\n \n // Ensure the sum;\n \n lin === lout;\n }\n }" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap deleted file mode 100644 index ee362e6..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__for_happy_test_statements.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: statements ---- -- "for(var i = 0; i < N-1; i++){\n comp[i] = Multiplier2();\n }" -- "comp[0].in1 <== in[0];" -- "comp[0].in2 <== in[1];" -- "for(var i = 0; i < N-2; i++){\n comp[i+1].in1 <== comp[i].out;\n comp[i+1].in2 <== in[i+2];\n\n }" -- "out <== comp[N-2].out;" diff --git a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap b/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap deleted file mode 100644 index d8f21fc..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__grammar_tests__function_happy_test_source.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: string_function ---- -"function nbits(a) {\n var n = 1;\n var r = 0;\n while (n-1.\n*/" -| EndLine 747..748 -| | EndLine 747..748 -| | | EndLine 747..748 "\n" -| BlockComment 748..1434 -| | BlockComment 748..1434 -| | | BlockComment 748..1434 "/*\n\nBinary Sum\n==========\n\nThis component creates a binary sum componet of ops operands and n bits each operand.\n\ne is Number of carries: Depends on the number of operands in the input.\n\nMain Constraint:\n in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) +\n + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) +\n + ..\n + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) +\n ===\n out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1)\n\nTo waranty binary outputs:\n\n out[0] * (out[0] - 1) === 0\n out[1] * (out[0] - 1) === 0\n .\n .\n .\n out[n+e-1] * (out[n+e-1] - 1) == 0\n\n */" -| EndLine 1434..1435 -| | EndLine 1434..1435 -| | | EndLine 1434..1435 "\n" -| EndLine 1435..1436 -| | EndLine 1435..1436 -| | | EndLine 1435..1436 "\n" -| EndLine 1436..1437 -| | EndLine 1436..1437 -| | | EndLine 1436..1437 "\n" -| BlockComment 1437..1531 -| | BlockComment 1437..1531 -| | | BlockComment 1437..1531 "/*\n This function calculates the number of extra bits in the output to do the full sum.\n */" -| EndLine 1531..1532 -| | EndLine 1531..1532 -| | | EndLine 1531..1532 "\n" -| WhiteSpace 1532..1533 -| | WhiteSpace 1532..1533 -| | | WhiteSpace 1532..1533 " " -| Pragma 1533..1553 -| | Pragma 1533..1539 -| | | Pragma 1533..1539 "pragma" -| | WhiteSpace 1539..1540 -| | | WhiteSpace 1539..1540 -| | | | WhiteSpace 1539..1540 " " -| | Circom 1540..1546 -| | | Circom 1540..1546 "circom" -| | WhiteSpace 1546..1547 -| | | WhiteSpace 1546..1547 -| | | | WhiteSpace 1546..1547 " " -| | Version 1547..1552 -| | | Version 1547..1552 "2.0.0" -| | Semicolon 1552..1553 -| | | Semicolon 1552..1553 ";" -| EndLine 1553..1554 -| | EndLine 1553..1554 -| | | EndLine 1553..1554 "\n" -| EndLine 1554..1555 -| | EndLine 1554..1555 -| | | EndLine 1554..1555 "\n" -| FunctionDef 1555..1807 -| | FunctionKw 1555..1563 -| | | FunctionKw 1555..1563 "function" -| | WhiteSpace 1563..1564 -| | | WhiteSpace 1563..1564 -| | | | WhiteSpace 1563..1564 " " -| | FunctionName 1564..1569 -| | | Identifier 1564..1569 -| | | | Identifier 1564..1569 "nbits" -| | LParen 1569..1570 -| | | LParen 1569..1570 "(" -| | ParameterList 1570..1571 -| | | Identifier 1570..1571 -| | | | Identifier 1570..1571 "a" -| | RParen 1571..1572 -| | | RParen 1571..1572 ")" -| | WhiteSpace 1572..1573 -| | | WhiteSpace 1572..1573 -| | | | WhiteSpace 1572..1573 " " -| | Block 1573..1807 -| | | LCurly 1573..1574 -| | | | LCurly 1573..1574 "{" -| | | EndLine 1574..1575 -| | | | EndLine 1574..1575 -| | | | | EndLine 1574..1575 "\n" -| | | WhiteSpace 1575..1579 -| | | | WhiteSpace 1575..1579 -| | | | | WhiteSpace 1575..1579 " " -| | | StatementList 1579..1806 -| | | | VarDecl 1579..1588 -| | | | | VarKw 1579..1582 -| | | | | | VarKw 1579..1582 "var" -| | | | | WhiteSpace 1582..1583 -| | | | | | WhiteSpace 1582..1583 -| | | | | | | WhiteSpace 1582..1583 " " -| | | | | Identifier 1583..1584 -| | | | | | Identifier 1583..1584 "n" -| | | | | WhiteSpace 1584..1585 -| | | | | | WhiteSpace 1584..1585 -| | | | | | | WhiteSpace 1584..1585 " " -| | | | | Assign 1585..1586 -| | | | | | Assign 1585..1586 "=" -| | | | | WhiteSpace 1586..1587 -| | | | | | WhiteSpace 1586..1587 -| | | | | | | WhiteSpace 1586..1587 " " -| | | | | Expression 1587..1588 -| | | | | | Number 1587..1588 -| | | | | | | Number 1587..1588 -| | | | | | | | Number 1587..1588 "1" -| | | | Semicolon 1588..1589 -| | | | | Semicolon 1588..1589 ";" -| | | | EndLine 1589..1590 -| | | | | EndLine 1589..1590 -| | | | | | EndLine 1589..1590 "\n" -| | | | WhiteSpace 1590..1594 -| | | | | WhiteSpace 1590..1594 -| | | | | | WhiteSpace 1590..1594 " " -| | | | VarDecl 1594..1603 -| | | | | VarKw 1594..1597 -| | | | | | VarKw 1594..1597 "var" -| | | | | WhiteSpace 1597..1598 -| | | | | | WhiteSpace 1597..1598 -| | | | | | | WhiteSpace 1597..1598 " " -| | | | | Identifier 1598..1599 -| | | | | | Identifier 1598..1599 "r" -| | | | | WhiteSpace 1599..1600 -| | | | | | WhiteSpace 1599..1600 -| | | | | | | WhiteSpace 1599..1600 " " -| | | | | Assign 1600..1601 -| | | | | | Assign 1600..1601 "=" -| | | | | WhiteSpace 1601..1602 -| | | | | | WhiteSpace 1601..1602 -| | | | | | | WhiteSpace 1601..1602 " " -| | | | | Expression 1602..1603 -| | | | | | Number 1602..1603 -| | | | | | | Number 1602..1603 -| | | | | | | | Number 1602..1603 "0" -| | | | Semicolon 1603..1604 -| | | | | Semicolon 1603..1604 ";" -| | | | EndLine 1604..1605 -| | | | | EndLine 1604..1605 -| | | | | | EndLine 1604..1605 "\n" -| | | | WhiteSpace 1605..1609 -| | | | | WhiteSpace 1605..1609 -| | | | | | WhiteSpace 1605..1609 " " -| | | | Statement 1609..1791 -| | | | | WhileKw 1609..1614 -| | | | | | WhileKw 1609..1614 "while" -| | | | | WhiteSpace 1614..1615 -| | | | | | WhiteSpace 1614..1615 -| | | | | | | WhiteSpace 1614..1615 " " -| | | | | LParen 1615..1616 -| | | | | | LParen 1615..1616 "(" -| | | | | Expression 1616..1621 -| | | | | | LessThan 1616..1621 -| | | | | | | Sub 1616..1619 -| | | | | | | | Identifier 1616..1617 -| | | | | | | | | Identifier 1616..1617 -| | | | | | | | | | Identifier 1616..1617 "n" -| | | | | | | | Sub 1617..1618 -| | | | | | | | | Sub 1617..1618 "-" -| | | | | | | | Number 1618..1619 -| | | | | | | | | Number 1618..1619 -| | | | | | | | | | Number 1618..1619 "1" -| | | | | | | LessThan 1619..1620 -| | | | | | | | LessThan 1619..1620 "<" -| | | | | | | Identifier 1620..1621 -| | | | | | | | Identifier 1620..1621 -| | | | | | | | | Identifier 1620..1621 "a" -| | | | | RParen 1621..1622 -| | | | | | RParen 1621..1622 ")" -| | | | | WhiteSpace 1622..1623 -| | | | | | WhiteSpace 1622..1623 -| | | | | | | WhiteSpace 1622..1623 " " -| | | | | Statement 1623..1791 -| | | | | | Block 1623..1791 -| | | | | | | LCurly 1623..1624 -| | | | | | | | LCurly 1623..1624 "{" -| | | | | | | EndLine 1624..1625 -| | | | | | | | EndLine 1624..1625 -| | | | | | | | | EndLine 1624..1625 "\n" -| | | | | | | WhiteSpace 1625..1633 -| | | | | | | | WhiteSpace 1625..1633 -| | | | | | | | | WhiteSpace 1625..1633 " " -| | | | | | | StatementList 1633..1790 -| | | | | | | | Statement 1633..1666 -| | | | | | | | | Error 1633..1634 -| | | | | | | | | | Expression 1633..1634 -| | | | | | | | | | | ComponentIdentifier 1633..1634 -| | | | | | | | | | | | Identifier 1633..1634 -| | | | | | | | | | | | | Identifier 1633..1634 "r" -| | | | | | | | | Error 1634..1666 -| | | | | | | | | | Error 1634..1666 -| | | | | | | | | | | Error 1634..1666 "expect Semicolon but got UnitInc" -| | | | | | | | Statement 1666..1713 -| | | | | | | | | Error 1666..1678 -| | | | | | | | | | Expression 1666..1678 -| | | | | | | | | | | UnitInc 1666..1669 -| | | | | | | | | | | | UnitInc 1666..1668 -| | | | | | | | | | | | | UnitInc 1666..1668 "++" -| | | | | | | | | | | | Error 1668..1669 -| | | | | | | | | | | | | Semicolon 1668..1669 -| | | | | | | | | | | | | | Semicolon 1668..1669 ";" -| | | | | | | | | | | EndLine 1669..1670 -| | | | | | | | | | | | EndLine 1669..1670 -| | | | | | | | | | | | | EndLine 1669..1670 "\n" -| | | | | | | | | | | WhiteSpace 1670..1678 -| | | | | | | | | | | | WhiteSpace 1670..1678 -| | | | | | | | | | | | | WhiteSpace 1670..1678 " " -| | | | | | | | | Error 1678..1713 -| | | | | | | | | | Error 1678..1713 -| | | | | | | | | | | Error 1678..1713 "expect Semicolon but got Identifier" -| | | | | | | | Statement 1713..1749 -| | | | | | | | | Error 1713..1715 -| | | | | | | | | | Expression 1713..1715 -| | | | | | | | | | | ComponentIdentifier 1713..1714 -| | | | | | | | | | | | Identifier 1713..1714 -| | | | | | | | | | | | | Identifier 1713..1714 "n" -| | | | | | | | | | | WhiteSpace 1714..1715 -| | | | | | | | | | | | WhiteSpace 1714..1715 -| | | | | | | | | | | | | WhiteSpace 1714..1715 " " -| | | | | | | | | Error 1715..1749 -| | | | | | | | | | Error 1715..1749 -| | | | | | | | | | | Error 1715..1749 "expect Semicolon but got MulAssign" -| | | | | | | | Statement 1749..1783 -| | | | | | | | | Error 1749..1752 -| | | | | | | | | | Expression 1749..1751 -| | | | | | | | | | | Error 1749..1751 -| | | | | | | | | | | | MulAssign 1749..1751 -| | | | | | | | | | | | | MulAssign 1749..1751 "*=" -| | | | | | | | | | WhiteSpace 1751..1752 -| | | | | | | | | | | WhiteSpace 1751..1752 -| | | | | | | | | | | | WhiteSpace 1751..1752 " " -| | | | | | | | | Error 1752..1783 -| | | | | | | | | | Error 1752..1783 -| | | | | | | | | | | Error 1752..1783 "expect Semicolon but got Number" -| | | | | | | | Statement 1783..1785 -| | | | | | | | | Error 1783..1784 -| | | | | | | | | | Expression 1783..1784 -| | | | | | | | | | | Number 1783..1784 -| | | | | | | | | | | | Number 1783..1784 -| | | | | | | | | | | | | Number 1783..1784 "2" -| | | | | | | | | Semicolon 1784..1785 -| | | | | | | | | | Semicolon 1784..1785 ";" -| | | | | | | | EndLine 1785..1786 -| | | | | | | | | EndLine 1785..1786 -| | | | | | | | | | EndLine 1785..1786 "\n" -| | | | | | | | WhiteSpace 1786..1790 -| | | | | | | | | WhiteSpace 1786..1790 -| | | | | | | | | | WhiteSpace 1786..1790 " " -| | | | | | | RCurly 1790..1791 -| | | | | | | | RCurly 1790..1791 "}" -| | | | EndLine 1791..1792 -| | | | | EndLine 1791..1792 -| | | | | | EndLine 1791..1792 "\n" -| | | | WhiteSpace 1792..1796 -| | | | | WhiteSpace 1792..1796 -| | | | | | WhiteSpace 1792..1796 " " -| | | | Statement 1796..1805 -| | | | | ReturnKw 1796..1804 -| | | | | | ReturnKw 1796..1802 -| | | | | | | ReturnKw 1796..1802 "return" -| | | | | | WhiteSpace 1802..1803 -| | | | | | | WhiteSpace 1802..1803 -| | | | | | | | WhiteSpace 1802..1803 " " -| | | | | | Expression 1803..1804 -| | | | | | | Identifier 1803..1804 -| | | | | | | | Identifier 1803..1804 -| | | | | | | | | Identifier 1803..1804 "r" -| | | | | Semicolon 1804..1805 -| | | | | | Semicolon 1804..1805 ";" + CircomProgram 0..2449 +| BlockComment 0..764 +| | BlockComment 0..764 +| | | BlockComment 0..764 "/*\r\n Copyright 2018 0KIMS association.\r\n\r\n This file is part of circom (Zero Knowledge Circuit Compiler).\r\n\r\n circom is a free software: you can redistribute it and/or modify it\r\n under the terms of the GNU General Public License as published by\r\n the Free Software Foundation, either version 3 of the License, or\r\n (at your option) any later version.\r\n\r\n circom is distributed in the hope that it will be useful, but WITHOUT\r\n ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r\n or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r\n License for more details.\r\n\r\n You should have received a copy of the GNU General Public License\r\n along with circom. If not, see .\r\n*/" +| Error 764..765 +| | Error 764..765 +| | | Error 764..765 "\r" +| EndLine 765..766 +| | EndLine 765..766 +| | | EndLine 765..766 "\n" +| BlockComment 766..1478 +| | BlockComment 766..1478 +| | | BlockComment 766..1478 "/*\r\n\r\nBinary Sum\r\n==========\r\n\r\nThis component creates a binary sum componet of ops operands and n bits each operand.\r\n\r\ne is Number of carries: Depends on the number of operands in the input.\r\n\r\nMain Constraint:\r\n in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) +\r\n + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) +\r\n + ..\r\n + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) +\r\n ===\r\n out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1)\r\n\r\nTo waranty binary outputs:\r\n\r\n out[0] * (out[0] - 1) === 0\r\n out[1] * (out[0] - 1) === 0\r\n .\r\n .\r\n .\r\n out[n+e-1] * (out[n+e-1] - 1) == 0\r\n\r\n */" +| Error 1478..1479 +| | Error 1478..1479 +| | | Error 1478..1479 "\r" +| EndLine 1479..1480 +| | EndLine 1479..1480 +| | | EndLine 1479..1480 "\n" +| Error 1480..1481 +| | Error 1480..1481 +| | | Error 1480..1481 "\r" +| EndLine 1481..1482 +| | EndLine 1481..1482 +| | | EndLine 1481..1482 "\n" +| Error 1482..1483 +| | Error 1482..1483 +| | | Error 1482..1483 "\r" +| EndLine 1483..1484 +| | EndLine 1483..1484 +| | | EndLine 1483..1484 "\n" +| BlockComment 1484..1580 +| | BlockComment 1484..1580 +| | | BlockComment 1484..1580 "/*\r\n This function calculates the number of extra bits in the output to do the full sum.\r\n */" +| Error 1580..1581 +| | Error 1580..1581 +| | | Error 1580..1581 "\r" +| EndLine 1581..1582 +| | EndLine 1581..1582 +| | | EndLine 1581..1582 "\n" +| WhiteSpace 1582..1583 +| | WhiteSpace 1582..1583 +| | | WhiteSpace 1582..1583 " " +| Pragma 1583..1603 +| | Pragma 1583..1589 +| | | Pragma 1583..1589 "pragma" +| | WhiteSpace 1589..1590 +| | | WhiteSpace 1589..1590 +| | | | WhiteSpace 1589..1590 " " +| | Circom 1590..1596 +| | | Circom 1590..1596 "circom" +| | WhiteSpace 1596..1597 +| | | WhiteSpace 1596..1597 +| | | | WhiteSpace 1596..1597 " " +| | Version 1597..1602 +| | | Version 1597..1602 "2.0.0" +| | Semicolon 1602..1603 +| | | Semicolon 1602..1603 ";" +| Error 1603..1604 +| | Error 1603..1604 +| | | Error 1603..1604 "\r" +| EndLine 1604..1605 +| | EndLine 1604..1605 +| | | EndLine 1604..1605 "\n" +| Error 1605..1606 +| | Error 1605..1606 +| | | Error 1605..1606 "\r" +| EndLine 1606..1607 +| | EndLine 1606..1607 +| | | EndLine 1606..1607 "\n" +| FunctionDef 1607..1735 +| | FunctionKw 1607..1615 +| | | FunctionKw 1607..1615 "function" +| | WhiteSpace 1615..1616 +| | | WhiteSpace 1615..1616 +| | | | WhiteSpace 1615..1616 " " +| | FunctionName 1616..1621 +| | | Identifier 1616..1621 +| | | | Identifier 1616..1621 "nbits" +| | ParameterList 1621..1624 +| | | LParen 1621..1622 +| | | | LParen 1621..1622 "(" +| | | Identifier 1622..1623 +| | | | Identifier 1622..1623 "a" +| | | RParen 1623..1624 +| | | | RParen 1623..1624 ")" +| | WhiteSpace 1624..1625 +| | | WhiteSpace 1624..1625 +| | | | WhiteSpace 1624..1625 " " +| | Block 1625..1735 +| | | LCurly 1625..1626 +| | | | LCurly 1625..1626 "{" +| | | Error 1626..1627 +| | | | Error 1626..1627 +| | | | | Error 1626..1627 "\r" +| | | EndLine 1627..1628 +| | | | EndLine 1627..1628 +| | | | | EndLine 1627..1628 "\n" +| | | WhiteSpace 1628..1632 +| | | | WhiteSpace 1628..1632 +| | | | | WhiteSpace 1628..1632 " " +| | | StatementList 1632..1734 +| | | | VarDecl 1632..1641 +| | | | | VarKw 1632..1635 +| | | | | | VarKw 1632..1635 "var" +| | | | | WhiteSpace 1635..1636 +| | | | | | WhiteSpace 1635..1636 +| | | | | | | WhiteSpace 1635..1636 " " +| | | | | Identifier 1636..1637 +| | | | | | Identifier 1636..1637 "n" +| | | | | WhiteSpace 1637..1638 +| | | | | | WhiteSpace 1637..1638 +| | | | | | | WhiteSpace 1637..1638 " " +| | | | | Assign 1638..1639 +| | | | | | Assign 1638..1639 "=" +| | | | | WhiteSpace 1639..1640 +| | | | | | WhiteSpace 1639..1640 +| | | | | | | WhiteSpace 1639..1640 " " +| | | | | Expression 1640..1641 +| | | | | | Number 1640..1641 +| | | | | | | Number 1640..1641 +| | | | | | | | Number 1640..1641 "1" +| | | | Semicolon 1641..1642 +| | | | | Semicolon 1641..1642 ";" +| | | | Error 1642..1643 +| | | | | Error 1642..1643 +| | | | | | Error 1642..1643 "\r" +| | | | EndLine 1643..1644 +| | | | | EndLine 1643..1644 +| | | | | | EndLine 1643..1644 "\n" +| | | | WhiteSpace 1644..1648 +| | | | | WhiteSpace 1644..1648 +| | | | | | WhiteSpace 1644..1648 " " +| | | | VarDecl 1648..1657 +| | | | | VarKw 1648..1651 +| | | | | | VarKw 1648..1651 "var" +| | | | | WhiteSpace 1651..1652 +| | | | | | WhiteSpace 1651..1652 +| | | | | | | WhiteSpace 1651..1652 " " +| | | | | Identifier 1652..1653 +| | | | | | Identifier 1652..1653 "r" +| | | | | WhiteSpace 1653..1654 +| | | | | | WhiteSpace 1653..1654 +| | | | | | | WhiteSpace 1653..1654 " " +| | | | | Assign 1654..1655 +| | | | | | Assign 1654..1655 "=" +| | | | | WhiteSpace 1655..1656 +| | | | | | WhiteSpace 1655..1656 +| | | | | | | WhiteSpace 1655..1656 " " +| | | | | Expression 1656..1657 +| | | | | | Number 1656..1657 +| | | | | | | Number 1656..1657 +| | | | | | | | Number 1656..1657 "0" +| | | | Semicolon 1657..1658 +| | | | | Semicolon 1657..1658 ";" +| | | | Error 1658..1659 +| | | | | Error 1658..1659 +| | | | | | Error 1658..1659 "\r" +| | | | EndLine 1659..1660 +| | | | | EndLine 1659..1660 +| | | | | | EndLine 1659..1660 "\n" +| | | | WhiteSpace 1660..1664 +| | | | | WhiteSpace 1660..1664 +| | | | | | WhiteSpace 1660..1664 " " +| | | | Statement 1664..1717 +| | | | | WhileLoop 1664..1717 +| | | | | | WhileKw 1664..1669 +| | | | | | | WhileKw 1664..1669 "while" +| | | | | | WhiteSpace 1669..1670 +| | | | | | | WhiteSpace 1669..1670 +| | | | | | | | WhiteSpace 1669..1670 " " +| | | | | | LParen 1670..1671 +| | | | | | | LParen 1670..1671 "(" +| | | | | | Expression 1671..1676 +| | | | | | | LessThan 1671..1676 +| | | | | | | | Sub 1671..1674 +| | | | | | | | | Identifier 1671..1672 +| | | | | | | | | | Identifier 1671..1672 +| | | | | | | | | | | Identifier 1671..1672 "n" +| | | | | | | | | Sub 1672..1673 +| | | | | | | | | | Sub 1672..1673 "-" +| | | | | | | | | Number 1673..1674 +| | | | | | | | | | Number 1673..1674 +| | | | | | | | | | | Number 1673..1674 "1" +| | | | | | | | LessThan 1674..1675 +| | | | | | | | | LessThan 1674..1675 "<" +| | | | | | | | Identifier 1675..1676 +| | | | | | | | | Identifier 1675..1676 +| | | | | | | | | | Identifier 1675..1676 "a" +| | | | | | RParen 1676..1677 +| | | | | | | RParen 1676..1677 ")" +| | | | | | WhiteSpace 1677..1678 +| | | | | | | WhiteSpace 1677..1678 +| | | | | | | | WhiteSpace 1677..1678 " " +| | | | | | Statement 1678..1717 +| | | | | | | Block 1678..1717 +| | | | | | | | LCurly 1678..1679 +| | | | | | | | | LCurly 1678..1679 "{" +| | | | | | | | Error 1679..1680 +| | | | | | | | | Error 1679..1680 +| | | | | | | | | | Error 1679..1680 "\r" +| | | | | | | | EndLine 1680..1681 +| | | | | | | | | EndLine 1680..1681 +| | | | | | | | | | EndLine 1680..1681 "\n" +| | | | | | | | WhiteSpace 1681..1689 +| | | | | | | | | WhiteSpace 1681..1689 +| | | | | | | | | | WhiteSpace 1681..1689 " " +| | | | | | | | StatementList 1689..1716 +| | | | | | | | | Statement 1689..1693 +| | | | | | | | | | AssignStatement 1689..1692 +| | | | | | | | | | | Expression 1689..1692 +| | | | | | | | | | | | Expression 1689..1692 +| | | | | | | | | | | | | Identifier 1689..1690 +| | | | | | | | | | | | | | Identifier 1689..1690 +| | | | | | | | | | | | | | | Identifier 1689..1690 "r" +| | | | | | | | | | | | | UnitInc 1690..1692 +| | | | | | | | | | | | | | UnitInc 1690..1692 "++" +| | | | | | | | | | Semicolon 1692..1693 +| | | | | | | | | | | Semicolon 1692..1693 ";" +| | | | | | | | | Error 1693..1694 +| | | | | | | | | | Error 1693..1694 +| | | | | | | | | | | Error 1693..1694 "\r" +| | | | | | | | | EndLine 1694..1695 +| | | | | | | | | | EndLine 1694..1695 +| | | | | | | | | | | EndLine 1694..1695 "\n" +| | | | | | | | | WhiteSpace 1695..1703 +| | | | | | | | | | WhiteSpace 1695..1703 +| | | | | | | | | | | WhiteSpace 1695..1703 " " +| | | | | | | | | Statement 1703..1710 +| | | | | | | | | | AssignStatement 1703..1709 +| | | | | | | | | | | Expression 1703..1705 +| | | | | | | | | | | | Identifier 1703..1704 +| | | | | | | | | | | | | Identifier 1703..1704 +| | | | | | | | | | | | | | Identifier 1703..1704 "n" +| | | | | | | | | | | | WhiteSpace 1704..1705 +| | | | | | | | | | | | | WhiteSpace 1704..1705 +| | | | | | | | | | | | | | WhiteSpace 1704..1705 " " +| | | | | | | | | | | MulAssign 1705..1707 +| | | | | | | | | | | | MulAssign 1705..1707 "*=" +| | | | | | | | | | | WhiteSpace 1707..1708 +| | | | | | | | | | | | WhiteSpace 1707..1708 +| | | | | | | | | | | | | WhiteSpace 1707..1708 " " +| | | | | | | | | | | Expression 1708..1709 +| | | | | | | | | | | | Number 1708..1709 +| | | | | | | | | | | | | Number 1708..1709 +| | | | | | | | | | | | | | Number 1708..1709 "2" +| | | | | | | | | | Semicolon 1709..1710 +| | | | | | | | | | | Semicolon 1709..1710 ";" +| | | | | | | | | Error 1710..1711 +| | | | | | | | | | Error 1710..1711 +| | | | | | | | | | | Error 1710..1711 "\r" +| | | | | | | | | EndLine 1711..1712 +| | | | | | | | | | EndLine 1711..1712 +| | | | | | | | | | | EndLine 1711..1712 "\n" +| | | | | | | | | WhiteSpace 1712..1716 +| | | | | | | | | | WhiteSpace 1712..1716 +| | | | | | | | | | | WhiteSpace 1712..1716 " " +| | | | | | | | RCurly 1716..1717 +| | | | | | | | | RCurly 1716..1717 "}" +| | | | Error 1717..1718 +| | | | | Error 1717..1718 +| | | | | | Error 1717..1718 "\r" +| | | | EndLine 1718..1719 +| | | | | EndLine 1718..1719 +| | | | | | EndLine 1718..1719 "\n" +| | | | WhiteSpace 1719..1723 +| | | | | WhiteSpace 1719..1723 +| | | | | | WhiteSpace 1719..1723 " " +| | | | Statement 1723..1732 +| | | | | ReturnStatement 1723..1731 +| | | | | | ReturnKw 1723..1729 +| | | | | | | ReturnKw 1723..1729 "return" +| | | | | | WhiteSpace 1729..1730 +| | | | | | | WhiteSpace 1729..1730 +| | | | | | | | WhiteSpace 1729..1730 " " +| | | | | | Expression 1730..1731 +| | | | | | | Identifier 1730..1731 +| | | | | | | | Identifier 1730..1731 +| | | | | | | | | Identifier 1730..1731 "r" +| | | | | Semicolon 1731..1732 +| | | | | | Semicolon 1731..1732 ";" +| | | | Error 1732..1733 +| | | | | Error 1732..1733 +| | | | | | Error 1732..1733 "\r" +| | | | EndLine 1733..1734 +| | | | | EndLine 1733..1734 +| | | | | | EndLine 1733..1734 "\n" +| | | RCurly 1734..1735 +| | | | RCurly 1734..1735 "}" +| Error 1735..1736 +| | Error 1735..1736 +| | | Error 1735..1736 "\r" +| EndLine 1736..1737 +| | EndLine 1736..1737 +| | | EndLine 1736..1737 "\n" +| Error 1737..1738 +| | Error 1737..1738 +| | | Error 1737..1738 "\r" +| EndLine 1738..1739 +| | EndLine 1738..1739 +| | | EndLine 1738..1739 "\n" +| Error 1739..1740 +| | Error 1739..1740 +| | | Error 1739..1740 "\r" +| EndLine 1740..1741 +| | EndLine 1740..1741 +| | | EndLine 1740..1741 "\n" +| TemplateDef 1741..2449 +| | TemplateKw 1741..1749 +| | | TemplateKw 1741..1749 "template" +| | WhiteSpace 1749..1750 +| | | WhiteSpace 1749..1750 +| | | | WhiteSpace 1749..1750 " " +| | TemplateName 1750..1756 +| | | Identifier 1750..1756 +| | | | Identifier 1750..1756 "BinSum" +| | ParameterList 1756..1764 +| | | LParen 1756..1757 +| | | | LParen 1756..1757 "(" +| | | Identifier 1757..1758 +| | | | Identifier 1757..1758 "n" +| | | Comma 1758..1759 +| | | | Comma 1758..1759 "," +| | | WhiteSpace 1759..1760 +| | | | WhiteSpace 1759..1760 +| | | | | WhiteSpace 1759..1760 " " +| | | Identifier 1760..1763 +| | | | Identifier 1760..1763 "ops" +| | | RParen 1763..1764 +| | | | RParen 1763..1764 ")" +| | WhiteSpace 1764..1765 +| | | WhiteSpace 1764..1765 +| | | | WhiteSpace 1764..1765 " " +| | Block 1765..2449 +| | | LCurly 1765..1766 +| | | | LCurly 1765..1766 "{" +| | | Error 1766..1767 +| | | | Error 1766..1767 +| | | | | Error 1766..1767 "\r" +| | | EndLine 1767..1768 +| | | | EndLine 1767..1768 +| | | | | EndLine 1767..1768 "\n" +| | | WhiteSpace 1768..1772 +| | | | WhiteSpace 1768..1772 +| | | | | WhiteSpace 1768..1772 " " +| | | StatementList 1772..2424 +| | | | VarDecl 1772..1803 +| | | | | VarKw 1772..1775 +| | | | | | VarKw 1772..1775 "var" +| | | | | WhiteSpace 1775..1776 +| | | | | | WhiteSpace 1775..1776 +| | | | | | | WhiteSpace 1775..1776 " " +| | | | | Identifier 1776..1780 +| | | | | | Identifier 1776..1780 "nout" +| | | | | WhiteSpace 1780..1781 +| | | | | | WhiteSpace 1780..1781 +| | | | | | | WhiteSpace 1780..1781 " " +| | | | | Assign 1781..1782 +| | | | | | Assign 1781..1782 "=" +| | | | | WhiteSpace 1782..1783 +| | | | | | WhiteSpace 1782..1783 +| | | | | | | WhiteSpace 1782..1783 " " +| | | | | Expression 1783..1803 +| | | | | | Call 1783..1803 +| | | | | | | Identifier 1783..1788 +| | | | | | | | Identifier 1783..1788 +| | | | | | | | | Identifier 1783..1788 "nbits" +| | | | | | | LParen 1788..1789 +| | | | | | | | LParen 1788..1789 "(" +| | | | | | | Expression 1789..1802 +| | | | | | | | Mul 1789..1802 +| | | | | | | | | Expression 1789..1798 +| | | | | | | | | | LParen 1789..1790 +| | | | | | | | | | | LParen 1789..1790 "(" +| | | | | | | | | | Sub 1790..1797 +| | | | | | | | | | | Power 1790..1795 +| | | | | | | | | | | | Number 1790..1791 +| | | | | | | | | | | | | Number 1790..1791 +| | | | | | | | | | | | | | Number 1790..1791 "2" +| | | | | | | | | | | | Power 1791..1793 +| | | | | | | | | | | | | Power 1791..1793 "**" +| | | | | | | | | | | | Identifier 1793..1794 +| | | | | | | | | | | | | Identifier 1793..1794 +| | | | | | | | | | | | | | Identifier 1793..1794 "n" +| | | | | | | | | | | | WhiteSpace 1794..1795 +| | | | | | | | | | | | | WhiteSpace 1794..1795 +| | | | | | | | | | | | | | WhiteSpace 1794..1795 " " +| | | | | | | | | | | Sub 1795..1796 +| | | | | | | | | | | | Sub 1795..1796 "-" +| | | | | | | | | | | Number 1796..1797 +| | | | | | | | | | | | Number 1796..1797 +| | | | | | | | | | | | | Number 1796..1797 "1" +| | | | | | | | | | RParen 1797..1798 +| | | | | | | | | | | RParen 1797..1798 ")" +| | | | | | | | | Mul 1798..1799 +| | | | | | | | | | Mul 1798..1799 "*" +| | | | | | | | | Identifier 1799..1802 +| | | | | | | | | | Identifier 1799..1802 +| | | | | | | | | | | Identifier 1799..1802 "ops" +| | | | | | | RParen 1802..1803 +| | | | | | | | RParen 1802..1803 ")" +| | | | Semicolon 1803..1804 +| | | | | Semicolon 1803..1804 ";" +| | | | Error 1804..1805 +| | | | | Error 1804..1805 +| | | | | | Error 1804..1805 "\r" | | | | EndLine 1805..1806 | | | | | EndLine 1805..1806 | | | | | | EndLine 1805..1806 "\n" -| | | RCurly 1806..1807 -| | | | RCurly 1806..1807 "}" -| EndLine 1807..1808 -| | EndLine 1807..1808 -| | | EndLine 1807..1808 "\n" -| EndLine 1808..1809 -| | EndLine 1808..1809 -| | | EndLine 1808..1809 "\n" -| EndLine 1809..1810 -| | EndLine 1809..1810 -| | | EndLine 1809..1810 "\n" -| TemplateDef 1810..3637 -| | TemplateKw 1810..1818 -| | | TemplateKw 1810..1818 "template" -| | WhiteSpace 1818..1819 -| | | WhiteSpace 1818..1819 -| | | | WhiteSpace 1818..1819 " " -| | TemplateName 1819..1825 -| | | Identifier 1819..1825 -| | | | Identifier 1819..1825 "BinSum" -| | LParen 1825..1826 -| | | LParen 1825..1826 "(" -| | ParameterList 1826..1832 -| | | Identifier 1826..1827 -| | | | Identifier 1826..1827 "n" -| | | Comma 1827..1828 -| | | | Comma 1827..1828 "," -| | | WhiteSpace 1828..1829 -| | | | WhiteSpace 1828..1829 -| | | | | WhiteSpace 1828..1829 " " -| | | Identifier 1829..1832 -| | | | Identifier 1829..1832 "ops" -| | RParen 1832..1833 -| | | RParen 1832..1833 ")" -| | WhiteSpace 1833..1834 -| | | WhiteSpace 1833..1834 -| | | | WhiteSpace 1833..1834 " " -| | Block 1834..3637 -| | | LCurly 1834..1835 -| | | | LCurly 1834..1835 "{" -| | | EndLine 1835..1836 +| | | | WhiteSpace 1806..1810 +| | | | | WhiteSpace 1806..1810 +| | | | | | WhiteSpace 1806..1810 " " +| | | | InputSignalDecl 1810..1833 +| | | | | SignalHeader 1810..1823 +| | | | | | SignalKw 1810..1816 +| | | | | | | SignalKw 1810..1816 "signal" +| | | | | | WhiteSpace 1816..1817 +| | | | | | | WhiteSpace 1816..1817 +| | | | | | | | WhiteSpace 1816..1817 " " +| | | | | | InputKw 1817..1822 +| | | | | | | InputKw 1817..1822 "input" +| | | | | | WhiteSpace 1822..1823 +| | | | | | | WhiteSpace 1822..1823 +| | | | | | | | WhiteSpace 1822..1823 " " +| | | | | Identifier 1823..1825 +| | | | | | Identifier 1823..1825 "in" +| | | | | ArrayQuery 1825..1830 +| | | | | | LBracket 1825..1826 +| | | | | | | LBracket 1825..1826 "[" +| | | | | | Expression 1826..1829 +| | | | | | | Identifier 1826..1829 +| | | | | | | | Identifier 1826..1829 +| | | | | | | | | Identifier 1826..1829 "ops" +| | | | | | RBracket 1829..1830 +| | | | | | | RBracket 1829..1830 "]" +| | | | | ArrayQuery 1830..1833 +| | | | | | LBracket 1830..1831 +| | | | | | | LBracket 1830..1831 "[" +| | | | | | Expression 1831..1832 +| | | | | | | Identifier 1831..1832 +| | | | | | | | Identifier 1831..1832 +| | | | | | | | | Identifier 1831..1832 "n" +| | | | | | RBracket 1832..1833 +| | | | | | | RBracket 1832..1833 "]" +| | | | Semicolon 1833..1834 +| | | | | Semicolon 1833..1834 ";" +| | | | Error 1834..1835 +| | | | | Error 1834..1835 +| | | | | | Error 1834..1835 "\r" | | | | EndLine 1835..1836 -| | | | | EndLine 1835..1836 "\n" -| | | WhiteSpace 1836..1840 +| | | | | EndLine 1835..1836 +| | | | | | EndLine 1835..1836 "\n" | | | | WhiteSpace 1836..1840 -| | | | | WhiteSpace 1836..1840 " " -| | | StatementList 1840..3612 -| | | | VarDecl 1840..1950 -| | | | | VarKw 1840..1843 -| | | | | | VarKw 1840..1843 "var" -| | | | | WhiteSpace 1843..1844 -| | | | | | WhiteSpace 1843..1844 -| | | | | | | WhiteSpace 1843..1844 " " -| | | | | Identifier 1844..1848 -| | | | | | Identifier 1844..1848 "nout" -| | | | | WhiteSpace 1848..1849 -| | | | | | WhiteSpace 1848..1849 -| | | | | | | WhiteSpace 1848..1849 " " -| | | | | Assign 1849..1850 -| | | | | | Assign 1849..1850 "=" -| | | | | WhiteSpace 1850..1851 -| | | | | | WhiteSpace 1850..1851 -| | | | | | | WhiteSpace 1850..1851 " " -| | | | | Expression 1851..1950 -| | | | | | ArrayQuery 1851..1950 -| | | | | | | Call 1851..1917 -| | | | | | | | Identifier 1851..1856 -| | | | | | | | | Identifier 1851..1856 -| | | | | | | | | | Identifier 1851..1856 "nbits" -| | | | | | | | Tuple 1856..1917 -| | | | | | | | | LParen 1856..1857 -| | | | | | | | | | LParen 1856..1857 "(" -| | | | | | | | | Error 1857..1889 -| | | | | | | | | | Error 1857..1889 -| | | | | | | | | | | Error 1857..1889 "expect Identifier but got LParen" -| | | | | | | | | Error 1889..1917 -| | | | | | | | | | Error 1889..1917 -| | | | | | | | | | | Error 1889..1917 "expect RParen but got LParen" -| | | | | | | LParen 1917..1918 -| | | | | | | | LParen 1917..1918 "(" -| | | | | | | Error 1918..1950 -| | | | | | | | Error 1918..1950 -| | | | | | | | | Error 1918..1950 "expect Identifier but got Number" -| | | | Error 1950..1981 -| | | | | Error 1950..1981 -| | | | | | Error 1950..1981 "expect Semicolon but got Number" -| | | | Statement 1981..2019 -| | | | | Error 1981..1988 -| | | | | | Expression 1981..1988 -| | | | | | | Sub 1981..1988 -| | | | | | | | Power 1981..1986 -| | | | | | | | | Number 1981..1982 -| | | | | | | | | | Number 1981..1982 -| | | | | | | | | | | Number 1981..1982 "2" -| | | | | | | | | Power 1982..1984 -| | | | | | | | | | Power 1982..1984 "**" -| | | | | | | | | Identifier 1984..1985 -| | | | | | | | | | Identifier 1984..1985 -| | | | | | | | | | | Identifier 1984..1985 "n" -| | | | | | | | | WhiteSpace 1985..1986 -| | | | | | | | | | WhiteSpace 1985..1986 -| | | | | | | | | | | WhiteSpace 1985..1986 " " -| | | | | | | | Sub 1986..1987 -| | | | | | | | | Sub 1986..1987 "-" -| | | | | | | | Number 1987..1988 -| | | | | | | | | Number 1987..1988 -| | | | | | | | | | Number 1987..1988 "1" -| | | | | Error 1988..2019 -| | | | | | Error 1988..2019 -| | | | | | | Error 1988..2019 "expect Semicolon but got RParen" -| | | | Statement 2019..2048 -| | | | | Error 2019..2020 -| | | | | | Expression 2019..2020 -| | | | | | | Error 2019..2020 -| | | | | | | | RParen 2019..2020 -| | | | | | | | | RParen 2019..2020 ")" -| | | | | Error 2020..2048 -| | | | | | Error 2020..2048 -| | | | | | | Error 2020..2048 "expect Semicolon but got Mul" -| | | | Statement 2048..2084 -| | | | | Error 2048..2049 -| | | | | | Expression 2048..2049 -| | | | | | | Error 2048..2049 -| | | | | | | | Mul 2048..2049 -| | | | | | | | | Mul 2048..2049 "*" -| | | | | Error 2049..2084 -| | | | | | Error 2049..2084 -| | | | | | | Error 2049..2084 "expect Semicolon but got Identifier" -| | | | Statement 2084..2118 -| | | | | Error 2084..2087 -| | | | | | Expression 2084..2087 -| | | | | | | ComponentIdentifier 2084..2087 -| | | | | | | | Identifier 2084..2087 -| | | | | | | | | Identifier 2084..2087 "ops" -| | | | | Error 2087..2118 -| | | | | | Error 2087..2118 -| | | | | | | Error 2087..2118 "expect Semicolon but got RParen" -| | | | Statement 2118..2120 -| | | | | Error 2118..2119 -| | | | | | Expression 2118..2119 -| | | | | | | Error 2118..2119 -| | | | | | | | RParen 2118..2119 -| | | | | | | | | RParen 2118..2119 ")" -| | | | | Semicolon 2119..2120 -| | | | | | Semicolon 2119..2120 ";" -| | | | EndLine 2120..2121 -| | | | | EndLine 2120..2121 -| | | | | | EndLine 2120..2121 "\n" -| | | | WhiteSpace 2121..2125 -| | | | | WhiteSpace 2121..2125 -| | | | | | WhiteSpace 2121..2125 " " -| | | | InputSignalDecl 2125..2140 -| | | | | SignalHeader 2125..2138 -| | | | | | SignalKw 2125..2131 -| | | | | | | SignalKw 2125..2131 "signal" -| | | | | | WhiteSpace 2131..2132 -| | | | | | | WhiteSpace 2131..2132 -| | | | | | | | WhiteSpace 2131..2132 " " -| | | | | | InputKw 2132..2137 -| | | | | | | InputKw 2132..2137 "input" -| | | | | | WhiteSpace 2137..2138 -| | | | | | | WhiteSpace 2137..2138 -| | | | | | | | WhiteSpace 2137..2138 " " -| | | | | Identifier 2138..2140 -| | | | | | Identifier 2138..2140 "in" -| | | | Error 2140..2173 -| | | | | Error 2140..2173 -| | | | | | Error 2140..2173 "expect Semicolon but got LBracket" -| | | | Statement 2173..2209 -| | | | | Error 2173..2174 -| | | | | | Expression 2173..2174 -| | | | | | | Error 2173..2174 -| | | | | | | | LBracket 2173..2174 -| | | | | | | | | LBracket 2173..2174 "[" -| | | | | Error 2174..2209 -| | | | | | Error 2174..2209 -| | | | | | | Error 2174..2209 "expect Semicolon but got Identifier" -| | | | Statement 2209..2245 -| | | | | Error 2209..2212 -| | | | | | Expression 2209..2212 -| | | | | | | ComponentIdentifier 2209..2212 -| | | | | | | | Identifier 2209..2212 -| | | | | | | | | Identifier 2209..2212 "ops" -| | | | | Error 2212..2245 -| | | | | | Error 2212..2245 -| | | | | | | Error 2212..2245 "expect Semicolon but got RBracket" -| | | | Statement 2245..2279 -| | | | | Error 2245..2246 -| | | | | | Expression 2245..2246 -| | | | | | | Error 2245..2246 -| | | | | | | | RBracket 2245..2246 -| | | | | | | | | RBracket 2245..2246 "]" -| | | | | Error 2246..2279 -| | | | | | Error 2246..2279 -| | | | | | | Error 2246..2279 "expect Semicolon but got LBracket" -| | | | Statement 2279..2315 -| | | | | Error 2279..2280 -| | | | | | Expression 2279..2280 -| | | | | | | Error 2279..2280 -| | | | | | | | LBracket 2279..2280 -| | | | | | | | | LBracket 2279..2280 "[" -| | | | | Error 2280..2315 -| | | | | | Error 2280..2315 -| | | | | | | Error 2280..2315 "expect Semicolon but got Identifier" -| | | | Statement 2315..2349 -| | | | | Error 2315..2316 -| | | | | | Expression 2315..2316 -| | | | | | | ComponentIdentifier 2315..2316 -| | | | | | | | Identifier 2315..2316 -| | | | | | | | | Identifier 2315..2316 "n" -| | | | | Error 2316..2349 -| | | | | | Error 2316..2349 -| | | | | | | Error 2316..2349 "expect Semicolon but got RBracket" -| | | | Statement 2349..2351 -| | | | | Error 2349..2350 -| | | | | | Expression 2349..2350 -| | | | | | | Error 2349..2350 -| | | | | | | | RBracket 2349..2350 -| | | | | | | | | RBracket 2349..2350 "]" -| | | | | Semicolon 2350..2351 -| | | | | | Semicolon 2350..2351 ";" -| | | | EndLine 2351..2352 -| | | | | EndLine 2351..2352 -| | | | | | EndLine 2351..2352 "\n" -| | | | WhiteSpace 2352..2356 -| | | | | WhiteSpace 2352..2356 -| | | | | | WhiteSpace 2352..2356 " " -| | | | OutputSignalDecl 2356..2373 -| | | | | SignalHeader 2356..2370 -| | | | | | SignalKw 2356..2362 -| | | | | | | SignalKw 2356..2362 "signal" -| | | | | | WhiteSpace 2362..2363 -| | | | | | | WhiteSpace 2362..2363 -| | | | | | | | WhiteSpace 2362..2363 " " -| | | | | | OutputKw 2363..2369 -| | | | | | | OutputKw 2363..2369 "output" -| | | | | | WhiteSpace 2369..2370 -| | | | | | | WhiteSpace 2369..2370 -| | | | | | | | WhiteSpace 2369..2370 " " -| | | | | Identifier 2370..2373 -| | | | | | Identifier 2370..2373 "out" -| | | | Error 2373..2406 -| | | | | Error 2373..2406 -| | | | | | Error 2373..2406 "expect Semicolon but got LBracket" -| | | | Statement 2406..2442 -| | | | | Error 2406..2407 -| | | | | | Expression 2406..2407 -| | | | | | | Error 2406..2407 -| | | | | | | | LBracket 2406..2407 -| | | | | | | | | LBracket 2406..2407 "[" -| | | | | Error 2407..2442 -| | | | | | Error 2407..2442 -| | | | | | | Error 2407..2442 "expect Semicolon but got Identifier" -| | | | Statement 2442..2479 -| | | | | Error 2442..2446 -| | | | | | Expression 2442..2446 -| | | | | | | ComponentIdentifier 2442..2446 -| | | | | | | | Identifier 2442..2446 -| | | | | | | | | Identifier 2442..2446 "nout" -| | | | | Error 2446..2479 -| | | | | | Error 2446..2479 -| | | | | | | Error 2446..2479 "expect Semicolon but got RBracket" -| | | | Statement 2479..2481 -| | | | | Error 2479..2480 -| | | | | | Expression 2479..2480 -| | | | | | | Error 2479..2480 -| | | | | | | | RBracket 2479..2480 -| | | | | | | | | RBracket 2479..2480 "]" -| | | | | Semicolon 2480..2481 -| | | | | | Semicolon 2480..2481 ";" -| | | | EndLine 2481..2482 -| | | | | EndLine 2481..2482 -| | | | | | EndLine 2481..2482 "\n" -| | | | EndLine 2482..2483 -| | | | | EndLine 2482..2483 -| | | | | | EndLine 2482..2483 "\n" -| | | | WhiteSpace 2483..2487 -| | | | | WhiteSpace 2483..2487 -| | | | | | WhiteSpace 2483..2487 " " -| | | | VarDecl 2487..2498 -| | | | | VarKw 2487..2490 -| | | | | | VarKw 2487..2490 "var" -| | | | | WhiteSpace 2490..2491 -| | | | | | WhiteSpace 2490..2491 -| | | | | | | WhiteSpace 2490..2491 " " -| | | | | Identifier 2491..2494 -| | | | | | Identifier 2491..2494 "lin" -| | | | | WhiteSpace 2494..2495 -| | | | | | WhiteSpace 2494..2495 -| | | | | | | WhiteSpace 2494..2495 " " -| | | | | Assign 2495..2496 -| | | | | | Assign 2495..2496 "=" -| | | | | WhiteSpace 2496..2497 -| | | | | | WhiteSpace 2496..2497 -| | | | | | | WhiteSpace 2496..2497 " " -| | | | | Expression 2497..2498 -| | | | | | Number 2497..2498 -| | | | | | | Number 2497..2498 -| | | | | | | | Number 2497..2498 "0" -| | | | Semicolon 2498..2499 -| | | | | Semicolon 2498..2499 ";" -| | | | EndLine 2499..2500 -| | | | | EndLine 2499..2500 -| | | | | | EndLine 2499..2500 "\n" -| | | | WhiteSpace 2500..2504 -| | | | | WhiteSpace 2500..2504 -| | | | | | WhiteSpace 2500..2504 " " -| | | | VarDecl 2504..2516 -| | | | | VarKw 2504..2507 -| | | | | | VarKw 2504..2507 "var" -| | | | | WhiteSpace 2507..2508 -| | | | | | WhiteSpace 2507..2508 -| | | | | | | WhiteSpace 2507..2508 " " -| | | | | Identifier 2508..2512 -| | | | | | Identifier 2508..2512 "lout" -| | | | | WhiteSpace 2512..2513 -| | | | | | WhiteSpace 2512..2513 -| | | | | | | WhiteSpace 2512..2513 " " -| | | | | Assign 2513..2514 -| | | | | | Assign 2513..2514 "=" -| | | | | WhiteSpace 2514..2515 -| | | | | | WhiteSpace 2514..2515 -| | | | | | | WhiteSpace 2514..2515 " " -| | | | | Expression 2515..2516 -| | | | | | Number 2515..2516 -| | | | | | | Number 2515..2516 -| | | | | | | | Number 2515..2516 "0" -| | | | Semicolon 2516..2517 -| | | | | Semicolon 2516..2517 ";" -| | | | EndLine 2517..2518 -| | | | | EndLine 2517..2518 -| | | | | | EndLine 2517..2518 "\n" -| | | | EndLine 2518..2519 -| | | | | EndLine 2518..2519 -| | | | | | EndLine 2518..2519 "\n" -| | | | WhiteSpace 2519..2523 -| | | | | WhiteSpace 2519..2523 -| | | | | | WhiteSpace 2519..2523 " " -| | | | VarDecl 2523..2528 -| | | | | VarKw 2523..2526 -| | | | | | VarKw 2523..2526 "var" -| | | | | WhiteSpace 2526..2527 -| | | | | | WhiteSpace 2526..2527 -| | | | | | | WhiteSpace 2526..2527 " " -| | | | | Identifier 2527..2528 -| | | | | | Identifier 2527..2528 "k" -| | | | Semicolon 2528..2529 -| | | | | Semicolon 2528..2529 ";" -| | | | EndLine 2529..2530 -| | | | | EndLine 2529..2530 -| | | | | | EndLine 2529..2530 "\n" -| | | | WhiteSpace 2530..2534 -| | | | | WhiteSpace 2530..2534 -| | | | | | WhiteSpace 2530..2534 " " -| | | | VarDecl 2534..2539 -| | | | | VarKw 2534..2537 -| | | | | | VarKw 2534..2537 "var" -| | | | | WhiteSpace 2537..2538 -| | | | | | WhiteSpace 2537..2538 -| | | | | | | WhiteSpace 2537..2538 " " -| | | | | Identifier 2538..2539 -| | | | | | Identifier 2538..2539 "j" -| | | | Semicolon 2539..2540 -| | | | | Semicolon 2539..2540 ";" -| | | | EndLine 2540..2541 -| | | | | EndLine 2540..2541 -| | | | | | EndLine 2540..2541 "\n" -| | | | EndLine 2541..2542 -| | | | | EndLine 2541..2542 -| | | | | | EndLine 2541..2542 "\n" -| | | | WhiteSpace 2542..2546 -| | | | | WhiteSpace 2542..2546 -| | | | | | WhiteSpace 2542..2546 " " -| | | | VarDecl 2546..2552 -| | | | | VarKw 2546..2549 -| | | | | | VarKw 2546..2549 "var" -| | | | | WhiteSpace 2549..2550 -| | | | | | WhiteSpace 2549..2550 -| | | | | | | WhiteSpace 2549..2550 " " -| | | | | Identifier 2550..2552 -| | | | | | Identifier 2550..2552 "e2" -| | | | Semicolon 2552..2553 -| | | | | Semicolon 2552..2553 ";" -| | | | EndLine 2553..2554 -| | | | | EndLine 2553..2554 -| | | | | | EndLine 2553..2554 "\n" -| | | | EndLine 2554..2555 -| | | | | EndLine 2554..2555 -| | | | | | EndLine 2554..2555 "\n" -| | | | WhiteSpace 2555..2559 -| | | | | WhiteSpace 2555..2559 -| | | | | | WhiteSpace 2555..2559 " " -| | | | Statement 2559..2566 -| | | | | AssignStatement 2559..2565 -| | | | | | Expression 2559..2562 -| | | | | | | ComponentIdentifier 2559..2561 -| | | | | | | | Identifier 2559..2561 -| | | | | | | | | Identifier 2559..2561 "e2" -| | | | | | | WhiteSpace 2561..2562 -| | | | | | | | WhiteSpace 2561..2562 -| | | | | | | | | WhiteSpace 2561..2562 " " -| | | | | | Assign 2562..2563 -| | | | | | | Assign 2562..2563 "=" -| | | | | | WhiteSpace 2563..2564 -| | | | | | | WhiteSpace 2563..2564 -| | | | | | | | WhiteSpace 2563..2564 " " -| | | | | | Expression 2564..2565 -| | | | | | | Number 2564..2565 -| | | | | | | | Number 2564..2565 -| | | | | | | | | Number 2564..2565 "1" -| | | | | Semicolon 2565..2566 -| | | | | | Semicolon 2565..2566 ";" -| | | | EndLine 2566..2567 -| | | | | EndLine 2566..2567 -| | | | | | EndLine 2566..2567 "\n" -| | | | WhiteSpace 2567..2571 -| | | | | WhiteSpace 2567..2571 -| | | | | | WhiteSpace 2567..2571 " " -| | | | Statement 2571..2651 -| | | | | ForLoop 2571..2651 -| | | | | | ForKw 2571..2574 -| | | | | | | ForKw 2571..2574 "for" -| | | | | | WhiteSpace 2574..2575 -| | | | | | | WhiteSpace 2574..2575 -| | | | | | | | WhiteSpace 2574..2575 " " -| | | | | | LParen 2575..2576 -| | | | | | | LParen 2575..2576 "(" -| | | | | | AssignStatement 2576..2579 -| | | | | | | Expression 2576..2577 -| | | | | | | | ComponentIdentifier 2576..2577 -| | | | | | | | | Identifier 2576..2577 -| | | | | | | | | | Identifier 2576..2577 "k" -| | | | | | | Assign 2577..2578 -| | | | | | | | Assign 2577..2578 "=" -| | | | | | | Expression 2578..2579 -| | | | | | | | Number 2578..2579 -| | | | | | | | | Number 2578..2579 -| | | | | | | | | | Number 2578..2579 "0" -| | | | | | Semicolon 2579..2580 -| | | | | | | Semicolon 2579..2580 ";" -| | | | | | WhiteSpace 2580..2581 -| | | | | | | WhiteSpace 2580..2581 -| | | | | | | | WhiteSpace 2580..2581 " " -| | | | | | Expression 2581..2584 -| | | | | | | LessThan 2581..2584 -| | | | | | | | Identifier 2581..2582 -| | | | | | | | | Identifier 2581..2582 -| | | | | | | | | | Identifier 2581..2582 "k" -| | | | | | | | LessThan 2582..2583 -| | | | | | | | | LessThan 2582..2583 "<" -| | | | | | | | Identifier 2583..2584 -| | | | | | | | | Identifier 2583..2584 -| | | | | | | | | | Identifier 2583..2584 "n" -| | | | | | Semicolon 2584..2585 -| | | | | | | Semicolon 2584..2585 ";" -| | | | | | WhiteSpace 2585..2586 -| | | | | | | WhiteSpace 2585..2586 -| | | | | | | | WhiteSpace 2585..2586 " " -| | | | | | Error 2586..2587 -| | | | | | | Expression 2586..2587 -| | | | | | | | ComponentIdentifier 2586..2587 -| | | | | | | | | Identifier 2586..2587 -| | | | | | | | | | Identifier 2586..2587 "k" -| | | | | | Error 2587..2616 -| | | | | | | Error 2587..2616 -| | | | | | | | Error 2587..2616 "expect RParen but got UnitInc" -| | | | | | Error 2616..2620 -| | | | | | | Expression 2616..2620 -| | | | | | | | UnitInc 2616..2619 -| | | | | | | | | UnitInc 2616..2618 -| | | | | | | | | | UnitInc 2616..2618 "++" -| | | | | | | | | Error 2618..2619 -| | | | | | | | | | RParen 2618..2619 -| | | | | | | | | | | RParen 2618..2619 ")" -| | | | | | | | WhiteSpace 2619..2620 -| | | | | | | | | WhiteSpace 2619..2620 -| | | | | | | | | | WhiteSpace 2619..2620 " " -| | | | | | Error 2620..2651 -| | | | | | | Error 2620..2651 -| | | | | | | | Error 2620..2651 "expect Semicolon but got LCurly" -| | | | Statement 2651..3611 -| | | | | Block 2651..3611 -| | | | | | LCurly 2651..2652 -| | | | | | | LCurly 2651..2652 "{" -| | | | | | EndLine 2652..2653 -| | | | | | | EndLine 2652..2653 -| | | | | | | | EndLine 2652..2653 "\n" -| | | | | | WhiteSpace 2653..2661 -| | | | | | | WhiteSpace 2653..2661 -| | | | | | | | WhiteSpace 2653..2661 " " -| | | | | | StatementList 2661..3610 -| | | | | | | Statement 2661..2743 -| | | | | | | | ForLoop 2661..2743 -| | | | | | | | | ForKw 2661..2664 -| | | | | | | | | | ForKw 2661..2664 "for" -| | | | | | | | | WhiteSpace 2664..2665 -| | | | | | | | | | WhiteSpace 2664..2665 -| | | | | | | | | | | WhiteSpace 2664..2665 " " -| | | | | | | | | LParen 2665..2666 -| | | | | | | | | | LParen 2665..2666 "(" -| | | | | | | | | AssignStatement 2666..2669 -| | | | | | | | | | Expression 2666..2667 -| | | | | | | | | | | ComponentIdentifier 2666..2667 -| | | | | | | | | | | | Identifier 2666..2667 -| | | | | | | | | | | | | Identifier 2666..2667 "j" -| | | | | | | | | | Assign 2667..2668 -| | | | | | | | | | | Assign 2667..2668 "=" -| | | | | | | | | | Expression 2668..2669 -| | | | | | | | | | | Number 2668..2669 -| | | | | | | | | | | | Number 2668..2669 -| | | | | | | | | | | | | Number 2668..2669 "0" -| | | | | | | | | Semicolon 2669..2670 -| | | | | | | | | | Semicolon 2669..2670 ";" -| | | | | | | | | WhiteSpace 2670..2671 -| | | | | | | | | | WhiteSpace 2670..2671 -| | | | | | | | | | | WhiteSpace 2670..2671 " " -| | | | | | | | | Expression 2671..2676 -| | | | | | | | | | LessThan 2671..2676 -| | | | | | | | | | | Identifier 2671..2672 -| | | | | | | | | | | | Identifier 2671..2672 -| | | | | | | | | | | | | Identifier 2671..2672 "j" -| | | | | | | | | | | LessThan 2672..2673 -| | | | | | | | | | | | LessThan 2672..2673 "<" -| | | | | | | | | | | Identifier 2673..2676 -| | | | | | | | | | | | Identifier 2673..2676 -| | | | | | | | | | | | | Identifier 2673..2676 "ops" -| | | | | | | | | Semicolon 2676..2677 -| | | | | | | | | | Semicolon 2676..2677 ";" -| | | | | | | | | WhiteSpace 2677..2678 -| | | | | | | | | | WhiteSpace 2677..2678 -| | | | | | | | | | | WhiteSpace 2677..2678 " " -| | | | | | | | | Error 2678..2679 -| | | | | | | | | | Expression 2678..2679 -| | | | | | | | | | | ComponentIdentifier 2678..2679 -| | | | | | | | | | | | Identifier 2678..2679 -| | | | | | | | | | | | | Identifier 2678..2679 "j" -| | | | | | | | | Error 2679..2708 -| | | | | | | | | | Error 2679..2708 -| | | | | | | | | | | Error 2679..2708 "expect RParen but got UnitInc" -| | | | | | | | | Error 2708..2712 -| | | | | | | | | | Expression 2708..2712 -| | | | | | | | | | | UnitInc 2708..2711 -| | | | | | | | | | | | UnitInc 2708..2710 -| | | | | | | | | | | | | UnitInc 2708..2710 "++" -| | | | | | | | | | | | Error 2710..2711 -| | | | | | | | | | | | | RParen 2710..2711 -| | | | | | | | | | | | | | RParen 2710..2711 ")" -| | | | | | | | | | | WhiteSpace 2711..2712 -| | | | | | | | | | | | WhiteSpace 2711..2712 -| | | | | | | | | | | | | WhiteSpace 2711..2712 " " -| | | | | | | | | Error 2712..2743 -| | | | | | | | | | Error 2712..2743 -| | | | | | | | | | | Error 2712..2743 "expect Semicolon but got LCurly" -| | | | | | | Statement 2743..3021 -| | | | | | | | Block 2743..3021 -| | | | | | | | | LCurly 2743..2744 -| | | | | | | | | | LCurly 2743..2744 "{" -| | | | | | | | | EndLine 2744..2745 -| | | | | | | | | | EndLine 2744..2745 -| | | | | | | | | | | EndLine 2744..2745 "\n" -| | | | | | | | | WhiteSpace 2745..2757 -| | | | | | | | | | WhiteSpace 2745..2757 -| | | | | | | | | | | WhiteSpace 2745..2757 " " -| | | | | | | | | StatementList 2757..3020 -| | | | | | | | | | Statement 2757..2795 -| | | | | | | | | | | Error 2757..2761 -| | | | | | | | | | | | Expression 2757..2761 -| | | | | | | | | | | | | ComponentIdentifier 2757..2760 -| | | | | | | | | | | | | | Identifier 2757..2760 -| | | | | | | | | | | | | | | Identifier 2757..2760 "lin" -| | | | | | | | | | | | | WhiteSpace 2760..2761 -| | | | | | | | | | | | | | WhiteSpace 2760..2761 -| | | | | | | | | | | | | | | WhiteSpace 2760..2761 " " -| | | | | | | | | | | Error 2761..2795 -| | | | | | | | | | | | Error 2761..2795 -| | | | | | | | | | | | | Error 2761..2795 "expect Semicolon but got AddAssign" -| | | | | | | | | | Statement 2795..2833 -| | | | | | | | | | | Error 2795..2798 -| | | | | | | | | | | | Expression 2795..2797 -| | | | | | | | | | | | | Error 2795..2797 -| | | | | | | | | | | | | | AddAssign 2795..2797 -| | | | | | | | | | | | | | | AddAssign 2795..2797 "+=" -| | | | | | | | | | | | WhiteSpace 2797..2798 -| | | | | | | | | | | | | WhiteSpace 2797..2798 -| | | | | | | | | | | | | | WhiteSpace 2797..2798 " " -| | | | | | | | | | | Error 2798..2833 -| | | | | | | | | | | | Error 2798..2833 -| | | | | | | | | | | | | Error 2798..2833 "expect Semicolon but got Identifier" -| | | | | | | | | | Statement 2833..2871 -| | | | | | | | | | | Error 2833..2838 -| | | | | | | | | | | | Expression 2833..2838 -| | | | | | | | | | | | | ComponentIdentifier 2833..2835 -| | | | | | | | | | | | | | Identifier 2833..2835 -| | | | | | | | | | | | | | | Identifier 2833..2835 "in" -| | | | | | | | | | | | | LBracket 2835..2836 -| | | | | | | | | | | | | | LBracket 2835..2836 "[" -| | | | | | | | | | | | | Expression 2836..2837 -| | | | | | | | | | | | | | Identifier 2836..2837 -| | | | | | | | | | | | | | | Identifier 2836..2837 -| | | | | | | | | | | | | | | | Identifier 2836..2837 "j" -| | | | | | | | | | | | | RBracket 2837..2838 -| | | | | | | | | | | | | | RBracket 2837..2838 "]" -| | | | | | | | | | | Error 2838..2871 -| | | | | | | | | | | | Error 2838..2871 -| | | | | | | | | | | | | Error 2838..2871 "expect Semicolon but got LBracket" -| | | | | | | | | | Statement 2871..2907 -| | | | | | | | | | | Error 2871..2872 -| | | | | | | | | | | | Expression 2871..2872 -| | | | | | | | | | | | | Error 2871..2872 -| | | | | | | | | | | | | | LBracket 2871..2872 -| | | | | | | | | | | | | | | LBracket 2871..2872 "[" -| | | | | | | | | | | Error 2872..2907 -| | | | | | | | | | | | Error 2872..2907 -| | | | | | | | | | | | | Error 2872..2907 "expect Semicolon but got Identifier" -| | | | | | | | | | Statement 2907..2941 -| | | | | | | | | | | Error 2907..2908 -| | | | | | | | | | | | Expression 2907..2908 -| | | | | | | | | | | | | ComponentIdentifier 2907..2908 -| | | | | | | | | | | | | | Identifier 2907..2908 -| | | | | | | | | | | | | | | Identifier 2907..2908 "k" -| | | | | | | | | | | Error 2908..2941 -| | | | | | | | | | | | Error 2908..2941 -| | | | | | | | | | | | | Error 2908..2941 "expect Semicolon but got RBracket" -| | | | | | | | | | Statement 2941..2971 -| | | | | | | | | | | Error 2941..2943 -| | | | | | | | | | | | Expression 2941..2942 -| | | | | | | | | | | | | Error 2941..2942 -| | | | | | | | | | | | | | RBracket 2941..2942 -| | | | | | | | | | | | | | | RBracket 2941..2942 "]" -| | | | | | | | | | | | WhiteSpace 2942..2943 -| | | | | | | | | | | | | WhiteSpace 2942..2943 -| | | | | | | | | | | | | | WhiteSpace 2942..2943 " " -| | | | | | | | | | | Error 2943..2971 -| | | | | | | | | | | | Error 2943..2971 -| | | | | | | | | | | | | Error 2943..2971 "expect Semicolon but got Mul" -| | | | | | | | | | Statement 2971..3008 -| | | | | | | | | | | Error 2971..2973 -| | | | | | | | | | | | Expression 2971..2972 -| | | | | | | | | | | | | Error 2971..2972 -| | | | | | | | | | | | | | Mul 2971..2972 -| | | | | | | | | | | | | | | Mul 2971..2972 "*" -| | | | | | | | | | | | WhiteSpace 2972..2973 -| | | | | | | | | | | | | WhiteSpace 2972..2973 -| | | | | | | | | | | | | | WhiteSpace 2972..2973 " " -| | | | | | | | | | | Error 2973..3008 -| | | | | | | | | | | | Error 2973..3008 -| | | | | | | | | | | | | Error 2973..3008 "expect Semicolon but got Identifier" -| | | | | | | | | | Statement 3008..3011 -| | | | | | | | | | | Error 3008..3010 -| | | | | | | | | | | | Expression 3008..3010 -| | | | | | | | | | | | | ComponentIdentifier 3008..3010 -| | | | | | | | | | | | | | Identifier 3008..3010 -| | | | | | | | | | | | | | | Identifier 3008..3010 "e2" -| | | | | | | | | | | Semicolon 3010..3011 -| | | | | | | | | | | | Semicolon 3010..3011 ";" -| | | | | | | | | | EndLine 3011..3012 -| | | | | | | | | | | EndLine 3011..3012 -| | | | | | | | | | | | EndLine 3011..3012 "\n" -| | | | | | | | | | WhiteSpace 3012..3020 -| | | | | | | | | | | WhiteSpace 3012..3020 -| | | | | | | | | | | | WhiteSpace 3012..3020 " " -| | | | | | | | | RCurly 3020..3021 -| | | | | | | | | | RCurly 3020..3021 "}" -| | | | | | | EndLine 3021..3022 -| | | | | | | | EndLine 3021..3022 -| | | | | | | | | EndLine 3021..3022 "\n" -| | | | | | | WhiteSpace 3022..3030 -| | | | | | | | WhiteSpace 3022..3030 -| | | | | | | | | WhiteSpace 3022..3030 " " -| | | | | | | Statement 3030..3043 -| | | | | | | | AssignStatement 3030..3042 -| | | | | | | | | Expression 3030..3033 -| | | | | | | | | | ComponentIdentifier 3030..3032 -| | | | | | | | | | | Identifier 3030..3032 -| | | | | | | | | | | | Identifier 3030..3032 "e2" -| | | | | | | | | | WhiteSpace 3032..3033 -| | | | | | | | | | | WhiteSpace 3032..3033 -| | | | | | | | | | | | WhiteSpace 3032..3033 " " -| | | | | | | | | Assign 3033..3034 -| | | | | | | | | | Assign 3033..3034 "=" -| | | | | | | | | WhiteSpace 3034..3035 -| | | | | | | | | | WhiteSpace 3034..3035 -| | | | | | | | | | | WhiteSpace 3034..3035 " " -| | | | | | | | | Expression 3035..3042 -| | | | | | | | | | Add 3035..3042 -| | | | | | | | | | | Identifier 3035..3037 -| | | | | | | | | | | | Identifier 3035..3037 -| | | | | | | | | | | | | Identifier 3035..3037 "e2" -| | | | | | | | | | | WhiteSpace 3037..3038 -| | | | | | | | | | | | WhiteSpace 3037..3038 -| | | | | | | | | | | | | WhiteSpace 3037..3038 " " -| | | | | | | | | | | Add 3038..3039 -| | | | | | | | | | | | Add 3038..3039 "+" -| | | | | | | | | | | WhiteSpace 3039..3040 -| | | | | | | | | | | | WhiteSpace 3039..3040 -| | | | | | | | | | | | | WhiteSpace 3039..3040 " " -| | | | | | | | | | | Identifier 3040..3042 -| | | | | | | | | | | | Identifier 3040..3042 -| | | | | | | | | | | | | Identifier 3040..3042 "e2" -| | | | | | | | Semicolon 3042..3043 -| | | | | | | | | Semicolon 3042..3043 ";" -| | | | | | | EndLine 3043..3044 -| | | | | | | | EndLine 3043..3044 -| | | | | | | | | EndLine 3043..3044 "\n" -| | | | | | | WhiteSpace 3044..3048 -| | | | | | | | WhiteSpace 3044..3048 -| | | | | | | | | WhiteSpace 3044..3048 " " -| | | | | | | EndLine 3048..3049 -| | | | | | | | EndLine 3048..3049 -| | | | | | | | | EndLine 3048..3049 "\n" -| | | | | | | WhiteSpace 3049..3057 -| | | | | | | | WhiteSpace 3049..3057 -| | | | | | | | | WhiteSpace 3049..3057 " " -| | | | | | | Statement 3057..3064 -| | | | | | | | AssignStatement 3057..3063 -| | | | | | | | | Expression 3057..3060 -| | | | | | | | | | ComponentIdentifier 3057..3059 -| | | | | | | | | | | Identifier 3057..3059 -| | | | | | | | | | | | Identifier 3057..3059 "e2" -| | | | | | | | | | WhiteSpace 3059..3060 -| | | | | | | | | | | WhiteSpace 3059..3060 -| | | | | | | | | | | | WhiteSpace 3059..3060 " " -| | | | | | | | | Assign 3060..3061 -| | | | | | | | | | Assign 3060..3061 "=" -| | | | | | | | | WhiteSpace 3061..3062 -| | | | | | | | | | WhiteSpace 3061..3062 -| | | | | | | | | | | WhiteSpace 3061..3062 " " -| | | | | | | | | Expression 3062..3063 -| | | | | | | | | | Number 3062..3063 -| | | | | | | | | | | Number 3062..3063 -| | | | | | | | | | | | Number 3062..3063 "1" -| | | | | | | | Semicolon 3063..3064 -| | | | | | | | | Semicolon 3063..3064 ";" -| | | | | | | EndLine 3064..3065 -| | | | | | | | EndLine 3064..3065 -| | | | | | | | | EndLine 3064..3065 "\n" -| | | | | | | WhiteSpace 3065..3073 -| | | | | | | | WhiteSpace 3065..3073 -| | | | | | | | | WhiteSpace 3065..3073 " " -| | | | | | | Statement 3073..3156 -| | | | | | | | ForLoop 3073..3156 -| | | | | | | | | ForKw 3073..3076 -| | | | | | | | | | ForKw 3073..3076 "for" -| | | | | | | | | WhiteSpace 3076..3077 -| | | | | | | | | | WhiteSpace 3076..3077 -| | | | | | | | | | | WhiteSpace 3076..3077 " " -| | | | | | | | | LParen 3077..3078 -| | | | | | | | | | LParen 3077..3078 "(" -| | | | | | | | | AssignStatement 3078..3081 -| | | | | | | | | | Expression 3078..3079 -| | | | | | | | | | | ComponentIdentifier 3078..3079 -| | | | | | | | | | | | Identifier 3078..3079 -| | | | | | | | | | | | | Identifier 3078..3079 "k" -| | | | | | | | | | Assign 3079..3080 -| | | | | | | | | | | Assign 3079..3080 "=" -| | | | | | | | | | Expression 3080..3081 -| | | | | | | | | | | Number 3080..3081 -| | | | | | | | | | | | Number 3080..3081 -| | | | | | | | | | | | | Number 3080..3081 "0" -| | | | | | | | | Semicolon 3081..3082 -| | | | | | | | | | Semicolon 3081..3082 ";" -| | | | | | | | | WhiteSpace 3082..3083 -| | | | | | | | | | WhiteSpace 3082..3083 -| | | | | | | | | | | WhiteSpace 3082..3083 " " -| | | | | | | | | Expression 3083..3089 -| | | | | | | | | | LessThan 3083..3089 -| | | | | | | | | | | Identifier 3083..3084 -| | | | | | | | | | | | Identifier 3083..3084 -| | | | | | | | | | | | | Identifier 3083..3084 "k" -| | | | | | | | | | | LessThan 3084..3085 -| | | | | | | | | | | | LessThan 3084..3085 "<" -| | | | | | | | | | | Identifier 3085..3089 -| | | | | | | | | | | | Identifier 3085..3089 -| | | | | | | | | | | | | Identifier 3085..3089 "nout" -| | | | | | | | | Semicolon 3089..3090 -| | | | | | | | | | Semicolon 3089..3090 ";" -| | | | | | | | | WhiteSpace 3090..3091 -| | | | | | | | | | WhiteSpace 3090..3091 -| | | | | | | | | | | WhiteSpace 3090..3091 " " -| | | | | | | | | Error 3091..3092 -| | | | | | | | | | Expression 3091..3092 -| | | | | | | | | | | ComponentIdentifier 3091..3092 -| | | | | | | | | | | | Identifier 3091..3092 -| | | | | | | | | | | | | Identifier 3091..3092 "k" -| | | | | | | | | Error 3092..3121 -| | | | | | | | | | Error 3092..3121 -| | | | | | | | | | | Error 3092..3121 "expect RParen but got UnitInc" -| | | | | | | | | Error 3121..3125 -| | | | | | | | | | Expression 3121..3125 -| | | | | | | | | | | UnitInc 3121..3124 -| | | | | | | | | | | | UnitInc 3121..3123 -| | | | | | | | | | | | | UnitInc 3121..3123 "++" -| | | | | | | | | | | | Error 3123..3124 -| | | | | | | | | | | | | RParen 3123..3124 -| | | | | | | | | | | | | | RParen 3123..3124 ")" -| | | | | | | | | | | WhiteSpace 3124..3125 -| | | | | | | | | | | | WhiteSpace 3124..3125 -| | | | | | | | | | | | | WhiteSpace 3124..3125 " " -| | | | | | | | | Error 3125..3156 -| | | | | | | | | | Error 3125..3156 -| | | | | | | | | | | Error 3125..3156 "expect Semicolon but got LCurly" -| | | | | | | Statement 3156..3546 -| | | | | | | | Block 3156..3546 -| | | | | | | | | LCurly 3156..3157 -| | | | | | | | | | LCurly 3156..3157 "{" -| | | | | | | | | EndLine 3157..3158 -| | | | | | | | | | EndLine 3157..3158 -| | | | | | | | | | | EndLine 3157..3158 "\n" -| | | | | | | | | WhiteSpace 3158..3170 -| | | | | | | | | | WhiteSpace 3158..3170 -| | | | | | | | | | | WhiteSpace 3158..3170 " " -| | | | | | | | | StatementList 3170..3545 -| | | | | | | | | | Statement 3170..3196 -| | | | | | | | | | | AssignStatement 3170..3195 -| | | | | | | | | | | | Expression 3170..3177 -| | | | | | | | | | | | | ComponentIdentifier 3170..3173 -| | | | | | | | | | | | | | Identifier 3170..3173 -| | | | | | | | | | | | | | | Identifier 3170..3173 "out" -| | | | | | | | | | | | | LBracket 3173..3174 -| | | | | | | | | | | | | | LBracket 3173..3174 "[" -| | | | | | | | | | | | | Expression 3174..3175 -| | | | | | | | | | | | | | Identifier 3174..3175 -| | | | | | | | | | | | | | | Identifier 3174..3175 -| | | | | | | | | | | | | | | | Identifier 3174..3175 "k" -| | | | | | | | | | | | | RBracket 3175..3176 -| | | | | | | | | | | | | | RBracket 3175..3176 "]" -| | | | | | | | | | | | | WhiteSpace 3176..3177 -| | | | | | | | | | | | | | WhiteSpace 3176..3177 -| | | | | | | | | | | | | | | WhiteSpace 3176..3177 " " -| | | | | | | | | | | | RAssignSignal 3177..3180 -| | | | | | | | | | | | | RAssignSignal 3177..3180 "<--" -| | | | | | | | | | | | WhiteSpace 3180..3181 -| | | | | | | | | | | | | WhiteSpace 3180..3181 -| | | | | | | | | | | | | | WhiteSpace 3180..3181 " " -| | | | | | | | | | | | Expression 3181..3195 -| | | | | | | | | | | | | BitAnd 3181..3195 -| | | | | | | | | | | | | | Tuple 3181..3191 -| | | | | | | | | | | | | | | LParen 3181..3182 -| | | | | | | | | | | | | | | | LParen 3181..3182 "(" -| | | | | | | | | | | | | | | ShiftR 3182..3190 -| | | | | | | | | | | | | | | | Identifier 3182..3185 -| | | | | | | | | | | | | | | | | Identifier 3182..3185 -| | | | | | | | | | | | | | | | | | Identifier 3182..3185 "lin" -| | | | | | | | | | | | | | | | WhiteSpace 3185..3186 -| | | | | | | | | | | | | | | | | WhiteSpace 3185..3186 -| | | | | | | | | | | | | | | | | | WhiteSpace 3185..3186 " " -| | | | | | | | | | | | | | | | ShiftR 3186..3188 -| | | | | | | | | | | | | | | | | ShiftR 3186..3188 ">>" -| | | | | | | | | | | | | | | | WhiteSpace 3188..3189 -| | | | | | | | | | | | | | | | | WhiteSpace 3188..3189 -| | | | | | | | | | | | | | | | | | WhiteSpace 3188..3189 " " -| | | | | | | | | | | | | | | | Identifier 3189..3190 -| | | | | | | | | | | | | | | | | Identifier 3189..3190 -| | | | | | | | | | | | | | | | | | Identifier 3189..3190 "k" -| | | | | | | | | | | | | | | RParen 3190..3191 -| | | | | | | | | | | | | | | | RParen 3190..3191 ")" -| | | | | | | | | | | | | | WhiteSpace 3191..3192 -| | | | | | | | | | | | | | | WhiteSpace 3191..3192 -| | | | | | | | | | | | | | | | WhiteSpace 3191..3192 " " -| | | | | | | | | | | | | | BitAnd 3192..3193 -| | | | | | | | | | | | | | | BitAnd 3192..3193 "&" -| | | | | | | | | | | | | | WhiteSpace 3193..3194 -| | | | | | | | | | | | | | | WhiteSpace 3193..3194 -| | | | | | | | | | | | | | | | WhiteSpace 3193..3194 " " -| | | | | | | | | | | | | | Number 3194..3195 -| | | | | | | | | | | | | | | Number 3194..3195 -| | | | | | | | | | | | | | | | Number 3194..3195 "1" -| | | | | | | | | | | Semicolon 3195..3196 -| | | | | | | | | | | | Semicolon 3195..3196 ";" -| | | | | | | | | | EndLine 3196..3197 -| | | | | | | | | | | EndLine 3196..3197 -| | | | | | | | | | | | EndLine 3196..3197 "\n" -| | | | | | | | | | WhiteSpace 3197..3201 -| | | | | | | | | | | WhiteSpace 3197..3201 -| | | | | | | | | | | | WhiteSpace 3197..3201 " " -| | | | | | | | | | EndLine 3201..3202 -| | | | | | | | | | | EndLine 3201..3202 -| | | | | | | | | | | | EndLine 3201..3202 "\n" -| | | | | | | | | | WhiteSpace 3202..3214 -| | | | | | | | | | | WhiteSpace 3202..3214 -| | | | | | | | | | | | WhiteSpace 3202..3214 " " -| | | | | | | | | | CommentLine 3214..3237 -| | | | | | | | | | | CommentLine 3214..3237 -| | | | | | | | | | | | CommentLine 3214..3237 "// Ensure out is binary" -| | | | | | | | | | EndLine 3237..3238 -| | | | | | | | | | | EndLine 3237..3238 -| | | | | | | | | | | | EndLine 3237..3238 "\n" -| | | | | | | | | | WhiteSpace 3238..3250 -| | | | | | | | | | | WhiteSpace 3238..3250 -| | | | | | | | | | | | WhiteSpace 3238..3250 " " -| | | | | | | | | | Statement 3250..3285 -| | | | | | | | | | | Error 3250..3257 -| | | | | | | | | | | | Expression 3250..3257 -| | | | | | | | | | | | | ComponentIdentifier 3250..3253 -| | | | | | | | | | | | | | Identifier 3250..3253 -| | | | | | | | | | | | | | | Identifier 3250..3253 "out" -| | | | | | | | | | | | | LBracket 3253..3254 -| | | | | | | | | | | | | | LBracket 3253..3254 "[" -| | | | | | | | | | | | | Expression 3254..3255 -| | | | | | | | | | | | | | Identifier 3254..3255 -| | | | | | | | | | | | | | | Identifier 3254..3255 -| | | | | | | | | | | | | | | | Identifier 3254..3255 "k" -| | | | | | | | | | | | | RBracket 3255..3256 -| | | | | | | | | | | | | | RBracket 3255..3256 "]" -| | | | | | | | | | | | | WhiteSpace 3256..3257 -| | | | | | | | | | | | | | WhiteSpace 3256..3257 -| | | | | | | | | | | | | | | WhiteSpace 3256..3257 " " -| | | | | | | | | | | Error 3257..3285 -| | | | | | | | | | | | Error 3257..3285 -| | | | | | | | | | | | | Error 3257..3285 "expect Semicolon but got Mul" -| | | | | | | | | | Statement 3285..3318 -| | | | | | | | | | | Error 3285..3287 -| | | | | | | | | | | | Expression 3285..3286 -| | | | | | | | | | | | | Error 3285..3286 -| | | | | | | | | | | | | | Mul 3285..3286 -| | | | | | | | | | | | | | | Mul 3285..3286 "*" -| | | | | | | | | | | | WhiteSpace 3286..3287 -| | | | | | | | | | | | | WhiteSpace 3286..3287 -| | | | | | | | | | | | | | WhiteSpace 3286..3287 " " -| | | | | | | | | | | Error 3287..3318 -| | | | | | | | | | | | Error 3287..3318 -| | | | | | | | | | | | | Error 3287..3318 "expect Semicolon but got LParen" -| | | | | | | | | | Statement 3318..3337 -| | | | | | | | | | | AssignStatement 3318..3336 -| | | | | | | | | | | | Expression 3318..3331 -| | | | | | | | | | | | | Tuple 3318..3330 -| | | | | | | | | | | | | | LParen 3318..3319 -| | | | | | | | | | | | | | | LParen 3318..3319 "(" -| | | | | | | | | | | | | | Sub 3319..3329 -| | | | | | | | | | | | | | | ArrayQuery 3319..3325 -| | | | | | | | | | | | | | | | Identifier 3319..3322 -| | | | | | | | | | | | | | | | | Identifier 3319..3322 -| | | | | | | | | | | | | | | | | | Identifier 3319..3322 "out" -| | | | | | | | | | | | | | | | LBracket 3322..3323 -| | | | | | | | | | | | | | | | | LBracket 3322..3323 "[" -| | | | | | | | | | | | | | | | Identifier 3323..3324 -| | | | | | | | | | | | | | | | | Identifier 3323..3324 -| | | | | | | | | | | | | | | | | | Identifier 3323..3324 "k" -| | | | | | | | | | | | | | | | RBracket 3324..3325 -| | | | | | | | | | | | | | | | | RBracket 3324..3325 "]" -| | | | | | | | | | | | | | | WhiteSpace 3325..3326 -| | | | | | | | | | | | | | | | WhiteSpace 3325..3326 -| | | | | | | | | | | | | | | | | WhiteSpace 3325..3326 " " -| | | | | | | | | | | | | | | Sub 3326..3327 -| | | | | | | | | | | | | | | | Sub 3326..3327 "-" -| | | | | | | | | | | | | | | WhiteSpace 3327..3328 -| | | | | | | | | | | | | | | | WhiteSpace 3327..3328 -| | | | | | | | | | | | | | | | | WhiteSpace 3327..3328 " " -| | | | | | | | | | | | | | | Number 3328..3329 -| | | | | | | | | | | | | | | | Number 3328..3329 -| | | | | | | | | | | | | | | | | Number 3328..3329 "1" -| | | | | | | | | | | | | | RParen 3329..3330 -| | | | | | | | | | | | | | | RParen 3329..3330 ")" -| | | | | | | | | | | | | WhiteSpace 3330..3331 -| | | | | | | | | | | | | | WhiteSpace 3330..3331 -| | | | | | | | | | | | | | | WhiteSpace 3330..3331 " " -| | | | | | | | | | | | EqualSignal 3331..3334 -| | | | | | | | | | | | | EqualSignal 3331..3334 "===" -| | | | | | | | | | | | WhiteSpace 3334..3335 -| | | | | | | | | | | | | WhiteSpace 3334..3335 -| | | | | | | | | | | | | | WhiteSpace 3334..3335 " " -| | | | | | | | | | | | Expression 3335..3336 -| | | | | | | | | | | | | Number 3335..3336 -| | | | | | | | | | | | | | Number 3335..3336 -| | | | | | | | | | | | | | | Number 3335..3336 "0" -| | | | | | | | | | | Semicolon 3336..3337 -| | | | | | | | | | | | Semicolon 3336..3337 ";" -| | | | | | | | | | EndLine 3337..3338 -| | | | | | | | | | | EndLine 3337..3338 -| | | | | | | | | | | | EndLine 3337..3338 "\n" -| | | | | | | | | | WhiteSpace 3338..3342 -| | | | | | | | | | | WhiteSpace 3338..3342 -| | | | | | | | | | | | WhiteSpace 3338..3342 " " -| | | | | | | | | | EndLine 3342..3343 -| | | | | | | | | | | EndLine 3342..3343 -| | | | | | | | | | | | EndLine 3342..3343 "\n" -| | | | | | | | | | WhiteSpace 3343..3355 -| | | | | | | | | | | WhiteSpace 3343..3355 -| | | | | | | | | | | | WhiteSpace 3343..3355 " " -| | | | | | | | | | Statement 3355..3394 -| | | | | | | | | | | Error 3355..3360 -| | | | | | | | | | | | Expression 3355..3360 -| | | | | | | | | | | | | ComponentIdentifier 3355..3359 -| | | | | | | | | | | | | | Identifier 3355..3359 -| | | | | | | | | | | | | | | Identifier 3355..3359 "lout" -| | | | | | | | | | | | | WhiteSpace 3359..3360 -| | | | | | | | | | | | | | WhiteSpace 3359..3360 -| | | | | | | | | | | | | | | WhiteSpace 3359..3360 " " -| | | | | | | | | | | Error 3360..3394 -| | | | | | | | | | | | Error 3360..3394 -| | | | | | | | | | | | | Error 3360..3394 "expect Semicolon but got AddAssign" -| | | | | | | | | | Statement 3394..3432 -| | | | | | | | | | | Error 3394..3397 -| | | | | | | | | | | | Expression 3394..3396 -| | | | | | | | | | | | | Error 3394..3396 -| | | | | | | | | | | | | | AddAssign 3394..3396 -| | | | | | | | | | | | | | | AddAssign 3394..3396 "+=" -| | | | | | | | | | | | WhiteSpace 3396..3397 -| | | | | | | | | | | | | WhiteSpace 3396..3397 -| | | | | | | | | | | | | | WhiteSpace 3396..3397 " " -| | | | | | | | | | | Error 3397..3432 -| | | | | | | | | | | | Error 3397..3432 -| | | | | | | | | | | | | Error 3397..3432 "expect Semicolon but got Identifier" -| | | | | | | | | | Statement 3432..3467 -| | | | | | | | | | | Error 3432..3439 -| | | | | | | | | | | | Expression 3432..3439 -| | | | | | | | | | | | | ComponentIdentifier 3432..3435 -| | | | | | | | | | | | | | Identifier 3432..3435 -| | | | | | | | | | | | | | | Identifier 3432..3435 "out" -| | | | | | | | | | | | | LBracket 3435..3436 -| | | | | | | | | | | | | | LBracket 3435..3436 "[" -| | | | | | | | | | | | | Expression 3436..3437 -| | | | | | | | | | | | | | Identifier 3436..3437 -| | | | | | | | | | | | | | | Identifier 3436..3437 -| | | | | | | | | | | | | | | | Identifier 3436..3437 "k" -| | | | | | | | | | | | | RBracket 3437..3438 -| | | | | | | | | | | | | | RBracket 3437..3438 "]" -| | | | | | | | | | | | | WhiteSpace 3438..3439 -| | | | | | | | | | | | | | WhiteSpace 3438..3439 -| | | | | | | | | | | | | | | WhiteSpace 3438..3439 " " -| | | | | | | | | | | Error 3439..3467 -| | | | | | | | | | | | Error 3439..3467 -| | | | | | | | | | | | | Error 3439..3467 "expect Semicolon but got Mul" -| | | | | | | | | | Statement 3467..3504 -| | | | | | | | | | | Error 3467..3469 -| | | | | | | | | | | | Expression 3467..3468 -| | | | | | | | | | | | | Error 3467..3468 -| | | | | | | | | | | | | | Mul 3467..3468 -| | | | | | | | | | | | | | | Mul 3467..3468 "*" -| | | | | | | | | | | | WhiteSpace 3468..3469 -| | | | | | | | | | | | | WhiteSpace 3468..3469 -| | | | | | | | | | | | | | WhiteSpace 3468..3469 " " -| | | | | | | | | | | Error 3469..3504 -| | | | | | | | | | | | Error 3469..3504 -| | | | | | | | | | | | | Error 3469..3504 "expect Semicolon but got Identifier" -| | | | | | | | | | Statement 3504..3507 -| | | | | | | | | | | Error 3504..3506 -| | | | | | | | | | | | Expression 3504..3506 -| | | | | | | | | | | | | ComponentIdentifier 3504..3506 -| | | | | | | | | | | | | | Identifier 3504..3506 -| | | | | | | | | | | | | | | Identifier 3504..3506 "e2" -| | | | | | | | | | | Semicolon 3506..3507 -| | | | | | | | | | | | Semicolon 3506..3507 ";" -| | | | | | | | | | EndLine 3507..3508 -| | | | | | | | | | | EndLine 3507..3508 -| | | | | | | | | | | | EndLine 3507..3508 "\n" -| | | | | | | | | | WhiteSpace 3508..3512 -| | | | | | | | | | | WhiteSpace 3508..3512 -| | | | | | | | | | | | WhiteSpace 3508..3512 " " -| | | | | | | | | | EndLine 3512..3513 -| | | | | | | | | | | EndLine 3512..3513 -| | | | | | | | | | | | EndLine 3512..3513 "\n" -| | | | | | | | | | WhiteSpace 3513..3525 -| | | | | | | | | | | WhiteSpace 3513..3525 -| | | | | | | | | | | | WhiteSpace 3513..3525 " " -| | | | | | | | | | Statement 3525..3536 -| | | | | | | | | | | AssignStatement 3525..3535 -| | | | | | | | | | | | Expression 3525..3528 -| | | | | | | | | | | | | ComponentIdentifier 3525..3527 -| | | | | | | | | | | | | | Identifier 3525..3527 -| | | | | | | | | | | | | | | Identifier 3525..3527 "e2" -| | | | | | | | | | | | | WhiteSpace 3527..3528 -| | | | | | | | | | | | | | WhiteSpace 3527..3528 -| | | | | | | | | | | | | | | WhiteSpace 3527..3528 " " -| | | | | | | | | | | | Assign 3528..3529 -| | | | | | | | | | | | | Assign 3528..3529 "=" -| | | | | | | | | | | | WhiteSpace 3529..3530 -| | | | | | | | | | | | | WhiteSpace 3529..3530 -| | | | | | | | | | | | | | WhiteSpace 3529..3530 " " -| | | | | | | | | | | | Expression 3530..3535 -| | | | | | | | | | | | | Add 3530..3535 -| | | | | | | | | | | | | | Identifier 3530..3532 -| | | | | | | | | | | | | | | Identifier 3530..3532 -| | | | | | | | | | | | | | | | Identifier 3530..3532 "e2" -| | | | | | | | | | | | | | Add 3532..3533 -| | | | | | | | | | | | | | | Add 3532..3533 "+" -| | | | | | | | | | | | | | Identifier 3533..3535 -| | | | | | | | | | | | | | | Identifier 3533..3535 -| | | | | | | | | | | | | | | | Identifier 3533..3535 "e2" -| | | | | | | | | | | Semicolon 3535..3536 -| | | | | | | | | | | | Semicolon 3535..3536 ";" -| | | | | | | | | | EndLine 3536..3537 -| | | | | | | | | | | EndLine 3536..3537 -| | | | | | | | | | | | EndLine 3536..3537 "\n" -| | | | | | | | | | WhiteSpace 3537..3545 -| | | | | | | | | | | WhiteSpace 3537..3545 -| | | | | | | | | | | | WhiteSpace 3537..3545 " " -| | | | | | | | | RCurly 3545..3546 -| | | | | | | | | | RCurly 3545..3546 "}" -| | | | | | | EndLine 3546..3547 -| | | | | | | | EndLine 3546..3547 -| | | | | | | | | EndLine 3546..3547 "\n" -| | | | | | | WhiteSpace 3547..3551 -| | | | | | | | WhiteSpace 3547..3551 -| | | | | | | | | WhiteSpace 3547..3551 " " -| | | | | | | EndLine 3551..3552 -| | | | | | | | EndLine 3551..3552 -| | | | | | | | | EndLine 3551..3552 "\n" -| | | | | | | WhiteSpace 3552..3560 -| | | | | | | | WhiteSpace 3552..3560 -| | | | | | | | | WhiteSpace 3552..3560 " " -| | | | | | | CommentLine 3560..3578 -| | | | | | | | CommentLine 3560..3578 -| | | | | | | | | CommentLine 3560..3578 "// Ensure the sum;" -| | | | | | | EndLine 3578..3579 -| | | | | | | | EndLine 3578..3579 -| | | | | | | | | EndLine 3578..3579 "\n" -| | | | | | | WhiteSpace 3579..3583 -| | | | | | | | WhiteSpace 3579..3583 -| | | | | | | | | WhiteSpace 3579..3583 " " -| | | | | | | EndLine 3583..3584 -| | | | | | | | EndLine 3583..3584 -| | | | | | | | | EndLine 3583..3584 "\n" -| | | | | | | WhiteSpace 3584..3592 -| | | | | | | | WhiteSpace 3584..3592 -| | | | | | | | | WhiteSpace 3584..3592 " " -| | | | | | | Statement 3592..3605 -| | | | | | | | AssignStatement 3592..3604 -| | | | | | | | | Expression 3592..3596 -| | | | | | | | | | ComponentIdentifier 3592..3595 -| | | | | | | | | | | Identifier 3592..3595 -| | | | | | | | | | | | Identifier 3592..3595 "lin" -| | | | | | | | | | WhiteSpace 3595..3596 -| | | | | | | | | | | WhiteSpace 3595..3596 -| | | | | | | | | | | | WhiteSpace 3595..3596 " " -| | | | | | | | | EqualSignal 3596..3599 -| | | | | | | | | | EqualSignal 3596..3599 "===" -| | | | | | | | | WhiteSpace 3599..3600 -| | | | | | | | | | WhiteSpace 3599..3600 -| | | | | | | | | | | WhiteSpace 3599..3600 " " -| | | | | | | | | Expression 3600..3604 -| | | | | | | | | | Identifier 3600..3604 -| | | | | | | | | | | Identifier 3600..3604 -| | | | | | | | | | | | Identifier 3600..3604 "lout" -| | | | | | | | Semicolon 3604..3605 -| | | | | | | | | Semicolon 3604..3605 ";" -| | | | | | | EndLine 3605..3606 -| | | | | | | | EndLine 3605..3606 -| | | | | | | | | EndLine 3605..3606 "\n" -| | | | | | | WhiteSpace 3606..3610 -| | | | | | | | WhiteSpace 3606..3610 -| | | | | | | | | WhiteSpace 3606..3610 " " -| | | | | | RCurly 3610..3611 -| | | | | | | RCurly 3610..3611 "}" -| | | | EndLine 3611..3612 -| | | | | EndLine 3611..3612 -| | | | | | EndLine 3611..3612 "\n" -| | | Error 3612..3637 -| | | | Error 3612..3637 -| | | | | Error 3612..3637 "expect RCurly but got EOF" +| | | | | WhiteSpace 1836..1840 +| | | | | | WhiteSpace 1836..1840 " " +| | | | OutputSignalDecl 1840..1863 +| | | | | SignalHeader 1840..1854 +| | | | | | SignalKw 1840..1846 +| | | | | | | SignalKw 1840..1846 "signal" +| | | | | | WhiteSpace 1846..1847 +| | | | | | | WhiteSpace 1846..1847 +| | | | | | | | WhiteSpace 1846..1847 " " +| | | | | | OutputKw 1847..1853 +| | | | | | | OutputKw 1847..1853 "output" +| | | | | | WhiteSpace 1853..1854 +| | | | | | | WhiteSpace 1853..1854 +| | | | | | | | WhiteSpace 1853..1854 " " +| | | | | Identifier 1854..1857 +| | | | | | Identifier 1854..1857 "out" +| | | | | ArrayQuery 1857..1863 +| | | | | | LBracket 1857..1858 +| | | | | | | LBracket 1857..1858 "[" +| | | | | | Expression 1858..1862 +| | | | | | | Identifier 1858..1862 +| | | | | | | | Identifier 1858..1862 +| | | | | | | | | Identifier 1858..1862 "nout" +| | | | | | RBracket 1862..1863 +| | | | | | | RBracket 1862..1863 "]" +| | | | Semicolon 1863..1864 +| | | | | Semicolon 1863..1864 ";" +| | | | Error 1864..1865 +| | | | | Error 1864..1865 +| | | | | | Error 1864..1865 "\r" +| | | | EndLine 1865..1866 +| | | | | EndLine 1865..1866 +| | | | | | EndLine 1865..1866 "\n" +| | | | Error 1866..1867 +| | | | | Error 1866..1867 +| | | | | | Error 1866..1867 "\r" +| | | | EndLine 1867..1868 +| | | | | EndLine 1867..1868 +| | | | | | EndLine 1867..1868 "\n" +| | | | WhiteSpace 1868..1872 +| | | | | WhiteSpace 1868..1872 +| | | | | | WhiteSpace 1868..1872 " " +| | | | VarDecl 1872..1883 +| | | | | VarKw 1872..1875 +| | | | | | VarKw 1872..1875 "var" +| | | | | WhiteSpace 1875..1876 +| | | | | | WhiteSpace 1875..1876 +| | | | | | | WhiteSpace 1875..1876 " " +| | | | | Identifier 1876..1879 +| | | | | | Identifier 1876..1879 "lin" +| | | | | WhiteSpace 1879..1880 +| | | | | | WhiteSpace 1879..1880 +| | | | | | | WhiteSpace 1879..1880 " " +| | | | | Assign 1880..1881 +| | | | | | Assign 1880..1881 "=" +| | | | | WhiteSpace 1881..1882 +| | | | | | WhiteSpace 1881..1882 +| | | | | | | WhiteSpace 1881..1882 " " +| | | | | Expression 1882..1883 +| | | | | | Number 1882..1883 +| | | | | | | Number 1882..1883 +| | | | | | | | Number 1882..1883 "0" +| | | | Semicolon 1883..1884 +| | | | | Semicolon 1883..1884 ";" +| | | | Error 1884..1885 +| | | | | Error 1884..1885 +| | | | | | Error 1884..1885 "\r" +| | | | EndLine 1885..1886 +| | | | | EndLine 1885..1886 +| | | | | | EndLine 1885..1886 "\n" +| | | | WhiteSpace 1886..1890 +| | | | | WhiteSpace 1886..1890 +| | | | | | WhiteSpace 1886..1890 " " +| | | | VarDecl 1890..1902 +| | | | | VarKw 1890..1893 +| | | | | | VarKw 1890..1893 "var" +| | | | | WhiteSpace 1893..1894 +| | | | | | WhiteSpace 1893..1894 +| | | | | | | WhiteSpace 1893..1894 " " +| | | | | Identifier 1894..1898 +| | | | | | Identifier 1894..1898 "lout" +| | | | | WhiteSpace 1898..1899 +| | | | | | WhiteSpace 1898..1899 +| | | | | | | WhiteSpace 1898..1899 " " +| | | | | Assign 1899..1900 +| | | | | | Assign 1899..1900 "=" +| | | | | WhiteSpace 1900..1901 +| | | | | | WhiteSpace 1900..1901 +| | | | | | | WhiteSpace 1900..1901 " " +| | | | | Expression 1901..1902 +| | | | | | Number 1901..1902 +| | | | | | | Number 1901..1902 +| | | | | | | | Number 1901..1902 "0" +| | | | Semicolon 1902..1903 +| | | | | Semicolon 1902..1903 ";" +| | | | Error 1903..1904 +| | | | | Error 1903..1904 +| | | | | | Error 1903..1904 "\r" +| | | | EndLine 1904..1905 +| | | | | EndLine 1904..1905 +| | | | | | EndLine 1904..1905 "\n" +| | | | Error 1905..1906 +| | | | | Error 1905..1906 +| | | | | | Error 1905..1906 "\r" +| | | | EndLine 1906..1907 +| | | | | EndLine 1906..1907 +| | | | | | EndLine 1906..1907 "\n" +| | | | WhiteSpace 1907..1911 +| | | | | WhiteSpace 1907..1911 +| | | | | | WhiteSpace 1907..1911 " " +| | | | VarDecl 1911..1916 +| | | | | VarKw 1911..1914 +| | | | | | VarKw 1911..1914 "var" +| | | | | WhiteSpace 1914..1915 +| | | | | | WhiteSpace 1914..1915 +| | | | | | | WhiteSpace 1914..1915 " " +| | | | | Identifier 1915..1916 +| | | | | | Identifier 1915..1916 "k" +| | | | Semicolon 1916..1917 +| | | | | Semicolon 1916..1917 ";" +| | | | Error 1917..1918 +| | | | | Error 1917..1918 +| | | | | | Error 1917..1918 "\r" +| | | | EndLine 1918..1919 +| | | | | EndLine 1918..1919 +| | | | | | EndLine 1918..1919 "\n" +| | | | WhiteSpace 1919..1923 +| | | | | WhiteSpace 1919..1923 +| | | | | | WhiteSpace 1919..1923 " " +| | | | VarDecl 1923..1928 +| | | | | VarKw 1923..1926 +| | | | | | VarKw 1923..1926 "var" +| | | | | WhiteSpace 1926..1927 +| | | | | | WhiteSpace 1926..1927 +| | | | | | | WhiteSpace 1926..1927 " " +| | | | | Identifier 1927..1928 +| | | | | | Identifier 1927..1928 "j" +| | | | Semicolon 1928..1929 +| | | | | Semicolon 1928..1929 ";" +| | | | Error 1929..1930 +| | | | | Error 1929..1930 +| | | | | | Error 1929..1930 "\r" +| | | | EndLine 1930..1931 +| | | | | EndLine 1930..1931 +| | | | | | EndLine 1930..1931 "\n" +| | | | Error 1931..1932 +| | | | | Error 1931..1932 +| | | | | | Error 1931..1932 "\r" +| | | | EndLine 1932..1933 +| | | | | EndLine 1932..1933 +| | | | | | EndLine 1932..1933 "\n" +| | | | WhiteSpace 1933..1937 +| | | | | WhiteSpace 1933..1937 +| | | | | | WhiteSpace 1933..1937 " " +| | | | VarDecl 1937..1943 +| | | | | VarKw 1937..1940 +| | | | | | VarKw 1937..1940 "var" +| | | | | WhiteSpace 1940..1941 +| | | | | | WhiteSpace 1940..1941 +| | | | | | | WhiteSpace 1940..1941 " " +| | | | | Identifier 1941..1943 +| | | | | | Identifier 1941..1943 "e2" +| | | | Semicolon 1943..1944 +| | | | | Semicolon 1943..1944 ";" +| | | | Error 1944..1945 +| | | | | Error 1944..1945 +| | | | | | Error 1944..1945 "\r" +| | | | EndLine 1945..1946 +| | | | | EndLine 1945..1946 +| | | | | | EndLine 1945..1946 "\n" +| | | | Error 1946..1947 +| | | | | Error 1946..1947 +| | | | | | Error 1946..1947 "\r" +| | | | EndLine 1947..1948 +| | | | | EndLine 1947..1948 +| | | | | | EndLine 1947..1948 "\n" +| | | | WhiteSpace 1948..1952 +| | | | | WhiteSpace 1948..1952 +| | | | | | WhiteSpace 1948..1952 " " +| | | | Statement 1952..1959 +| | | | | AssignStatement 1952..1958 +| | | | | | Expression 1952..1955 +| | | | | | | Identifier 1952..1954 +| | | | | | | | Identifier 1952..1954 +| | | | | | | | | Identifier 1952..1954 "e2" +| | | | | | | WhiteSpace 1954..1955 +| | | | | | | | WhiteSpace 1954..1955 +| | | | | | | | | WhiteSpace 1954..1955 " " +| | | | | | Assign 1955..1956 +| | | | | | | Assign 1955..1956 "=" +| | | | | | WhiteSpace 1956..1957 +| | | | | | | WhiteSpace 1956..1957 +| | | | | | | | WhiteSpace 1956..1957 " " +| | | | | | Expression 1957..1958 +| | | | | | | Number 1957..1958 +| | | | | | | | Number 1957..1958 +| | | | | | | | | Number 1957..1958 "1" +| | | | | Semicolon 1958..1959 +| | | | | | Semicolon 1958..1959 ";" +| | | | Error 1959..1960 +| | | | | Error 1959..1960 +| | | | | | Error 1959..1960 "\r" +| | | | EndLine 1960..1961 +| | | | | EndLine 1960..1961 +| | | | | | EndLine 1960..1961 "\n" +| | | | WhiteSpace 1961..1965 +| | | | | WhiteSpace 1961..1965 +| | | | | | WhiteSpace 1961..1965 " " +| | | | Statement 1965..2422 +| | | | | ForLoop 1965..2422 +| | | | | | ForKw 1965..1968 +| | | | | | | ForKw 1965..1968 "for" +| | | | | | WhiteSpace 1968..1969 +| | | | | | | WhiteSpace 1968..1969 +| | | | | | | | WhiteSpace 1968..1969 " " +| | | | | | LParen 1969..1970 +| | | | | | | LParen 1969..1970 "(" +| | | | | | AssignStatement 1970..1973 +| | | | | | | Expression 1970..1971 +| | | | | | | | Identifier 1970..1971 +| | | | | | | | | Identifier 1970..1971 +| | | | | | | | | | Identifier 1970..1971 "k" +| | | | | | | Assign 1971..1972 +| | | | | | | | Assign 1971..1972 "=" +| | | | | | | Expression 1972..1973 +| | | | | | | | Number 1972..1973 +| | | | | | | | | Number 1972..1973 +| | | | | | | | | | Number 1972..1973 "0" +| | | | | | Semicolon 1973..1974 +| | | | | | | Semicolon 1973..1974 ";" +| | | | | | WhiteSpace 1974..1975 +| | | | | | | WhiteSpace 1974..1975 +| | | | | | | | WhiteSpace 1974..1975 " " +| | | | | | Expression 1975..1978 +| | | | | | | LessThan 1975..1978 +| | | | | | | | Identifier 1975..1976 +| | | | | | | | | Identifier 1975..1976 +| | | | | | | | | | Identifier 1975..1976 "k" +| | | | | | | | LessThan 1976..1977 +| | | | | | | | | LessThan 1976..1977 "<" +| | | | | | | | Identifier 1977..1978 +| | | | | | | | | Identifier 1977..1978 +| | | | | | | | | | Identifier 1977..1978 "n" +| | | | | | Semicolon 1978..1979 +| | | | | | | Semicolon 1978..1979 ";" +| | | | | | WhiteSpace 1979..1980 +| | | | | | | WhiteSpace 1979..1980 +| | | | | | | | WhiteSpace 1979..1980 " " +| | | | | | AssignStatement 1980..1983 +| | | | | | | Expression 1980..1983 +| | | | | | | | Expression 1980..1983 +| | | | | | | | | Identifier 1980..1981 +| | | | | | | | | | Identifier 1980..1981 +| | | | | | | | | | | Identifier 1980..1981 "k" +| | | | | | | | | UnitInc 1981..1983 +| | | | | | | | | | UnitInc 1981..1983 "++" +| | | | | | RParen 1983..1984 +| | | | | | | RParen 1983..1984 ")" +| | | | | | WhiteSpace 1984..1985 +| | | | | | | WhiteSpace 1984..1985 +| | | | | | | | WhiteSpace 1984..1985 " " +| | | | | | Statement 1985..2422 +| | | | | | | Block 1985..2422 +| | | | | | | | LCurly 1985..1986 +| | | | | | | | | LCurly 1985..1986 "{" +| | | | | | | | Error 1986..1987 +| | | | | | | | | Error 1986..1987 +| | | | | | | | | | Error 1986..1987 "\r" +| | | | | | | | EndLine 1987..1988 +| | | | | | | | | EndLine 1987..1988 +| | | | | | | | | | EndLine 1987..1988 "\n" +| | | | | | | | WhiteSpace 1988..1996 +| | | | | | | | | WhiteSpace 1988..1996 +| | | | | | | | | | WhiteSpace 1988..1996 " " +| | | | | | | | StatementList 1996..2421 +| | | | | | | | | Statement 1996..2065 +| | | | | | | | | | ForLoop 1996..2065 +| | | | | | | | | | | ForKw 1996..1999 +| | | | | | | | | | | | ForKw 1996..1999 "for" +| | | | | | | | | | | WhiteSpace 1999..2000 +| | | | | | | | | | | | WhiteSpace 1999..2000 +| | | | | | | | | | | | | WhiteSpace 1999..2000 " " +| | | | | | | | | | | LParen 2000..2001 +| | | | | | | | | | | | LParen 2000..2001 "(" +| | | | | | | | | | | AssignStatement 2001..2004 +| | | | | | | | | | | | Expression 2001..2002 +| | | | | | | | | | | | | Identifier 2001..2002 +| | | | | | | | | | | | | | Identifier 2001..2002 +| | | | | | | | | | | | | | | Identifier 2001..2002 "j" +| | | | | | | | | | | | Assign 2002..2003 +| | | | | | | | | | | | | Assign 2002..2003 "=" +| | | | | | | | | | | | Expression 2003..2004 +| | | | | | | | | | | | | Number 2003..2004 +| | | | | | | | | | | | | | Number 2003..2004 +| | | | | | | | | | | | | | | Number 2003..2004 "0" +| | | | | | | | | | | Semicolon 2004..2005 +| | | | | | | | | | | | Semicolon 2004..2005 ";" +| | | | | | | | | | | WhiteSpace 2005..2006 +| | | | | | | | | | | | WhiteSpace 2005..2006 +| | | | | | | | | | | | | WhiteSpace 2005..2006 " " +| | | | | | | | | | | Expression 2006..2011 +| | | | | | | | | | | | LessThan 2006..2011 +| | | | | | | | | | | | | Identifier 2006..2007 +| | | | | | | | | | | | | | Identifier 2006..2007 +| | | | | | | | | | | | | | | Identifier 2006..2007 "j" +| | | | | | | | | | | | | LessThan 2007..2008 +| | | | | | | | | | | | | | LessThan 2007..2008 "<" +| | | | | | | | | | | | | Identifier 2008..2011 +| | | | | | | | | | | | | | Identifier 2008..2011 +| | | | | | | | | | | | | | | Identifier 2008..2011 "ops" +| | | | | | | | | | | Semicolon 2011..2012 +| | | | | | | | | | | | Semicolon 2011..2012 ";" +| | | | | | | | | | | WhiteSpace 2012..2013 +| | | | | | | | | | | | WhiteSpace 2012..2013 +| | | | | | | | | | | | | WhiteSpace 2012..2013 " " +| | | | | | | | | | | AssignStatement 2013..2016 +| | | | | | | | | | | | Expression 2013..2016 +| | | | | | | | | | | | | Expression 2013..2016 +| | | | | | | | | | | | | | Identifier 2013..2014 +| | | | | | | | | | | | | | | Identifier 2013..2014 +| | | | | | | | | | | | | | | | Identifier 2013..2014 "j" +| | | | | | | | | | | | | | UnitInc 2014..2016 +| | | | | | | | | | | | | | | UnitInc 2014..2016 "++" +| | | | | | | | | | | RParen 2016..2017 +| | | | | | | | | | | | RParen 2016..2017 ")" +| | | | | | | | | | | WhiteSpace 2017..2018 +| | | | | | | | | | | | WhiteSpace 2017..2018 +| | | | | | | | | | | | | WhiteSpace 2017..2018 " " +| | | | | | | | | | | Statement 2018..2065 +| | | | | | | | | | | | Block 2018..2065 +| | | | | | | | | | | | | LCurly 2018..2019 +| | | | | | | | | | | | | | LCurly 2018..2019 "{" +| | | | | | | | | | | | | Error 2019..2020 +| | | | | | | | | | | | | | Error 2019..2020 +| | | | | | | | | | | | | | | Error 2019..2020 "\r" +| | | | | | | | | | | | | EndLine 2020..2021 +| | | | | | | | | | | | | | EndLine 2020..2021 +| | | | | | | | | | | | | | | EndLine 2020..2021 "\n" +| | | | | | | | | | | | | WhiteSpace 2021..2033 +| | | | | | | | | | | | | | WhiteSpace 2021..2033 +| | | | | | | | | | | | | | | WhiteSpace 2021..2033 " " +| | | | | | | | | | | | | StatementList 2033..2064 +| | | | | | | | | | | | | | Statement 2033..2054 +| | | | | | | | | | | | | | | AssignStatement 2033..2053 +| | | | | | | | | | | | | | | | Expression 2033..2037 +| | | | | | | | | | | | | | | | | Identifier 2033..2036 +| | | | | | | | | | | | | | | | | | Identifier 2033..2036 +| | | | | | | | | | | | | | | | | | | Identifier 2033..2036 "lin" +| | | | | | | | | | | | | | | | | WhiteSpace 2036..2037 +| | | | | | | | | | | | | | | | | | WhiteSpace 2036..2037 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2036..2037 " " +| | | | | | | | | | | | | | | | AddAssign 2037..2039 +| | | | | | | | | | | | | | | | | AddAssign 2037..2039 "+=" +| | | | | | | | | | | | | | | | WhiteSpace 2039..2040 +| | | | | | | | | | | | | | | | | WhiteSpace 2039..2040 +| | | | | | | | | | | | | | | | | | WhiteSpace 2039..2040 " " +| | | | | | | | | | | | | | | | Expression 2040..2053 +| | | | | | | | | | | | | | | | | Mul 2040..2053 +| | | | | | | | | | | | | | | | | | ArrayQuery 2040..2048 +| | | | | | | | | | | | | | | | | | | ArrayQuery 2040..2045 +| | | | | | | | | | | | | | | | | | | | Identifier 2040..2042 +| | | | | | | | | | | | | | | | | | | | | Identifier 2040..2042 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2040..2042 "in" +| | | | | | | | | | | | | | | | | | | | LBracket 2042..2043 +| | | | | | | | | | | | | | | | | | | | | LBracket 2042..2043 "[" +| | | | | | | | | | | | | | | | | | | | Expression 2043..2044 +| | | | | | | | | | | | | | | | | | | | | Identifier 2043..2044 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2043..2044 +| | | | | | | | | | | | | | | | | | | | | | | Identifier 2043..2044 "j" +| | | | | | | | | | | | | | | | | | | | RBracket 2044..2045 +| | | | | | | | | | | | | | | | | | | | | RBracket 2044..2045 "]" +| | | | | | | | | | | | | | | | | | | LBracket 2045..2046 +| | | | | | | | | | | | | | | | | | | | LBracket 2045..2046 "[" +| | | | | | | | | | | | | | | | | | | Expression 2046..2047 +| | | | | | | | | | | | | | | | | | | | Identifier 2046..2047 +| | | | | | | | | | | | | | | | | | | | | Identifier 2046..2047 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2046..2047 "k" +| | | | | | | | | | | | | | | | | | | RBracket 2047..2048 +| | | | | | | | | | | | | | | | | | | | RBracket 2047..2048 "]" +| | | | | | | | | | | | | | | | | | WhiteSpace 2048..2049 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2048..2049 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2048..2049 " " +| | | | | | | | | | | | | | | | | | Mul 2049..2050 +| | | | | | | | | | | | | | | | | | | Mul 2049..2050 "*" +| | | | | | | | | | | | | | | | | | WhiteSpace 2050..2051 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2050..2051 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2050..2051 " " +| | | | | | | | | | | | | | | | | | Identifier 2051..2053 +| | | | | | | | | | | | | | | | | | | Identifier 2051..2053 +| | | | | | | | | | | | | | | | | | | | Identifier 2051..2053 "e2" +| | | | | | | | | | | | | | | Semicolon 2053..2054 +| | | | | | | | | | | | | | | | Semicolon 2053..2054 ";" +| | | | | | | | | | | | | | Error 2054..2055 +| | | | | | | | | | | | | | | Error 2054..2055 +| | | | | | | | | | | | | | | | Error 2054..2055 "\r" +| | | | | | | | | | | | | | EndLine 2055..2056 +| | | | | | | | | | | | | | | EndLine 2055..2056 +| | | | | | | | | | | | | | | | EndLine 2055..2056 "\n" +| | | | | | | | | | | | | | WhiteSpace 2056..2064 +| | | | | | | | | | | | | | | WhiteSpace 2056..2064 +| | | | | | | | | | | | | | | | WhiteSpace 2056..2064 " " +| | | | | | | | | | | | | RCurly 2064..2065 +| | | | | | | | | | | | | | RCurly 2064..2065 "}" +| | | | | | | | | Error 2065..2066 +| | | | | | | | | | Error 2065..2066 +| | | | | | | | | | | Error 2065..2066 "\r" +| | | | | | | | | EndLine 2066..2067 +| | | | | | | | | | EndLine 2066..2067 +| | | | | | | | | | | EndLine 2066..2067 "\n" +| | | | | | | | | WhiteSpace 2067..2075 +| | | | | | | | | | WhiteSpace 2067..2075 +| | | | | | | | | | | WhiteSpace 2067..2075 " " +| | | | | | | | | Statement 2075..2088 +| | | | | | | | | | AssignStatement 2075..2087 +| | | | | | | | | | | Expression 2075..2078 +| | | | | | | | | | | | Identifier 2075..2077 +| | | | | | | | | | | | | Identifier 2075..2077 +| | | | | | | | | | | | | | Identifier 2075..2077 "e2" +| | | | | | | | | | | | WhiteSpace 2077..2078 +| | | | | | | | | | | | | WhiteSpace 2077..2078 +| | | | | | | | | | | | | | WhiteSpace 2077..2078 " " +| | | | | | | | | | | Assign 2078..2079 +| | | | | | | | | | | | Assign 2078..2079 "=" +| | | | | | | | | | | WhiteSpace 2079..2080 +| | | | | | | | | | | | WhiteSpace 2079..2080 +| | | | | | | | | | | | | WhiteSpace 2079..2080 " " +| | | | | | | | | | | Expression 2080..2087 +| | | | | | | | | | | | Add 2080..2087 +| | | | | | | | | | | | | Identifier 2080..2082 +| | | | | | | | | | | | | | Identifier 2080..2082 +| | | | | | | | | | | | | | | Identifier 2080..2082 "e2" +| | | | | | | | | | | | | WhiteSpace 2082..2083 +| | | | | | | | | | | | | | WhiteSpace 2082..2083 +| | | | | | | | | | | | | | | WhiteSpace 2082..2083 " " +| | | | | | | | | | | | | Add 2083..2084 +| | | | | | | | | | | | | | Add 2083..2084 "+" +| | | | | | | | | | | | | WhiteSpace 2084..2085 +| | | | | | | | | | | | | | WhiteSpace 2084..2085 +| | | | | | | | | | | | | | | WhiteSpace 2084..2085 " " +| | | | | | | | | | | | | Identifier 2085..2087 +| | | | | | | | | | | | | | Identifier 2085..2087 +| | | | | | | | | | | | | | | Identifier 2085..2087 "e2" +| | | | | | | | | | Semicolon 2087..2088 +| | | | | | | | | | | Semicolon 2087..2088 ";" +| | | | | | | | | Error 2088..2089 +| | | | | | | | | | Error 2088..2089 +| | | | | | | | | | | Error 2088..2089 "\r" +| | | | | | | | | EndLine 2089..2090 +| | | | | | | | | | EndLine 2089..2090 +| | | | | | | | | | | EndLine 2089..2090 "\n" +| | | | | | | | | WhiteSpace 2090..2094 +| | | | | | | | | | WhiteSpace 2090..2094 +| | | | | | | | | | | WhiteSpace 2090..2094 " " +| | | | | | | | | Error 2094..2095 +| | | | | | | | | | Error 2094..2095 +| | | | | | | | | | | Error 2094..2095 "\r" +| | | | | | | | | EndLine 2095..2096 +| | | | | | | | | | EndLine 2095..2096 +| | | | | | | | | | | EndLine 2095..2096 "\n" +| | | | | | | | | WhiteSpace 2096..2104 +| | | | | | | | | | WhiteSpace 2096..2104 +| | | | | | | | | | | WhiteSpace 2096..2104 " " +| | | | | | | | | Statement 2104..2111 +| | | | | | | | | | AssignStatement 2104..2110 +| | | | | | | | | | | Expression 2104..2107 +| | | | | | | | | | | | Identifier 2104..2106 +| | | | | | | | | | | | | Identifier 2104..2106 +| | | | | | | | | | | | | | Identifier 2104..2106 "e2" +| | | | | | | | | | | | WhiteSpace 2106..2107 +| | | | | | | | | | | | | WhiteSpace 2106..2107 +| | | | | | | | | | | | | | WhiteSpace 2106..2107 " " +| | | | | | | | | | | Assign 2107..2108 +| | | | | | | | | | | | Assign 2107..2108 "=" +| | | | | | | | | | | WhiteSpace 2108..2109 +| | | | | | | | | | | | WhiteSpace 2108..2109 +| | | | | | | | | | | | | WhiteSpace 2108..2109 " " +| | | | | | | | | | | Expression 2109..2110 +| | | | | | | | | | | | Number 2109..2110 +| | | | | | | | | | | | | Number 2109..2110 +| | | | | | | | | | | | | | Number 2109..2110 "1" +| | | | | | | | | | Semicolon 2110..2111 +| | | | | | | | | | | Semicolon 2110..2111 ";" +| | | | | | | | | Error 2111..2112 +| | | | | | | | | | Error 2111..2112 +| | | | | | | | | | | Error 2111..2112 "\r" +| | | | | | | | | EndLine 2112..2113 +| | | | | | | | | | EndLine 2112..2113 +| | | | | | | | | | | EndLine 2112..2113 "\n" +| | | | | | | | | WhiteSpace 2113..2121 +| | | | | | | | | | WhiteSpace 2113..2121 +| | | | | | | | | | | WhiteSpace 2113..2121 " " +| | | | | | | | | Statement 2121..2352 +| | | | | | | | | | ForLoop 2121..2352 +| | | | | | | | | | | ForKw 2121..2124 +| | | | | | | | | | | | ForKw 2121..2124 "for" +| | | | | | | | | | | WhiteSpace 2124..2125 +| | | | | | | | | | | | WhiteSpace 2124..2125 +| | | | | | | | | | | | | WhiteSpace 2124..2125 " " +| | | | | | | | | | | LParen 2125..2126 +| | | | | | | | | | | | LParen 2125..2126 "(" +| | | | | | | | | | | AssignStatement 2126..2129 +| | | | | | | | | | | | Expression 2126..2127 +| | | | | | | | | | | | | Identifier 2126..2127 +| | | | | | | | | | | | | | Identifier 2126..2127 +| | | | | | | | | | | | | | | Identifier 2126..2127 "k" +| | | | | | | | | | | | Assign 2127..2128 +| | | | | | | | | | | | | Assign 2127..2128 "=" +| | | | | | | | | | | | Expression 2128..2129 +| | | | | | | | | | | | | Number 2128..2129 +| | | | | | | | | | | | | | Number 2128..2129 +| | | | | | | | | | | | | | | Number 2128..2129 "0" +| | | | | | | | | | | Semicolon 2129..2130 +| | | | | | | | | | | | Semicolon 2129..2130 ";" +| | | | | | | | | | | WhiteSpace 2130..2131 +| | | | | | | | | | | | WhiteSpace 2130..2131 +| | | | | | | | | | | | | WhiteSpace 2130..2131 " " +| | | | | | | | | | | Expression 2131..2137 +| | | | | | | | | | | | LessThan 2131..2137 +| | | | | | | | | | | | | Identifier 2131..2132 +| | | | | | | | | | | | | | Identifier 2131..2132 +| | | | | | | | | | | | | | | Identifier 2131..2132 "k" +| | | | | | | | | | | | | LessThan 2132..2133 +| | | | | | | | | | | | | | LessThan 2132..2133 "<" +| | | | | | | | | | | | | Identifier 2133..2137 +| | | | | | | | | | | | | | Identifier 2133..2137 +| | | | | | | | | | | | | | | Identifier 2133..2137 "nout" +| | | | | | | | | | | Semicolon 2137..2138 +| | | | | | | | | | | | Semicolon 2137..2138 ";" +| | | | | | | | | | | WhiteSpace 2138..2139 +| | | | | | | | | | | | WhiteSpace 2138..2139 +| | | | | | | | | | | | | WhiteSpace 2138..2139 " " +| | | | | | | | | | | AssignStatement 2139..2142 +| | | | | | | | | | | | Expression 2139..2142 +| | | | | | | | | | | | | Expression 2139..2142 +| | | | | | | | | | | | | | Identifier 2139..2140 +| | | | | | | | | | | | | | | Identifier 2139..2140 +| | | | | | | | | | | | | | | | Identifier 2139..2140 "k" +| | | | | | | | | | | | | | UnitInc 2140..2142 +| | | | | | | | | | | | | | | UnitInc 2140..2142 "++" +| | | | | | | | | | | RParen 2142..2143 +| | | | | | | | | | | | RParen 2142..2143 ")" +| | | | | | | | | | | WhiteSpace 2143..2144 +| | | | | | | | | | | | WhiteSpace 2143..2144 +| | | | | | | | | | | | | WhiteSpace 2143..2144 " " +| | | | | | | | | | | Statement 2144..2352 +| | | | | | | | | | | | Block 2144..2352 +| | | | | | | | | | | | | LCurly 2144..2145 +| | | | | | | | | | | | | | LCurly 2144..2145 "{" +| | | | | | | | | | | | | Error 2145..2146 +| | | | | | | | | | | | | | Error 2145..2146 +| | | | | | | | | | | | | | | Error 2145..2146 "\r" +| | | | | | | | | | | | | EndLine 2146..2147 +| | | | | | | | | | | | | | EndLine 2146..2147 +| | | | | | | | | | | | | | | EndLine 2146..2147 "\n" +| | | | | | | | | | | | | WhiteSpace 2147..2159 +| | | | | | | | | | | | | | WhiteSpace 2147..2159 +| | | | | | | | | | | | | | | WhiteSpace 2147..2159 " " +| | | | | | | | | | | | | StatementList 2159..2351 +| | | | | | | | | | | | | | Statement 2159..2185 +| | | | | | | | | | | | | | | AssignStatement 2159..2184 +| | | | | | | | | | | | | | | | Expression 2159..2166 +| | | | | | | | | | | | | | | | | ArrayQuery 2159..2165 +| | | | | | | | | | | | | | | | | | Identifier 2159..2162 +| | | | | | | | | | | | | | | | | | | Identifier 2159..2162 +| | | | | | | | | | | | | | | | | | | | Identifier 2159..2162 "out" +| | | | | | | | | | | | | | | | | | LBracket 2162..2163 +| | | | | | | | | | | | | | | | | | | LBracket 2162..2163 "[" +| | | | | | | | | | | | | | | | | | Expression 2163..2164 +| | | | | | | | | | | | | | | | | | | Identifier 2163..2164 +| | | | | | | | | | | | | | | | | | | | Identifier 2163..2164 +| | | | | | | | | | | | | | | | | | | | | Identifier 2163..2164 "k" +| | | | | | | | | | | | | | | | | | RBracket 2164..2165 +| | | | | | | | | | | | | | | | | | | RBracket 2164..2165 "]" +| | | | | | | | | | | | | | | | | WhiteSpace 2165..2166 +| | | | | | | | | | | | | | | | | | WhiteSpace 2165..2166 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2165..2166 " " +| | | | | | | | | | | | | | | | RAssignSignal 2166..2169 +| | | | | | | | | | | | | | | | | RAssignSignal 2166..2169 "<--" +| | | | | | | | | | | | | | | | WhiteSpace 2169..2170 +| | | | | | | | | | | | | | | | | WhiteSpace 2169..2170 +| | | | | | | | | | | | | | | | | | WhiteSpace 2169..2170 " " +| | | | | | | | | | | | | | | | Expression 2170..2184 +| | | | | | | | | | | | | | | | | BitAnd 2170..2184 +| | | | | | | | | | | | | | | | | | Expression 2170..2180 +| | | | | | | | | | | | | | | | | | | LParen 2170..2171 +| | | | | | | | | | | | | | | | | | | | LParen 2170..2171 "(" +| | | | | | | | | | | | | | | | | | | ShiftR 2171..2179 +| | | | | | | | | | | | | | | | | | | | Identifier 2171..2174 +| | | | | | | | | | | | | | | | | | | | | Identifier 2171..2174 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2171..2174 "lin" +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2174..2175 +| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2174..2175 +| | | | | | | | | | | | | | | | | | | | | | WhiteSpace 2174..2175 " " +| | | | | | | | | | | | | | | | | | | | ShiftR 2175..2177 +| | | | | | | | | | | | | | | | | | | | | ShiftR 2175..2177 ">>" +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2177..2178 +| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2177..2178 +| | | | | | | | | | | | | | | | | | | | | | WhiteSpace 2177..2178 " " +| | | | | | | | | | | | | | | | | | | | Identifier 2178..2179 +| | | | | | | | | | | | | | | | | | | | | Identifier 2178..2179 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2178..2179 "k" +| | | | | | | | | | | | | | | | | | | RParen 2179..2180 +| | | | | | | | | | | | | | | | | | | | RParen 2179..2180 ")" +| | | | | | | | | | | | | | | | | | WhiteSpace 2180..2181 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2180..2181 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2180..2181 " " +| | | | | | | | | | | | | | | | | | BitAnd 2181..2182 +| | | | | | | | | | | | | | | | | | | BitAnd 2181..2182 "&" +| | | | | | | | | | | | | | | | | | WhiteSpace 2182..2183 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2182..2183 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2182..2183 " " +| | | | | | | | | | | | | | | | | | Number 2183..2184 +| | | | | | | | | | | | | | | | | | | Number 2183..2184 +| | | | | | | | | | | | | | | | | | | | Number 2183..2184 "1" +| | | | | | | | | | | | | | | Semicolon 2184..2185 +| | | | | | | | | | | | | | | | Semicolon 2184..2185 ";" +| | | | | | | | | | | | | | Error 2185..2186 +| | | | | | | | | | | | | | | Error 2185..2186 +| | | | | | | | | | | | | | | | Error 2185..2186 "\r" +| | | | | | | | | | | | | | EndLine 2186..2187 +| | | | | | | | | | | | | | | EndLine 2186..2187 +| | | | | | | | | | | | | | | | EndLine 2186..2187 "\n" +| | | | | | | | | | | | | | WhiteSpace 2187..2191 +| | | | | | | | | | | | | | | WhiteSpace 2187..2191 +| | | | | | | | | | | | | | | | WhiteSpace 2187..2191 " " +| | | | | | | | | | | | | | Error 2191..2192 +| | | | | | | | | | | | | | | Error 2191..2192 +| | | | | | | | | | | | | | | | Error 2191..2192 "\r" +| | | | | | | | | | | | | | EndLine 2192..2193 +| | | | | | | | | | | | | | | EndLine 2192..2193 +| | | | | | | | | | | | | | | | EndLine 2192..2193 "\n" +| | | | | | | | | | | | | | WhiteSpace 2193..2205 +| | | | | | | | | | | | | | | WhiteSpace 2193..2205 +| | | | | | | | | | | | | | | | WhiteSpace 2193..2205 " " +| | | | | | | | | | | | | | CommentLine 2205..2229 +| | | | | | | | | | | | | | | CommentLine 2205..2229 +| | | | | | | | | | | | | | | | CommentLine 2205..2229 "// Ensure out is binary\r" +| | | | | | | | | | | | | | EndLine 2229..2230 +| | | | | | | | | | | | | | | EndLine 2229..2230 +| | | | | | | | | | | | | | | | EndLine 2229..2230 "\n" +| | | | | | | | | | | | | | WhiteSpace 2230..2242 +| | | | | | | | | | | | | | | WhiteSpace 2230..2242 +| | | | | | | | | | | | | | | | WhiteSpace 2230..2242 " " +| | | | | | | | | | | | | | Statement 2242..2270 +| | | | | | | | | | | | | | | AssignStatement 2242..2269 +| | | | | | | | | | | | | | | | Expression 2242..2264 +| | | | | | | | | | | | | | | | | Mul 2242..2264 +| | | | | | | | | | | | | | | | | | ArrayQuery 2242..2248 +| | | | | | | | | | | | | | | | | | | Identifier 2242..2245 +| | | | | | | | | | | | | | | | | | | | Identifier 2242..2245 +| | | | | | | | | | | | | | | | | | | | | Identifier 2242..2245 "out" +| | | | | | | | | | | | | | | | | | | LBracket 2245..2246 +| | | | | | | | | | | | | | | | | | | | LBracket 2245..2246 "[" +| | | | | | | | | | | | | | | | | | | Expression 2246..2247 +| | | | | | | | | | | | | | | | | | | | Identifier 2246..2247 +| | | | | | | | | | | | | | | | | | | | | Identifier 2246..2247 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2246..2247 "k" +| | | | | | | | | | | | | | | | | | | RBracket 2247..2248 +| | | | | | | | | | | | | | | | | | | | RBracket 2247..2248 "]" +| | | | | | | | | | | | | | | | | | WhiteSpace 2248..2249 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2248..2249 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2248..2249 " " +| | | | | | | | | | | | | | | | | | Mul 2249..2250 +| | | | | | | | | | | | | | | | | | | Mul 2249..2250 "*" +| | | | | | | | | | | | | | | | | | WhiteSpace 2250..2251 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2250..2251 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2250..2251 " " +| | | | | | | | | | | | | | | | | | Expression 2251..2263 +| | | | | | | | | | | | | | | | | | | LParen 2251..2252 +| | | | | | | | | | | | | | | | | | | | LParen 2251..2252 "(" +| | | | | | | | | | | | | | | | | | | Sub 2252..2262 +| | | | | | | | | | | | | | | | | | | | ArrayQuery 2252..2258 +| | | | | | | | | | | | | | | | | | | | | Identifier 2252..2255 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2252..2255 +| | | | | | | | | | | | | | | | | | | | | | | Identifier 2252..2255 "out" +| | | | | | | | | | | | | | | | | | | | | LBracket 2255..2256 +| | | | | | | | | | | | | | | | | | | | | | LBracket 2255..2256 "[" +| | | | | | | | | | | | | | | | | | | | | Expression 2256..2257 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2256..2257 +| | | | | | | | | | | | | | | | | | | | | | | Identifier 2256..2257 +| | | | | | | | | | | | | | | | | | | | | | | | Identifier 2256..2257 "k" +| | | | | | | | | | | | | | | | | | | | | RBracket 2257..2258 +| | | | | | | | | | | | | | | | | | | | | | RBracket 2257..2258 "]" +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2258..2259 +| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2258..2259 +| | | | | | | | | | | | | | | | | | | | | | WhiteSpace 2258..2259 " " +| | | | | | | | | | | | | | | | | | | | Sub 2259..2260 +| | | | | | | | | | | | | | | | | | | | | Sub 2259..2260 "-" +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2260..2261 +| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2260..2261 +| | | | | | | | | | | | | | | | | | | | | | WhiteSpace 2260..2261 " " +| | | | | | | | | | | | | | | | | | | | Number 2261..2262 +| | | | | | | | | | | | | | | | | | | | | Number 2261..2262 +| | | | | | | | | | | | | | | | | | | | | | Number 2261..2262 "1" +| | | | | | | | | | | | | | | | | | | RParen 2262..2263 +| | | | | | | | | | | | | | | | | | | | RParen 2262..2263 ")" +| | | | | | | | | | | | | | | | | | WhiteSpace 2263..2264 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2263..2264 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2263..2264 " " +| | | | | | | | | | | | | | | | EqualSignal 2264..2267 +| | | | | | | | | | | | | | | | | EqualSignal 2264..2267 "===" +| | | | | | | | | | | | | | | | WhiteSpace 2267..2268 +| | | | | | | | | | | | | | | | | WhiteSpace 2267..2268 +| | | | | | | | | | | | | | | | | | WhiteSpace 2267..2268 " " +| | | | | | | | | | | | | | | | Expression 2268..2269 +| | | | | | | | | | | | | | | | | Number 2268..2269 +| | | | | | | | | | | | | | | | | | Number 2268..2269 +| | | | | | | | | | | | | | | | | | | Number 2268..2269 "0" +| | | | | | | | | | | | | | | Semicolon 2269..2270 +| | | | | | | | | | | | | | | | Semicolon 2269..2270 ";" +| | | | | | | | | | | | | | Error 2270..2271 +| | | | | | | | | | | | | | | Error 2270..2271 +| | | | | | | | | | | | | | | | Error 2270..2271 "\r" +| | | | | | | | | | | | | | EndLine 2271..2272 +| | | | | | | | | | | | | | | EndLine 2271..2272 +| | | | | | | | | | | | | | | | EndLine 2271..2272 "\n" +| | | | | | | | | | | | | | WhiteSpace 2272..2276 +| | | | | | | | | | | | | | | WhiteSpace 2272..2276 +| | | | | | | | | | | | | | | | WhiteSpace 2272..2276 " " +| | | | | | | | | | | | | | Error 2276..2277 +| | | | | | | | | | | | | | | Error 2276..2277 +| | | | | | | | | | | | | | | | Error 2276..2277 "\r" +| | | | | | | | | | | | | | EndLine 2277..2278 +| | | | | | | | | | | | | | | EndLine 2277..2278 +| | | | | | | | | | | | | | | | EndLine 2277..2278 "\n" +| | | | | | | | | | | | | | WhiteSpace 2278..2290 +| | | | | | | | | | | | | | | WhiteSpace 2278..2290 +| | | | | | | | | | | | | | | | WhiteSpace 2278..2290 " " +| | | | | | | | | | | | | | Statement 2290..2310 +| | | | | | | | | | | | | | | AssignStatement 2290..2309 +| | | | | | | | | | | | | | | | Expression 2290..2295 +| | | | | | | | | | | | | | | | | Identifier 2290..2294 +| | | | | | | | | | | | | | | | | | Identifier 2290..2294 +| | | | | | | | | | | | | | | | | | | Identifier 2290..2294 "lout" +| | | | | | | | | | | | | | | | | WhiteSpace 2294..2295 +| | | | | | | | | | | | | | | | | | WhiteSpace 2294..2295 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2294..2295 " " +| | | | | | | | | | | | | | | | AddAssign 2295..2297 +| | | | | | | | | | | | | | | | | AddAssign 2295..2297 "+=" +| | | | | | | | | | | | | | | | WhiteSpace 2297..2298 +| | | | | | | | | | | | | | | | | WhiteSpace 2297..2298 +| | | | | | | | | | | | | | | | | | WhiteSpace 2297..2298 " " +| | | | | | | | | | | | | | | | Expression 2298..2309 +| | | | | | | | | | | | | | | | | Mul 2298..2309 +| | | | | | | | | | | | | | | | | | ArrayQuery 2298..2304 +| | | | | | | | | | | | | | | | | | | Identifier 2298..2301 +| | | | | | | | | | | | | | | | | | | | Identifier 2298..2301 +| | | | | | | | | | | | | | | | | | | | | Identifier 2298..2301 "out" +| | | | | | | | | | | | | | | | | | | LBracket 2301..2302 +| | | | | | | | | | | | | | | | | | | | LBracket 2301..2302 "[" +| | | | | | | | | | | | | | | | | | | Expression 2302..2303 +| | | | | | | | | | | | | | | | | | | | Identifier 2302..2303 +| | | | | | | | | | | | | | | | | | | | | Identifier 2302..2303 +| | | | | | | | | | | | | | | | | | | | | | Identifier 2302..2303 "k" +| | | | | | | | | | | | | | | | | | | RBracket 2303..2304 +| | | | | | | | | | | | | | | | | | | | RBracket 2303..2304 "]" +| | | | | | | | | | | | | | | | | | WhiteSpace 2304..2305 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2304..2305 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2304..2305 " " +| | | | | | | | | | | | | | | | | | Mul 2305..2306 +| | | | | | | | | | | | | | | | | | | Mul 2305..2306 "*" +| | | | | | | | | | | | | | | | | | WhiteSpace 2306..2307 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2306..2307 +| | | | | | | | | | | | | | | | | | | | WhiteSpace 2306..2307 " " +| | | | | | | | | | | | | | | | | | Identifier 2307..2309 +| | | | | | | | | | | | | | | | | | | Identifier 2307..2309 +| | | | | | | | | | | | | | | | | | | | Identifier 2307..2309 "e2" +| | | | | | | | | | | | | | | Semicolon 2309..2310 +| | | | | | | | | | | | | | | | Semicolon 2309..2310 ";" +| | | | | | | | | | | | | | Error 2310..2311 +| | | | | | | | | | | | | | | Error 2310..2311 +| | | | | | | | | | | | | | | | Error 2310..2311 "\r" +| | | | | | | | | | | | | | EndLine 2311..2312 +| | | | | | | | | | | | | | | EndLine 2311..2312 +| | | | | | | | | | | | | | | | EndLine 2311..2312 "\n" +| | | | | | | | | | | | | | WhiteSpace 2312..2316 +| | | | | | | | | | | | | | | WhiteSpace 2312..2316 +| | | | | | | | | | | | | | | | WhiteSpace 2312..2316 " " +| | | | | | | | | | | | | | Error 2316..2317 +| | | | | | | | | | | | | | | Error 2316..2317 +| | | | | | | | | | | | | | | | Error 2316..2317 "\r" +| | | | | | | | | | | | | | EndLine 2317..2318 +| | | | | | | | | | | | | | | EndLine 2317..2318 +| | | | | | | | | | | | | | | | EndLine 2317..2318 "\n" +| | | | | | | | | | | | | | WhiteSpace 2318..2330 +| | | | | | | | | | | | | | | WhiteSpace 2318..2330 +| | | | | | | | | | | | | | | | WhiteSpace 2318..2330 " " +| | | | | | | | | | | | | | Statement 2330..2341 +| | | | | | | | | | | | | | | AssignStatement 2330..2340 +| | | | | | | | | | | | | | | | Expression 2330..2333 +| | | | | | | | | | | | | | | | | Identifier 2330..2332 +| | | | | | | | | | | | | | | | | | Identifier 2330..2332 +| | | | | | | | | | | | | | | | | | | Identifier 2330..2332 "e2" +| | | | | | | | | | | | | | | | | WhiteSpace 2332..2333 +| | | | | | | | | | | | | | | | | | WhiteSpace 2332..2333 +| | | | | | | | | | | | | | | | | | | WhiteSpace 2332..2333 " " +| | | | | | | | | | | | | | | | Assign 2333..2334 +| | | | | | | | | | | | | | | | | Assign 2333..2334 "=" +| | | | | | | | | | | | | | | | WhiteSpace 2334..2335 +| | | | | | | | | | | | | | | | | WhiteSpace 2334..2335 +| | | | | | | | | | | | | | | | | | WhiteSpace 2334..2335 " " +| | | | | | | | | | | | | | | | Expression 2335..2340 +| | | | | | | | | | | | | | | | | Add 2335..2340 +| | | | | | | | | | | | | | | | | | Identifier 2335..2337 +| | | | | | | | | | | | | | | | | | | Identifier 2335..2337 +| | | | | | | | | | | | | | | | | | | | Identifier 2335..2337 "e2" +| | | | | | | | | | | | | | | | | | Add 2337..2338 +| | | | | | | | | | | | | | | | | | | Add 2337..2338 "+" +| | | | | | | | | | | | | | | | | | Identifier 2338..2340 +| | | | | | | | | | | | | | | | | | | Identifier 2338..2340 +| | | | | | | | | | | | | | | | | | | | Identifier 2338..2340 "e2" +| | | | | | | | | | | | | | | Semicolon 2340..2341 +| | | | | | | | | | | | | | | | Semicolon 2340..2341 ";" +| | | | | | | | | | | | | | Error 2341..2342 +| | | | | | | | | | | | | | | Error 2341..2342 +| | | | | | | | | | | | | | | | Error 2341..2342 "\r" +| | | | | | | | | | | | | | EndLine 2342..2343 +| | | | | | | | | | | | | | | EndLine 2342..2343 +| | | | | | | | | | | | | | | | EndLine 2342..2343 "\n" +| | | | | | | | | | | | | | WhiteSpace 2343..2351 +| | | | | | | | | | | | | | | WhiteSpace 2343..2351 +| | | | | | | | | | | | | | | | WhiteSpace 2343..2351 " " +| | | | | | | | | | | | | RCurly 2351..2352 +| | | | | | | | | | | | | | RCurly 2351..2352 "}" +| | | | | | | | | Error 2352..2353 +| | | | | | | | | | Error 2352..2353 +| | | | | | | | | | | Error 2352..2353 "\r" +| | | | | | | | | EndLine 2353..2354 +| | | | | | | | | | EndLine 2353..2354 +| | | | | | | | | | | EndLine 2353..2354 "\n" +| | | | | | | | | WhiteSpace 2354..2358 +| | | | | | | | | | WhiteSpace 2354..2358 +| | | | | | | | | | | WhiteSpace 2354..2358 " " +| | | | | | | | | Error 2358..2359 +| | | | | | | | | | Error 2358..2359 +| | | | | | | | | | | Error 2358..2359 "\r" +| | | | | | | | | EndLine 2359..2360 +| | | | | | | | | | EndLine 2359..2360 +| | | | | | | | | | | EndLine 2359..2360 "\n" +| | | | | | | | | WhiteSpace 2360..2368 +| | | | | | | | | | WhiteSpace 2360..2368 +| | | | | | | | | | | WhiteSpace 2360..2368 " " +| | | | | | | | | CommentLine 2368..2387 +| | | | | | | | | | CommentLine 2368..2387 +| | | | | | | | | | | CommentLine 2368..2387 "// Ensure the sum;\r" +| | | | | | | | | EndLine 2387..2388 +| | | | | | | | | | EndLine 2387..2388 +| | | | | | | | | | | EndLine 2387..2388 "\n" +| | | | | | | | | WhiteSpace 2388..2392 +| | | | | | | | | | WhiteSpace 2388..2392 +| | | | | | | | | | | WhiteSpace 2388..2392 " " +| | | | | | | | | Error 2392..2393 +| | | | | | | | | | Error 2392..2393 +| | | | | | | | | | | Error 2392..2393 "\r" +| | | | | | | | | EndLine 2393..2394 +| | | | | | | | | | EndLine 2393..2394 +| | | | | | | | | | | EndLine 2393..2394 "\n" +| | | | | | | | | WhiteSpace 2394..2402 +| | | | | | | | | | WhiteSpace 2394..2402 +| | | | | | | | | | | WhiteSpace 2394..2402 " " +| | | | | | | | | Statement 2402..2415 +| | | | | | | | | | AssignStatement 2402..2414 +| | | | | | | | | | | Expression 2402..2406 +| | | | | | | | | | | | Identifier 2402..2405 +| | | | | | | | | | | | | Identifier 2402..2405 +| | | | | | | | | | | | | | Identifier 2402..2405 "lin" +| | | | | | | | | | | | WhiteSpace 2405..2406 +| | | | | | | | | | | | | WhiteSpace 2405..2406 +| | | | | | | | | | | | | | WhiteSpace 2405..2406 " " +| | | | | | | | | | | EqualSignal 2406..2409 +| | | | | | | | | | | | EqualSignal 2406..2409 "===" +| | | | | | | | | | | WhiteSpace 2409..2410 +| | | | | | | | | | | | WhiteSpace 2409..2410 +| | | | | | | | | | | | | WhiteSpace 2409..2410 " " +| | | | | | | | | | | Expression 2410..2414 +| | | | | | | | | | | | Identifier 2410..2414 +| | | | | | | | | | | | | Identifier 2410..2414 +| | | | | | | | | | | | | | Identifier 2410..2414 "lout" +| | | | | | | | | | Semicolon 2414..2415 +| | | | | | | | | | | Semicolon 2414..2415 ";" +| | | | | | | | | Error 2415..2416 +| | | | | | | | | | Error 2415..2416 +| | | | | | | | | | | Error 2415..2416 "\r" +| | | | | | | | | EndLine 2416..2417 +| | | | | | | | | | EndLine 2416..2417 +| | | | | | | | | | | EndLine 2416..2417 "\n" +| | | | | | | | | WhiteSpace 2417..2421 +| | | | | | | | | | WhiteSpace 2417..2421 +| | | | | | | | | | | WhiteSpace 2417..2421 " " +| | | | | | | | RCurly 2421..2422 +| | | | | | | | | RCurly 2421..2422 "}" +| | | | Error 2422..2423 +| | | | | Error 2422..2423 +| | | | | | Error 2422..2423 "\r" +| | | | EndLine 2423..2424 +| | | | | EndLine 2423..2424 +| | | | | | EndLine 2423..2424 "\n" +| | | Error 2424..2449 +| | | | Error 2424..2449 +| | | | | Error 2424..2449 "expect RCurly but got EOF" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__line_comment.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__line_comment.circom.snap index cb78791..4e063b5 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__line_comment.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__line_comment.circom.snap @@ -1,38 +1,47 @@ --- source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" +expression: "crate :: view_syntax :: view_ast(& syntax)" --- - CircomProgram 0..41 -| EndLine 0..1 -| | EndLine 0..1 -| | | EndLine 0..1 "\n" -| CommentLine 1..14 -| | CommentLine 1..14 -| | | CommentLine 1..14 "// comment :>" -| EndLine 14..15 -| | EndLine 14..15 -| | | EndLine 14..15 "\n" -| EndLine 15..16 -| | EndLine 15..16 -| | | EndLine 15..16 "\n" -| WhiteSpace 16..20 -| | WhiteSpace 16..20 -| | | WhiteSpace 16..20 " " -| Pragma 20..40 -| | Pragma 20..26 -| | | Pragma 20..26 "pragma" -| | WhiteSpace 26..27 -| | | WhiteSpace 26..27 -| | | | WhiteSpace 26..27 " " -| | Circom 27..33 -| | | Circom 27..33 "circom" -| | WhiteSpace 33..34 -| | | WhiteSpace 33..34 -| | | | WhiteSpace 33..34 " " -| | Version 34..39 -| | | Version 34..39 "2.0.0" -| | Semicolon 39..40 -| | | Semicolon 39..40 ";" -| EndLine 40..41 -| | EndLine 40..41 -| | | EndLine 40..41 "\n" + CircomProgram 0..45 +| Error 0..1 +| | Error 0..1 +| | | Error 0..1 "\r" +| EndLine 1..2 +| | EndLine 1..2 +| | | EndLine 1..2 "\n" +| CommentLine 2..16 +| | CommentLine 2..16 +| | | CommentLine 2..16 "// comment :>\r" +| EndLine 16..17 +| | EndLine 16..17 +| | | EndLine 16..17 "\n" +| Error 17..18 +| | Error 17..18 +| | | Error 17..18 "\r" +| EndLine 18..19 +| | EndLine 18..19 +| | | EndLine 18..19 "\n" +| WhiteSpace 19..23 +| | WhiteSpace 19..23 +| | | WhiteSpace 19..23 " " +| Pragma 23..43 +| | Pragma 23..29 +| | | Pragma 23..29 "pragma" +| | WhiteSpace 29..30 +| | | WhiteSpace 29..30 +| | | | WhiteSpace 29..30 " " +| | Circom 30..36 +| | | Circom 30..36 "circom" +| | WhiteSpace 36..37 +| | | WhiteSpace 36..37 +| | | | WhiteSpace 36..37 " " +| | Version 37..42 +| | | Version 37..42 "2.0.0" +| | Semicolon 42..43 +| | | Semicolon 42..43 ";" +| Error 43..44 +| | Error 43..44 +| | | Error 43..44 "\r" +| EndLine 44..45 +| | EndLine 44..45 +| | | EndLine 44..45 "\n" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__pragma.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__pragma.circom.snap index f84ef6f..3e98fd0 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__pragma.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__pragma.circom.snap @@ -1,6 +1,6 @@ --- source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" +expression: "crate :: view_syntax :: view_ast(& syntax)" --- Pragma 0..20 | Pragma 0..6 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap index 6d1a073..3e055cc 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap @@ -1,8 +1,8 @@ --- source: crates/syntax/src/syntax.rs -expression: "crate::view_syntax::view_ast(&syntax)" +expression: "crate :: view_syntax :: view_ast(& syntax)" --- - TemplateDef 0..784 + TemplateDef 0..349 | TemplateKw 0..8 | | TemplateKw 0..8 "template" | WhiteSpace 8..9 @@ -14,9 +14,9 @@ expression: "crate::view_syntax::view_ast(&syntax)" | WhiteSpace 20..21 | | WhiteSpace 20..21 | | | WhiteSpace 20..21 " " -| LParen 21..22 -| | LParen 21..22 "(" -| ParameterList 22..30 +| ParameterList 21..31 +| | LParen 21..22 +| | | LParen 21..22 "(" | | Identifier 22..23 | | | Identifier 22..23 "N" | | Comma 23..24 @@ -33,326 +33,286 @@ expression: "crate::view_syntax::view_ast(&syntax)" | | | | WhiteSpace 27..28 " " | | Identifier 28..30 | | | Identifier 28..30 "QQ" -| RParen 30..31 -| | RParen 30..31 ")" +| | RParen 30..31 +| | | RParen 30..31 ")" | WhiteSpace 31..32 | | WhiteSpace 31..32 | | | WhiteSpace 31..32 " " -| Block 32..784 +| Block 32..349 | | LCurly 32..33 | | | LCurly 32..33 "{" -| | EndLine 33..34 -| | | EndLine 33..34 -| | | | EndLine 33..34 "\n" -| | WhiteSpace 34..46 -| | | WhiteSpace 34..46 -| | | | WhiteSpace 34..46 " " -| | CommentLine 46..86 -| | | CommentLine 46..86 -| | | | CommentLine 46..86 "//Declaration of signals and components." -| | EndLine 86..87 -| | | EndLine 86..87 -| | | | EndLine 86..87 "\n" -| | WhiteSpace 87..99 -| | | WhiteSpace 87..99 -| | | | WhiteSpace 87..99 " " -| | StatementList 99..783 -| | | InputSignalDecl 99..114 -| | | | SignalHeader 99..112 -| | | | | SignalKw 99..105 -| | | | | | SignalKw 99..105 "signal" -| | | | | WhiteSpace 105..106 -| | | | | | WhiteSpace 105..106 -| | | | | | | WhiteSpace 105..106 " " -| | | | | InputKw 106..111 -| | | | | | InputKw 106..111 "input" -| | | | | WhiteSpace 111..112 -| | | | | | WhiteSpace 111..112 -| | | | | | | WhiteSpace 111..112 " " -| | | | Identifier 112..114 -| | | | | Identifier 112..114 "in" -| | | Error 114..147 -| | | | Error 114..147 -| | | | | Error 114..147 "expect Semicolon but got LBracket" -| | | Statement 147..183 -| | | | Error 147..148 -| | | | | Expression 147..148 -| | | | | | Error 147..148 -| | | | | | | LBracket 147..148 -| | | | | | | | LBracket 147..148 "[" -| | | | Error 148..183 -| | | | | Error 148..183 -| | | | | | Error 148..183 "expect Semicolon but got Identifier" -| | | Statement 183..217 -| | | | Error 183..184 -| | | | | Expression 183..184 -| | | | | | ComponentIdentifier 183..184 -| | | | | | | Identifier 183..184 -| | | | | | | | Identifier 183..184 "N" -| | | | Error 184..217 -| | | | | Error 184..217 -| | | | | | Error 184..217 "expect Semicolon but got RBracket" -| | | Statement 217..219 -| | | | Error 217..218 -| | | | | Expression 217..218 -| | | | | | Error 217..218 -| | | | | | | RBracket 217..218 -| | | | | | | | RBracket 217..218 "]" -| | | | Semicolon 218..219 -| | | | | Semicolon 218..219 ";" -| | | EndLine 219..220 -| | | | EndLine 219..220 -| | | | | EndLine 219..220 "\n" -| | | WhiteSpace 220..232 -| | | | WhiteSpace 220..232 -| | | | | WhiteSpace 220..232 " " -| | | OutputSignalDecl 232..249 -| | | | SignalHeader 232..246 -| | | | | SignalKw 232..238 -| | | | | | SignalKw 232..238 "signal" -| | | | | WhiteSpace 238..239 -| | | | | | WhiteSpace 238..239 -| | | | | | | WhiteSpace 238..239 " " -| | | | | OutputKw 239..245 -| | | | | | OutputKw 239..245 "output" -| | | | | WhiteSpace 245..246 -| | | | | | WhiteSpace 245..246 -| | | | | | | WhiteSpace 245..246 " " -| | | | Identifier 246..249 -| | | | | Identifier 246..249 "out" -| | | Semicolon 249..250 -| | | | Semicolon 249..250 ";" -| | | EndLine 250..251 -| | | | EndLine 250..251 -| | | | | EndLine 250..251 "\n" -| | | WhiteSpace 251..263 -| | | | WhiteSpace 251..263 -| | | | | WhiteSpace 251..263 " " -| | | ComponentDecl 263..401 -| | | | ComponentKw 263..272 -| | | | | ComponentKw 263..272 "component" -| | | | WhiteSpace 272..273 -| | | | | WhiteSpace 272..273 -| | | | | | WhiteSpace 272..273 " " -| | | | ComponentIdentifier 273..277 -| | | | | Identifier 273..277 -| | | | | | Identifier 273..277 "comp" -| | | | Error 277..307 -| | | | | Error 277..307 -| | | | | | Error 277..307 "expect Assign but got LBracket" -| | | | TemplateName 307..341 -| | | | | Error 307..341 -| | | | | | Error 307..341 -| | | | | | | Error 307..341 "expect Identifier but got LBracket" -| | | | Error 341..371 -| | | | | Error 341..371 -| | | | | | Error 341..371 "expect LParen but got LBracket" -| | | | Error 371..401 -| | | | | Error 371..401 -| | | | | | Error 371..401 "expect RParen but got LBracket" -| | | Error 401..434 -| | | | Error 401..434 -| | | | | Error 401..434 "expect Semicolon but got LBracket" -| | | Statement 434..470 -| | | | Error 434..435 -| | | | | Expression 434..435 -| | | | | | Error 434..435 -| | | | | | | LBracket 434..435 -| | | | | | | | LBracket 434..435 "[" -| | | | Error 435..470 -| | | | | Error 435..470 -| | | | | | Error 435..470 "expect Semicolon but got Identifier" -| | | Statement 470..499 -| | | | Error 470..471 -| | | | | Expression 470..471 -| | | | | | ComponentIdentifier 470..471 -| | | | | | | Identifier 470..471 -| | | | | | | | Identifier 470..471 "N" -| | | | Error 471..499 -| | | | | Error 471..499 -| | | | | | Error 471..499 "expect Semicolon but got Sub" -| | | Statement 499..534 -| | | | Error 499..501 -| | | | | Expression 499..501 -| | | | | | Sub 499..501 -| | | | | | | Sub 499..500 -| | | | | | | | Sub 499..500 "-" -| | | | | | | Number 500..501 -| | | | | | | | Number 500..501 -| | | | | | | | | Number 500..501 "1" -| | | | Error 501..534 -| | | | | Error 501..534 -| | | | | | Error 501..534 "expect Semicolon but got RBracket" -| | | Statement 534..536 -| | | | Error 534..535 -| | | | | Expression 534..535 -| | | | | | Error 534..535 -| | | | | | | RBracket 534..535 -| | | | | | | | RBracket 534..535 "]" -| | | | Semicolon 535..536 -| | | | | Semicolon 535..536 ";" -| | | EndLine 536..537 -| | | | EndLine 536..537 -| | | | | EndLine 536..537 "\n" -| | | WhiteSpace 537..550 -| | | | WhiteSpace 537..550 -| | | | | WhiteSpace 537..550 " " -| | | EndLine 550..551 -| | | | EndLine 550..551 -| | | | | EndLine 550..551 "\n" -| | | WhiteSpace 551..563 -| | | | WhiteSpace 551..563 -| | | | | WhiteSpace 551..563 " " -| | | CommentLine 563..576 -| | | | CommentLine 563..576 -| | | | | CommentLine 563..576 "//Statements." -| | | EndLine 576..577 -| | | | EndLine 576..577 -| | | | | EndLine 576..577 "\n" -| | | WhiteSpace 577..589 -| | | | WhiteSpace 577..589 -| | | | | WhiteSpace 577..589 " " -| | | Statement 589..677 -| | | | ForLoop 589..677 -| | | | | ForKw 589..592 -| | | | | | ForKw 589..592 "for" -| | | | | LParen 592..593 -| | | | | | LParen 592..593 "(" -| | | | | VarDecl 593..602 -| | | | | | VarKw 593..596 -| | | | | | | VarKw 593..596 "var" -| | | | | | WhiteSpace 596..597 -| | | | | | | WhiteSpace 596..597 -| | | | | | | | WhiteSpace 596..597 " " -| | | | | | Identifier 597..598 -| | | | | | | Identifier 597..598 "i" -| | | | | | WhiteSpace 598..599 -| | | | | | | WhiteSpace 598..599 -| | | | | | | | WhiteSpace 598..599 " " -| | | | | | Assign 599..600 -| | | | | | | Assign 599..600 "=" -| | | | | | WhiteSpace 600..601 -| | | | | | | WhiteSpace 600..601 -| | | | | | | | WhiteSpace 600..601 " " -| | | | | | Expression 601..602 -| | | | | | | Number 601..602 -| | | | | | | | Number 601..602 -| | | | | | | | | Number 601..602 "0" -| | | | | Semicolon 602..603 -| | | | | | Semicolon 602..603 ";" -| | | | | WhiteSpace 603..604 -| | | | | | WhiteSpace 603..604 -| | | | | | | WhiteSpace 603..604 " " -| | | | | Expression 604..611 -| | | | | | LessThan 604..611 -| | | | | | | Identifier 604..605 -| | | | | | | | Identifier 604..605 -| | | | | | | | | Identifier 604..605 "i" -| | | | | | | WhiteSpace 605..606 -| | | | | | | | WhiteSpace 605..606 -| | | | | | | | | WhiteSpace 605..606 " " -| | | | | | | LessThan 606..607 -| | | | | | | | LessThan 606..607 "<" -| | | | | | | WhiteSpace 607..608 -| | | | | | | | WhiteSpace 607..608 -| | | | | | | | | WhiteSpace 607..608 " " -| | | | | | | Sub 608..611 -| | | | | | | | Identifier 608..609 -| | | | | | | | | Identifier 608..609 -| | | | | | | | | | Identifier 608..609 "N" -| | | | | | | | Sub 609..610 -| | | | | | | | | Sub 609..610 "-" -| | | | | | | | Number 610..611 -| | | | | | | | | Number 610..611 -| | | | | | | | | | Number 610..611 "1" -| | | | | Semicolon 611..612 -| | | | | | Semicolon 611..612 ";" -| | | | | WhiteSpace 612..613 -| | | | | | WhiteSpace 612..613 -| | | | | | | WhiteSpace 612..613 " " -| | | | | Error 613..614 -| | | | | | Expression 613..614 -| | | | | | | ComponentIdentifier 613..614 -| | | | | | | | Identifier 613..614 -| | | | | | | | | Identifier 613..614 "i" -| | | | | Error 614..643 -| | | | | | Error 614..643 -| | | | | | | Error 614..643 "expect RParen but got UnitInc" -| | | | | Error 643..646 -| | | | | | Expression 643..646 -| | | | | | | UnitInc 643..646 -| | | | | | | | UnitInc 643..645 -| | | | | | | | | UnitInc 643..645 "++" -| | | | | | | | Error 645..646 -| | | | | | | | | RParen 645..646 -| | | | | | | | | | RParen 645..646 ")" -| | | | | Error 646..677 -| | | | | | Error 646..677 -| | | | | | | Error 646..677 "expect Semicolon but got LCurly" -| | | Statement 677..765 -| | | | Block 677..765 -| | | | | LCurly 677..678 -| | | | | | LCurly 677..678 "{" -| | | | | EndLine 678..679 -| | | | | | EndLine 678..679 -| | | | | | | EndLine 678..679 "\n" -| | | | | WhiteSpace 679..695 -| | | | | | WhiteSpace 679..695 -| | | | | | | WhiteSpace 679..695 " " -| | | | | StatementList 695..764 -| | | | | | Statement 695..751 -| | | | | | | AssignStatement 695..750 -| | | | | | | | Expression 695..703 -| | | | | | | | | ComponentIdentifier 695..699 -| | | | | | | | | | Identifier 695..699 -| | | | | | | | | | | Identifier 695..699 "comp" -| | | | | | | | | LBracket 699..700 -| | | | | | | | | | LBracket 699..700 "[" -| | | | | | | | | Expression 700..701 -| | | | | | | | | | Identifier 700..701 -| | | | | | | | | | | Identifier 700..701 -| | | | | | | | | | | | Identifier 700..701 "i" -| | | | | | | | | RBracket 701..702 -| | | | | | | | | | RBracket 701..702 "]" -| | | | | | | | | WhiteSpace 702..703 -| | | | | | | | | | WhiteSpace 702..703 -| | | | | | | | | | | WhiteSpace 702..703 " " -| | | | | | | | Assign 703..704 -| | | | | | | | | Assign 703..704 "=" -| | | | | | | | WhiteSpace 704..705 -| | | | | | | | | WhiteSpace 704..705 -| | | | | | | | | | WhiteSpace 704..705 " " -| | | | | | | | Expression 705..750 -| | | | | | | | | Call 705..750 -| | | | | | | | | | Identifier 705..716 -| | | | | | | | | | | Identifier 705..716 -| | | | | | | | | | | | Identifier 705..716 "Multiplier2" -| | | | | | | | | | Tuple 716..750 -| | | | | | | | | | | LParen 716..717 -| | | | | | | | | | | | LParen 716..717 "(" -| | | | | | | | | | | Error 717..749 -| | | | | | | | | | | | Error 717..749 -| | | | | | | | | | | | | Error 717..749 "expect Identifier but got RParen" -| | | | | | | | | | | RParen 749..750 -| | | | | | | | | | | | RParen 749..750 ")" -| | | | | | | Semicolon 750..751 -| | | | | | | | Semicolon 750..751 ";" -| | | | | | EndLine 751..752 -| | | | | | | EndLine 751..752 -| | | | | | | | EndLine 751..752 "\n" -| | | | | | WhiteSpace 752..764 -| | | | | | | WhiteSpace 752..764 -| | | | | | | | WhiteSpace 752..764 " " -| | | | | RCurly 764..765 -| | | | | | RCurly 764..765 "}" -| | | EndLine 765..766 -| | | | EndLine 765..766 -| | | | | EndLine 765..766 "\n" -| | | WhiteSpace 766..782 -| | | | WhiteSpace 766..782 -| | | | | WhiteSpace 766..782 " " -| | | EndLine 782..783 -| | | | EndLine 782..783 -| | | | | EndLine 782..783 "\n" -| | RCurly 783..784 -| | | RCurly 783..784 "}" +| | Error 33..34 +| | | Error 33..34 +| | | | Error 33..34 "\r" +| | EndLine 34..35 +| | | EndLine 34..35 +| | | | EndLine 34..35 "\n" +| | WhiteSpace 35..47 +| | | WhiteSpace 35..47 +| | | | WhiteSpace 35..47 " " +| | CommentLine 47..88 +| | | CommentLine 47..88 +| | | | CommentLine 47..88 "//Declaration of signals and components.\r" +| | EndLine 88..89 +| | | EndLine 88..89 +| | | | EndLine 88..89 "\n" +| | WhiteSpace 89..101 +| | | WhiteSpace 89..101 +| | | | WhiteSpace 89..101 " " +| | StatementList 101..348 +| | | InputSignalDecl 101..119 +| | | | SignalHeader 101..114 +| | | | | SignalKw 101..107 +| | | | | | SignalKw 101..107 "signal" +| | | | | WhiteSpace 107..108 +| | | | | | WhiteSpace 107..108 +| | | | | | | WhiteSpace 107..108 " " +| | | | | InputKw 108..113 +| | | | | | InputKw 108..113 "input" +| | | | | WhiteSpace 113..114 +| | | | | | WhiteSpace 113..114 +| | | | | | | WhiteSpace 113..114 " " +| | | | Identifier 114..116 +| | | | | Identifier 114..116 "in" +| | | | ArrayQuery 116..119 +| | | | | LBracket 116..117 +| | | | | | LBracket 116..117 "[" +| | | | | Expression 117..118 +| | | | | | Identifier 117..118 +| | | | | | | Identifier 117..118 +| | | | | | | | Identifier 117..118 "N" +| | | | | RBracket 118..119 +| | | | | | RBracket 118..119 "]" +| | | Semicolon 119..120 +| | | | Semicolon 119..120 ";" +| | | Error 120..121 +| | | | Error 120..121 +| | | | | Error 120..121 "\r" +| | | EndLine 121..122 +| | | | EndLine 121..122 +| | | | | EndLine 121..122 "\n" +| | | WhiteSpace 122..134 +| | | | WhiteSpace 122..134 +| | | | | WhiteSpace 122..134 " " +| | | OutputSignalDecl 134..151 +| | | | SignalHeader 134..148 +| | | | | SignalKw 134..140 +| | | | | | SignalKw 134..140 "signal" +| | | | | WhiteSpace 140..141 +| | | | | | WhiteSpace 140..141 +| | | | | | | WhiteSpace 140..141 " " +| | | | | OutputKw 141..147 +| | | | | | OutputKw 141..147 "output" +| | | | | WhiteSpace 147..148 +| | | | | | WhiteSpace 147..148 +| | | | | | | WhiteSpace 147..148 " " +| | | | Identifier 148..151 +| | | | | Identifier 148..151 "out" +| | | Semicolon 151..152 +| | | | Semicolon 151..152 ";" +| | | Error 152..153 +| | | | Error 152..153 +| | | | | Error 152..153 "\r" +| | | EndLine 153..154 +| | | | EndLine 153..154 +| | | | | EndLine 153..154 "\n" +| | | WhiteSpace 154..166 +| | | | WhiteSpace 154..166 +| | | | | WhiteSpace 154..166 " " +| | | ComponentDecl 166..185 +| | | | ComponentKw 166..175 +| | | | | ComponentKw 166..175 "component" +| | | | WhiteSpace 175..176 +| | | | | WhiteSpace 175..176 +| | | | | | WhiteSpace 175..176 " " +| | | | ComponentIdentifier 176..180 +| | | | | Identifier 176..180 +| | | | | | Identifier 176..180 "comp" +| | | | ArrayQuery 180..185 +| | | | | LBracket 180..181 +| | | | | | LBracket 180..181 "[" +| | | | | Expression 181..184 +| | | | | | Sub 181..184 +| | | | | | | Identifier 181..182 +| | | | | | | | Identifier 181..182 +| | | | | | | | | Identifier 181..182 "N" +| | | | | | | Sub 182..183 +| | | | | | | | Sub 182..183 "-" +| | | | | | | Number 183..184 +| | | | | | | | Number 183..184 +| | | | | | | | | Number 183..184 "1" +| | | | | RBracket 184..185 +| | | | | | RBracket 184..185 "]" +| | | Semicolon 185..186 +| | | | Semicolon 185..186 ";" +| | | Error 186..187 +| | | | Error 186..187 +| | | | | Error 186..187 "\r" +| | | EndLine 187..188 +| | | | EndLine 187..188 +| | | | | EndLine 187..188 "\n" +| | | WhiteSpace 188..201 +| | | | WhiteSpace 188..201 +| | | | | WhiteSpace 188..201 " " +| | | Error 201..202 +| | | | Error 201..202 +| | | | | Error 201..202 "\r" +| | | EndLine 202..203 +| | | | EndLine 202..203 +| | | | | EndLine 202..203 "\n" +| | | WhiteSpace 203..215 +| | | | WhiteSpace 203..215 +| | | | | WhiteSpace 203..215 " " +| | | CommentLine 215..229 +| | | | CommentLine 215..229 +| | | | | CommentLine 215..229 "//Statements.\r" +| | | EndLine 229..230 +| | | | EndLine 229..230 +| | | | | EndLine 229..230 "\n" +| | | WhiteSpace 230..242 +| | | | WhiteSpace 230..242 +| | | | | WhiteSpace 230..242 " " +| | | Statement 242..328 +| | | | ForLoop 242..328 +| | | | | ForKw 242..245 +| | | | | | ForKw 242..245 "for" +| | | | | LParen 245..246 +| | | | | | LParen 245..246 "(" +| | | | | VarDecl 246..255 +| | | | | | VarKw 246..249 +| | | | | | | VarKw 246..249 "var" +| | | | | | WhiteSpace 249..250 +| | | | | | | WhiteSpace 249..250 +| | | | | | | | WhiteSpace 249..250 " " +| | | | | | Identifier 250..251 +| | | | | | | Identifier 250..251 "i" +| | | | | | WhiteSpace 251..252 +| | | | | | | WhiteSpace 251..252 +| | | | | | | | WhiteSpace 251..252 " " +| | | | | | Assign 252..253 +| | | | | | | Assign 252..253 "=" +| | | | | | WhiteSpace 253..254 +| | | | | | | WhiteSpace 253..254 +| | | | | | | | WhiteSpace 253..254 " " +| | | | | | Expression 254..255 +| | | | | | | Number 254..255 +| | | | | | | | Number 254..255 +| | | | | | | | | Number 254..255 "0" +| | | | | Semicolon 255..256 +| | | | | | Semicolon 255..256 ";" +| | | | | WhiteSpace 256..257 +| | | | | | WhiteSpace 256..257 +| | | | | | | WhiteSpace 256..257 " " +| | | | | Expression 257..264 +| | | | | | LessThan 257..264 +| | | | | | | Identifier 257..258 +| | | | | | | | Identifier 257..258 +| | | | | | | | | Identifier 257..258 "i" +| | | | | | | WhiteSpace 258..259 +| | | | | | | | WhiteSpace 258..259 +| | | | | | | | | WhiteSpace 258..259 " " +| | | | | | | LessThan 259..260 +| | | | | | | | LessThan 259..260 "<" +| | | | | | | WhiteSpace 260..261 +| | | | | | | | WhiteSpace 260..261 +| | | | | | | | | WhiteSpace 260..261 " " +| | | | | | | Sub 261..264 +| | | | | | | | Identifier 261..262 +| | | | | | | | | Identifier 261..262 +| | | | | | | | | | Identifier 261..262 "N" +| | | | | | | | Sub 262..263 +| | | | | | | | | Sub 262..263 "-" +| | | | | | | | Number 263..264 +| | | | | | | | | Number 263..264 +| | | | | | | | | | Number 263..264 "1" +| | | | | Semicolon 264..265 +| | | | | | Semicolon 264..265 ";" +| | | | | WhiteSpace 265..266 +| | | | | | WhiteSpace 265..266 +| | | | | | | WhiteSpace 265..266 " " +| | | | | AssignStatement 266..269 +| | | | | | Expression 266..269 +| | | | | | | Expression 266..269 +| | | | | | | | Identifier 266..267 +| | | | | | | | | Identifier 266..267 +| | | | | | | | | | Identifier 266..267 "i" +| | | | | | | | UnitInc 267..269 +| | | | | | | | | UnitInc 267..269 "++" +| | | | | RParen 269..270 +| | | | | | RParen 269..270 ")" +| | | | | Statement 270..328 +| | | | | | Block 270..328 +| | | | | | | LCurly 270..271 +| | | | | | | | LCurly 270..271 "{" +| | | | | | | Error 271..272 +| | | | | | | | Error 271..272 +| | | | | | | | | Error 271..272 "\r" +| | | | | | | EndLine 272..273 +| | | | | | | | EndLine 272..273 +| | | | | | | | | EndLine 272..273 "\n" +| | | | | | | WhiteSpace 273..289 +| | | | | | | | WhiteSpace 273..289 +| | | | | | | | | WhiteSpace 273..289 " " +| | | | | | | StatementList 289..327 +| | | | | | | | Statement 289..313 +| | | | | | | | | AssignStatement 289..312 +| | | | | | | | | | Expression 289..297 +| | | | | | | | | | | ArrayQuery 289..296 +| | | | | | | | | | | | Identifier 289..293 +| | | | | | | | | | | | | Identifier 289..293 +| | | | | | | | | | | | | | Identifier 289..293 "comp" +| | | | | | | | | | | | LBracket 293..294 +| | | | | | | | | | | | | LBracket 293..294 "[" +| | | | | | | | | | | | Expression 294..295 +| | | | | | | | | | | | | Identifier 294..295 +| | | | | | | | | | | | | | Identifier 294..295 +| | | | | | | | | | | | | | | Identifier 294..295 "i" +| | | | | | | | | | | | RBracket 295..296 +| | | | | | | | | | | | | RBracket 295..296 "]" +| | | | | | | | | | | WhiteSpace 296..297 +| | | | | | | | | | | | WhiteSpace 296..297 +| | | | | | | | | | | | | WhiteSpace 296..297 " " +| | | | | | | | | | Assign 297..298 +| | | | | | | | | | | Assign 297..298 "=" +| | | | | | | | | | WhiteSpace 298..299 +| | | | | | | | | | | WhiteSpace 298..299 +| | | | | | | | | | | | WhiteSpace 298..299 " " +| | | | | | | | | | Expression 299..312 +| | | | | | | | | | | Call 299..312 +| | | | | | | | | | | | Identifier 299..310 +| | | | | | | | | | | | | Identifier 299..310 +| | | | | | | | | | | | | | Identifier 299..310 "Multiplier2" +| | | | | | | | | | | | LParen 310..311 +| | | | | | | | | | | | | LParen 310..311 "(" +| | | | | | | | | | | | RParen 311..312 +| | | | | | | | | | | | | RParen 311..312 ")" +| | | | | | | | | Semicolon 312..313 +| | | | | | | | | | Semicolon 312..313 ";" +| | | | | | | | Error 313..314 +| | | | | | | | | Error 313..314 +| | | | | | | | | | Error 313..314 "\r" +| | | | | | | | EndLine 314..315 +| | | | | | | | | EndLine 314..315 +| | | | | | | | | | EndLine 314..315 "\n" +| | | | | | | | WhiteSpace 315..327 +| | | | | | | | | WhiteSpace 315..327 +| | | | | | | | | | WhiteSpace 315..327 " " +| | | | | | | RCurly 327..328 +| | | | | | | | RCurly 327..328 "}" +| | | Error 328..329 +| | | | Error 328..329 +| | | | | Error 328..329 "\r" +| | | EndLine 329..330 +| | | | EndLine 329..330 +| | | | | EndLine 329..330 "\n" +| | | WhiteSpace 330..346 +| | | | WhiteSpace 330..346 +| | | | | WhiteSpace 330..346 " " +| | | Error 346..347 +| | | | Error 346..347 +| | | | | Error 346..347 "\r" +| | | EndLine 347..348 +| | | | EndLine 347..348 +| | | | | EndLine 347..348 "\n" +| | RCurly 348..349 +| | | RCurly 348..349 "}" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap deleted file mode 100644 index b1feddb..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_1_children.snap +++ /dev/null @@ -1,17 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: children_string ---- -- pragma circom 2.0.0; -- "\n" -- "\n" -- " " -- "\n" -- " " -- "template Multiplier2 () {}" -- "\n" -- " " -- "template Multiplier2 () {}" -- " " -- "\n" -- " " diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap deleted file mode 100644 index 0913804..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_functions.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: function_names ---- -- nbits diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap deleted file mode 100644 index db61c87..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_2_templates.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: template_names ---- -- BinSum diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap deleted file mode 100644 index 8050901..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_5_templates.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: template_names ---- -- Multiplier2 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap b/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap deleted file mode 100644 index 8050901..0000000 --- a/crates/syntax/src/snapshots/syntax__syntax__tests__syntax_test_6_templates.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: crates/syntax/src/syntax.rs -expression: template_names ---- -- Multiplier2 diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 855c612..4b8c46c 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -1,251 +1,130 @@ -use parser::grammar::entry::Scope; -use parser::input::Input; -use parser::output::{Child, Output}; -use parser::parser::Parser; -use parser::token_kind::TokenKind; -use rowan::{GreenNode, GreenNodeBuilder}; - -pub use rowan::{ - api::Preorder, Direction, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, - WalkEvent, -}; - -use crate::syntax_node::SyntaxNode; - -pub struct SyntaxTreeBuilder<'a> { - builder: GreenNodeBuilder<'static>, - input: &'a Input<'a>, -} - -impl<'a> SyntaxTreeBuilder<'a> { - pub fn new(input: &'a Input) -> Self { - Self { - builder: GreenNodeBuilder::new(), - input, - } - } - pub fn build_rec(&mut self, tree: &Output) { - self.builder.start_node(tree.kind().into()); - for child in tree.children() { - match child { - Child::Token(token_id) => { - let token_kind = self.input.kind_of(*token_id); - // TODO: return Error to replace .unwrap() - let token_value = self.input.token_value(*token_id).unwrap(); - self.builder.start_node(token_kind.into()); - self.builder.token(token_kind.into(), token_value); - self.builder.finish_node(); - } - Child::Tree(child_tree) => self.build_rec(child_tree), - Child::Error(error) => { - let token_kind = TokenKind::Error; - let token_value = error.as_str(); - - self.builder.start_node(token_kind.into()); - self.builder.token(token_kind.into(), token_value); - self.builder.finish_node(); - } - } - } - - self.builder.finish_node(); - } - - pub fn build(&mut self, tree: Output) { - self.build_rec(&tree); - } - - pub fn finish(self) -> GreenNode { - self.builder.finish() - } - - pub fn syntax_tree(source: &str) -> SyntaxNode { - let input = Input::new(source); - - let output = Parser::parsing(&input); - - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - SyntaxNode::new_root(green) - } -} - -pub fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { - let input = Input::new(&source); - let output = Parser::parsing_with_scope(&input, scope); - - // output is a tree whose node is index of token, no content of token - // convert output into green node - let mut builder = SyntaxTreeBuilder::new(&input); - builder.build(output); - let green = builder.finish(); - - // then cast green node into syntax node - let syntax = SyntaxNode::new_root(green); - - syntax -} - -#[cfg(test)] -mod tests { - use crate::test_syntax; - use parser::grammar::entry::Scope; - - #[test] - fn pragma_happy_test() { - test_syntax!("/src/test_files/happy/pragma.circom", Scope::Pragma); - } - - #[test] - fn template_happy_test() { - // SOURCE & EXPECTED RESULT - test_syntax!("/src/test_files/happy/template.circom", Scope::Template); - } - - #[test] - fn block_happy_test() { - test_syntax!("/src/test_files/happy/block.circom", Scope::Block); - } - - #[test] - fn comment_happy_test() { - test_syntax!( - "/src/test_files/happy/block_comment.circom", - Scope::CircomProgram - ); - test_syntax!( - "/src/test_files/happy/line_comment.circom", - Scope::CircomProgram - ); - } - - #[test] - fn full_circom_program() { - test_syntax!( - "/src/test_files/happy/full_circom_program.circom", - Scope::CircomProgram - ); - } - - #[test] - fn statement_happy_test() { - let source = r#"{ - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - comp[0].in1 <== in[0]; - comp[0].in2 <== in[1]; - for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; - - } - out <== comp[N-2].out; - - // just for testing statement - while (out) { - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - } - assert(comp); - log("Print something...", out); - - if (1 < 2) { - log("Match...", 1 < 2); - } else { - log("Does not match...", 1 < 2); - } - - return out + comp; - }"#; - - let syntax = syntax_node_from_source(&source, Scope::Block); - - // cast syntax node into ast node to retrieve more information - let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); - - let statements = block.statement_list().unwrap().statement_list(); - let statements: Vec = statements - .into_iter() - .map(|statement| statement.syntax().text().to_string()) - .collect(); - insta::assert_yaml_snapshot!("statement_happy_test_statements", statements); - } - - #[test] - fn declaration_happy_test() { - // [scope: block] source must start with { - let source = r#"{ - var nout = nbits((2**n -1)*ops); - signal input in[ops][n]; - signal output out[nout]; - - var lin = 0; - var lout = 0; - - var k; - var j; - - var e2; - - e2 = 1; - for (k=0; k> k) & 1; - - // Ensure out is binary - out[k] * (out[k] - 1) === 0; - - lout += out[k] * e2; - - e2 = e2+e2; - } - - // Ensure the sum; - - lin === lout; - } - }"#; - - let syntax = syntax_node_from_source(&source, Scope::Block); - - // cast syntax node into ast node to retrieve more information - let block = AstBlock::cast(syntax).expect("Can not cast syntax node into ast block"); - - let string_syntax = block.syntax().text().to_string(); - insta::assert_yaml_snapshot!("declaration_happy_test_source", string_syntax); - } - - #[test] - fn function_happy_test() { - let source = r#" - function nbits(a) { - var n = 1; - var r = 0; - while (n-1 { + builder: GreenNodeBuilder<'static>, + input: &'a Input<'a>, +} + +impl<'a> SyntaxTreeBuilder<'a> { + pub fn new(input: &'a Input) -> Self { + Self { + builder: GreenNodeBuilder::new(), + input, + } + } + pub fn build_rec(&mut self, tree: &Output) { + self.builder.start_node(tree.kind().into()); + for child in tree.children() { + match child { + Child::Token(token_id) => { + let token_kind = self.input.kind_of(*token_id); + // TODO: return Error to replace .unwrap() + let token_value = self.input.token_value(*token_id).unwrap(); + self.builder.start_node(token_kind.into()); + self.builder.token(token_kind.into(), token_value); + self.builder.finish_node(); + } + Child::Tree(child_tree) => self.build_rec(child_tree), + Child::Error(error) => { + let token_kind = TokenKind::Error; + let token_value = error.as_str(); + + self.builder.start_node(token_kind.into()); + self.builder.token(token_kind.into(), token_value); + self.builder.finish_node(); + } + } + } + + self.builder.finish_node(); + } + + pub fn build(&mut self, tree: Output) { + self.build_rec(&tree); + } + + pub fn finish(self) -> GreenNode { + self.builder.finish() + } + + pub fn syntax_tree(source: &str) -> SyntaxNode { + let input = Input::new(source); + + let output = Parser::parsing(&input); + + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + SyntaxNode::new_root(green) + } +} + +pub fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { + let input = Input::new(&source); + let output = Parser::parsing_with_scope(&input, scope); + + // output is a tree whose node is index of token, no content of token + // convert output into green node + let mut builder = SyntaxTreeBuilder::new(&input); + builder.build(output); + let green = builder.finish(); + + // then cast green node into syntax node + let syntax = SyntaxNode::new_root(green); + + syntax +} + +#[cfg(test)] +mod tests { + use crate::test_syntax; + use parser::grammar::entry::Scope; + + #[test] + fn pragma_happy_test() { + test_syntax!("/src/test_files/happy/pragma.circom", Scope::Pragma); + } + + #[test] + fn template_happy_test() { + // SOURCE & EXPECTED RESULT + test_syntax!("/src/test_files/happy/template.circom", Scope::Template); + } + + #[test] + fn block_happy_test() { + test_syntax!("/src/test_files/happy/block.circom", Scope::Block); + } + + #[test] + fn comment_happy_test() { + test_syntax!( + "/src/test_files/happy/block_comment.circom", + Scope::CircomProgram + ); + test_syntax!( + "/src/test_files/happy/line_comment.circom", + Scope::CircomProgram + ); + } + + #[test] + fn full_circom_program() { + test_syntax!( + "/src/test_files/happy/full_circom_program.circom", + Scope::CircomProgram + ); + } +} diff --git a/crates/syntax/src/test_files/happy/block.circom b/crates/syntax/src/test_files/happy/block.circom index fdfa1a7..31ba343 100644 --- a/crates/syntax/src/test_files/happy/block.circom +++ b/crates/syntax/src/test_files/happy/block.circom @@ -1,19 +1,19 @@ -{ - //Declaration of signals. - signal input in[N]; - signal output out; - component comp[N-1]; - - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - comp[0].in1 <== in[0]; - comp[0].in2 <== in[1]; - for(var i = 0; i < N-2; i++){ - comp[i+1].in1 <== comp[i].out; - comp[i+1].in2 <== in[i+2]; - - } - out <== comp[N-2].out; +{ + //Declaration of signals. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + comp[0].in1 <== in[0]; + comp[0].in2 <== in[1]; + for(var i = 0; i < N-2; i++){ + comp[i+1].in1 <== comp[i].out; + comp[i+1].in2 <== in[i+2]; + + } + out <== comp[N-2].out; } \ No newline at end of file diff --git a/crates/syntax/src/test_files/happy/block_comment.circom b/crates/syntax/src/test_files/happy/block_comment.circom index 603f889..3946f7a 100644 --- a/crates/syntax/src/test_files/happy/block_comment.circom +++ b/crates/syntax/src/test_files/happy/block_comment.circom @@ -1,6 +1,6 @@ - -/* -comment -blocks -*/ + +/* +comment +blocks +*/ pragma circom 2.0.0; \ No newline at end of file diff --git a/crates/syntax/src/test_files/happy/full_circom_program.circom b/crates/syntax/src/test_files/happy/full_circom_program.circom index d2a7757..95d1d88 100644 --- a/crates/syntax/src/test_files/happy/full_circom_program.circom +++ b/crates/syntax/src/test_files/happy/full_circom_program.circom @@ -1,99 +1,99 @@ -/* - Copyright 2018 0KIMS association. - - This file is part of circom (Zero Knowledge Circuit Compiler). - - circom is a free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - circom is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU General Public License - along with circom. If not, see . -*/ -/* - -Binary Sum -========== - -This component creates a binary sum componet of ops operands and n bits each operand. - -e is Number of carries: Depends on the number of operands in the input. - -Main Constraint: - in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + - + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + - + .. - + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) + - === - out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1) - -To waranty binary outputs: - - out[0] * (out[0] - 1) === 0 - out[1] * (out[0] - 1) === 0 - . - . - . - out[n+e-1] * (out[n+e-1] - 1) == 0 - - */ - - -/* - This function calculates the number of extra bits in the output to do the full sum. - */ - pragma circom 2.0.0; - -function nbits(a) { - var n = 1; - var r = 0; - while (n-1> k) & 1; - - // Ensure out is binary - out[k] * (out[k] - 1) === 0; - - lout += out[k] * e2; - - e2 = e2+e2; - } - - // Ensure the sum; - - lin === lout; - } +/* + Copyright 2018 0KIMS association. + + This file is part of circom (Zero Knowledge Circuit Compiler). + + circom is a free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + circom is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with circom. If not, see . +*/ +/* + +Binary Sum +========== + +This component creates a binary sum componet of ops operands and n bits each operand. + +e is Number of carries: Depends on the number of operands in the input. + +Main Constraint: + in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + + + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + + + .. + + in[ops-1][0] * 2^0 + in[ops-1][1] * 2^1 + ..... + in[ops-1][n-1] * 2^(n-1) + + === + out[0] * 2^0 + out[1] * 2^1 + + out[n+e-1] *2(n+e-1) + +To waranty binary outputs: + + out[0] * (out[0] - 1) === 0 + out[1] * (out[0] - 1) === 0 + . + . + . + out[n+e-1] * (out[n+e-1] - 1) == 0 + + */ + + +/* + This function calculates the number of extra bits in the output to do the full sum. + */ + pragma circom 2.0.0; + +function nbits(a) { + var n = 1; + var r = 0; + while (n-1> k) & 1; + + // Ensure out is binary + out[k] * (out[k] - 1) === 0; + + lout += out[k] * e2; + + e2 = e2+e2; + } + + // Ensure the sum; + + lin === lout; + } diff --git a/crates/syntax/src/test_files/happy/line_comment.circom b/crates/syntax/src/test_files/happy/line_comment.circom index d293753..5458e32 100644 --- a/crates/syntax/src/test_files/happy/line_comment.circom +++ b/crates/syntax/src/test_files/happy/line_comment.circom @@ -1,4 +1,4 @@ - -// comment :> - - pragma circom 2.0.0; + +// comment :> + + pragma circom 2.0.0; diff --git a/crates/syntax/src/test_files/happy/no_pragma.circom b/crates/syntax/src/test_files/happy/no_pragma.circom index 678dd3d..0e46b54 100644 --- a/crates/syntax/src/test_files/happy/no_pragma.circom +++ b/crates/syntax/src/test_files/happy/no_pragma.circom @@ -1,2 +1,2 @@ -// no pragma here +// no pragma here template Multiplier2 () {} \ No newline at end of file diff --git a/crates/syntax/src/test_files/happy/pragma.circom b/crates/syntax/src/test_files/happy/pragma.circom index 8a5d3da..8aa217d 100644 --- a/crates/syntax/src/test_files/happy/pragma.circom +++ b/crates/syntax/src/test_files/happy/pragma.circom @@ -1 +1 @@ -pragma circom 2.0.0; +pragma circom 2.0.0; diff --git a/crates/syntax/src/test_files/happy/template.circom b/crates/syntax/src/test_files/happy/template.circom index ad25810..c39d42d 100644 --- a/crates/syntax/src/test_files/happy/template.circom +++ b/crates/syntax/src/test_files/happy/template.circom @@ -1,13 +1,13 @@ -template MultiplierN (N, P, QQ) { - //Declaration of signals and components. - signal input in[N]; - signal output out; - component comp[N-1]; - - //Statements. - for(var i = 0; i < N-1; i++){ - comp[i] = Multiplier2(); - } - -} +template MultiplierN (N, P, QQ) { + //Declaration of signals and components. + signal input in[N]; + signal output out; + component comp[N-1]; + + //Statements. + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + +} \ No newline at end of file diff --git a/crates/syntax/src/utils.rs b/crates/syntax/src/utils.rs index 76de9f3..f173682 100644 --- a/crates/syntax/src/utils.rs +++ b/crates/syntax/src/utils.rs @@ -1,10 +1,10 @@ -#[macro_export] -macro_rules! test_syntax { - ($file_path:expr, $scope: expr) => { - let crate_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let full_path = format!("{}{}", crate_path, $file_path); - let source = std::fs::read_to_string(full_path).expect("Should not failed"); - let syntax = crate::syntax::syntax_node_from_source(&source, $scope); - insta::assert_snapshot!($file_path, crate::view_syntax::view_ast(&syntax)); - }; -} +#[macro_export] +macro_rules! test_syntax { + ($file_path:expr, $scope: expr) => { + let crate_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let full_path = format!("{}{}", crate_path, $file_path); + let source = std::fs::read_to_string(full_path).expect("Should not failed"); + let syntax = crate::syntax::syntax_node_from_source(&source, $scope); + insta::assert_snapshot!($file_path, crate::view_syntax::view_ast(&syntax)); + }; +} diff --git a/crates/syntax/src/view_syntax.rs b/crates/syntax/src/view_syntax.rs index 35edfb6..6cf6aa9 100644 --- a/crates/syntax/src/view_syntax.rs +++ b/crates/syntax/src/view_syntax.rs @@ -1,52 +1,52 @@ -use crate::syntax_node::{SyntaxNode, SyntaxToken}; - -pub use rowan::{ - api::Preorder, Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, - TokenAtOffset, WalkEvent, -}; - -fn level_str(level: u32) -> String { - let mut ans = String::from(""); - - for _i in 0..level { - ans.push_str("| "); - } - ans -} - -pub(crate) fn view_ast(node: &SyntaxNode) -> String { - let mut level = 0; - let mut result = String::new(); - for event in node.preorder_with_tokens() { - match event { - WalkEvent::Enter(it) => { - match it { - NodeOrToken::Node(node) => { - result.push_str(&format!( - "{} {:?} {:?}", - level_str(level), - node.kind(), - node.text_range() - )); - } - NodeOrToken::Token(token) => { - result.push_str(&format!( - "{} {:?} {:?} {:?}", - level_str(level), - token.kind(), - token.text_range(), - token.text() - )); - } - } - result.push('\n'); - level = level + 1; - } - - WalkEvent::Leave(_it) => { - level = level - 1; - } - } - } - return result; -} +use crate::syntax_node::{SyntaxNode, SyntaxToken}; + +pub use rowan::{ + api::Preorder, Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, + TokenAtOffset, WalkEvent, +}; + +fn level_str(level: u32) -> String { + let mut ans = String::from(""); + + for _i in 0..level { + ans.push_str("| "); + } + ans +} + +pub(crate) fn view_ast(node: &SyntaxNode) -> String { + let mut level = 0; + let mut result = String::new(); + for event in node.preorder_with_tokens() { + match event { + WalkEvent::Enter(it) => { + match it { + NodeOrToken::Node(node) => { + result.push_str(&format!( + "{} {:?} {:?}", + level_str(level), + node.kind(), + node.text_range() + )); + } + NodeOrToken::Token(token) => { + result.push_str(&format!( + "{} {:?} {:?} {:?}", + level_str(level), + token.kind(), + token.text_range(), + token.text() + )); + } + } + result.push('\n'); + level = level + 1; + } + + WalkEvent::Leave(_it) => { + level = level - 1; + } + } + } + return result; +} From 20130de416919a9eff58ef0d982d1eca73b19f26 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Thu, 6 Feb 2025 13:40:35 +0700 Subject: [PATCH 66/71] update full circom program for syntax test --- ...st_files__happy__full_circom_program.circom.snap | 13 +++++++------ .../src/test_files/happy/full_circom_program.circom | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap index 325b1e2..5344f45 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap @@ -2,7 +2,7 @@ source: crates/syntax/src/syntax.rs expression: "crate :: view_syntax :: view_ast(& syntax)" --- - CircomProgram 0..2449 + CircomProgram 0..2427 | BlockComment 0..764 | | BlockComment 0..764 "/*\r\n Copyright 2018 0KIMS association.\r\n\r\n This file is part of circom (Zero Knowledge Circuit Compiler).\r\n\r\n circom is a free software: you can redistribute it and/or modify it\r\n under the terms of the GNU General Public License as published by\r\n the Free Software Foundation, either version 3 of the License, or\r\n (at your option) any later version.\r\n\r\n circom is distributed in the hope that it will be useful, but WITHOUT\r\n ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r\n or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public\r\n License for more details.\r\n\r\n You should have received a copy of the GNU General Public License\r\n along with circom. If not, see .\r\n*/" | EndLine 764..766 @@ -213,7 +213,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | EndLine 1737..1739 "\r\n" | EndLine 1739..1741 | | EndLine 1739..1741 "\r\n" -| TemplateDef 1741..2449 +| TemplateDef 1741..2425 | | TemplateKw 1741..1749 | | | TemplateKw 1741..1749 "template" | | WhiteSpace 1749..1750 @@ -236,7 +236,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | RParen 1763..1764 ")" | | WhiteSpace 1764..1765 | | | WhiteSpace 1764..1765 " " -| | Block 1765..2449 +| | Block 1765..2425 | | | LCurly 1765..1766 | | | | LCurly 1765..1766 "{" | | | EndLine 1766..1768 @@ -1026,6 +1026,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | | | | RCurly 2421..2422 "}" | | | | EndLine 2422..2424 | | | | | EndLine 2422..2424 "\r\n" -| | | Error 2424..2449 -| | | | Error 2424..2449 -| | | | | Error 2424..2449 "expect RCurly but got EOF" +| | | RCurly 2424..2425 +| | | | RCurly 2424..2425 "}" +| EndLine 2425..2427 +| | EndLine 2425..2427 "\r\n" diff --git a/crates/syntax/src/test_files/happy/full_circom_program.circom b/crates/syntax/src/test_files/happy/full_circom_program.circom index 95d1d88..acbf135 100644 --- a/crates/syntax/src/test_files/happy/full_circom_program.circom +++ b/crates/syntax/src/test_files/happy/full_circom_program.circom @@ -97,3 +97,4 @@ template BinSum(n, ops) { lin === lout; } +} From 2f92a509aa2cb3c420e9f9ecd741e9d36ef3f1e2 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 9 Feb 2025 19:29:34 +0700 Subject: [PATCH 67/71] refactor: simplify comma condition and update grammar formatting --- crates/parser/src/grammar/declaration.rs | 2 +- crates/parser/src/grammar/list.rs | 7 ++++--- crates/parser/src/grammar/statement.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index b841f4a..1c0dc2c 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -174,7 +174,7 @@ pub(super) fn component_declaration(p: &mut Parser) { // support array component // eg: comp[N - 1][10] - let _ = array(p); + array(p); p.close(m_c, ComponentIdentifier); // support array component diff --git a/crates/parser/src/grammar/list.rs b/crates/parser/src/grammar/list.rs index 3b8575d..bf97c21 100644 --- a/crates/parser/src/grammar/list.rs +++ b/crates/parser/src/grammar/list.rs @@ -13,7 +13,7 @@ pub(super) fn tuple_expression(p: &mut Parser) { expression(p); // there are no expressions remaining - if p.eat(Comma) == false { + if !p.eat(Comma) { break; } } @@ -35,7 +35,7 @@ pub(super) fn tuple_identifier(p: &mut Parser) { while p.at(Identifier) && !p.eof() { p.expect(Identifier); - if p.eat(Comma) == false { + if !p.eat(Comma) { break; } } @@ -47,6 +47,7 @@ pub(super) fn tuple_identifier(p: &mut Parser) { /** * grammar: "[iden1, iden2,..., idenn]" * can be an empty () + * only use in main component. */ pub(super) fn list_identifier(p: &mut Parser) { // let m = p.open(); @@ -56,7 +57,7 @@ pub(super) fn list_identifier(p: &mut Parser) { while p.at(Identifier) && !p.eof() { p.expect(Identifier); - if p.eat(Comma) == false { + if !p.eat(Comma) { break; } } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index a2e57f6..7fa522e 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -143,7 +143,7 @@ fn log_statement(p: &mut Parser) { _ => expression(p), } - if p.eat(Comma) == false { + if !p.eat(Comma) { break; } } From 5d2a6a0d0654171ec20717c70a51a2c058ddb01d Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 9 Feb 2025 20:42:09 +0700 Subject: [PATCH 68/71] add statements hapy test --- crates/syntax/src/syntax.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index 4b8c46c..bc07f3b 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -108,6 +108,11 @@ mod tests { test_syntax!("/src/test_files/happy/block.circom", Scope::Block); } + #[test] + fn statements_happy_test() { + test_syntax!("/src/test_files/happy/statements.circom", Scope::Block); + } + #[test] fn comment_happy_test() { test_syntax!( From 1ac2f6bed8e829f49fbd5bd46303d3f3a8d6f943 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 9 Feb 2025 20:42:39 +0700 Subject: [PATCH 69/71] remove statement events --- crates/parser/src/grammar/statement.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index 7fa522e..93976d9 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,12 +1,12 @@ use super::{block::block, expression::expression, *}; pub(super) fn statement(p: &mut Parser) { - let open_marker = p.open(); + // let open_marker = p.open(); match p.current() { IfKw => if_statement(p), _ => statement_no_condition(p), } - p.close(open_marker, Statement); + // p.close(open_marker, Statement); } /* From 6aec8c3d9614906cfd410b57f8de05b938e754eb Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 9 Feb 2025 20:43:09 +0700 Subject: [PATCH 70/71] rename UnitDec/UnitDec expression --- crates/parser/src/grammar/expression.rs | 2 +- ..._src__test_files__happy__block.circom.snap | 824 ++++++----- ...es__happy__full_circom_program.circom.snap | 1272 ++++++++--------- ..._test_files__happy__statements.circom.snap | 483 +++++++ ...c__test_files__happy__template.circom.snap | 215 ++- .../src/test_files/happy/statements.circom | 32 + 6 files changed, 1655 insertions(+), 1173 deletions(-) create mode 100644 crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap create mode 100644 crates/syntax/src/test_files/happy/statements.circom diff --git a/crates/parser/src/grammar/expression.rs b/crates/parser/src/grammar/expression.rs index 6c77774..8b069a5 100644 --- a/crates/parser/src/grammar/expression.rs +++ b/crates/parser/src/grammar/expression.rs @@ -134,7 +134,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option { let open_marker = p.open_before(lhs); // consume token ++/-- and do nothing p.advance(); - p.close(open_marker, Expression); + p.close(open_marker, kind); } _ => { // not a postfix token diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap index 11106df..29ff0f2 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap @@ -98,439 +98,429 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | EndLine 157..159 "\r\n" | | WhiteSpace 159..171 | | | WhiteSpace 159..171 " " -| | Statement 171..257 -| | | ForLoop 171..257 -| | | | ForKw 171..174 -| | | | | ForKw 171..174 "for" -| | | | LParen 174..175 -| | | | | LParen 174..175 "(" -| | | | VarDecl 175..184 -| | | | | VarKw 175..178 -| | | | | | VarKw 175..178 "var" -| | | | | WhiteSpace 178..179 -| | | | | | WhiteSpace 178..179 " " -| | | | | VarIdentifier 179..181 -| | | | | | Identifier 179..180 -| | | | | | | Identifier 179..180 "i" -| | | | | | WhiteSpace 180..181 -| | | | | | | WhiteSpace 180..181 " " -| | | | | Assign 181..182 -| | | | | | Assign 181..182 "=" -| | | | | WhiteSpace 182..183 -| | | | | | WhiteSpace 182..183 " " -| | | | | Expression 183..184 -| | | | | | ExpressionAtom 183..184 -| | | | | | | Number 183..184 -| | | | | | | | Number 183..184 "0" -| | | | Semicolon 184..185 -| | | | | Semicolon 184..185 ";" -| | | | WhiteSpace 185..186 -| | | | | WhiteSpace 185..186 " " -| | | | Expression 186..193 -| | | | | LessThan 186..193 -| | | | | | ExpressionAtom 186..187 -| | | | | | | Identifier 186..187 -| | | | | | | | Identifier 186..187 "i" -| | | | | | WhiteSpace 187..188 -| | | | | | | WhiteSpace 187..188 " " -| | | | | | LessThan 188..189 -| | | | | | | LessThan 188..189 "<" -| | | | | | WhiteSpace 189..190 -| | | | | | | WhiteSpace 189..190 " " -| | | | | | Sub 190..193 -| | | | | | | ExpressionAtom 190..191 -| | | | | | | | Identifier 190..191 -| | | | | | | | | Identifier 190..191 "N" -| | | | | | | Sub 191..192 -| | | | | | | | Sub 191..192 "-" -| | | | | | | ExpressionAtom 192..193 -| | | | | | | | Number 192..193 -| | | | | | | | | Number 192..193 "1" -| | | | Semicolon 193..194 -| | | | | Semicolon 193..194 ";" -| | | | WhiteSpace 194..195 -| | | | | WhiteSpace 194..195 " " -| | | | AssignStatement 195..198 -| | | | | Expression 195..198 -| | | | | | Expression 195..198 -| | | | | | | ExpressionAtom 195..196 -| | | | | | | | Identifier 195..196 -| | | | | | | | | Identifier 195..196 "i" -| | | | | | | UnitInc 196..198 -| | | | | | | | UnitInc 196..198 "++" -| | | | RParen 198..199 -| | | | | RParen 198..199 ")" -| | | | Statement 199..257 -| | | | | Block 199..257 -| | | | | | LCurly 199..200 -| | | | | | | LCurly 199..200 "{" -| | | | | | EndLine 200..202 -| | | | | | | EndLine 200..202 "\r\n" -| | | | | | WhiteSpace 202..218 -| | | | | | | WhiteSpace 202..218 " " -| | | | | | StatementList 218..256 -| | | | | | | Statement 218..242 -| | | | | | | | AssignStatement 218..241 -| | | | | | | | | Expression 218..226 -| | | | | | | | | | ArrayQuery 218..225 -| | | | | | | | | | | ExpressionAtom 218..222 -| | | | | | | | | | | | Identifier 218..222 -| | | | | | | | | | | | | Identifier 218..222 "comp" -| | | | | | | | | | | LBracket 222..223 -| | | | | | | | | | | | LBracket 222..223 "[" -| | | | | | | | | | | Expression 223..224 -| | | | | | | | | | | | ExpressionAtom 223..224 -| | | | | | | | | | | | | Identifier 223..224 -| | | | | | | | | | | | | | Identifier 223..224 "i" -| | | | | | | | | | | RBracket 224..225 -| | | | | | | | | | | | RBracket 224..225 "]" -| | | | | | | | | | WhiteSpace 225..226 -| | | | | | | | | | | WhiteSpace 225..226 " " -| | | | | | | | | Assign 226..227 -| | | | | | | | | | Assign 226..227 "=" -| | | | | | | | | WhiteSpace 227..228 -| | | | | | | | | | WhiteSpace 227..228 " " -| | | | | | | | | Expression 228..241 -| | | | | | | | | | Call 228..241 -| | | | | | | | | | | ExpressionAtom 228..239 -| | | | | | | | | | | | Identifier 228..239 -| | | | | | | | | | | | | Identifier 228..239 "Multiplier2" -| | | | | | | | | | | LParen 239..240 -| | | | | | | | | | | | LParen 239..240 "(" -| | | | | | | | | | | RParen 240..241 -| | | | | | | | | | | | RParen 240..241 ")" -| | | | | | | | Semicolon 241..242 -| | | | | | | | | Semicolon 241..242 ";" -| | | | | | | EndLine 242..244 -| | | | | | | | EndLine 242..244 "\r\n" -| | | | | | | WhiteSpace 244..256 -| | | | | | | | WhiteSpace 244..256 " " -| | | | | | RCurly 256..257 -| | | | | | | RCurly 256..257 "}" +| | ForLoop 171..257 +| | | ForKw 171..174 +| | | | ForKw 171..174 "for" +| | | LParen 174..175 +| | | | LParen 174..175 "(" +| | | VarDecl 175..184 +| | | | VarKw 175..178 +| | | | | VarKw 175..178 "var" +| | | | WhiteSpace 178..179 +| | | | | WhiteSpace 178..179 " " +| | | | VarIdentifier 179..181 +| | | | | Identifier 179..180 +| | | | | | Identifier 179..180 "i" +| | | | | WhiteSpace 180..181 +| | | | | | WhiteSpace 180..181 " " +| | | | Assign 181..182 +| | | | | Assign 181..182 "=" +| | | | WhiteSpace 182..183 +| | | | | WhiteSpace 182..183 " " +| | | | Expression 183..184 +| | | | | ExpressionAtom 183..184 +| | | | | | Number 183..184 +| | | | | | | Number 183..184 "0" +| | | Semicolon 184..185 +| | | | Semicolon 184..185 ";" +| | | WhiteSpace 185..186 +| | | | WhiteSpace 185..186 " " +| | | Expression 186..193 +| | | | LessThan 186..193 +| | | | | ExpressionAtom 186..187 +| | | | | | Identifier 186..187 +| | | | | | | Identifier 186..187 "i" +| | | | | WhiteSpace 187..188 +| | | | | | WhiteSpace 187..188 " " +| | | | | LessThan 188..189 +| | | | | | LessThan 188..189 "<" +| | | | | WhiteSpace 189..190 +| | | | | | WhiteSpace 189..190 " " +| | | | | Sub 190..193 +| | | | | | ExpressionAtom 190..191 +| | | | | | | Identifier 190..191 +| | | | | | | | Identifier 190..191 "N" +| | | | | | Sub 191..192 +| | | | | | | Sub 191..192 "-" +| | | | | | ExpressionAtom 192..193 +| | | | | | | Number 192..193 +| | | | | | | | Number 192..193 "1" +| | | Semicolon 193..194 +| | | | Semicolon 193..194 ";" +| | | WhiteSpace 194..195 +| | | | WhiteSpace 194..195 " " +| | | AssignStatement 195..198 +| | | | Expression 195..198 +| | | | | UnitInc 195..198 +| | | | | | ExpressionAtom 195..196 +| | | | | | | Identifier 195..196 +| | | | | | | | Identifier 195..196 "i" +| | | | | | UnitInc 196..198 +| | | | | | | UnitInc 196..198 "++" +| | | RParen 198..199 +| | | | RParen 198..199 ")" +| | | Block 199..257 +| | | | LCurly 199..200 +| | | | | LCurly 199..200 "{" +| | | | EndLine 200..202 +| | | | | EndLine 200..202 "\r\n" +| | | | WhiteSpace 202..218 +| | | | | WhiteSpace 202..218 " " +| | | | StatementList 218..256 +| | | | | AssignStatement 218..241 +| | | | | | Expression 218..226 +| | | | | | | ArrayQuery 218..225 +| | | | | | | | ExpressionAtom 218..222 +| | | | | | | | | Identifier 218..222 +| | | | | | | | | | Identifier 218..222 "comp" +| | | | | | | | LBracket 222..223 +| | | | | | | | | LBracket 222..223 "[" +| | | | | | | | Expression 223..224 +| | | | | | | | | ExpressionAtom 223..224 +| | | | | | | | | | Identifier 223..224 +| | | | | | | | | | | Identifier 223..224 "i" +| | | | | | | | RBracket 224..225 +| | | | | | | | | RBracket 224..225 "]" +| | | | | | | WhiteSpace 225..226 +| | | | | | | | WhiteSpace 225..226 " " +| | | | | | Assign 226..227 +| | | | | | | Assign 226..227 "=" +| | | | | | WhiteSpace 227..228 +| | | | | | | WhiteSpace 227..228 " " +| | | | | | Expression 228..241 +| | | | | | | Call 228..241 +| | | | | | | | ExpressionAtom 228..239 +| | | | | | | | | Identifier 228..239 +| | | | | | | | | | Identifier 228..239 "Multiplier2" +| | | | | | | | LParen 239..240 +| | | | | | | | | LParen 239..240 "(" +| | | | | | | | RParen 240..241 +| | | | | | | | | RParen 240..241 ")" +| | | | | Semicolon 241..242 +| | | | | | Semicolon 241..242 ";" +| | | | | EndLine 242..244 +| | | | | | EndLine 242..244 "\r\n" +| | | | | WhiteSpace 244..256 +| | | | | | WhiteSpace 244..256 " " +| | | | RCurly 256..257 +| | | | | RCurly 256..257 "}" | | EndLine 257..259 | | | EndLine 257..259 "\r\n" | | WhiteSpace 259..271 | | | WhiteSpace 259..271 " " -| | Statement 271..293 -| | | AssignStatement 271..292 -| | | | Expression 271..283 -| | | | | ComponentCall 271..282 -| | | | | | ArrayQuery 271..278 -| | | | | | | ExpressionAtom 271..275 -| | | | | | | | Identifier 271..275 -| | | | | | | | | Identifier 271..275 "comp" -| | | | | | | LBracket 275..276 -| | | | | | | | LBracket 275..276 "[" -| | | | | | | Expression 276..277 -| | | | | | | | ExpressionAtom 276..277 -| | | | | | | | | Number 276..277 -| | | | | | | | | | Number 276..277 "0" -| | | | | | | RBracket 277..278 -| | | | | | | | RBracket 277..278 "]" -| | | | | | Dot 278..279 -| | | | | | | Dot 278..279 "." -| | | | | | Identifier 279..282 -| | | | | | | Identifier 279..282 "in1" -| | | | | WhiteSpace 282..283 -| | | | | | WhiteSpace 282..283 " " -| | | | RAssignConstraintSignal 283..286 -| | | | | RAssignConstraintSignal 283..286 "<==" -| | | | WhiteSpace 286..287 -| | | | | WhiteSpace 286..287 " " -| | | | Expression 287..292 -| | | | | ArrayQuery 287..292 -| | | | | | ExpressionAtom 287..289 -| | | | | | | Identifier 287..289 -| | | | | | | | Identifier 287..289 "in" -| | | | | | LBracket 289..290 -| | | | | | | LBracket 289..290 "[" -| | | | | | Expression 290..291 -| | | | | | | ExpressionAtom 290..291 -| | | | | | | | Number 290..291 -| | | | | | | | | Number 290..291 "0" -| | | | | | RBracket 291..292 -| | | | | | | RBracket 291..292 "]" -| | | Semicolon 292..293 -| | | | Semicolon 292..293 ";" +| | AssignStatement 271..292 +| | | Expression 271..283 +| | | | ComponentCall 271..282 +| | | | | ArrayQuery 271..278 +| | | | | | ExpressionAtom 271..275 +| | | | | | | Identifier 271..275 +| | | | | | | | Identifier 271..275 "comp" +| | | | | | LBracket 275..276 +| | | | | | | LBracket 275..276 "[" +| | | | | | Expression 276..277 +| | | | | | | ExpressionAtom 276..277 +| | | | | | | | Number 276..277 +| | | | | | | | | Number 276..277 "0" +| | | | | | RBracket 277..278 +| | | | | | | RBracket 277..278 "]" +| | | | | Dot 278..279 +| | | | | | Dot 278..279 "." +| | | | | Identifier 279..282 +| | | | | | Identifier 279..282 "in1" +| | | | WhiteSpace 282..283 +| | | | | WhiteSpace 282..283 " " +| | | RAssignConstraintSignal 283..286 +| | | | RAssignConstraintSignal 283..286 "<==" +| | | WhiteSpace 286..287 +| | | | WhiteSpace 286..287 " " +| | | Expression 287..292 +| | | | ArrayQuery 287..292 +| | | | | ExpressionAtom 287..289 +| | | | | | Identifier 287..289 +| | | | | | | Identifier 287..289 "in" +| | | | | LBracket 289..290 +| | | | | | LBracket 289..290 "[" +| | | | | Expression 290..291 +| | | | | | ExpressionAtom 290..291 +| | | | | | | Number 290..291 +| | | | | | | | Number 290..291 "0" +| | | | | RBracket 291..292 +| | | | | | RBracket 291..292 "]" +| | Semicolon 292..293 +| | | Semicolon 292..293 ";" | | EndLine 293..295 | | | EndLine 293..295 "\r\n" | | WhiteSpace 295..307 | | | WhiteSpace 295..307 " " -| | Statement 307..329 -| | | AssignStatement 307..328 -| | | | Expression 307..319 -| | | | | ComponentCall 307..318 -| | | | | | ArrayQuery 307..314 -| | | | | | | ExpressionAtom 307..311 -| | | | | | | | Identifier 307..311 -| | | | | | | | | Identifier 307..311 "comp" -| | | | | | | LBracket 311..312 -| | | | | | | | LBracket 311..312 "[" -| | | | | | | Expression 312..313 -| | | | | | | | ExpressionAtom 312..313 -| | | | | | | | | Number 312..313 -| | | | | | | | | | Number 312..313 "0" -| | | | | | | RBracket 313..314 -| | | | | | | | RBracket 313..314 "]" -| | | | | | Dot 314..315 -| | | | | | | Dot 314..315 "." -| | | | | | Identifier 315..318 -| | | | | | | Identifier 315..318 "in2" -| | | | | WhiteSpace 318..319 -| | | | | | WhiteSpace 318..319 " " -| | | | RAssignConstraintSignal 319..322 -| | | | | RAssignConstraintSignal 319..322 "<==" -| | | | WhiteSpace 322..323 -| | | | | WhiteSpace 322..323 " " -| | | | Expression 323..328 -| | | | | ArrayQuery 323..328 -| | | | | | ExpressionAtom 323..325 -| | | | | | | Identifier 323..325 -| | | | | | | | Identifier 323..325 "in" -| | | | | | LBracket 325..326 -| | | | | | | LBracket 325..326 "[" -| | | | | | Expression 326..327 -| | | | | | | ExpressionAtom 326..327 -| | | | | | | | Number 326..327 -| | | | | | | | | Number 326..327 "1" -| | | | | | RBracket 327..328 -| | | | | | | RBracket 327..328 "]" -| | | Semicolon 328..329 -| | | | Semicolon 328..329 ";" +| | AssignStatement 307..328 +| | | Expression 307..319 +| | | | ComponentCall 307..318 +| | | | | ArrayQuery 307..314 +| | | | | | ExpressionAtom 307..311 +| | | | | | | Identifier 307..311 +| | | | | | | | Identifier 307..311 "comp" +| | | | | | LBracket 311..312 +| | | | | | | LBracket 311..312 "[" +| | | | | | Expression 312..313 +| | | | | | | ExpressionAtom 312..313 +| | | | | | | | Number 312..313 +| | | | | | | | | Number 312..313 "0" +| | | | | | RBracket 313..314 +| | | | | | | RBracket 313..314 "]" +| | | | | Dot 314..315 +| | | | | | Dot 314..315 "." +| | | | | Identifier 315..318 +| | | | | | Identifier 315..318 "in2" +| | | | WhiteSpace 318..319 +| | | | | WhiteSpace 318..319 " " +| | | RAssignConstraintSignal 319..322 +| | | | RAssignConstraintSignal 319..322 "<==" +| | | WhiteSpace 322..323 +| | | | WhiteSpace 322..323 " " +| | | Expression 323..328 +| | | | ArrayQuery 323..328 +| | | | | ExpressionAtom 323..325 +| | | | | | Identifier 323..325 +| | | | | | | Identifier 323..325 "in" +| | | | | LBracket 325..326 +| | | | | | LBracket 325..326 "[" +| | | | | Expression 326..327 +| | | | | | ExpressionAtom 326..327 +| | | | | | | Number 326..327 +| | | | | | | | Number 326..327 "1" +| | | | | RBracket 327..328 +| | | | | | RBracket 327..328 "]" +| | Semicolon 328..329 +| | | Semicolon 328..329 ";" | | EndLine 329..331 | | | EndLine 329..331 "\r\n" | | WhiteSpace 331..343 | | | WhiteSpace 331..343 " " -| | Statement 343..481 -| | | ForLoop 343..481 -| | | | ForKw 343..346 -| | | | | ForKw 343..346 "for" -| | | | LParen 346..347 -| | | | | LParen 346..347 "(" -| | | | VarDecl 347..356 -| | | | | VarKw 347..350 -| | | | | | VarKw 347..350 "var" -| | | | | WhiteSpace 350..351 -| | | | | | WhiteSpace 350..351 " " -| | | | | VarIdentifier 351..353 -| | | | | | Identifier 351..352 -| | | | | | | Identifier 351..352 "i" -| | | | | | WhiteSpace 352..353 -| | | | | | | WhiteSpace 352..353 " " -| | | | | Assign 353..354 -| | | | | | Assign 353..354 "=" -| | | | | WhiteSpace 354..355 -| | | | | | WhiteSpace 354..355 " " -| | | | | Expression 355..356 -| | | | | | ExpressionAtom 355..356 -| | | | | | | Number 355..356 -| | | | | | | | Number 355..356 "0" -| | | | Semicolon 356..357 -| | | | | Semicolon 356..357 ";" -| | | | WhiteSpace 357..358 -| | | | | WhiteSpace 357..358 " " -| | | | Expression 358..365 -| | | | | LessThan 358..365 -| | | | | | ExpressionAtom 358..359 -| | | | | | | Identifier 358..359 -| | | | | | | | Identifier 358..359 "i" -| | | | | | WhiteSpace 359..360 -| | | | | | | WhiteSpace 359..360 " " -| | | | | | LessThan 360..361 -| | | | | | | LessThan 360..361 "<" -| | | | | | WhiteSpace 361..362 -| | | | | | | WhiteSpace 361..362 " " -| | | | | | Sub 362..365 -| | | | | | | ExpressionAtom 362..363 -| | | | | | | | Identifier 362..363 -| | | | | | | | | Identifier 362..363 "N" -| | | | | | | Sub 363..364 -| | | | | | | | Sub 363..364 "-" -| | | | | | | ExpressionAtom 364..365 -| | | | | | | | Number 364..365 -| | | | | | | | | Number 364..365 "2" -| | | | Semicolon 365..366 -| | | | | Semicolon 365..366 ";" -| | | | WhiteSpace 366..367 -| | | | | WhiteSpace 366..367 " " -| | | | AssignStatement 367..370 -| | | | | Expression 367..370 -| | | | | | Expression 367..370 -| | | | | | | ExpressionAtom 367..368 -| | | | | | | | Identifier 367..368 -| | | | | | | | | Identifier 367..368 "i" -| | | | | | | UnitInc 368..370 -| | | | | | | | UnitInc 368..370 "++" -| | | | RParen 370..371 -| | | | | RParen 370..371 ")" -| | | | Statement 371..481 -| | | | | Block 371..481 -| | | | | | LCurly 371..372 -| | | | | | | LCurly 371..372 "{" -| | | | | | EndLine 372..374 -| | | | | | | EndLine 372..374 "\r\n" -| | | | | | WhiteSpace 374..390 -| | | | | | | WhiteSpace 374..390 " " -| | | | | | StatementList 390..480 -| | | | | | | Statement 390..420 -| | | | | | | | AssignStatement 390..419 -| | | | | | | | | Expression 390..404 -| | | | | | | | | | ComponentCall 390..403 -| | | | | | | | | | | ArrayQuery 390..399 -| | | | | | | | | | | | ExpressionAtom 390..394 -| | | | | | | | | | | | | Identifier 390..394 -| | | | | | | | | | | | | | Identifier 390..394 "comp" -| | | | | | | | | | | | LBracket 394..395 -| | | | | | | | | | | | | LBracket 394..395 "[" -| | | | | | | | | | | | Expression 395..398 -| | | | | | | | | | | | | Add 395..398 -| | | | | | | | | | | | | | ExpressionAtom 395..396 -| | | | | | | | | | | | | | | Identifier 395..396 -| | | | | | | | | | | | | | | | Identifier 395..396 "i" -| | | | | | | | | | | | | | Add 396..397 -| | | | | | | | | | | | | | | Add 396..397 "+" -| | | | | | | | | | | | | | ExpressionAtom 397..398 -| | | | | | | | | | | | | | | Number 397..398 -| | | | | | | | | | | | | | | | Number 397..398 "1" -| | | | | | | | | | | | RBracket 398..399 -| | | | | | | | | | | | | RBracket 398..399 "]" -| | | | | | | | | | | Dot 399..400 -| | | | | | | | | | | | Dot 399..400 "." -| | | | | | | | | | | Identifier 400..403 -| | | | | | | | | | | | Identifier 400..403 "in1" -| | | | | | | | | | WhiteSpace 403..404 -| | | | | | | | | | | WhiteSpace 403..404 " " -| | | | | | | | | RAssignConstraintSignal 404..407 -| | | | | | | | | | RAssignConstraintSignal 404..407 "<==" -| | | | | | | | | WhiteSpace 407..408 -| | | | | | | | | | WhiteSpace 407..408 " " -| | | | | | | | | Expression 408..419 -| | | | | | | | | | ComponentCall 408..419 -| | | | | | | | | | | ArrayQuery 408..415 -| | | | | | | | | | | | ExpressionAtom 408..412 -| | | | | | | | | | | | | Identifier 408..412 -| | | | | | | | | | | | | | Identifier 408..412 "comp" -| | | | | | | | | | | | LBracket 412..413 -| | | | | | | | | | | | | LBracket 412..413 "[" -| | | | | | | | | | | | Expression 413..414 -| | | | | | | | | | | | | ExpressionAtom 413..414 -| | | | | | | | | | | | | | Identifier 413..414 -| | | | | | | | | | | | | | | Identifier 413..414 "i" -| | | | | | | | | | | | RBracket 414..415 -| | | | | | | | | | | | | RBracket 414..415 "]" -| | | | | | | | | | | Dot 415..416 -| | | | | | | | | | | | Dot 415..416 "." -| | | | | | | | | | | Identifier 416..419 -| | | | | | | | | | | | Identifier 416..419 "out" -| | | | | | | | Semicolon 419..420 -| | | | | | | | | Semicolon 419..420 ";" -| | | | | | | EndLine 420..422 -| | | | | | | | EndLine 420..422 "\r\n" -| | | | | | | WhiteSpace 422..438 -| | | | | | | | WhiteSpace 422..438 " " -| | | | | | | Statement 438..464 -| | | | | | | | AssignStatement 438..463 -| | | | | | | | | Expression 438..452 -| | | | | | | | | | ComponentCall 438..451 -| | | | | | | | | | | ArrayQuery 438..447 -| | | | | | | | | | | | ExpressionAtom 438..442 -| | | | | | | | | | | | | Identifier 438..442 -| | | | | | | | | | | | | | Identifier 438..442 "comp" -| | | | | | | | | | | | LBracket 442..443 -| | | | | | | | | | | | | LBracket 442..443 "[" -| | | | | | | | | | | | Expression 443..446 -| | | | | | | | | | | | | Add 443..446 -| | | | | | | | | | | | | | ExpressionAtom 443..444 -| | | | | | | | | | | | | | | Identifier 443..444 -| | | | | | | | | | | | | | | | Identifier 443..444 "i" -| | | | | | | | | | | | | | Add 444..445 -| | | | | | | | | | | | | | | Add 444..445 "+" -| | | | | | | | | | | | | | ExpressionAtom 445..446 -| | | | | | | | | | | | | | | Number 445..446 -| | | | | | | | | | | | | | | | Number 445..446 "1" -| | | | | | | | | | | | RBracket 446..447 -| | | | | | | | | | | | | RBracket 446..447 "]" -| | | | | | | | | | | Dot 447..448 -| | | | | | | | | | | | Dot 447..448 "." -| | | | | | | | | | | Identifier 448..451 -| | | | | | | | | | | | Identifier 448..451 "in2" -| | | | | | | | | | WhiteSpace 451..452 -| | | | | | | | | | | WhiteSpace 451..452 " " -| | | | | | | | | RAssignConstraintSignal 452..455 -| | | | | | | | | | RAssignConstraintSignal 452..455 "<==" -| | | | | | | | | WhiteSpace 455..456 -| | | | | | | | | | WhiteSpace 455..456 " " -| | | | | | | | | Expression 456..463 -| | | | | | | | | | ArrayQuery 456..463 -| | | | | | | | | | | ExpressionAtom 456..458 -| | | | | | | | | | | | Identifier 456..458 -| | | | | | | | | | | | | Identifier 456..458 "in" -| | | | | | | | | | | LBracket 458..459 -| | | | | | | | | | | | LBracket 458..459 "[" -| | | | | | | | | | | Expression 459..462 -| | | | | | | | | | | | Add 459..462 -| | | | | | | | | | | | | ExpressionAtom 459..460 -| | | | | | | | | | | | | | Identifier 459..460 -| | | | | | | | | | | | | | | Identifier 459..460 "i" -| | | | | | | | | | | | | Add 460..461 -| | | | | | | | | | | | | | Add 460..461 "+" -| | | | | | | | | | | | | ExpressionAtom 461..462 -| | | | | | | | | | | | | | Number 461..462 -| | | | | | | | | | | | | | | Number 461..462 "2" -| | | | | | | | | | | RBracket 462..463 -| | | | | | | | | | | | RBracket 462..463 "]" -| | | | | | | | Semicolon 463..464 -| | | | | | | | | Semicolon 463..464 ";" -| | | | | | | EndLine 464..466 -| | | | | | | | EndLine 464..466 "\r\n" -| | | | | | | EndLine 466..468 -| | | | | | | | EndLine 466..468 "\r\n" -| | | | | | | WhiteSpace 468..480 -| | | | | | | | WhiteSpace 468..480 " " -| | | | | | RCurly 480..481 -| | | | | | | RCurly 480..481 "}" +| | ForLoop 343..481 +| | | ForKw 343..346 +| | | | ForKw 343..346 "for" +| | | LParen 346..347 +| | | | LParen 346..347 "(" +| | | VarDecl 347..356 +| | | | VarKw 347..350 +| | | | | VarKw 347..350 "var" +| | | | WhiteSpace 350..351 +| | | | | WhiteSpace 350..351 " " +| | | | VarIdentifier 351..353 +| | | | | Identifier 351..352 +| | | | | | Identifier 351..352 "i" +| | | | | WhiteSpace 352..353 +| | | | | | WhiteSpace 352..353 " " +| | | | Assign 353..354 +| | | | | Assign 353..354 "=" +| | | | WhiteSpace 354..355 +| | | | | WhiteSpace 354..355 " " +| | | | Expression 355..356 +| | | | | ExpressionAtom 355..356 +| | | | | | Number 355..356 +| | | | | | | Number 355..356 "0" +| | | Semicolon 356..357 +| | | | Semicolon 356..357 ";" +| | | WhiteSpace 357..358 +| | | | WhiteSpace 357..358 " " +| | | Expression 358..365 +| | | | LessThan 358..365 +| | | | | ExpressionAtom 358..359 +| | | | | | Identifier 358..359 +| | | | | | | Identifier 358..359 "i" +| | | | | WhiteSpace 359..360 +| | | | | | WhiteSpace 359..360 " " +| | | | | LessThan 360..361 +| | | | | | LessThan 360..361 "<" +| | | | | WhiteSpace 361..362 +| | | | | | WhiteSpace 361..362 " " +| | | | | Sub 362..365 +| | | | | | ExpressionAtom 362..363 +| | | | | | | Identifier 362..363 +| | | | | | | | Identifier 362..363 "N" +| | | | | | Sub 363..364 +| | | | | | | Sub 363..364 "-" +| | | | | | ExpressionAtom 364..365 +| | | | | | | Number 364..365 +| | | | | | | | Number 364..365 "2" +| | | Semicolon 365..366 +| | | | Semicolon 365..366 ";" +| | | WhiteSpace 366..367 +| | | | WhiteSpace 366..367 " " +| | | AssignStatement 367..370 +| | | | Expression 367..370 +| | | | | UnitInc 367..370 +| | | | | | ExpressionAtom 367..368 +| | | | | | | Identifier 367..368 +| | | | | | | | Identifier 367..368 "i" +| | | | | | UnitInc 368..370 +| | | | | | | UnitInc 368..370 "++" +| | | RParen 370..371 +| | | | RParen 370..371 ")" +| | | Block 371..481 +| | | | LCurly 371..372 +| | | | | LCurly 371..372 "{" +| | | | EndLine 372..374 +| | | | | EndLine 372..374 "\r\n" +| | | | WhiteSpace 374..390 +| | | | | WhiteSpace 374..390 " " +| | | | StatementList 390..480 +| | | | | AssignStatement 390..419 +| | | | | | Expression 390..404 +| | | | | | | ComponentCall 390..403 +| | | | | | | | ArrayQuery 390..399 +| | | | | | | | | ExpressionAtom 390..394 +| | | | | | | | | | Identifier 390..394 +| | | | | | | | | | | Identifier 390..394 "comp" +| | | | | | | | | LBracket 394..395 +| | | | | | | | | | LBracket 394..395 "[" +| | | | | | | | | Expression 395..398 +| | | | | | | | | | Add 395..398 +| | | | | | | | | | | ExpressionAtom 395..396 +| | | | | | | | | | | | Identifier 395..396 +| | | | | | | | | | | | | Identifier 395..396 "i" +| | | | | | | | | | | Add 396..397 +| | | | | | | | | | | | Add 396..397 "+" +| | | | | | | | | | | ExpressionAtom 397..398 +| | | | | | | | | | | | Number 397..398 +| | | | | | | | | | | | | Number 397..398 "1" +| | | | | | | | | RBracket 398..399 +| | | | | | | | | | RBracket 398..399 "]" +| | | | | | | | Dot 399..400 +| | | | | | | | | Dot 399..400 "." +| | | | | | | | Identifier 400..403 +| | | | | | | | | Identifier 400..403 "in1" +| | | | | | | WhiteSpace 403..404 +| | | | | | | | WhiteSpace 403..404 " " +| | | | | | RAssignConstraintSignal 404..407 +| | | | | | | RAssignConstraintSignal 404..407 "<==" +| | | | | | WhiteSpace 407..408 +| | | | | | | WhiteSpace 407..408 " " +| | | | | | Expression 408..419 +| | | | | | | ComponentCall 408..419 +| | | | | | | | ArrayQuery 408..415 +| | | | | | | | | ExpressionAtom 408..412 +| | | | | | | | | | Identifier 408..412 +| | | | | | | | | | | Identifier 408..412 "comp" +| | | | | | | | | LBracket 412..413 +| | | | | | | | | | LBracket 412..413 "[" +| | | | | | | | | Expression 413..414 +| | | | | | | | | | ExpressionAtom 413..414 +| | | | | | | | | | | Identifier 413..414 +| | | | | | | | | | | | Identifier 413..414 "i" +| | | | | | | | | RBracket 414..415 +| | | | | | | | | | RBracket 414..415 "]" +| | | | | | | | Dot 415..416 +| | | | | | | | | Dot 415..416 "." +| | | | | | | | Identifier 416..419 +| | | | | | | | | Identifier 416..419 "out" +| | | | | Semicolon 419..420 +| | | | | | Semicolon 419..420 ";" +| | | | | EndLine 420..422 +| | | | | | EndLine 420..422 "\r\n" +| | | | | WhiteSpace 422..438 +| | | | | | WhiteSpace 422..438 " " +| | | | | AssignStatement 438..463 +| | | | | | Expression 438..452 +| | | | | | | ComponentCall 438..451 +| | | | | | | | ArrayQuery 438..447 +| | | | | | | | | ExpressionAtom 438..442 +| | | | | | | | | | Identifier 438..442 +| | | | | | | | | | | Identifier 438..442 "comp" +| | | | | | | | | LBracket 442..443 +| | | | | | | | | | LBracket 442..443 "[" +| | | | | | | | | Expression 443..446 +| | | | | | | | | | Add 443..446 +| | | | | | | | | | | ExpressionAtom 443..444 +| | | | | | | | | | | | Identifier 443..444 +| | | | | | | | | | | | | Identifier 443..444 "i" +| | | | | | | | | | | Add 444..445 +| | | | | | | | | | | | Add 444..445 "+" +| | | | | | | | | | | ExpressionAtom 445..446 +| | | | | | | | | | | | Number 445..446 +| | | | | | | | | | | | | Number 445..446 "1" +| | | | | | | | | RBracket 446..447 +| | | | | | | | | | RBracket 446..447 "]" +| | | | | | | | Dot 447..448 +| | | | | | | | | Dot 447..448 "." +| | | | | | | | Identifier 448..451 +| | | | | | | | | Identifier 448..451 "in2" +| | | | | | | WhiteSpace 451..452 +| | | | | | | | WhiteSpace 451..452 " " +| | | | | | RAssignConstraintSignal 452..455 +| | | | | | | RAssignConstraintSignal 452..455 "<==" +| | | | | | WhiteSpace 455..456 +| | | | | | | WhiteSpace 455..456 " " +| | | | | | Expression 456..463 +| | | | | | | ArrayQuery 456..463 +| | | | | | | | ExpressionAtom 456..458 +| | | | | | | | | Identifier 456..458 +| | | | | | | | | | Identifier 456..458 "in" +| | | | | | | | LBracket 458..459 +| | | | | | | | | LBracket 458..459 "[" +| | | | | | | | Expression 459..462 +| | | | | | | | | Add 459..462 +| | | | | | | | | | ExpressionAtom 459..460 +| | | | | | | | | | | Identifier 459..460 +| | | | | | | | | | | | Identifier 459..460 "i" +| | | | | | | | | | Add 460..461 +| | | | | | | | | | | Add 460..461 "+" +| | | | | | | | | | ExpressionAtom 461..462 +| | | | | | | | | | | Number 461..462 +| | | | | | | | | | | | Number 461..462 "2" +| | | | | | | | RBracket 462..463 +| | | | | | | | | RBracket 462..463 "]" +| | | | | Semicolon 463..464 +| | | | | | Semicolon 463..464 ";" +| | | | | EndLine 464..466 +| | | | | | EndLine 464..466 "\r\n" +| | | | | EndLine 466..468 +| | | | | | EndLine 466..468 "\r\n" +| | | | | WhiteSpace 468..480 +| | | | | | WhiteSpace 468..480 " " +| | | | RCurly 480..481 +| | | | | RCurly 480..481 "}" | | EndLine 481..483 | | | EndLine 481..483 "\r\n" | | WhiteSpace 483..495 | | | WhiteSpace 483..495 " " -| | Statement 495..517 -| | | AssignStatement 495..516 -| | | | Expression 495..499 -| | | | | ExpressionAtom 495..498 -| | | | | | Identifier 495..498 -| | | | | | | Identifier 495..498 "out" -| | | | | WhiteSpace 498..499 -| | | | | | WhiteSpace 498..499 " " -| | | | RAssignConstraintSignal 499..502 -| | | | | RAssignConstraintSignal 499..502 "<==" -| | | | WhiteSpace 502..503 -| | | | | WhiteSpace 502..503 " " -| | | | Expression 503..516 -| | | | | ComponentCall 503..516 -| | | | | | ArrayQuery 503..512 -| | | | | | | ExpressionAtom 503..507 -| | | | | | | | Identifier 503..507 -| | | | | | | | | Identifier 503..507 "comp" -| | | | | | | LBracket 507..508 -| | | | | | | | LBracket 507..508 "[" -| | | | | | | Expression 508..511 -| | | | | | | | Sub 508..511 -| | | | | | | | | ExpressionAtom 508..509 -| | | | | | | | | | Identifier 508..509 -| | | | | | | | | | | Identifier 508..509 "N" -| | | | | | | | | Sub 509..510 -| | | | | | | | | | Sub 509..510 "-" -| | | | | | | | | ExpressionAtom 510..511 -| | | | | | | | | | Number 510..511 -| | | | | | | | | | | Number 510..511 "2" -| | | | | | | RBracket 511..512 -| | | | | | | | RBracket 511..512 "]" -| | | | | | Dot 512..513 -| | | | | | | Dot 512..513 "." -| | | | | | Identifier 513..516 -| | | | | | | Identifier 513..516 "out" -| | | Semicolon 516..517 -| | | | Semicolon 516..517 ";" +| | AssignStatement 495..516 +| | | Expression 495..499 +| | | | ExpressionAtom 495..498 +| | | | | Identifier 495..498 +| | | | | | Identifier 495..498 "out" +| | | | WhiteSpace 498..499 +| | | | | WhiteSpace 498..499 " " +| | | RAssignConstraintSignal 499..502 +| | | | RAssignConstraintSignal 499..502 "<==" +| | | WhiteSpace 502..503 +| | | | WhiteSpace 502..503 " " +| | | Expression 503..516 +| | | | ComponentCall 503..516 +| | | | | ArrayQuery 503..512 +| | | | | | ExpressionAtom 503..507 +| | | | | | | Identifier 503..507 +| | | | | | | | Identifier 503..507 "comp" +| | | | | | LBracket 507..508 +| | | | | | | LBracket 507..508 "[" +| | | | | | Expression 508..511 +| | | | | | | Sub 508..511 +| | | | | | | | ExpressionAtom 508..509 +| | | | | | | | | Identifier 508..509 +| | | | | | | | | | Identifier 508..509 "N" +| | | | | | | | Sub 509..510 +| | | | | | | | | Sub 509..510 "-" +| | | | | | | | ExpressionAtom 510..511 +| | | | | | | | | Number 510..511 +| | | | | | | | | | Number 510..511 "2" +| | | | | | RBracket 511..512 +| | | | | | | RBracket 511..512 "]" +| | | | | Dot 512..513 +| | | | | | Dot 512..513 "." +| | | | | Identifier 513..516 +| | | | | | Identifier 513..516 "out" +| | Semicolon 516..517 +| | | Semicolon 516..517 ";" | | WhiteSpace 517..518 | | | WhiteSpace 517..518 " " | | EndLine 518..520 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap index 5344f45..93e945f 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap @@ -111,98 +111,93 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | EndLine 1658..1660 "\r\n" | | | | WhiteSpace 1660..1664 | | | | | WhiteSpace 1660..1664 " " -| | | | Statement 1664..1717 -| | | | | WhileLoop 1664..1717 -| | | | | | WhileKw 1664..1669 -| | | | | | | WhileKw 1664..1669 "while" -| | | | | | WhiteSpace 1669..1670 -| | | | | | | WhiteSpace 1669..1670 " " -| | | | | | LParen 1670..1671 -| | | | | | | LParen 1670..1671 "(" -| | | | | | Expression 1671..1676 -| | | | | | | LessThan 1671..1676 -| | | | | | | | Sub 1671..1674 -| | | | | | | | | ExpressionAtom 1671..1672 -| | | | | | | | | | Identifier 1671..1672 -| | | | | | | | | | | Identifier 1671..1672 "n" -| | | | | | | | | Sub 1672..1673 -| | | | | | | | | | Sub 1672..1673 "-" -| | | | | | | | | ExpressionAtom 1673..1674 -| | | | | | | | | | Number 1673..1674 -| | | | | | | | | | | Number 1673..1674 "1" -| | | | | | | | LessThan 1674..1675 -| | | | | | | | | LessThan 1674..1675 "<" -| | | | | | | | ExpressionAtom 1675..1676 -| | | | | | | | | Identifier 1675..1676 -| | | | | | | | | | Identifier 1675..1676 "a" -| | | | | | RParen 1676..1677 -| | | | | | | RParen 1676..1677 ")" -| | | | | | WhiteSpace 1677..1678 -| | | | | | | WhiteSpace 1677..1678 " " -| | | | | | Statement 1678..1717 -| | | | | | | Block 1678..1717 -| | | | | | | | LCurly 1678..1679 -| | | | | | | | | LCurly 1678..1679 "{" -| | | | | | | | EndLine 1679..1681 -| | | | | | | | | EndLine 1679..1681 "\r\n" -| | | | | | | | WhiteSpace 1681..1689 -| | | | | | | | | WhiteSpace 1681..1689 " " -| | | | | | | | StatementList 1689..1716 -| | | | | | | | | Statement 1689..1693 -| | | | | | | | | | AssignStatement 1689..1692 -| | | | | | | | | | | Expression 1689..1692 -| | | | | | | | | | | | Expression 1689..1692 -| | | | | | | | | | | | | ExpressionAtom 1689..1690 -| | | | | | | | | | | | | | Identifier 1689..1690 -| | | | | | | | | | | | | | | Identifier 1689..1690 "r" -| | | | | | | | | | | | | UnitInc 1690..1692 -| | | | | | | | | | | | | | UnitInc 1690..1692 "++" -| | | | | | | | | | Semicolon 1692..1693 -| | | | | | | | | | | Semicolon 1692..1693 ";" -| | | | | | | | | EndLine 1693..1695 -| | | | | | | | | | EndLine 1693..1695 "\r\n" -| | | | | | | | | WhiteSpace 1695..1703 -| | | | | | | | | | WhiteSpace 1695..1703 " " -| | | | | | | | | Statement 1703..1710 -| | | | | | | | | | AssignStatement 1703..1709 -| | | | | | | | | | | Expression 1703..1705 -| | | | | | | | | | | | ExpressionAtom 1703..1704 -| | | | | | | | | | | | | Identifier 1703..1704 -| | | | | | | | | | | | | | Identifier 1703..1704 "n" -| | | | | | | | | | | | WhiteSpace 1704..1705 -| | | | | | | | | | | | | WhiteSpace 1704..1705 " " -| | | | | | | | | | | MulAssign 1705..1707 -| | | | | | | | | | | | MulAssign 1705..1707 "*=" -| | | | | | | | | | | WhiteSpace 1707..1708 -| | | | | | | | | | | | WhiteSpace 1707..1708 " " -| | | | | | | | | | | Expression 1708..1709 -| | | | | | | | | | | | ExpressionAtom 1708..1709 -| | | | | | | | | | | | | Number 1708..1709 -| | | | | | | | | | | | | | Number 1708..1709 "2" -| | | | | | | | | | Semicolon 1709..1710 -| | | | | | | | | | | Semicolon 1709..1710 ";" -| | | | | | | | | EndLine 1710..1712 -| | | | | | | | | | EndLine 1710..1712 "\r\n" -| | | | | | | | | WhiteSpace 1712..1716 -| | | | | | | | | | WhiteSpace 1712..1716 " " -| | | | | | | | RCurly 1716..1717 -| | | | | | | | | RCurly 1716..1717 "}" +| | | | WhileLoop 1664..1717 +| | | | | WhileKw 1664..1669 +| | | | | | WhileKw 1664..1669 "while" +| | | | | WhiteSpace 1669..1670 +| | | | | | WhiteSpace 1669..1670 " " +| | | | | LParen 1670..1671 +| | | | | | LParen 1670..1671 "(" +| | | | | Expression 1671..1676 +| | | | | | LessThan 1671..1676 +| | | | | | | Sub 1671..1674 +| | | | | | | | ExpressionAtom 1671..1672 +| | | | | | | | | Identifier 1671..1672 +| | | | | | | | | | Identifier 1671..1672 "n" +| | | | | | | | Sub 1672..1673 +| | | | | | | | | Sub 1672..1673 "-" +| | | | | | | | ExpressionAtom 1673..1674 +| | | | | | | | | Number 1673..1674 +| | | | | | | | | | Number 1673..1674 "1" +| | | | | | | LessThan 1674..1675 +| | | | | | | | LessThan 1674..1675 "<" +| | | | | | | ExpressionAtom 1675..1676 +| | | | | | | | Identifier 1675..1676 +| | | | | | | | | Identifier 1675..1676 "a" +| | | | | RParen 1676..1677 +| | | | | | RParen 1676..1677 ")" +| | | | | WhiteSpace 1677..1678 +| | | | | | WhiteSpace 1677..1678 " " +| | | | | Block 1678..1717 +| | | | | | LCurly 1678..1679 +| | | | | | | LCurly 1678..1679 "{" +| | | | | | EndLine 1679..1681 +| | | | | | | EndLine 1679..1681 "\r\n" +| | | | | | WhiteSpace 1681..1689 +| | | | | | | WhiteSpace 1681..1689 " " +| | | | | | StatementList 1689..1716 +| | | | | | | AssignStatement 1689..1692 +| | | | | | | | Expression 1689..1692 +| | | | | | | | | UnitInc 1689..1692 +| | | | | | | | | | ExpressionAtom 1689..1690 +| | | | | | | | | | | Identifier 1689..1690 +| | | | | | | | | | | | Identifier 1689..1690 "r" +| | | | | | | | | | UnitInc 1690..1692 +| | | | | | | | | | | UnitInc 1690..1692 "++" +| | | | | | | Semicolon 1692..1693 +| | | | | | | | Semicolon 1692..1693 ";" +| | | | | | | EndLine 1693..1695 +| | | | | | | | EndLine 1693..1695 "\r\n" +| | | | | | | WhiteSpace 1695..1703 +| | | | | | | | WhiteSpace 1695..1703 " " +| | | | | | | AssignStatement 1703..1709 +| | | | | | | | Expression 1703..1705 +| | | | | | | | | ExpressionAtom 1703..1704 +| | | | | | | | | | Identifier 1703..1704 +| | | | | | | | | | | Identifier 1703..1704 "n" +| | | | | | | | | WhiteSpace 1704..1705 +| | | | | | | | | | WhiteSpace 1704..1705 " " +| | | | | | | | MulAssign 1705..1707 +| | | | | | | | | MulAssign 1705..1707 "*=" +| | | | | | | | WhiteSpace 1707..1708 +| | | | | | | | | WhiteSpace 1707..1708 " " +| | | | | | | | Expression 1708..1709 +| | | | | | | | | ExpressionAtom 1708..1709 +| | | | | | | | | | Number 1708..1709 +| | | | | | | | | | | Number 1708..1709 "2" +| | | | | | | Semicolon 1709..1710 +| | | | | | | | Semicolon 1709..1710 ";" +| | | | | | | EndLine 1710..1712 +| | | | | | | | EndLine 1710..1712 "\r\n" +| | | | | | | WhiteSpace 1712..1716 +| | | | | | | | WhiteSpace 1712..1716 " " +| | | | | | RCurly 1716..1717 +| | | | | | | RCurly 1716..1717 "}" | | | | EndLine 1717..1719 | | | | | EndLine 1717..1719 "\r\n" | | | | WhiteSpace 1719..1723 | | | | | WhiteSpace 1719..1723 " " -| | | | Statement 1723..1732 -| | | | | ReturnStatement 1723..1731 -| | | | | | ReturnKw 1723..1729 -| | | | | | | ReturnKw 1723..1729 "return" -| | | | | | WhiteSpace 1729..1730 -| | | | | | | WhiteSpace 1729..1730 " " -| | | | | | Expression 1730..1731 -| | | | | | | ExpressionAtom 1730..1731 -| | | | | | | | Identifier 1730..1731 -| | | | | | | | | Identifier 1730..1731 "r" -| | | | | Semicolon 1731..1732 -| | | | | | Semicolon 1731..1732 ";" +| | | | ReturnStatement 1723..1731 +| | | | | ReturnKw 1723..1729 +| | | | | | ReturnKw 1723..1729 "return" +| | | | | WhiteSpace 1729..1730 +| | | | | | WhiteSpace 1729..1730 " " +| | | | | Expression 1730..1731 +| | | | | | ExpressionAtom 1730..1731 +| | | | | | | Identifier 1730..1731 +| | | | | | | | Identifier 1730..1731 "r" +| | | | Semicolon 1731..1732 +| | | | | Semicolon 1731..1732 ";" | | | | EndLine 1732..1734 | | | | | EndLine 1732..1734 "\r\n" | | | RCurly 1734..1735 @@ -462,568 +457,553 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | EndLine 1946..1948 "\r\n" | | | | WhiteSpace 1948..1952 | | | | | WhiteSpace 1948..1952 " " -| | | | Statement 1952..1959 -| | | | | AssignStatement 1952..1958 -| | | | | | Expression 1952..1955 -| | | | | | | ExpressionAtom 1952..1954 -| | | | | | | | Identifier 1952..1954 -| | | | | | | | | Identifier 1952..1954 "e2" -| | | | | | | WhiteSpace 1954..1955 -| | | | | | | | WhiteSpace 1954..1955 " " -| | | | | | Assign 1955..1956 -| | | | | | | Assign 1955..1956 "=" -| | | | | | WhiteSpace 1956..1957 -| | | | | | | WhiteSpace 1956..1957 " " -| | | | | | Expression 1957..1958 -| | | | | | | ExpressionAtom 1957..1958 -| | | | | | | | Number 1957..1958 -| | | | | | | | | Number 1957..1958 "1" -| | | | | Semicolon 1958..1959 -| | | | | | Semicolon 1958..1959 ";" +| | | | AssignStatement 1952..1958 +| | | | | Expression 1952..1955 +| | | | | | ExpressionAtom 1952..1954 +| | | | | | | Identifier 1952..1954 +| | | | | | | | Identifier 1952..1954 "e2" +| | | | | | WhiteSpace 1954..1955 +| | | | | | | WhiteSpace 1954..1955 " " +| | | | | Assign 1955..1956 +| | | | | | Assign 1955..1956 "=" +| | | | | WhiteSpace 1956..1957 +| | | | | | WhiteSpace 1956..1957 " " +| | | | | Expression 1957..1958 +| | | | | | ExpressionAtom 1957..1958 +| | | | | | | Number 1957..1958 +| | | | | | | | Number 1957..1958 "1" +| | | | Semicolon 1958..1959 +| | | | | Semicolon 1958..1959 ";" | | | | EndLine 1959..1961 | | | | | EndLine 1959..1961 "\r\n" | | | | WhiteSpace 1961..1965 | | | | | WhiteSpace 1961..1965 " " -| | | | Statement 1965..2422 -| | | | | ForLoop 1965..2422 -| | | | | | ForKw 1965..1968 -| | | | | | | ForKw 1965..1968 "for" -| | | | | | WhiteSpace 1968..1969 -| | | | | | | WhiteSpace 1968..1969 " " -| | | | | | LParen 1969..1970 -| | | | | | | LParen 1969..1970 "(" -| | | | | | AssignStatement 1970..1973 -| | | | | | | Expression 1970..1971 -| | | | | | | | ExpressionAtom 1970..1971 -| | | | | | | | | Identifier 1970..1971 -| | | | | | | | | | Identifier 1970..1971 "k" -| | | | | | | Assign 1971..1972 -| | | | | | | | Assign 1971..1972 "=" -| | | | | | | Expression 1972..1973 -| | | | | | | | ExpressionAtom 1972..1973 -| | | | | | | | | Number 1972..1973 -| | | | | | | | | | Number 1972..1973 "0" -| | | | | | Semicolon 1973..1974 -| | | | | | | Semicolon 1973..1974 ";" -| | | | | | WhiteSpace 1974..1975 -| | | | | | | WhiteSpace 1974..1975 " " -| | | | | | Expression 1975..1978 -| | | | | | | LessThan 1975..1978 -| | | | | | | | ExpressionAtom 1975..1976 -| | | | | | | | | Identifier 1975..1976 -| | | | | | | | | | Identifier 1975..1976 "k" -| | | | | | | | LessThan 1976..1977 -| | | | | | | | | LessThan 1976..1977 "<" -| | | | | | | | ExpressionAtom 1977..1978 -| | | | | | | | | Identifier 1977..1978 -| | | | | | | | | | Identifier 1977..1978 "n" -| | | | | | Semicolon 1978..1979 -| | | | | | | Semicolon 1978..1979 ";" -| | | | | | WhiteSpace 1979..1980 -| | | | | | | WhiteSpace 1979..1980 " " -| | | | | | AssignStatement 1980..1983 -| | | | | | | Expression 1980..1983 -| | | | | | | | Expression 1980..1983 -| | | | | | | | | ExpressionAtom 1980..1981 -| | | | | | | | | | Identifier 1980..1981 -| | | | | | | | | | | Identifier 1980..1981 "k" -| | | | | | | | | UnitInc 1981..1983 -| | | | | | | | | | UnitInc 1981..1983 "++" -| | | | | | RParen 1983..1984 -| | | | | | | RParen 1983..1984 ")" -| | | | | | WhiteSpace 1984..1985 -| | | | | | | WhiteSpace 1984..1985 " " -| | | | | | Statement 1985..2422 -| | | | | | | Block 1985..2422 -| | | | | | | | LCurly 1985..1986 -| | | | | | | | | LCurly 1985..1986 "{" -| | | | | | | | EndLine 1986..1988 -| | | | | | | | | EndLine 1986..1988 "\r\n" -| | | | | | | | WhiteSpace 1988..1996 -| | | | | | | | | WhiteSpace 1988..1996 " " -| | | | | | | | StatementList 1996..2421 -| | | | | | | | | Statement 1996..2065 -| | | | | | | | | | ForLoop 1996..2065 -| | | | | | | | | | | ForKw 1996..1999 -| | | | | | | | | | | | ForKw 1996..1999 "for" -| | | | | | | | | | | WhiteSpace 1999..2000 -| | | | | | | | | | | | WhiteSpace 1999..2000 " " -| | | | | | | | | | | LParen 2000..2001 -| | | | | | | | | | | | LParen 2000..2001 "(" -| | | | | | | | | | | AssignStatement 2001..2004 -| | | | | | | | | | | | Expression 2001..2002 -| | | | | | | | | | | | | ExpressionAtom 2001..2002 -| | | | | | | | | | | | | | Identifier 2001..2002 -| | | | | | | | | | | | | | | Identifier 2001..2002 "j" -| | | | | | | | | | | | Assign 2002..2003 -| | | | | | | | | | | | | Assign 2002..2003 "=" -| | | | | | | | | | | | Expression 2003..2004 -| | | | | | | | | | | | | ExpressionAtom 2003..2004 -| | | | | | | | | | | | | | Number 2003..2004 -| | | | | | | | | | | | | | | Number 2003..2004 "0" -| | | | | | | | | | | Semicolon 2004..2005 -| | | | | | | | | | | | Semicolon 2004..2005 ";" -| | | | | | | | | | | WhiteSpace 2005..2006 -| | | | | | | | | | | | WhiteSpace 2005..2006 " " -| | | | | | | | | | | Expression 2006..2011 -| | | | | | | | | | | | LessThan 2006..2011 -| | | | | | | | | | | | | ExpressionAtom 2006..2007 -| | | | | | | | | | | | | | Identifier 2006..2007 -| | | | | | | | | | | | | | | Identifier 2006..2007 "j" -| | | | | | | | | | | | | LessThan 2007..2008 -| | | | | | | | | | | | | | LessThan 2007..2008 "<" -| | | | | | | | | | | | | ExpressionAtom 2008..2011 -| | | | | | | | | | | | | | Identifier 2008..2011 -| | | | | | | | | | | | | | | Identifier 2008..2011 "ops" -| | | | | | | | | | | Semicolon 2011..2012 -| | | | | | | | | | | | Semicolon 2011..2012 ";" -| | | | | | | | | | | WhiteSpace 2012..2013 -| | | | | | | | | | | | WhiteSpace 2012..2013 " " -| | | | | | | | | | | AssignStatement 2013..2016 -| | | | | | | | | | | | Expression 2013..2016 -| | | | | | | | | | | | | Expression 2013..2016 -| | | | | | | | | | | | | | ExpressionAtom 2013..2014 -| | | | | | | | | | | | | | | Identifier 2013..2014 -| | | | | | | | | | | | | | | | Identifier 2013..2014 "j" -| | | | | | | | | | | | | | UnitInc 2014..2016 -| | | | | | | | | | | | | | | UnitInc 2014..2016 "++" -| | | | | | | | | | | RParen 2016..2017 -| | | | | | | | | | | | RParen 2016..2017 ")" -| | | | | | | | | | | WhiteSpace 2017..2018 -| | | | | | | | | | | | WhiteSpace 2017..2018 " " -| | | | | | | | | | | Statement 2018..2065 -| | | | | | | | | | | | Block 2018..2065 -| | | | | | | | | | | | | LCurly 2018..2019 -| | | | | | | | | | | | | | LCurly 2018..2019 "{" -| | | | | | | | | | | | | EndLine 2019..2021 -| | | | | | | | | | | | | | EndLine 2019..2021 "\r\n" -| | | | | | | | | | | | | WhiteSpace 2021..2033 -| | | | | | | | | | | | | | WhiteSpace 2021..2033 " " -| | | | | | | | | | | | | StatementList 2033..2064 -| | | | | | | | | | | | | | Statement 2033..2054 -| | | | | | | | | | | | | | | AssignStatement 2033..2053 -| | | | | | | | | | | | | | | | Expression 2033..2037 -| | | | | | | | | | | | | | | | | ExpressionAtom 2033..2036 -| | | | | | | | | | | | | | | | | | Identifier 2033..2036 -| | | | | | | | | | | | | | | | | | | Identifier 2033..2036 "lin" -| | | | | | | | | | | | | | | | | WhiteSpace 2036..2037 -| | | | | | | | | | | | | | | | | | WhiteSpace 2036..2037 " " -| | | | | | | | | | | | | | | | AddAssign 2037..2039 -| | | | | | | | | | | | | | | | | AddAssign 2037..2039 "+=" -| | | | | | | | | | | | | | | | WhiteSpace 2039..2040 -| | | | | | | | | | | | | | | | | WhiteSpace 2039..2040 " " -| | | | | | | | | | | | | | | | Expression 2040..2053 -| | | | | | | | | | | | | | | | | Mul 2040..2053 -| | | | | | | | | | | | | | | | | | ArrayQuery 2040..2048 -| | | | | | | | | | | | | | | | | | | ArrayQuery 2040..2045 -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2040..2042 -| | | | | | | | | | | | | | | | | | | | | Identifier 2040..2042 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2040..2042 "in" -| | | | | | | | | | | | | | | | | | | | LBracket 2042..2043 -| | | | | | | | | | | | | | | | | | | | | LBracket 2042..2043 "[" -| | | | | | | | | | | | | | | | | | | | Expression 2043..2044 -| | | | | | | | | | | | | | | | | | | | | ExpressionAtom 2043..2044 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2043..2044 -| | | | | | | | | | | | | | | | | | | | | | | Identifier 2043..2044 "j" -| | | | | | | | | | | | | | | | | | | | RBracket 2044..2045 -| | | | | | | | | | | | | | | | | | | | | RBracket 2044..2045 "]" -| | | | | | | | | | | | | | | | | | | LBracket 2045..2046 -| | | | | | | | | | | | | | | | | | | | LBracket 2045..2046 "[" -| | | | | | | | | | | | | | | | | | | Expression 2046..2047 -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2046..2047 -| | | | | | | | | | | | | | | | | | | | | Identifier 2046..2047 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2046..2047 "k" -| | | | | | | | | | | | | | | | | | | RBracket 2047..2048 -| | | | | | | | | | | | | | | | | | | | RBracket 2047..2048 "]" -| | | | | | | | | | | | | | | | | | WhiteSpace 2048..2049 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2048..2049 " " -| | | | | | | | | | | | | | | | | | Mul 2049..2050 -| | | | | | | | | | | | | | | | | | | Mul 2049..2050 "*" -| | | | | | | | | | | | | | | | | | WhiteSpace 2050..2051 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2050..2051 " " -| | | | | | | | | | | | | | | | | | ExpressionAtom 2051..2053 -| | | | | | | | | | | | | | | | | | | Identifier 2051..2053 -| | | | | | | | | | | | | | | | | | | | Identifier 2051..2053 "e2" -| | | | | | | | | | | | | | | Semicolon 2053..2054 -| | | | | | | | | | | | | | | | Semicolon 2053..2054 ";" -| | | | | | | | | | | | | | EndLine 2054..2056 -| | | | | | | | | | | | | | | EndLine 2054..2056 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2056..2064 -| | | | | | | | | | | | | | | WhiteSpace 2056..2064 " " -| | | | | | | | | | | | | RCurly 2064..2065 -| | | | | | | | | | | | | | RCurly 2064..2065 "}" -| | | | | | | | | EndLine 2065..2067 -| | | | | | | | | | EndLine 2065..2067 "\r\n" -| | | | | | | | | WhiteSpace 2067..2075 -| | | | | | | | | | WhiteSpace 2067..2075 " " -| | | | | | | | | Statement 2075..2088 -| | | | | | | | | | AssignStatement 2075..2087 -| | | | | | | | | | | Expression 2075..2078 -| | | | | | | | | | | | ExpressionAtom 2075..2077 -| | | | | | | | | | | | | Identifier 2075..2077 -| | | | | | | | | | | | | | Identifier 2075..2077 "e2" -| | | | | | | | | | | | WhiteSpace 2077..2078 -| | | | | | | | | | | | | WhiteSpace 2077..2078 " " -| | | | | | | | | | | Assign 2078..2079 -| | | | | | | | | | | | Assign 2078..2079 "=" -| | | | | | | | | | | WhiteSpace 2079..2080 -| | | | | | | | | | | | WhiteSpace 2079..2080 " " -| | | | | | | | | | | Expression 2080..2087 -| | | | | | | | | | | | Add 2080..2087 -| | | | | | | | | | | | | ExpressionAtom 2080..2082 -| | | | | | | | | | | | | | Identifier 2080..2082 -| | | | | | | | | | | | | | | Identifier 2080..2082 "e2" -| | | | | | | | | | | | | WhiteSpace 2082..2083 -| | | | | | | | | | | | | | WhiteSpace 2082..2083 " " -| | | | | | | | | | | | | Add 2083..2084 -| | | | | | | | | | | | | | Add 2083..2084 "+" -| | | | | | | | | | | | | WhiteSpace 2084..2085 -| | | | | | | | | | | | | | WhiteSpace 2084..2085 " " -| | | | | | | | | | | | | ExpressionAtom 2085..2087 -| | | | | | | | | | | | | | Identifier 2085..2087 -| | | | | | | | | | | | | | | Identifier 2085..2087 "e2" -| | | | | | | | | | Semicolon 2087..2088 -| | | | | | | | | | | Semicolon 2087..2088 ";" -| | | | | | | | | EndLine 2088..2090 -| | | | | | | | | | EndLine 2088..2090 "\r\n" -| | | | | | | | | WhiteSpace 2090..2094 -| | | | | | | | | | WhiteSpace 2090..2094 " " -| | | | | | | | | EndLine 2094..2096 -| | | | | | | | | | EndLine 2094..2096 "\r\n" -| | | | | | | | | WhiteSpace 2096..2104 -| | | | | | | | | | WhiteSpace 2096..2104 " " -| | | | | | | | | Statement 2104..2111 -| | | | | | | | | | AssignStatement 2104..2110 -| | | | | | | | | | | Expression 2104..2107 -| | | | | | | | | | | | ExpressionAtom 2104..2106 -| | | | | | | | | | | | | Identifier 2104..2106 -| | | | | | | | | | | | | | Identifier 2104..2106 "e2" -| | | | | | | | | | | | WhiteSpace 2106..2107 -| | | | | | | | | | | | | WhiteSpace 2106..2107 " " -| | | | | | | | | | | Assign 2107..2108 -| | | | | | | | | | | | Assign 2107..2108 "=" -| | | | | | | | | | | WhiteSpace 2108..2109 -| | | | | | | | | | | | WhiteSpace 2108..2109 " " -| | | | | | | | | | | Expression 2109..2110 -| | | | | | | | | | | | ExpressionAtom 2109..2110 -| | | | | | | | | | | | | Number 2109..2110 -| | | | | | | | | | | | | | Number 2109..2110 "1" -| | | | | | | | | | Semicolon 2110..2111 -| | | | | | | | | | | Semicolon 2110..2111 ";" -| | | | | | | | | EndLine 2111..2113 -| | | | | | | | | | EndLine 2111..2113 "\r\n" -| | | | | | | | | WhiteSpace 2113..2121 -| | | | | | | | | | WhiteSpace 2113..2121 " " -| | | | | | | | | Statement 2121..2352 -| | | | | | | | | | ForLoop 2121..2352 -| | | | | | | | | | | ForKw 2121..2124 -| | | | | | | | | | | | ForKw 2121..2124 "for" -| | | | | | | | | | | WhiteSpace 2124..2125 -| | | | | | | | | | | | WhiteSpace 2124..2125 " " -| | | | | | | | | | | LParen 2125..2126 -| | | | | | | | | | | | LParen 2125..2126 "(" -| | | | | | | | | | | AssignStatement 2126..2129 -| | | | | | | | | | | | Expression 2126..2127 -| | | | | | | | | | | | | ExpressionAtom 2126..2127 -| | | | | | | | | | | | | | Identifier 2126..2127 -| | | | | | | | | | | | | | | Identifier 2126..2127 "k" -| | | | | | | | | | | | Assign 2127..2128 -| | | | | | | | | | | | | Assign 2127..2128 "=" -| | | | | | | | | | | | Expression 2128..2129 -| | | | | | | | | | | | | ExpressionAtom 2128..2129 -| | | | | | | | | | | | | | Number 2128..2129 -| | | | | | | | | | | | | | | Number 2128..2129 "0" -| | | | | | | | | | | Semicolon 2129..2130 -| | | | | | | | | | | | Semicolon 2129..2130 ";" -| | | | | | | | | | | WhiteSpace 2130..2131 -| | | | | | | | | | | | WhiteSpace 2130..2131 " " -| | | | | | | | | | | Expression 2131..2137 -| | | | | | | | | | | | LessThan 2131..2137 -| | | | | | | | | | | | | ExpressionAtom 2131..2132 -| | | | | | | | | | | | | | Identifier 2131..2132 -| | | | | | | | | | | | | | | Identifier 2131..2132 "k" -| | | | | | | | | | | | | LessThan 2132..2133 -| | | | | | | | | | | | | | LessThan 2132..2133 "<" -| | | | | | | | | | | | | ExpressionAtom 2133..2137 -| | | | | | | | | | | | | | Identifier 2133..2137 -| | | | | | | | | | | | | | | Identifier 2133..2137 "nout" -| | | | | | | | | | | Semicolon 2137..2138 -| | | | | | | | | | | | Semicolon 2137..2138 ";" -| | | | | | | | | | | WhiteSpace 2138..2139 -| | | | | | | | | | | | WhiteSpace 2138..2139 " " -| | | | | | | | | | | AssignStatement 2139..2142 -| | | | | | | | | | | | Expression 2139..2142 -| | | | | | | | | | | | | Expression 2139..2142 -| | | | | | | | | | | | | | ExpressionAtom 2139..2140 -| | | | | | | | | | | | | | | Identifier 2139..2140 -| | | | | | | | | | | | | | | | Identifier 2139..2140 "k" -| | | | | | | | | | | | | | UnitInc 2140..2142 -| | | | | | | | | | | | | | | UnitInc 2140..2142 "++" -| | | | | | | | | | | RParen 2142..2143 -| | | | | | | | | | | | RParen 2142..2143 ")" -| | | | | | | | | | | WhiteSpace 2143..2144 -| | | | | | | | | | | | WhiteSpace 2143..2144 " " -| | | | | | | | | | | Statement 2144..2352 -| | | | | | | | | | | | Block 2144..2352 -| | | | | | | | | | | | | LCurly 2144..2145 -| | | | | | | | | | | | | | LCurly 2144..2145 "{" -| | | | | | | | | | | | | EndLine 2145..2147 -| | | | | | | | | | | | | | EndLine 2145..2147 "\r\n" -| | | | | | | | | | | | | WhiteSpace 2147..2159 -| | | | | | | | | | | | | | WhiteSpace 2147..2159 " " -| | | | | | | | | | | | | StatementList 2159..2351 -| | | | | | | | | | | | | | Statement 2159..2185 -| | | | | | | | | | | | | | | AssignStatement 2159..2184 -| | | | | | | | | | | | | | | | Expression 2159..2166 -| | | | | | | | | | | | | | | | | ArrayQuery 2159..2165 -| | | | | | | | | | | | | | | | | | ExpressionAtom 2159..2162 -| | | | | | | | | | | | | | | | | | | Identifier 2159..2162 -| | | | | | | | | | | | | | | | | | | | Identifier 2159..2162 "out" -| | | | | | | | | | | | | | | | | | LBracket 2162..2163 -| | | | | | | | | | | | | | | | | | | LBracket 2162..2163 "[" -| | | | | | | | | | | | | | | | | | Expression 2163..2164 -| | | | | | | | | | | | | | | | | | | ExpressionAtom 2163..2164 -| | | | | | | | | | | | | | | | | | | | Identifier 2163..2164 -| | | | | | | | | | | | | | | | | | | | | Identifier 2163..2164 "k" -| | | | | | | | | | | | | | | | | | RBracket 2164..2165 -| | | | | | | | | | | | | | | | | | | RBracket 2164..2165 "]" -| | | | | | | | | | | | | | | | | WhiteSpace 2165..2166 -| | | | | | | | | | | | | | | | | | WhiteSpace 2165..2166 " " -| | | | | | | | | | | | | | | | RAssignSignal 2166..2169 -| | | | | | | | | | | | | | | | | RAssignSignal 2166..2169 "<--" -| | | | | | | | | | | | | | | | WhiteSpace 2169..2170 -| | | | | | | | | | | | | | | | | WhiteSpace 2169..2170 " " -| | | | | | | | | | | | | | | | Expression 2170..2184 -| | | | | | | | | | | | | | | | | BitAnd 2170..2184 -| | | | | | | | | | | | | | | | | | Expression 2170..2180 -| | | | | | | | | | | | | | | | | | | LParen 2170..2171 -| | | | | | | | | | | | | | | | | | | | LParen 2170..2171 "(" -| | | | | | | | | | | | | | | | | | | ShiftR 2171..2179 -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2171..2174 -| | | | | | | | | | | | | | | | | | | | | Identifier 2171..2174 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2171..2174 "lin" -| | | | | | | | | | | | | | | | | | | | WhiteSpace 2174..2175 -| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2174..2175 " " -| | | | | | | | | | | | | | | | | | | | ShiftR 2175..2177 -| | | | | | | | | | | | | | | | | | | | | ShiftR 2175..2177 ">>" -| | | | | | | | | | | | | | | | | | | | WhiteSpace 2177..2178 -| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2177..2178 " " -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2178..2179 -| | | | | | | | | | | | | | | | | | | | | Identifier 2178..2179 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2178..2179 "k" -| | | | | | | | | | | | | | | | | | | RParen 2179..2180 -| | | | | | | | | | | | | | | | | | | | RParen 2179..2180 ")" -| | | | | | | | | | | | | | | | | | WhiteSpace 2180..2181 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2180..2181 " " -| | | | | | | | | | | | | | | | | | BitAnd 2181..2182 -| | | | | | | | | | | | | | | | | | | BitAnd 2181..2182 "&" -| | | | | | | | | | | | | | | | | | WhiteSpace 2182..2183 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2182..2183 " " -| | | | | | | | | | | | | | | | | | ExpressionAtom 2183..2184 -| | | | | | | | | | | | | | | | | | | Number 2183..2184 -| | | | | | | | | | | | | | | | | | | | Number 2183..2184 "1" -| | | | | | | | | | | | | | | Semicolon 2184..2185 -| | | | | | | | | | | | | | | | Semicolon 2184..2185 ";" -| | | | | | | | | | | | | | EndLine 2185..2187 -| | | | | | | | | | | | | | | EndLine 2185..2187 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2187..2191 -| | | | | | | | | | | | | | | WhiteSpace 2187..2191 " " -| | | | | | | | | | | | | | EndLine 2191..2193 -| | | | | | | | | | | | | | | EndLine 2191..2193 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2193..2205 -| | | | | | | | | | | | | | | WhiteSpace 2193..2205 " " -| | | | | | | | | | | | | | CommentLine 2205..2228 -| | | | | | | | | | | | | | | CommentLine 2205..2228 "// Ensure out is binary" -| | | | | | | | | | | | | | EndLine 2228..2230 -| | | | | | | | | | | | | | | EndLine 2228..2230 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2230..2242 -| | | | | | | | | | | | | | | WhiteSpace 2230..2242 " " -| | | | | | | | | | | | | | Statement 2242..2270 -| | | | | | | | | | | | | | | AssignStatement 2242..2269 -| | | | | | | | | | | | | | | | Expression 2242..2264 -| | | | | | | | | | | | | | | | | Mul 2242..2264 -| | | | | | | | | | | | | | | | | | ArrayQuery 2242..2248 -| | | | | | | | | | | | | | | | | | | ExpressionAtom 2242..2245 -| | | | | | | | | | | | | | | | | | | | Identifier 2242..2245 -| | | | | | | | | | | | | | | | | | | | | Identifier 2242..2245 "out" -| | | | | | | | | | | | | | | | | | | LBracket 2245..2246 -| | | | | | | | | | | | | | | | | | | | LBracket 2245..2246 "[" -| | | | | | | | | | | | | | | | | | | Expression 2246..2247 -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2246..2247 -| | | | | | | | | | | | | | | | | | | | | Identifier 2246..2247 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2246..2247 "k" -| | | | | | | | | | | | | | | | | | | RBracket 2247..2248 -| | | | | | | | | | | | | | | | | | | | RBracket 2247..2248 "]" -| | | | | | | | | | | | | | | | | | WhiteSpace 2248..2249 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2248..2249 " " -| | | | | | | | | | | | | | | | | | Mul 2249..2250 -| | | | | | | | | | | | | | | | | | | Mul 2249..2250 "*" -| | | | | | | | | | | | | | | | | | WhiteSpace 2250..2251 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2250..2251 " " -| | | | | | | | | | | | | | | | | | Expression 2251..2263 -| | | | | | | | | | | | | | | | | | | LParen 2251..2252 -| | | | | | | | | | | | | | | | | | | | LParen 2251..2252 "(" -| | | | | | | | | | | | | | | | | | | Sub 2252..2262 -| | | | | | | | | | | | | | | | | | | | ArrayQuery 2252..2258 -| | | | | | | | | | | | | | | | | | | | | ExpressionAtom 2252..2255 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2252..2255 -| | | | | | | | | | | | | | | | | | | | | | | Identifier 2252..2255 "out" -| | | | | | | | | | | | | | | | | | | | | LBracket 2255..2256 -| | | | | | | | | | | | | | | | | | | | | | LBracket 2255..2256 "[" -| | | | | | | | | | | | | | | | | | | | | Expression 2256..2257 -| | | | | | | | | | | | | | | | | | | | | | ExpressionAtom 2256..2257 -| | | | | | | | | | | | | | | | | | | | | | | Identifier 2256..2257 -| | | | | | | | | | | | | | | | | | | | | | | | Identifier 2256..2257 "k" -| | | | | | | | | | | | | | | | | | | | | RBracket 2257..2258 -| | | | | | | | | | | | | | | | | | | | | | RBracket 2257..2258 "]" -| | | | | | | | | | | | | | | | | | | | WhiteSpace 2258..2259 -| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2258..2259 " " -| | | | | | | | | | | | | | | | | | | | Sub 2259..2260 -| | | | | | | | | | | | | | | | | | | | | Sub 2259..2260 "-" -| | | | | | | | | | | | | | | | | | | | WhiteSpace 2260..2261 -| | | | | | | | | | | | | | | | | | | | | WhiteSpace 2260..2261 " " -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2261..2262 -| | | | | | | | | | | | | | | | | | | | | Number 2261..2262 -| | | | | | | | | | | | | | | | | | | | | | Number 2261..2262 "1" -| | | | | | | | | | | | | | | | | | | RParen 2262..2263 -| | | | | | | | | | | | | | | | | | | | RParen 2262..2263 ")" -| | | | | | | | | | | | | | | | | | WhiteSpace 2263..2264 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2263..2264 " " -| | | | | | | | | | | | | | | | EqualSignal 2264..2267 -| | | | | | | | | | | | | | | | | EqualSignal 2264..2267 "===" -| | | | | | | | | | | | | | | | WhiteSpace 2267..2268 -| | | | | | | | | | | | | | | | | WhiteSpace 2267..2268 " " -| | | | | | | | | | | | | | | | Expression 2268..2269 -| | | | | | | | | | | | | | | | | ExpressionAtom 2268..2269 -| | | | | | | | | | | | | | | | | | Number 2268..2269 -| | | | | | | | | | | | | | | | | | | Number 2268..2269 "0" -| | | | | | | | | | | | | | | Semicolon 2269..2270 -| | | | | | | | | | | | | | | | Semicolon 2269..2270 ";" -| | | | | | | | | | | | | | EndLine 2270..2272 -| | | | | | | | | | | | | | | EndLine 2270..2272 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2272..2276 -| | | | | | | | | | | | | | | WhiteSpace 2272..2276 " " -| | | | | | | | | | | | | | EndLine 2276..2278 -| | | | | | | | | | | | | | | EndLine 2276..2278 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2278..2290 -| | | | | | | | | | | | | | | WhiteSpace 2278..2290 " " -| | | | | | | | | | | | | | Statement 2290..2310 -| | | | | | | | | | | | | | | AssignStatement 2290..2309 -| | | | | | | | | | | | | | | | Expression 2290..2295 -| | | | | | | | | | | | | | | | | ExpressionAtom 2290..2294 -| | | | | | | | | | | | | | | | | | Identifier 2290..2294 -| | | | | | | | | | | | | | | | | | | Identifier 2290..2294 "lout" -| | | | | | | | | | | | | | | | | WhiteSpace 2294..2295 -| | | | | | | | | | | | | | | | | | WhiteSpace 2294..2295 " " -| | | | | | | | | | | | | | | | AddAssign 2295..2297 -| | | | | | | | | | | | | | | | | AddAssign 2295..2297 "+=" -| | | | | | | | | | | | | | | | WhiteSpace 2297..2298 -| | | | | | | | | | | | | | | | | WhiteSpace 2297..2298 " " -| | | | | | | | | | | | | | | | Expression 2298..2309 -| | | | | | | | | | | | | | | | | Mul 2298..2309 -| | | | | | | | | | | | | | | | | | ArrayQuery 2298..2304 -| | | | | | | | | | | | | | | | | | | ExpressionAtom 2298..2301 -| | | | | | | | | | | | | | | | | | | | Identifier 2298..2301 -| | | | | | | | | | | | | | | | | | | | | Identifier 2298..2301 "out" -| | | | | | | | | | | | | | | | | | | LBracket 2301..2302 -| | | | | | | | | | | | | | | | | | | | LBracket 2301..2302 "[" -| | | | | | | | | | | | | | | | | | | Expression 2302..2303 -| | | | | | | | | | | | | | | | | | | | ExpressionAtom 2302..2303 -| | | | | | | | | | | | | | | | | | | | | Identifier 2302..2303 -| | | | | | | | | | | | | | | | | | | | | | Identifier 2302..2303 "k" -| | | | | | | | | | | | | | | | | | | RBracket 2303..2304 -| | | | | | | | | | | | | | | | | | | | RBracket 2303..2304 "]" -| | | | | | | | | | | | | | | | | | WhiteSpace 2304..2305 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2304..2305 " " -| | | | | | | | | | | | | | | | | | Mul 2305..2306 -| | | | | | | | | | | | | | | | | | | Mul 2305..2306 "*" -| | | | | | | | | | | | | | | | | | WhiteSpace 2306..2307 -| | | | | | | | | | | | | | | | | | | WhiteSpace 2306..2307 " " -| | | | | | | | | | | | | | | | | | ExpressionAtom 2307..2309 -| | | | | | | | | | | | | | | | | | | Identifier 2307..2309 -| | | | | | | | | | | | | | | | | | | | Identifier 2307..2309 "e2" -| | | | | | | | | | | | | | | Semicolon 2309..2310 -| | | | | | | | | | | | | | | | Semicolon 2309..2310 ";" -| | | | | | | | | | | | | | EndLine 2310..2312 -| | | | | | | | | | | | | | | EndLine 2310..2312 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2312..2316 -| | | | | | | | | | | | | | | WhiteSpace 2312..2316 " " -| | | | | | | | | | | | | | EndLine 2316..2318 -| | | | | | | | | | | | | | | EndLine 2316..2318 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2318..2330 -| | | | | | | | | | | | | | | WhiteSpace 2318..2330 " " -| | | | | | | | | | | | | | Statement 2330..2341 -| | | | | | | | | | | | | | | AssignStatement 2330..2340 -| | | | | | | | | | | | | | | | Expression 2330..2333 -| | | | | | | | | | | | | | | | | ExpressionAtom 2330..2332 -| | | | | | | | | | | | | | | | | | Identifier 2330..2332 -| | | | | | | | | | | | | | | | | | | Identifier 2330..2332 "e2" -| | | | | | | | | | | | | | | | | WhiteSpace 2332..2333 -| | | | | | | | | | | | | | | | | | WhiteSpace 2332..2333 " " -| | | | | | | | | | | | | | | | Assign 2333..2334 -| | | | | | | | | | | | | | | | | Assign 2333..2334 "=" -| | | | | | | | | | | | | | | | WhiteSpace 2334..2335 -| | | | | | | | | | | | | | | | | WhiteSpace 2334..2335 " " -| | | | | | | | | | | | | | | | Expression 2335..2340 -| | | | | | | | | | | | | | | | | Add 2335..2340 -| | | | | | | | | | | | | | | | | | ExpressionAtom 2335..2337 -| | | | | | | | | | | | | | | | | | | Identifier 2335..2337 -| | | | | | | | | | | | | | | | | | | | Identifier 2335..2337 "e2" -| | | | | | | | | | | | | | | | | | Add 2337..2338 -| | | | | | | | | | | | | | | | | | | Add 2337..2338 "+" -| | | | | | | | | | | | | | | | | | ExpressionAtom 2338..2340 -| | | | | | | | | | | | | | | | | | | Identifier 2338..2340 -| | | | | | | | | | | | | | | | | | | | Identifier 2338..2340 "e2" -| | | | | | | | | | | | | | | Semicolon 2340..2341 -| | | | | | | | | | | | | | | | Semicolon 2340..2341 ";" -| | | | | | | | | | | | | | EndLine 2341..2343 -| | | | | | | | | | | | | | | EndLine 2341..2343 "\r\n" -| | | | | | | | | | | | | | WhiteSpace 2343..2351 -| | | | | | | | | | | | | | | WhiteSpace 2343..2351 " " -| | | | | | | | | | | | | RCurly 2351..2352 -| | | | | | | | | | | | | | RCurly 2351..2352 "}" -| | | | | | | | | EndLine 2352..2354 -| | | | | | | | | | EndLine 2352..2354 "\r\n" -| | | | | | | | | WhiteSpace 2354..2358 -| | | | | | | | | | WhiteSpace 2354..2358 " " -| | | | | | | | | EndLine 2358..2360 -| | | | | | | | | | EndLine 2358..2360 "\r\n" -| | | | | | | | | WhiteSpace 2360..2368 -| | | | | | | | | | WhiteSpace 2360..2368 " " -| | | | | | | | | CommentLine 2368..2386 -| | | | | | | | | | CommentLine 2368..2386 "// Ensure the sum;" -| | | | | | | | | EndLine 2386..2388 -| | | | | | | | | | EndLine 2386..2388 "\r\n" -| | | | | | | | | WhiteSpace 2388..2392 -| | | | | | | | | | WhiteSpace 2388..2392 " " -| | | | | | | | | EndLine 2392..2394 -| | | | | | | | | | EndLine 2392..2394 "\r\n" -| | | | | | | | | WhiteSpace 2394..2402 -| | | | | | | | | | WhiteSpace 2394..2402 " " -| | | | | | | | | Statement 2402..2415 -| | | | | | | | | | AssignStatement 2402..2414 -| | | | | | | | | | | Expression 2402..2406 -| | | | | | | | | | | | ExpressionAtom 2402..2405 -| | | | | | | | | | | | | Identifier 2402..2405 -| | | | | | | | | | | | | | Identifier 2402..2405 "lin" -| | | | | | | | | | | | WhiteSpace 2405..2406 -| | | | | | | | | | | | | WhiteSpace 2405..2406 " " -| | | | | | | | | | | EqualSignal 2406..2409 -| | | | | | | | | | | | EqualSignal 2406..2409 "===" -| | | | | | | | | | | WhiteSpace 2409..2410 -| | | | | | | | | | | | WhiteSpace 2409..2410 " " -| | | | | | | | | | | Expression 2410..2414 -| | | | | | | | | | | | ExpressionAtom 2410..2414 -| | | | | | | | | | | | | Identifier 2410..2414 -| | | | | | | | | | | | | | Identifier 2410..2414 "lout" -| | | | | | | | | | Semicolon 2414..2415 -| | | | | | | | | | | Semicolon 2414..2415 ";" -| | | | | | | | | EndLine 2415..2417 -| | | | | | | | | | EndLine 2415..2417 "\r\n" -| | | | | | | | | WhiteSpace 2417..2421 -| | | | | | | | | | WhiteSpace 2417..2421 " " -| | | | | | | | RCurly 2421..2422 -| | | | | | | | | RCurly 2421..2422 "}" +| | | | ForLoop 1965..2422 +| | | | | ForKw 1965..1968 +| | | | | | ForKw 1965..1968 "for" +| | | | | WhiteSpace 1968..1969 +| | | | | | WhiteSpace 1968..1969 " " +| | | | | LParen 1969..1970 +| | | | | | LParen 1969..1970 "(" +| | | | | AssignStatement 1970..1973 +| | | | | | Expression 1970..1971 +| | | | | | | ExpressionAtom 1970..1971 +| | | | | | | | Identifier 1970..1971 +| | | | | | | | | Identifier 1970..1971 "k" +| | | | | | Assign 1971..1972 +| | | | | | | Assign 1971..1972 "=" +| | | | | | Expression 1972..1973 +| | | | | | | ExpressionAtom 1972..1973 +| | | | | | | | Number 1972..1973 +| | | | | | | | | Number 1972..1973 "0" +| | | | | Semicolon 1973..1974 +| | | | | | Semicolon 1973..1974 ";" +| | | | | WhiteSpace 1974..1975 +| | | | | | WhiteSpace 1974..1975 " " +| | | | | Expression 1975..1978 +| | | | | | LessThan 1975..1978 +| | | | | | | ExpressionAtom 1975..1976 +| | | | | | | | Identifier 1975..1976 +| | | | | | | | | Identifier 1975..1976 "k" +| | | | | | | LessThan 1976..1977 +| | | | | | | | LessThan 1976..1977 "<" +| | | | | | | ExpressionAtom 1977..1978 +| | | | | | | | Identifier 1977..1978 +| | | | | | | | | Identifier 1977..1978 "n" +| | | | | Semicolon 1978..1979 +| | | | | | Semicolon 1978..1979 ";" +| | | | | WhiteSpace 1979..1980 +| | | | | | WhiteSpace 1979..1980 " " +| | | | | AssignStatement 1980..1983 +| | | | | | Expression 1980..1983 +| | | | | | | UnitInc 1980..1983 +| | | | | | | | ExpressionAtom 1980..1981 +| | | | | | | | | Identifier 1980..1981 +| | | | | | | | | | Identifier 1980..1981 "k" +| | | | | | | | UnitInc 1981..1983 +| | | | | | | | | UnitInc 1981..1983 "++" +| | | | | RParen 1983..1984 +| | | | | | RParen 1983..1984 ")" +| | | | | WhiteSpace 1984..1985 +| | | | | | WhiteSpace 1984..1985 " " +| | | | | Block 1985..2422 +| | | | | | LCurly 1985..1986 +| | | | | | | LCurly 1985..1986 "{" +| | | | | | EndLine 1986..1988 +| | | | | | | EndLine 1986..1988 "\r\n" +| | | | | | WhiteSpace 1988..1996 +| | | | | | | WhiteSpace 1988..1996 " " +| | | | | | StatementList 1996..2421 +| | | | | | | ForLoop 1996..2065 +| | | | | | | | ForKw 1996..1999 +| | | | | | | | | ForKw 1996..1999 "for" +| | | | | | | | WhiteSpace 1999..2000 +| | | | | | | | | WhiteSpace 1999..2000 " " +| | | | | | | | LParen 2000..2001 +| | | | | | | | | LParen 2000..2001 "(" +| | | | | | | | AssignStatement 2001..2004 +| | | | | | | | | Expression 2001..2002 +| | | | | | | | | | ExpressionAtom 2001..2002 +| | | | | | | | | | | Identifier 2001..2002 +| | | | | | | | | | | | Identifier 2001..2002 "j" +| | | | | | | | | Assign 2002..2003 +| | | | | | | | | | Assign 2002..2003 "=" +| | | | | | | | | Expression 2003..2004 +| | | | | | | | | | ExpressionAtom 2003..2004 +| | | | | | | | | | | Number 2003..2004 +| | | | | | | | | | | | Number 2003..2004 "0" +| | | | | | | | Semicolon 2004..2005 +| | | | | | | | | Semicolon 2004..2005 ";" +| | | | | | | | WhiteSpace 2005..2006 +| | | | | | | | | WhiteSpace 2005..2006 " " +| | | | | | | | Expression 2006..2011 +| | | | | | | | | LessThan 2006..2011 +| | | | | | | | | | ExpressionAtom 2006..2007 +| | | | | | | | | | | Identifier 2006..2007 +| | | | | | | | | | | | Identifier 2006..2007 "j" +| | | | | | | | | | LessThan 2007..2008 +| | | | | | | | | | | LessThan 2007..2008 "<" +| | | | | | | | | | ExpressionAtom 2008..2011 +| | | | | | | | | | | Identifier 2008..2011 +| | | | | | | | | | | | Identifier 2008..2011 "ops" +| | | | | | | | Semicolon 2011..2012 +| | | | | | | | | Semicolon 2011..2012 ";" +| | | | | | | | WhiteSpace 2012..2013 +| | | | | | | | | WhiteSpace 2012..2013 " " +| | | | | | | | AssignStatement 2013..2016 +| | | | | | | | | Expression 2013..2016 +| | | | | | | | | | UnitInc 2013..2016 +| | | | | | | | | | | ExpressionAtom 2013..2014 +| | | | | | | | | | | | Identifier 2013..2014 +| | | | | | | | | | | | | Identifier 2013..2014 "j" +| | | | | | | | | | | UnitInc 2014..2016 +| | | | | | | | | | | | UnitInc 2014..2016 "++" +| | | | | | | | RParen 2016..2017 +| | | | | | | | | RParen 2016..2017 ")" +| | | | | | | | WhiteSpace 2017..2018 +| | | | | | | | | WhiteSpace 2017..2018 " " +| | | | | | | | Block 2018..2065 +| | | | | | | | | LCurly 2018..2019 +| | | | | | | | | | LCurly 2018..2019 "{" +| | | | | | | | | EndLine 2019..2021 +| | | | | | | | | | EndLine 2019..2021 "\r\n" +| | | | | | | | | WhiteSpace 2021..2033 +| | | | | | | | | | WhiteSpace 2021..2033 " " +| | | | | | | | | StatementList 2033..2064 +| | | | | | | | | | AssignStatement 2033..2053 +| | | | | | | | | | | Expression 2033..2037 +| | | | | | | | | | | | ExpressionAtom 2033..2036 +| | | | | | | | | | | | | Identifier 2033..2036 +| | | | | | | | | | | | | | Identifier 2033..2036 "lin" +| | | | | | | | | | | | WhiteSpace 2036..2037 +| | | | | | | | | | | | | WhiteSpace 2036..2037 " " +| | | | | | | | | | | AddAssign 2037..2039 +| | | | | | | | | | | | AddAssign 2037..2039 "+=" +| | | | | | | | | | | WhiteSpace 2039..2040 +| | | | | | | | | | | | WhiteSpace 2039..2040 " " +| | | | | | | | | | | Expression 2040..2053 +| | | | | | | | | | | | Mul 2040..2053 +| | | | | | | | | | | | | ArrayQuery 2040..2048 +| | | | | | | | | | | | | | ArrayQuery 2040..2045 +| | | | | | | | | | | | | | | ExpressionAtom 2040..2042 +| | | | | | | | | | | | | | | | Identifier 2040..2042 +| | | | | | | | | | | | | | | | | Identifier 2040..2042 "in" +| | | | | | | | | | | | | | | LBracket 2042..2043 +| | | | | | | | | | | | | | | | LBracket 2042..2043 "[" +| | | | | | | | | | | | | | | Expression 2043..2044 +| | | | | | | | | | | | | | | | ExpressionAtom 2043..2044 +| | | | | | | | | | | | | | | | | Identifier 2043..2044 +| | | | | | | | | | | | | | | | | | Identifier 2043..2044 "j" +| | | | | | | | | | | | | | | RBracket 2044..2045 +| | | | | | | | | | | | | | | | RBracket 2044..2045 "]" +| | | | | | | | | | | | | | LBracket 2045..2046 +| | | | | | | | | | | | | | | LBracket 2045..2046 "[" +| | | | | | | | | | | | | | Expression 2046..2047 +| | | | | | | | | | | | | | | ExpressionAtom 2046..2047 +| | | | | | | | | | | | | | | | Identifier 2046..2047 +| | | | | | | | | | | | | | | | | Identifier 2046..2047 "k" +| | | | | | | | | | | | | | RBracket 2047..2048 +| | | | | | | | | | | | | | | RBracket 2047..2048 "]" +| | | | | | | | | | | | | WhiteSpace 2048..2049 +| | | | | | | | | | | | | | WhiteSpace 2048..2049 " " +| | | | | | | | | | | | | Mul 2049..2050 +| | | | | | | | | | | | | | Mul 2049..2050 "*" +| | | | | | | | | | | | | WhiteSpace 2050..2051 +| | | | | | | | | | | | | | WhiteSpace 2050..2051 " " +| | | | | | | | | | | | | ExpressionAtom 2051..2053 +| | | | | | | | | | | | | | Identifier 2051..2053 +| | | | | | | | | | | | | | | Identifier 2051..2053 "e2" +| | | | | | | | | | Semicolon 2053..2054 +| | | | | | | | | | | Semicolon 2053..2054 ";" +| | | | | | | | | | EndLine 2054..2056 +| | | | | | | | | | | EndLine 2054..2056 "\r\n" +| | | | | | | | | | WhiteSpace 2056..2064 +| | | | | | | | | | | WhiteSpace 2056..2064 " " +| | | | | | | | | RCurly 2064..2065 +| | | | | | | | | | RCurly 2064..2065 "}" +| | | | | | | EndLine 2065..2067 +| | | | | | | | EndLine 2065..2067 "\r\n" +| | | | | | | WhiteSpace 2067..2075 +| | | | | | | | WhiteSpace 2067..2075 " " +| | | | | | | AssignStatement 2075..2087 +| | | | | | | | Expression 2075..2078 +| | | | | | | | | ExpressionAtom 2075..2077 +| | | | | | | | | | Identifier 2075..2077 +| | | | | | | | | | | Identifier 2075..2077 "e2" +| | | | | | | | | WhiteSpace 2077..2078 +| | | | | | | | | | WhiteSpace 2077..2078 " " +| | | | | | | | Assign 2078..2079 +| | | | | | | | | Assign 2078..2079 "=" +| | | | | | | | WhiteSpace 2079..2080 +| | | | | | | | | WhiteSpace 2079..2080 " " +| | | | | | | | Expression 2080..2087 +| | | | | | | | | Add 2080..2087 +| | | | | | | | | | ExpressionAtom 2080..2082 +| | | | | | | | | | | Identifier 2080..2082 +| | | | | | | | | | | | Identifier 2080..2082 "e2" +| | | | | | | | | | WhiteSpace 2082..2083 +| | | | | | | | | | | WhiteSpace 2082..2083 " " +| | | | | | | | | | Add 2083..2084 +| | | | | | | | | | | Add 2083..2084 "+" +| | | | | | | | | | WhiteSpace 2084..2085 +| | | | | | | | | | | WhiteSpace 2084..2085 " " +| | | | | | | | | | ExpressionAtom 2085..2087 +| | | | | | | | | | | Identifier 2085..2087 +| | | | | | | | | | | | Identifier 2085..2087 "e2" +| | | | | | | Semicolon 2087..2088 +| | | | | | | | Semicolon 2087..2088 ";" +| | | | | | | EndLine 2088..2090 +| | | | | | | | EndLine 2088..2090 "\r\n" +| | | | | | | WhiteSpace 2090..2094 +| | | | | | | | WhiteSpace 2090..2094 " " +| | | | | | | EndLine 2094..2096 +| | | | | | | | EndLine 2094..2096 "\r\n" +| | | | | | | WhiteSpace 2096..2104 +| | | | | | | | WhiteSpace 2096..2104 " " +| | | | | | | AssignStatement 2104..2110 +| | | | | | | | Expression 2104..2107 +| | | | | | | | | ExpressionAtom 2104..2106 +| | | | | | | | | | Identifier 2104..2106 +| | | | | | | | | | | Identifier 2104..2106 "e2" +| | | | | | | | | WhiteSpace 2106..2107 +| | | | | | | | | | WhiteSpace 2106..2107 " " +| | | | | | | | Assign 2107..2108 +| | | | | | | | | Assign 2107..2108 "=" +| | | | | | | | WhiteSpace 2108..2109 +| | | | | | | | | WhiteSpace 2108..2109 " " +| | | | | | | | Expression 2109..2110 +| | | | | | | | | ExpressionAtom 2109..2110 +| | | | | | | | | | Number 2109..2110 +| | | | | | | | | | | Number 2109..2110 "1" +| | | | | | | Semicolon 2110..2111 +| | | | | | | | Semicolon 2110..2111 ";" +| | | | | | | EndLine 2111..2113 +| | | | | | | | EndLine 2111..2113 "\r\n" +| | | | | | | WhiteSpace 2113..2121 +| | | | | | | | WhiteSpace 2113..2121 " " +| | | | | | | ForLoop 2121..2352 +| | | | | | | | ForKw 2121..2124 +| | | | | | | | | ForKw 2121..2124 "for" +| | | | | | | | WhiteSpace 2124..2125 +| | | | | | | | | WhiteSpace 2124..2125 " " +| | | | | | | | LParen 2125..2126 +| | | | | | | | | LParen 2125..2126 "(" +| | | | | | | | AssignStatement 2126..2129 +| | | | | | | | | Expression 2126..2127 +| | | | | | | | | | ExpressionAtom 2126..2127 +| | | | | | | | | | | Identifier 2126..2127 +| | | | | | | | | | | | Identifier 2126..2127 "k" +| | | | | | | | | Assign 2127..2128 +| | | | | | | | | | Assign 2127..2128 "=" +| | | | | | | | | Expression 2128..2129 +| | | | | | | | | | ExpressionAtom 2128..2129 +| | | | | | | | | | | Number 2128..2129 +| | | | | | | | | | | | Number 2128..2129 "0" +| | | | | | | | Semicolon 2129..2130 +| | | | | | | | | Semicolon 2129..2130 ";" +| | | | | | | | WhiteSpace 2130..2131 +| | | | | | | | | WhiteSpace 2130..2131 " " +| | | | | | | | Expression 2131..2137 +| | | | | | | | | LessThan 2131..2137 +| | | | | | | | | | ExpressionAtom 2131..2132 +| | | | | | | | | | | Identifier 2131..2132 +| | | | | | | | | | | | Identifier 2131..2132 "k" +| | | | | | | | | | LessThan 2132..2133 +| | | | | | | | | | | LessThan 2132..2133 "<" +| | | | | | | | | | ExpressionAtom 2133..2137 +| | | | | | | | | | | Identifier 2133..2137 +| | | | | | | | | | | | Identifier 2133..2137 "nout" +| | | | | | | | Semicolon 2137..2138 +| | | | | | | | | Semicolon 2137..2138 ";" +| | | | | | | | WhiteSpace 2138..2139 +| | | | | | | | | WhiteSpace 2138..2139 " " +| | | | | | | | AssignStatement 2139..2142 +| | | | | | | | | Expression 2139..2142 +| | | | | | | | | | UnitInc 2139..2142 +| | | | | | | | | | | ExpressionAtom 2139..2140 +| | | | | | | | | | | | Identifier 2139..2140 +| | | | | | | | | | | | | Identifier 2139..2140 "k" +| | | | | | | | | | | UnitInc 2140..2142 +| | | | | | | | | | | | UnitInc 2140..2142 "++" +| | | | | | | | RParen 2142..2143 +| | | | | | | | | RParen 2142..2143 ")" +| | | | | | | | WhiteSpace 2143..2144 +| | | | | | | | | WhiteSpace 2143..2144 " " +| | | | | | | | Block 2144..2352 +| | | | | | | | | LCurly 2144..2145 +| | | | | | | | | | LCurly 2144..2145 "{" +| | | | | | | | | EndLine 2145..2147 +| | | | | | | | | | EndLine 2145..2147 "\r\n" +| | | | | | | | | WhiteSpace 2147..2159 +| | | | | | | | | | WhiteSpace 2147..2159 " " +| | | | | | | | | StatementList 2159..2351 +| | | | | | | | | | AssignStatement 2159..2184 +| | | | | | | | | | | Expression 2159..2166 +| | | | | | | | | | | | ArrayQuery 2159..2165 +| | | | | | | | | | | | | ExpressionAtom 2159..2162 +| | | | | | | | | | | | | | Identifier 2159..2162 +| | | | | | | | | | | | | | | Identifier 2159..2162 "out" +| | | | | | | | | | | | | LBracket 2162..2163 +| | | | | | | | | | | | | | LBracket 2162..2163 "[" +| | | | | | | | | | | | | Expression 2163..2164 +| | | | | | | | | | | | | | ExpressionAtom 2163..2164 +| | | | | | | | | | | | | | | Identifier 2163..2164 +| | | | | | | | | | | | | | | | Identifier 2163..2164 "k" +| | | | | | | | | | | | | RBracket 2164..2165 +| | | | | | | | | | | | | | RBracket 2164..2165 "]" +| | | | | | | | | | | | WhiteSpace 2165..2166 +| | | | | | | | | | | | | WhiteSpace 2165..2166 " " +| | | | | | | | | | | RAssignSignal 2166..2169 +| | | | | | | | | | | | RAssignSignal 2166..2169 "<--" +| | | | | | | | | | | WhiteSpace 2169..2170 +| | | | | | | | | | | | WhiteSpace 2169..2170 " " +| | | | | | | | | | | Expression 2170..2184 +| | | | | | | | | | | | BitAnd 2170..2184 +| | | | | | | | | | | | | Expression 2170..2180 +| | | | | | | | | | | | | | LParen 2170..2171 +| | | | | | | | | | | | | | | LParen 2170..2171 "(" +| | | | | | | | | | | | | | ShiftR 2171..2179 +| | | | | | | | | | | | | | | ExpressionAtom 2171..2174 +| | | | | | | | | | | | | | | | Identifier 2171..2174 +| | | | | | | | | | | | | | | | | Identifier 2171..2174 "lin" +| | | | | | | | | | | | | | | WhiteSpace 2174..2175 +| | | | | | | | | | | | | | | | WhiteSpace 2174..2175 " " +| | | | | | | | | | | | | | | ShiftR 2175..2177 +| | | | | | | | | | | | | | | | ShiftR 2175..2177 ">>" +| | | | | | | | | | | | | | | WhiteSpace 2177..2178 +| | | | | | | | | | | | | | | | WhiteSpace 2177..2178 " " +| | | | | | | | | | | | | | | ExpressionAtom 2178..2179 +| | | | | | | | | | | | | | | | Identifier 2178..2179 +| | | | | | | | | | | | | | | | | Identifier 2178..2179 "k" +| | | | | | | | | | | | | | RParen 2179..2180 +| | | | | | | | | | | | | | | RParen 2179..2180 ")" +| | | | | | | | | | | | | WhiteSpace 2180..2181 +| | | | | | | | | | | | | | WhiteSpace 2180..2181 " " +| | | | | | | | | | | | | BitAnd 2181..2182 +| | | | | | | | | | | | | | BitAnd 2181..2182 "&" +| | | | | | | | | | | | | WhiteSpace 2182..2183 +| | | | | | | | | | | | | | WhiteSpace 2182..2183 " " +| | | | | | | | | | | | | ExpressionAtom 2183..2184 +| | | | | | | | | | | | | | Number 2183..2184 +| | | | | | | | | | | | | | | Number 2183..2184 "1" +| | | | | | | | | | Semicolon 2184..2185 +| | | | | | | | | | | Semicolon 2184..2185 ";" +| | | | | | | | | | EndLine 2185..2187 +| | | | | | | | | | | EndLine 2185..2187 "\r\n" +| | | | | | | | | | WhiteSpace 2187..2191 +| | | | | | | | | | | WhiteSpace 2187..2191 " " +| | | | | | | | | | EndLine 2191..2193 +| | | | | | | | | | | EndLine 2191..2193 "\r\n" +| | | | | | | | | | WhiteSpace 2193..2205 +| | | | | | | | | | | WhiteSpace 2193..2205 " " +| | | | | | | | | | CommentLine 2205..2228 +| | | | | | | | | | | CommentLine 2205..2228 "// Ensure out is binary" +| | | | | | | | | | EndLine 2228..2230 +| | | | | | | | | | | EndLine 2228..2230 "\r\n" +| | | | | | | | | | WhiteSpace 2230..2242 +| | | | | | | | | | | WhiteSpace 2230..2242 " " +| | | | | | | | | | AssignStatement 2242..2269 +| | | | | | | | | | | Expression 2242..2264 +| | | | | | | | | | | | Mul 2242..2264 +| | | | | | | | | | | | | ArrayQuery 2242..2248 +| | | | | | | | | | | | | | ExpressionAtom 2242..2245 +| | | | | | | | | | | | | | | Identifier 2242..2245 +| | | | | | | | | | | | | | | | Identifier 2242..2245 "out" +| | | | | | | | | | | | | | LBracket 2245..2246 +| | | | | | | | | | | | | | | LBracket 2245..2246 "[" +| | | | | | | | | | | | | | Expression 2246..2247 +| | | | | | | | | | | | | | | ExpressionAtom 2246..2247 +| | | | | | | | | | | | | | | | Identifier 2246..2247 +| | | | | | | | | | | | | | | | | Identifier 2246..2247 "k" +| | | | | | | | | | | | | | RBracket 2247..2248 +| | | | | | | | | | | | | | | RBracket 2247..2248 "]" +| | | | | | | | | | | | | WhiteSpace 2248..2249 +| | | | | | | | | | | | | | WhiteSpace 2248..2249 " " +| | | | | | | | | | | | | Mul 2249..2250 +| | | | | | | | | | | | | | Mul 2249..2250 "*" +| | | | | | | | | | | | | WhiteSpace 2250..2251 +| | | | | | | | | | | | | | WhiteSpace 2250..2251 " " +| | | | | | | | | | | | | Expression 2251..2263 +| | | | | | | | | | | | | | LParen 2251..2252 +| | | | | | | | | | | | | | | LParen 2251..2252 "(" +| | | | | | | | | | | | | | Sub 2252..2262 +| | | | | | | | | | | | | | | ArrayQuery 2252..2258 +| | | | | | | | | | | | | | | | ExpressionAtom 2252..2255 +| | | | | | | | | | | | | | | | | Identifier 2252..2255 +| | | | | | | | | | | | | | | | | | Identifier 2252..2255 "out" +| | | | | | | | | | | | | | | | LBracket 2255..2256 +| | | | | | | | | | | | | | | | | LBracket 2255..2256 "[" +| | | | | | | | | | | | | | | | Expression 2256..2257 +| | | | | | | | | | | | | | | | | ExpressionAtom 2256..2257 +| | | | | | | | | | | | | | | | | | Identifier 2256..2257 +| | | | | | | | | | | | | | | | | | | Identifier 2256..2257 "k" +| | | | | | | | | | | | | | | | RBracket 2257..2258 +| | | | | | | | | | | | | | | | | RBracket 2257..2258 "]" +| | | | | | | | | | | | | | | WhiteSpace 2258..2259 +| | | | | | | | | | | | | | | | WhiteSpace 2258..2259 " " +| | | | | | | | | | | | | | | Sub 2259..2260 +| | | | | | | | | | | | | | | | Sub 2259..2260 "-" +| | | | | | | | | | | | | | | WhiteSpace 2260..2261 +| | | | | | | | | | | | | | | | WhiteSpace 2260..2261 " " +| | | | | | | | | | | | | | | ExpressionAtom 2261..2262 +| | | | | | | | | | | | | | | | Number 2261..2262 +| | | | | | | | | | | | | | | | | Number 2261..2262 "1" +| | | | | | | | | | | | | | RParen 2262..2263 +| | | | | | | | | | | | | | | RParen 2262..2263 ")" +| | | | | | | | | | | | | WhiteSpace 2263..2264 +| | | | | | | | | | | | | | WhiteSpace 2263..2264 " " +| | | | | | | | | | | EqualSignal 2264..2267 +| | | | | | | | | | | | EqualSignal 2264..2267 "===" +| | | | | | | | | | | WhiteSpace 2267..2268 +| | | | | | | | | | | | WhiteSpace 2267..2268 " " +| | | | | | | | | | | Expression 2268..2269 +| | | | | | | | | | | | ExpressionAtom 2268..2269 +| | | | | | | | | | | | | Number 2268..2269 +| | | | | | | | | | | | | | Number 2268..2269 "0" +| | | | | | | | | | Semicolon 2269..2270 +| | | | | | | | | | | Semicolon 2269..2270 ";" +| | | | | | | | | | EndLine 2270..2272 +| | | | | | | | | | | EndLine 2270..2272 "\r\n" +| | | | | | | | | | WhiteSpace 2272..2276 +| | | | | | | | | | | WhiteSpace 2272..2276 " " +| | | | | | | | | | EndLine 2276..2278 +| | | | | | | | | | | EndLine 2276..2278 "\r\n" +| | | | | | | | | | WhiteSpace 2278..2290 +| | | | | | | | | | | WhiteSpace 2278..2290 " " +| | | | | | | | | | AssignStatement 2290..2309 +| | | | | | | | | | | Expression 2290..2295 +| | | | | | | | | | | | ExpressionAtom 2290..2294 +| | | | | | | | | | | | | Identifier 2290..2294 +| | | | | | | | | | | | | | Identifier 2290..2294 "lout" +| | | | | | | | | | | | WhiteSpace 2294..2295 +| | | | | | | | | | | | | WhiteSpace 2294..2295 " " +| | | | | | | | | | | AddAssign 2295..2297 +| | | | | | | | | | | | AddAssign 2295..2297 "+=" +| | | | | | | | | | | WhiteSpace 2297..2298 +| | | | | | | | | | | | WhiteSpace 2297..2298 " " +| | | | | | | | | | | Expression 2298..2309 +| | | | | | | | | | | | Mul 2298..2309 +| | | | | | | | | | | | | ArrayQuery 2298..2304 +| | | | | | | | | | | | | | ExpressionAtom 2298..2301 +| | | | | | | | | | | | | | | Identifier 2298..2301 +| | | | | | | | | | | | | | | | Identifier 2298..2301 "out" +| | | | | | | | | | | | | | LBracket 2301..2302 +| | | | | | | | | | | | | | | LBracket 2301..2302 "[" +| | | | | | | | | | | | | | Expression 2302..2303 +| | | | | | | | | | | | | | | ExpressionAtom 2302..2303 +| | | | | | | | | | | | | | | | Identifier 2302..2303 +| | | | | | | | | | | | | | | | | Identifier 2302..2303 "k" +| | | | | | | | | | | | | | RBracket 2303..2304 +| | | | | | | | | | | | | | | RBracket 2303..2304 "]" +| | | | | | | | | | | | | WhiteSpace 2304..2305 +| | | | | | | | | | | | | | WhiteSpace 2304..2305 " " +| | | | | | | | | | | | | Mul 2305..2306 +| | | | | | | | | | | | | | Mul 2305..2306 "*" +| | | | | | | | | | | | | WhiteSpace 2306..2307 +| | | | | | | | | | | | | | WhiteSpace 2306..2307 " " +| | | | | | | | | | | | | ExpressionAtom 2307..2309 +| | | | | | | | | | | | | | Identifier 2307..2309 +| | | | | | | | | | | | | | | Identifier 2307..2309 "e2" +| | | | | | | | | | Semicolon 2309..2310 +| | | | | | | | | | | Semicolon 2309..2310 ";" +| | | | | | | | | | EndLine 2310..2312 +| | | | | | | | | | | EndLine 2310..2312 "\r\n" +| | | | | | | | | | WhiteSpace 2312..2316 +| | | | | | | | | | | WhiteSpace 2312..2316 " " +| | | | | | | | | | EndLine 2316..2318 +| | | | | | | | | | | EndLine 2316..2318 "\r\n" +| | | | | | | | | | WhiteSpace 2318..2330 +| | | | | | | | | | | WhiteSpace 2318..2330 " " +| | | | | | | | | | AssignStatement 2330..2340 +| | | | | | | | | | | Expression 2330..2333 +| | | | | | | | | | | | ExpressionAtom 2330..2332 +| | | | | | | | | | | | | Identifier 2330..2332 +| | | | | | | | | | | | | | Identifier 2330..2332 "e2" +| | | | | | | | | | | | WhiteSpace 2332..2333 +| | | | | | | | | | | | | WhiteSpace 2332..2333 " " +| | | | | | | | | | | Assign 2333..2334 +| | | | | | | | | | | | Assign 2333..2334 "=" +| | | | | | | | | | | WhiteSpace 2334..2335 +| | | | | | | | | | | | WhiteSpace 2334..2335 " " +| | | | | | | | | | | Expression 2335..2340 +| | | | | | | | | | | | Add 2335..2340 +| | | | | | | | | | | | | ExpressionAtom 2335..2337 +| | | | | | | | | | | | | | Identifier 2335..2337 +| | | | | | | | | | | | | | | Identifier 2335..2337 "e2" +| | | | | | | | | | | | | Add 2337..2338 +| | | | | | | | | | | | | | Add 2337..2338 "+" +| | | | | | | | | | | | | ExpressionAtom 2338..2340 +| | | | | | | | | | | | | | Identifier 2338..2340 +| | | | | | | | | | | | | | | Identifier 2338..2340 "e2" +| | | | | | | | | | Semicolon 2340..2341 +| | | | | | | | | | | Semicolon 2340..2341 ";" +| | | | | | | | | | EndLine 2341..2343 +| | | | | | | | | | | EndLine 2341..2343 "\r\n" +| | | | | | | | | | WhiteSpace 2343..2351 +| | | | | | | | | | | WhiteSpace 2343..2351 " " +| | | | | | | | | RCurly 2351..2352 +| | | | | | | | | | RCurly 2351..2352 "}" +| | | | | | | EndLine 2352..2354 +| | | | | | | | EndLine 2352..2354 "\r\n" +| | | | | | | WhiteSpace 2354..2358 +| | | | | | | | WhiteSpace 2354..2358 " " +| | | | | | | EndLine 2358..2360 +| | | | | | | | EndLine 2358..2360 "\r\n" +| | | | | | | WhiteSpace 2360..2368 +| | | | | | | | WhiteSpace 2360..2368 " " +| | | | | | | CommentLine 2368..2386 +| | | | | | | | CommentLine 2368..2386 "// Ensure the sum;" +| | | | | | | EndLine 2386..2388 +| | | | | | | | EndLine 2386..2388 "\r\n" +| | | | | | | WhiteSpace 2388..2392 +| | | | | | | | WhiteSpace 2388..2392 " " +| | | | | | | EndLine 2392..2394 +| | | | | | | | EndLine 2392..2394 "\r\n" +| | | | | | | WhiteSpace 2394..2402 +| | | | | | | | WhiteSpace 2394..2402 " " +| | | | | | | AssignStatement 2402..2414 +| | | | | | | | Expression 2402..2406 +| | | | | | | | | ExpressionAtom 2402..2405 +| | | | | | | | | | Identifier 2402..2405 +| | | | | | | | | | | Identifier 2402..2405 "lin" +| | | | | | | | | WhiteSpace 2405..2406 +| | | | | | | | | | WhiteSpace 2405..2406 " " +| | | | | | | | EqualSignal 2406..2409 +| | | | | | | | | EqualSignal 2406..2409 "===" +| | | | | | | | WhiteSpace 2409..2410 +| | | | | | | | | WhiteSpace 2409..2410 " " +| | | | | | | | Expression 2410..2414 +| | | | | | | | | ExpressionAtom 2410..2414 +| | | | | | | | | | Identifier 2410..2414 +| | | | | | | | | | | Identifier 2410..2414 "lout" +| | | | | | | Semicolon 2414..2415 +| | | | | | | | Semicolon 2414..2415 ";" +| | | | | | | EndLine 2415..2417 +| | | | | | | | EndLine 2415..2417 "\r\n" +| | | | | | | WhiteSpace 2417..2421 +| | | | | | | | WhiteSpace 2417..2421 " " +| | | | | | RCurly 2421..2422 +| | | | | | | RCurly 2421..2422 "}" | | | | EndLine 2422..2424 | | | | | EndLine 2422..2424 "\r\n" | | | RCurly 2424..2425 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap new file mode 100644 index 0000000..0fed8a2 --- /dev/null +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap @@ -0,0 +1,483 @@ +--- +source: crates/syntax/src/syntax.rs +expression: "crate :: view_syntax :: view_ast(& syntax)" +--- + Block 0..425 +| LCurly 0..1 +| | LCurly 0..1 "{" +| EndLine 1..2 +| | EndLine 1..2 "\n" +| WhiteSpace 2..6 +| | WhiteSpace 2..6 " " +| CommentLine 6..21 +| | CommentLine 6..21 "// if ... else " +| EndLine 21..22 +| | EndLine 21..22 "\n" +| WhiteSpace 22..26 +| | WhiteSpace 22..26 " " +| StatementList 26..424 +| | IfStatement 26..121 +| | | IfKw 26..28 +| | | | IfKw 26..28 "if" +| | | LParen 28..29 +| | | | LParen 28..29 "(" +| | | Expression 29..35 +| | | | Equal 29..35 +| | | | | ExpressionAtom 29..30 +| | | | | | Identifier 29..30 +| | | | | | | Identifier 29..30 "n" +| | | | | WhiteSpace 30..31 +| | | | | | WhiteSpace 30..31 " " +| | | | | Equal 31..33 +| | | | | | Equal 31..33 "==" +| | | | | WhiteSpace 33..34 +| | | | | | WhiteSpace 33..34 " " +| | | | | ExpressionAtom 34..35 +| | | | | | Number 34..35 +| | | | | | | Number 34..35 "2" +| | | RParen 35..36 +| | | | RParen 35..36 ")" +| | | WhiteSpace 36..37 +| | | | WhiteSpace 36..37 " " +| | | Block 37..89 +| | | | LCurly 37..38 +| | | | | LCurly 37..38 "{" +| | | | EndLine 38..39 +| | | | | EndLine 38..39 "\n" +| | | | WhiteSpace 39..47 +| | | | | WhiteSpace 39..47 " " +| | | | StatementList 47..88 +| | | | | AssignStatement 47..56 +| | | | | | Expression 47..51 +| | | | | | | ExpressionAtom 47..50 +| | | | | | | | Identifier 47..50 +| | | | | | | | | Identifier 47..50 "aux" +| | | | | | | WhiteSpace 50..51 +| | | | | | | | WhiteSpace 50..51 " " +| | | | | | RAssignConstraintSignal 51..54 +| | | | | | | RAssignConstraintSignal 51..54 "<==" +| | | | | | WhiteSpace 54..55 +| | | | | | | WhiteSpace 54..55 " " +| | | | | | Expression 55..56 +| | | | | | | ExpressionAtom 55..56 +| | | | | | | | Number 55..56 +| | | | | | | | | Number 55..56 "2" +| | | | | Semicolon 56..57 +| | | | | | Semicolon 56..57 ";" +| | | | | EndLine 57..58 +| | | | | | EndLine 57..58 "\n" +| | | | | WhiteSpace 58..66 +| | | | | | WhiteSpace 58..66 " " +| | | | | AssignStatement 66..82 +| | | | | | Expression 66..70 +| | | | | | | ExpressionAtom 66..69 +| | | | | | | | Identifier 66..69 +| | | | | | | | | Identifier 66..69 "out" +| | | | | | | WhiteSpace 69..70 +| | | | | | | | WhiteSpace 69..70 " " +| | | | | | RAssignConstraintSignal 70..73 +| | | | | | | RAssignConstraintSignal 70..73 "<==" +| | | | | | WhiteSpace 73..74 +| | | | | | | WhiteSpace 73..74 " " +| | | | | | Expression 74..82 +| | | | | | | Call 74..82 +| | | | | | | | Call 74..77 +| | | | | | | | | ExpressionAtom 74..75 +| | | | | | | | | | Identifier 74..75 +| | | | | | | | | | | Identifier 74..75 "B" +| | | | | | | | | LParen 75..76 +| | | | | | | | | | LParen 75..76 "(" +| | | | | | | | | RParen 76..77 +| | | | | | | | | | RParen 76..77 ")" +| | | | | | | | LParen 77..78 +| | | | | | | | | LParen 77..78 "(" +| | | | | | | | Expression 78..81 +| | | | | | | | | ExpressionAtom 78..81 +| | | | | | | | | | Identifier 78..81 +| | | | | | | | | | | Identifier 78..81 "aux" +| | | | | | | | RParen 81..82 +| | | | | | | | | RParen 81..82 ")" +| | | | | Semicolon 82..83 +| | | | | | Semicolon 82..83 ";" +| | | | | EndLine 83..84 +| | | | | | EndLine 83..84 "\n" +| | | | | WhiteSpace 84..88 +| | | | | | WhiteSpace 84..88 " " +| | | | RCurly 88..89 +| | | | | RCurly 88..89 "}" +| | | WhiteSpace 89..90 +| | | | WhiteSpace 89..90 " " +| | | ElseKw 90..94 +| | | | ElseKw 90..94 "else" +| | | WhiteSpace 94..95 +| | | | WhiteSpace 94..95 " " +| | | Block 95..121 +| | | | LCurly 95..96 +| | | | | LCurly 95..96 "{" +| | | | EndLine 96..97 +| | | | | EndLine 96..97 "\n" +| | | | WhiteSpace 97..105 +| | | | | WhiteSpace 97..105 " " +| | | | StatementList 105..120 +| | | | | AssignStatement 105..114 +| | | | | | Expression 105..109 +| | | | | | | ExpressionAtom 105..108 +| | | | | | | | Identifier 105..108 +| | | | | | | | | Identifier 105..108 "out" +| | | | | | | WhiteSpace 108..109 +| | | | | | | | WhiteSpace 108..109 " " +| | | | | | RAssignConstraintSignal 109..112 +| | | | | | | RAssignConstraintSignal 109..112 "<==" +| | | | | | WhiteSpace 112..113 +| | | | | | | WhiteSpace 112..113 " " +| | | | | | Expression 113..114 +| | | | | | | ExpressionAtom 113..114 +| | | | | | | | Number 113..114 +| | | | | | | | | Number 113..114 "5" +| | | | | Semicolon 114..115 +| | | | | | Semicolon 114..115 ";" +| | | | | EndLine 115..116 +| | | | | | EndLine 115..116 "\n" +| | | | | WhiteSpace 116..120 +| | | | | | WhiteSpace 116..120 " " +| | | | RCurly 120..121 +| | | | | RCurly 120..121 "}" +| | EndLine 121..122 +| | | EndLine 121..122 "\n" +| | EndLine 122..123 +| | | EndLine 122..123 "\n" +| | WhiteSpace 123..127 +| | | WhiteSpace 123..127 " " +| | CommentLine 127..133 +| | | CommentLine 127..133 "// for" +| | EndLine 133..134 +| | | EndLine 133..134 "\n" +| | WhiteSpace 134..138 +| | | WhiteSpace 134..138 " " +| | ForLoop 138..206 +| | | ForKw 138..141 +| | | | ForKw 138..141 "for" +| | | LParen 141..142 +| | | | LParen 141..142 "(" +| | | VarDecl 142..151 +| | | | VarKw 142..145 +| | | | | VarKw 142..145 "var" +| | | | WhiteSpace 145..146 +| | | | | WhiteSpace 145..146 " " +| | | | VarIdentifier 146..148 +| | | | | Identifier 146..147 +| | | | | | Identifier 146..147 "i" +| | | | | WhiteSpace 147..148 +| | | | | | WhiteSpace 147..148 " " +| | | | Assign 148..149 +| | | | | Assign 148..149 "=" +| | | | WhiteSpace 149..150 +| | | | | WhiteSpace 149..150 " " +| | | | Expression 150..151 +| | | | | ExpressionAtom 150..151 +| | | | | | Number 150..151 +| | | | | | | Number 150..151 "0" +| | | Semicolon 151..152 +| | | | Semicolon 151..152 ";" +| | | WhiteSpace 152..153 +| | | | WhiteSpace 152..153 " " +| | | Expression 153..160 +| | | | LessThan 153..160 +| | | | | ExpressionAtom 153..154 +| | | | | | Identifier 153..154 +| | | | | | | Identifier 153..154 "i" +| | | | | WhiteSpace 154..155 +| | | | | | WhiteSpace 154..155 " " +| | | | | LessThan 155..156 +| | | | | | LessThan 155..156 "<" +| | | | | WhiteSpace 156..157 +| | | | | | WhiteSpace 156..157 " " +| | | | | Sub 157..160 +| | | | | | ExpressionAtom 157..158 +| | | | | | | Identifier 157..158 +| | | | | | | | Identifier 157..158 "N" +| | | | | | Sub 158..159 +| | | | | | | Sub 158..159 "-" +| | | | | | ExpressionAtom 159..160 +| | | | | | | Number 159..160 +| | | | | | | | Number 159..160 "1" +| | | Semicolon 160..161 +| | | | Semicolon 160..161 ";" +| | | WhiteSpace 161..162 +| | | | WhiteSpace 161..162 " " +| | | AssignStatement 162..165 +| | | | Expression 162..165 +| | | | | UnitInc 162..165 +| | | | | | ExpressionAtom 162..163 +| | | | | | | Identifier 162..163 +| | | | | | | | Identifier 162..163 "i" +| | | | | | UnitInc 163..165 +| | | | | | | UnitInc 163..165 "++" +| | | RParen 165..166 +| | | | RParen 165..166 ")" +| | | Block 166..206 +| | | | LCurly 166..167 +| | | | | LCurly 166..167 "{" +| | | | EndLine 167..168 +| | | | | EndLine 167..168 "\n" +| | | | WhiteSpace 168..176 +| | | | | WhiteSpace 168..176 " " +| | | | StatementList 176..205 +| | | | | AssignStatement 176..199 +| | | | | | Expression 176..184 +| | | | | | | ArrayQuery 176..183 +| | | | | | | | ExpressionAtom 176..180 +| | | | | | | | | Identifier 176..180 +| | | | | | | | | | Identifier 176..180 "comp" +| | | | | | | | LBracket 180..181 +| | | | | | | | | LBracket 180..181 "[" +| | | | | | | | Expression 181..182 +| | | | | | | | | ExpressionAtom 181..182 +| | | | | | | | | | Identifier 181..182 +| | | | | | | | | | | Identifier 181..182 "i" +| | | | | | | | RBracket 182..183 +| | | | | | | | | RBracket 182..183 "]" +| | | | | | | WhiteSpace 183..184 +| | | | | | | | WhiteSpace 183..184 " " +| | | | | | Assign 184..185 +| | | | | | | Assign 184..185 "=" +| | | | | | WhiteSpace 185..186 +| | | | | | | WhiteSpace 185..186 " " +| | | | | | Expression 186..199 +| | | | | | | Call 186..199 +| | | | | | | | ExpressionAtom 186..197 +| | | | | | | | | Identifier 186..197 +| | | | | | | | | | Identifier 186..197 "Multiplier2" +| | | | | | | | LParen 197..198 +| | | | | | | | | LParen 197..198 "(" +| | | | | | | | RParen 198..199 +| | | | | | | | | RParen 198..199 ")" +| | | | | Semicolon 199..200 +| | | | | | Semicolon 199..200 ";" +| | | | | EndLine 200..201 +| | | | | | EndLine 200..201 "\n" +| | | | | WhiteSpace 201..205 +| | | | | | WhiteSpace 201..205 " " +| | | | RCurly 205..206 +| | | | | RCurly 205..206 "}" +| | EndLine 206..207 +| | | EndLine 206..207 "\n" +| | EndLine 207..208 +| | | EndLine 207..208 "\n" +| | WhiteSpace 208..212 +| | | WhiteSpace 208..212 " " +| | CommentLine 212..220 +| | | CommentLine 212..220 "// while" +| | EndLine 220..221 +| | | EndLine 220..221 "\n" +| | WhiteSpace 221..225 +| | | WhiteSpace 221..225 " " +| | WhileLoop 225..275 +| | | WhileKw 225..230 +| | | | WhileKw 225..230 "while" +| | | WhiteSpace 230..231 +| | | | WhiteSpace 230..231 " " +| | | LParen 231..232 +| | | | LParen 231..232 "(" +| | | Expression 232..237 +| | | | LessThan 232..237 +| | | | | Sub 232..235 +| | | | | | ExpressionAtom 232..233 +| | | | | | | Identifier 232..233 +| | | | | | | | Identifier 232..233 "n" +| | | | | | Sub 233..234 +| | | | | | | Sub 233..234 "-" +| | | | | | ExpressionAtom 234..235 +| | | | | | | Number 234..235 +| | | | | | | | Number 234..235 "1" +| | | | | LessThan 235..236 +| | | | | | LessThan 235..236 "<" +| | | | | ExpressionAtom 236..237 +| | | | | | Identifier 236..237 +| | | | | | | Identifier 236..237 "a" +| | | RParen 237..238 +| | | | RParen 237..238 ")" +| | | WhiteSpace 238..239 +| | | | WhiteSpace 238..239 " " +| | | Block 239..275 +| | | | LCurly 239..240 +| | | | | LCurly 239..240 "{" +| | | | EndLine 240..241 +| | | | | EndLine 240..241 "\n" +| | | | WhiteSpace 241..249 +| | | | | WhiteSpace 241..249 " " +| | | | StatementList 249..274 +| | | | | AssignStatement 249..252 +| | | | | | Expression 249..252 +| | | | | | | UnitInc 249..252 +| | | | | | | | ExpressionAtom 249..250 +| | | | | | | | | Identifier 249..250 +| | | | | | | | | | Identifier 249..250 "r" +| | | | | | | | UnitInc 250..252 +| | | | | | | | | UnitInc 250..252 "++" +| | | | | Semicolon 252..253 +| | | | | | Semicolon 252..253 ";" +| | | | | EndLine 253..254 +| | | | | | EndLine 253..254 "\n" +| | | | | WhiteSpace 254..262 +| | | | | | WhiteSpace 254..262 " " +| | | | | AssignStatement 262..268 +| | | | | | Expression 262..264 +| | | | | | | ExpressionAtom 262..263 +| | | | | | | | Identifier 262..263 +| | | | | | | | | Identifier 262..263 "n" +| | | | | | | WhiteSpace 263..264 +| | | | | | | | WhiteSpace 263..264 " " +| | | | | | MulAssign 264..266 +| | | | | | | MulAssign 264..266 "*=" +| | | | | | WhiteSpace 266..267 +| | | | | | | WhiteSpace 266..267 " " +| | | | | | Expression 267..268 +| | | | | | | ExpressionAtom 267..268 +| | | | | | | | Number 267..268 +| | | | | | | | | Number 267..268 "2" +| | | | | Semicolon 268..269 +| | | | | | Semicolon 268..269 ";" +| | | | | EndLine 269..270 +| | | | | | EndLine 269..270 "\n" +| | | | | WhiteSpace 270..274 +| | | | | | WhiteSpace 270..274 " " +| | | | RCurly 274..275 +| | | | | RCurly 274..275 "}" +| | EndLine 275..276 +| | | EndLine 275..276 "\n" +| | EndLine 276..277 +| | | EndLine 276..277 "\n" +| | WhiteSpace 277..281 +| | | WhiteSpace 277..281 " " +| | CommentLine 281..290 +| | | CommentLine 281..290 "// return" +| | EndLine 290..291 +| | | EndLine 290..291 "\n" +| | WhiteSpace 291..295 +| | | WhiteSpace 291..295 " " +| | ReturnStatement 295..303 +| | | ReturnKw 295..301 +| | | | ReturnKw 295..301 "return" +| | | WhiteSpace 301..302 +| | | | WhiteSpace 301..302 " " +| | | Expression 302..303 +| | | | ExpressionAtom 302..303 +| | | | | Identifier 302..303 +| | | | | | Identifier 302..303 "r" +| | Semicolon 303..304 +| | | Semicolon 303..304 ";" +| | EndLine 304..305 +| | | EndLine 304..305 "\n" +| | EndLine 305..306 +| | | EndLine 305..306 "\n" +| | WhiteSpace 306..310 +| | | WhiteSpace 306..310 " " +| | CommentLine 310..316 +| | | CommentLine 310..316 "// log" +| | EndLine 316..317 +| | | EndLine 316..317 "\n" +| | WhiteSpace 317..321 +| | | WhiteSpace 317..321 " " +| | LogStatement 321..342 +| | | LogKw 321..324 +| | | | LogKw 321..324 "log" +| | | LParen 324..325 +| | | | LParen 324..325 "(" +| | | CircomString 325..331 +| | | | CircomString 325..331 "\"hash\"" +| | | Comma 331..332 +| | | | Comma 331..332 "," +| | | WhiteSpace 332..333 +| | | | WhiteSpace 332..333 " " +| | | Expression 333..341 +| | | | ComponentCall 333..341 +| | | | | ExpressionAtom 333..337 +| | | | | | Identifier 333..337 +| | | | | | | Identifier 333..337 "hash" +| | | | | Dot 337..338 +| | | | | | Dot 337..338 "." +| | | | | Identifier 338..341 +| | | | | | Identifier 338..341 "out" +| | | RParen 341..342 +| | | | RParen 341..342 ")" +| | Semicolon 342..343 +| | | Semicolon 342..343 ";" +| | EndLine 343..344 +| | | EndLine 343..344 "\n" +| | EndLine 344..345 +| | | EndLine 344..345 "\n" +| | WhiteSpace 345..349 +| | | WhiteSpace 345..349 " " +| | CommentLine 349..358 +| | | CommentLine 349..358 "// assert" +| | EndLine 358..359 +| | | EndLine 358..359 "\n" +| | WhiteSpace 359..363 +| | | WhiteSpace 359..363 " " +| | AssertStatement 363..376 +| | | AssertKw 363..369 +| | | | AssertKw 363..369 "assert" +| | | LParen 369..370 +| | | | LParen 369..370 "(" +| | | Expression 370..375 +| | | | GreaterThan 370..375 +| | | | | ExpressionAtom 370..371 +| | | | | | Identifier 370..371 +| | | | | | | Identifier 370..371 "a" +| | | | | WhiteSpace 371..372 +| | | | | | WhiteSpace 371..372 " " +| | | | | GreaterThan 372..373 +| | | | | | GreaterThan 372..373 ">" +| | | | | WhiteSpace 373..374 +| | | | | | WhiteSpace 373..374 " " +| | | | | ExpressionAtom 374..375 +| | | | | | Number 374..375 +| | | | | | | Number 374..375 "2" +| | | RParen 375..376 +| | | | RParen 375..376 ")" +| | Semicolon 376..377 +| | | Semicolon 376..377 ";" +| | EndLine 377..378 +| | | EndLine 377..378 "\n" +| | EndLine 378..379 +| | | EndLine 378..379 "\n" +| | WhiteSpace 379..383 +| | | WhiteSpace 379..383 " " +| | CommentLine 383..406 +| | | CommentLine 383..406 "// assignment statement" +| | EndLine 406..407 +| | | EndLine 406..407 "\n" +| | WhiteSpace 407..411 +| | | WhiteSpace 407..411 " " +| | AssignStatement 411..422 +| | | Expression 411..413 +| | | | ExpressionAtom 411..412 +| | | | | Identifier 411..412 +| | | | | | Identifier 411..412 "c" +| | | | WhiteSpace 412..413 +| | | | | WhiteSpace 412..413 " " +| | | RAssignConstraintSignal 413..416 +| | | | RAssignConstraintSignal 413..416 "<==" +| | | WhiteSpace 416..417 +| | | | WhiteSpace 416..417 " " +| | | Expression 417..422 +| | | | Mul 417..422 +| | | | | ExpressionAtom 417..418 +| | | | | | Identifier 417..418 +| | | | | | | Identifier 417..418 "a" +| | | | | WhiteSpace 418..419 +| | | | | | WhiteSpace 418..419 " " +| | | | | Mul 419..420 +| | | | | | Mul 419..420 "*" +| | | | | WhiteSpace 420..421 +| | | | | | WhiteSpace 420..421 " " +| | | | | ExpressionAtom 421..422 +| | | | | | Identifier 421..422 +| | | | | | | Identifier 421..422 "b" +| | Semicolon 422..423 +| | | Semicolon 422..423 ";" +| | EndLine 423..424 +| | | EndLine 423..424 "\n" +| RCurly 424..425 +| | RCurly 424..425 "}" diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap index 287ef65..0bdbad0 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap @@ -131,115 +131,112 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | EndLine 228..230 "\r\n" | | | WhiteSpace 230..242 | | | | WhiteSpace 230..242 " " -| | | Statement 242..328 -| | | | ForLoop 242..328 -| | | | | ForKw 242..245 -| | | | | | ForKw 242..245 "for" -| | | | | LParen 245..246 -| | | | | | LParen 245..246 "(" -| | | | | VarDecl 246..255 -| | | | | | VarKw 246..249 -| | | | | | | VarKw 246..249 "var" -| | | | | | WhiteSpace 249..250 -| | | | | | | WhiteSpace 249..250 " " -| | | | | | VarIdentifier 250..252 -| | | | | | | Identifier 250..251 -| | | | | | | | Identifier 250..251 "i" -| | | | | | | WhiteSpace 251..252 -| | | | | | | | WhiteSpace 251..252 " " -| | | | | | Assign 252..253 -| | | | | | | Assign 252..253 "=" -| | | | | | WhiteSpace 253..254 -| | | | | | | WhiteSpace 253..254 " " -| | | | | | Expression 254..255 -| | | | | | | ExpressionAtom 254..255 -| | | | | | | | Number 254..255 -| | | | | | | | | Number 254..255 "0" -| | | | | Semicolon 255..256 -| | | | | | Semicolon 255..256 ";" -| | | | | WhiteSpace 256..257 -| | | | | | WhiteSpace 256..257 " " -| | | | | Expression 257..264 -| | | | | | LessThan 257..264 -| | | | | | | ExpressionAtom 257..258 -| | | | | | | | Identifier 257..258 -| | | | | | | | | Identifier 257..258 "i" -| | | | | | | WhiteSpace 258..259 -| | | | | | | | WhiteSpace 258..259 " " -| | | | | | | LessThan 259..260 -| | | | | | | | LessThan 259..260 "<" -| | | | | | | WhiteSpace 260..261 -| | | | | | | | WhiteSpace 260..261 " " -| | | | | | | Sub 261..264 -| | | | | | | | ExpressionAtom 261..262 -| | | | | | | | | Identifier 261..262 -| | | | | | | | | | Identifier 261..262 "N" -| | | | | | | | Sub 262..263 -| | | | | | | | | Sub 262..263 "-" -| | | | | | | | ExpressionAtom 263..264 -| | | | | | | | | Number 263..264 -| | | | | | | | | | Number 263..264 "1" -| | | | | Semicolon 264..265 -| | | | | | Semicolon 264..265 ";" -| | | | | WhiteSpace 265..266 -| | | | | | WhiteSpace 265..266 " " -| | | | | AssignStatement 266..269 -| | | | | | Expression 266..269 -| | | | | | | Expression 266..269 -| | | | | | | | ExpressionAtom 266..267 -| | | | | | | | | Identifier 266..267 -| | | | | | | | | | Identifier 266..267 "i" -| | | | | | | | UnitInc 267..269 -| | | | | | | | | UnitInc 267..269 "++" -| | | | | RParen 269..270 -| | | | | | RParen 269..270 ")" -| | | | | Statement 270..328 -| | | | | | Block 270..328 -| | | | | | | LCurly 270..271 -| | | | | | | | LCurly 270..271 "{" -| | | | | | | EndLine 271..273 -| | | | | | | | EndLine 271..273 "\r\n" -| | | | | | | WhiteSpace 273..289 -| | | | | | | | WhiteSpace 273..289 " " -| | | | | | | StatementList 289..327 -| | | | | | | | Statement 289..313 -| | | | | | | | | AssignStatement 289..312 -| | | | | | | | | | Expression 289..297 -| | | | | | | | | | | ArrayQuery 289..296 -| | | | | | | | | | | | ExpressionAtom 289..293 -| | | | | | | | | | | | | Identifier 289..293 -| | | | | | | | | | | | | | Identifier 289..293 "comp" -| | | | | | | | | | | | LBracket 293..294 -| | | | | | | | | | | | | LBracket 293..294 "[" -| | | | | | | | | | | | Expression 294..295 -| | | | | | | | | | | | | ExpressionAtom 294..295 -| | | | | | | | | | | | | | Identifier 294..295 -| | | | | | | | | | | | | | | Identifier 294..295 "i" -| | | | | | | | | | | | RBracket 295..296 -| | | | | | | | | | | | | RBracket 295..296 "]" -| | | | | | | | | | | WhiteSpace 296..297 -| | | | | | | | | | | | WhiteSpace 296..297 " " -| | | | | | | | | | Assign 297..298 -| | | | | | | | | | | Assign 297..298 "=" -| | | | | | | | | | WhiteSpace 298..299 -| | | | | | | | | | | WhiteSpace 298..299 " " -| | | | | | | | | | Expression 299..312 -| | | | | | | | | | | Call 299..312 -| | | | | | | | | | | | ExpressionAtom 299..310 -| | | | | | | | | | | | | Identifier 299..310 -| | | | | | | | | | | | | | Identifier 299..310 "Multiplier2" -| | | | | | | | | | | | LParen 310..311 -| | | | | | | | | | | | | LParen 310..311 "(" -| | | | | | | | | | | | RParen 311..312 -| | | | | | | | | | | | | RParen 311..312 ")" -| | | | | | | | | Semicolon 312..313 -| | | | | | | | | | Semicolon 312..313 ";" -| | | | | | | | EndLine 313..315 -| | | | | | | | | EndLine 313..315 "\r\n" -| | | | | | | | WhiteSpace 315..327 -| | | | | | | | | WhiteSpace 315..327 " " -| | | | | | | RCurly 327..328 -| | | | | | | | RCurly 327..328 "}" +| | | ForLoop 242..328 +| | | | ForKw 242..245 +| | | | | ForKw 242..245 "for" +| | | | LParen 245..246 +| | | | | LParen 245..246 "(" +| | | | VarDecl 246..255 +| | | | | VarKw 246..249 +| | | | | | VarKw 246..249 "var" +| | | | | WhiteSpace 249..250 +| | | | | | WhiteSpace 249..250 " " +| | | | | VarIdentifier 250..252 +| | | | | | Identifier 250..251 +| | | | | | | Identifier 250..251 "i" +| | | | | | WhiteSpace 251..252 +| | | | | | | WhiteSpace 251..252 " " +| | | | | Assign 252..253 +| | | | | | Assign 252..253 "=" +| | | | | WhiteSpace 253..254 +| | | | | | WhiteSpace 253..254 " " +| | | | | Expression 254..255 +| | | | | | ExpressionAtom 254..255 +| | | | | | | Number 254..255 +| | | | | | | | Number 254..255 "0" +| | | | Semicolon 255..256 +| | | | | Semicolon 255..256 ";" +| | | | WhiteSpace 256..257 +| | | | | WhiteSpace 256..257 " " +| | | | Expression 257..264 +| | | | | LessThan 257..264 +| | | | | | ExpressionAtom 257..258 +| | | | | | | Identifier 257..258 +| | | | | | | | Identifier 257..258 "i" +| | | | | | WhiteSpace 258..259 +| | | | | | | WhiteSpace 258..259 " " +| | | | | | LessThan 259..260 +| | | | | | | LessThan 259..260 "<" +| | | | | | WhiteSpace 260..261 +| | | | | | | WhiteSpace 260..261 " " +| | | | | | Sub 261..264 +| | | | | | | ExpressionAtom 261..262 +| | | | | | | | Identifier 261..262 +| | | | | | | | | Identifier 261..262 "N" +| | | | | | | Sub 262..263 +| | | | | | | | Sub 262..263 "-" +| | | | | | | ExpressionAtom 263..264 +| | | | | | | | Number 263..264 +| | | | | | | | | Number 263..264 "1" +| | | | Semicolon 264..265 +| | | | | Semicolon 264..265 ";" +| | | | WhiteSpace 265..266 +| | | | | WhiteSpace 265..266 " " +| | | | AssignStatement 266..269 +| | | | | Expression 266..269 +| | | | | | UnitInc 266..269 +| | | | | | | ExpressionAtom 266..267 +| | | | | | | | Identifier 266..267 +| | | | | | | | | Identifier 266..267 "i" +| | | | | | | UnitInc 267..269 +| | | | | | | | UnitInc 267..269 "++" +| | | | RParen 269..270 +| | | | | RParen 269..270 ")" +| | | | Block 270..328 +| | | | | LCurly 270..271 +| | | | | | LCurly 270..271 "{" +| | | | | EndLine 271..273 +| | | | | | EndLine 271..273 "\r\n" +| | | | | WhiteSpace 273..289 +| | | | | | WhiteSpace 273..289 " " +| | | | | StatementList 289..327 +| | | | | | AssignStatement 289..312 +| | | | | | | Expression 289..297 +| | | | | | | | ArrayQuery 289..296 +| | | | | | | | | ExpressionAtom 289..293 +| | | | | | | | | | Identifier 289..293 +| | | | | | | | | | | Identifier 289..293 "comp" +| | | | | | | | | LBracket 293..294 +| | | | | | | | | | LBracket 293..294 "[" +| | | | | | | | | Expression 294..295 +| | | | | | | | | | ExpressionAtom 294..295 +| | | | | | | | | | | Identifier 294..295 +| | | | | | | | | | | | Identifier 294..295 "i" +| | | | | | | | | RBracket 295..296 +| | | | | | | | | | RBracket 295..296 "]" +| | | | | | | | WhiteSpace 296..297 +| | | | | | | | | WhiteSpace 296..297 " " +| | | | | | | Assign 297..298 +| | | | | | | | Assign 297..298 "=" +| | | | | | | WhiteSpace 298..299 +| | | | | | | | WhiteSpace 298..299 " " +| | | | | | | Expression 299..312 +| | | | | | | | Call 299..312 +| | | | | | | | | ExpressionAtom 299..310 +| | | | | | | | | | Identifier 299..310 +| | | | | | | | | | | Identifier 299..310 "Multiplier2" +| | | | | | | | | LParen 310..311 +| | | | | | | | | | LParen 310..311 "(" +| | | | | | | | | RParen 311..312 +| | | | | | | | | | RParen 311..312 ")" +| | | | | | Semicolon 312..313 +| | | | | | | Semicolon 312..313 ";" +| | | | | | EndLine 313..315 +| | | | | | | EndLine 313..315 "\r\n" +| | | | | | WhiteSpace 315..327 +| | | | | | | WhiteSpace 315..327 " " +| | | | | RCurly 327..328 +| | | | | | RCurly 327..328 "}" | | | EndLine 328..330 | | | | EndLine 328..330 "\r\n" | | | WhiteSpace 330..346 diff --git a/crates/syntax/src/test_files/happy/statements.circom b/crates/syntax/src/test_files/happy/statements.circom new file mode 100644 index 0000000..77da8af --- /dev/null +++ b/crates/syntax/src/test_files/happy/statements.circom @@ -0,0 +1,32 @@ +{ + // if ... else + if(n == 2) { + aux <== 2; + out <== B()(aux); + } else { + out <== 5; + } + + // for + for(var i = 0; i < N-1; i++){ + comp[i] = Multiplier2(); + } + + // while + while (n-1 2); + + // assignment statement + c <== a * b; +} \ No newline at end of file From bc83c83436be53f8c7d410781c4afa1c42aca118 Mon Sep 17 00:00:00 2001 From: NTTVy03 Date: Sun, 9 Feb 2025 21:05:10 +0700 Subject: [PATCH 71/71] remove duplicate in declaration --- crates/parser/src/grammar/declaration.rs | 50 +++++++++---------- crates/parser/src/token_kind.rs | 8 +-- crates/syntax/src/abstract_syntax_tree/ast.rs | 42 ++++++---------- ..._src__test_files__happy__block.circom.snap | 10 ++-- ...es__happy__full_circom_program.circom.snap | 20 ++++---- ..._test_files__happy__statements.circom.snap | 2 +- ...c__test_files__happy__template.circom.snap | 8 +-- 7 files changed, 64 insertions(+), 76 deletions(-) diff --git a/crates/parser/src/grammar/declaration.rs b/crates/parser/src/grammar/declaration.rs index 1c0dc2c..5023b8b 100644 --- a/crates/parser/src/grammar/declaration.rs +++ b/crates/parser/src/grammar/declaration.rs @@ -18,6 +18,21 @@ fn array(p: &mut Parser) -> bool { is_array } +/* +* eg: a, a[N], a[N][M - 1],... +*/ +pub(crate) fn complex_identifier(p: &mut Parser) { + let open_marker = p.open(); + + // name + p.expect(Identifier); + + // eg: [N - 1][M] + array(p); + + p.close(open_marker, ComplexIdentifier); +} + /* "signal" --> None "signal input" --> Some(true) @@ -54,14 +69,9 @@ var_init does not include `var` keyword eg: tmp = 10; */ pub(crate) fn var_init(p: &mut Parser) { - let var_identifier_open_marker = p.open(); - - // name of variable - p.expect(Identifier); - // eg: [N - 1][M] - array(p); - - p.close(var_identifier_open_marker, VarIdentifier); + // var identifier + // eg: a[N] + complex_identifier(p); // assign for variable // eg: = 10 @@ -73,12 +83,9 @@ pub(crate) fn var_init(p: &mut Parser) { // eg: in[N - 1] <== c.in; pub(crate) fn signal_init(p: &mut Parser, assign_able: bool) { - let signal_identifier_open_marker = p.open(); - // name of signal - p.expect(Identifier); - // eg: [N][M-1] - array(p); - p.close(signal_identifier_open_marker, SignalIdentifier); + // signal identifier + // eg: in[N] + complex_identifier(p); // assign for intermediate and outputs signals // eg: <== Multiplier2().out @@ -169,20 +176,13 @@ pub(super) fn component_declaration(p: &mut Parser) { let m = p.open(); p.expect(ComponentKw); - let m_c = p.open(); - p.expect(Identifier); - - // support array component - // eg: comp[N - 1][10] - array(p); - p.close(m_c, ComponentIdentifier); - - // support array component + // component identifier // eg: comp[N - 1][10] - let is_array = array(p); + complex_identifier(p); // do not assign for array components - if !is_array && p.at(Assign) { + // but we will not catch this error + if p.at(Assign) { p.expect(Assign); // TODO: support `parallel` tag diff --git a/crates/parser/src/token_kind.rs b/crates/parser/src/token_kind.rs index 581c77f..ef40c54 100644 --- a/crates/parser/src/token_kind.rs +++ b/crates/parser/src/token_kind.rs @@ -205,19 +205,21 @@ pub enum TokenKind { // Template TemplateDef, TemplateName, + // ComplexIdentifier, which will replace: + // ___ SignalIdentifier, + // ___ VarIdentifier, + // ___ ComponentIdentifier, + ComplexIdentifier, // Signal SignalDecl, InputSignalDecl, OutputSignalDecl, SignalHeader, - SignalIdentifier, // Variable VarDecl, - VarIdentifier, // Component ComponentDecl, ComponentCall, - ComponentIdentifier, SignalOfComponent, // Expression ExpressionAtom, diff --git a/crates/syntax/src/abstract_syntax_tree/ast.rs b/crates/syntax/src/abstract_syntax_tree/ast.rs index 3351383..3eef19c 100644 --- a/crates/syntax/src/abstract_syntax_tree/ast.rs +++ b/crates/syntax/src/abstract_syntax_tree/ast.rs @@ -14,43 +14,29 @@ ast_node!(AstSignalHeader, SignalHeader); ast_node!(AstInputSignalDecl, InputSignalDecl); ast_node!(AstOutputSignalDecl, OutputSignalDecl); ast_node!(AstSignalDecl, SignalDecl); -ast_node!(AstSignalIdentifier, SignalIdentifier); impl AstInputSignalDecl { - pub fn signal_identifier(&self) -> Option { + pub fn signal_identifier(&self) -> Option { support::child(self.syntax()) } } impl AstOutputSignalDecl { - pub fn signal_identifier(&self) -> Option { + pub fn signal_identifier(&self) -> Option { support::child(self.syntax()) } } impl AstSignalDecl { - pub fn signal_identifier(&self) -> Option { - support::child(self.syntax()) - } -} - -impl AstSignalIdentifier { - pub fn name(&self) -> Option { + pub fn signal_identifier(&self) -> Option { support::child(self.syntax()) } } ast_node!(AstVarDecl, VarDecl); -ast_node!(AstVarIdentifier, VarIdentifier); impl AstVarDecl { - pub fn var_identifier(&self) -> Option { - support::child(self.syntax()) - } -} - -impl AstVarIdentifier { - pub fn name(&self) -> Option { + pub fn var_identifier(&self) -> Option { support::child(self.syntax()) } } @@ -64,7 +50,7 @@ impl AstComponentDecl { pub fn template(&self) -> Option { support::child(self.syntax()) } - pub fn component_identifier(&self) -> Option { + pub fn component_identifier(&self) -> Option { support::child(self.syntax()) } } @@ -109,6 +95,14 @@ impl AstParameterList { } } +ast_node!(AstComplexIdentifier, ComplexIdentifier); + +impl AstComplexIdentifier { + pub fn name(&self) -> Option { + support::child(self.syntax()) + } +} + ast_node!(AstIdentifier, Identifier); impl AstIdentifier { @@ -180,7 +174,7 @@ impl AstCircomProgram { ast_node!(AstComponentCall, ComponentCall); impl AstComponentCall { - pub fn component_name(&self) -> Option { + pub fn component_name(&self) -> Option { support::child(self.syntax()) } pub fn signal(&self) -> Option { @@ -188,14 +182,6 @@ impl AstComponentCall { } } -ast_node!(AstComponentIdentifier, ComponentIdentifier); - -impl AstComponentIdentifier { - pub fn name(&self) -> Option { - support::child(self.syntax()) - } -} - ast_node!(AstCircomString, CircomString); impl AstCircomString { pub fn value(&self) -> String { diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap index 29ff0f2..6b68e8b 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__block.circom.snap @@ -26,7 +26,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | InputKw 50..55 "input" | | | | WhiteSpace 55..56 | | | | | WhiteSpace 55..56 " " -| | | SignalIdentifier 56..61 +| | | ComplexIdentifier 56..61 | | | | Identifier 56..58 | | | | | Identifier 56..58 "in" | | | | LBracket 58..59 @@ -53,7 +53,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | OutputKw 83..89 "output" | | | | WhiteSpace 89..90 | | | | | WhiteSpace 89..90 " " -| | | SignalIdentifier 90..93 +| | | ComplexIdentifier 90..93 | | | | Identifier 90..93 | | | | | Identifier 90..93 "out" | | Semicolon 93..94 @@ -67,7 +67,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | ComponentKw 108..117 "component" | | | WhiteSpace 117..118 | | | | WhiteSpace 117..118 " " -| | | ComponentIdentifier 118..127 +| | | ComplexIdentifier 118..127 | | | | Identifier 118..122 | | | | | Identifier 118..122 "comp" | | | | LBracket 122..123 @@ -108,7 +108,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | VarKw 175..178 "var" | | | | WhiteSpace 178..179 | | | | | WhiteSpace 178..179 " " -| | | | VarIdentifier 179..181 +| | | | ComplexIdentifier 179..181 | | | | | Identifier 179..180 | | | | | | Identifier 179..180 "i" | | | | | WhiteSpace 180..181 @@ -306,7 +306,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | VarKw 347..350 "var" | | | | WhiteSpace 350..351 | | | | | WhiteSpace 350..351 " " -| | | | VarIdentifier 351..353 +| | | | ComplexIdentifier 351..353 | | | | | Identifier 351..352 | | | | | | Identifier 351..352 "i" | | | | | WhiteSpace 352..353 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap index 93e945f..4a6a0a1 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__full_circom_program.circom.snap @@ -68,7 +68,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1632..1635 "var" | | | | | WhiteSpace 1635..1636 | | | | | | WhiteSpace 1635..1636 " " -| | | | | VarIdentifier 1636..1638 +| | | | | ComplexIdentifier 1636..1638 | | | | | | Identifier 1636..1637 | | | | | | | Identifier 1636..1637 "n" | | | | | | WhiteSpace 1637..1638 @@ -92,7 +92,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1648..1651 "var" | | | | | WhiteSpace 1651..1652 | | | | | | WhiteSpace 1651..1652 " " -| | | | | VarIdentifier 1652..1654 +| | | | | ComplexIdentifier 1652..1654 | | | | | | Identifier 1652..1653 | | | | | | | Identifier 1652..1653 "r" | | | | | | WhiteSpace 1653..1654 @@ -244,7 +244,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1772..1775 "var" | | | | | WhiteSpace 1775..1776 | | | | | | WhiteSpace 1775..1776 " " -| | | | | VarIdentifier 1776..1781 +| | | | | ComplexIdentifier 1776..1781 | | | | | | Identifier 1776..1780 | | | | | | | Identifier 1776..1780 "nout" | | | | | | WhiteSpace 1780..1781 @@ -307,7 +307,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | | InputKw 1817..1822 "input" | | | | | | WhiteSpace 1822..1823 | | | | | | | WhiteSpace 1822..1823 " " -| | | | | SignalIdentifier 1823..1833 +| | | | | ComplexIdentifier 1823..1833 | | | | | | Identifier 1823..1825 | | | | | | | Identifier 1823..1825 "in" | | | | | | LBracket 1825..1826 @@ -342,7 +342,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | | OutputKw 1847..1853 "output" | | | | | | WhiteSpace 1853..1854 | | | | | | | WhiteSpace 1853..1854 " " -| | | | | SignalIdentifier 1854..1863 +| | | | | ComplexIdentifier 1854..1863 | | | | | | Identifier 1854..1857 | | | | | | | Identifier 1854..1857 "out" | | | | | | LBracket 1857..1858 @@ -366,7 +366,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1872..1875 "var" | | | | | WhiteSpace 1875..1876 | | | | | | WhiteSpace 1875..1876 " " -| | | | | VarIdentifier 1876..1880 +| | | | | ComplexIdentifier 1876..1880 | | | | | | Identifier 1876..1879 | | | | | | | Identifier 1876..1879 "lin" | | | | | | WhiteSpace 1879..1880 @@ -390,7 +390,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1890..1893 "var" | | | | | WhiteSpace 1893..1894 | | | | | | WhiteSpace 1893..1894 " " -| | | | | VarIdentifier 1894..1899 +| | | | | ComplexIdentifier 1894..1899 | | | | | | Identifier 1894..1898 | | | | | | | Identifier 1894..1898 "lout" | | | | | | WhiteSpace 1898..1899 @@ -416,7 +416,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1911..1914 "var" | | | | | WhiteSpace 1914..1915 | | | | | | WhiteSpace 1914..1915 " " -| | | | | VarIdentifier 1915..1916 +| | | | | ComplexIdentifier 1915..1916 | | | | | | Identifier 1915..1916 | | | | | | | Identifier 1915..1916 "k" | | | | Semicolon 1916..1917 @@ -430,7 +430,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1923..1926 "var" | | | | | WhiteSpace 1926..1927 | | | | | | WhiteSpace 1926..1927 " " -| | | | | VarIdentifier 1927..1928 +| | | | | ComplexIdentifier 1927..1928 | | | | | | Identifier 1927..1928 | | | | | | | Identifier 1927..1928 "j" | | | | Semicolon 1928..1929 @@ -446,7 +446,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 1937..1940 "var" | | | | | WhiteSpace 1940..1941 | | | | | | WhiteSpace 1940..1941 " " -| | | | | VarIdentifier 1941..1943 +| | | | | ComplexIdentifier 1941..1943 | | | | | | Identifier 1941..1943 | | | | | | | Identifier 1941..1943 "e2" | | | | Semicolon 1943..1944 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap index 0fed8a2..33f7d40 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__statements.circom.snap @@ -164,7 +164,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | VarKw 142..145 "var" | | | | WhiteSpace 145..146 | | | | | WhiteSpace 145..146 " " -| | | | VarIdentifier 146..148 +| | | | ComplexIdentifier 146..148 | | | | | Identifier 146..147 | | | | | | Identifier 146..147 "i" | | | | | WhiteSpace 147..148 diff --git a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap index 0bdbad0..5997ae2 100644 --- a/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap +++ b/crates/syntax/src/snapshots/syntax__syntax__tests____src__test_files__happy__template.circom.snap @@ -57,7 +57,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | InputKw 108..113 "input" | | | | | WhiteSpace 113..114 | | | | | | WhiteSpace 113..114 " " -| | | | SignalIdentifier 114..119 +| | | | ComplexIdentifier 114..119 | | | | | Identifier 114..116 | | | | | | Identifier 114..116 "in" | | | | | LBracket 116..117 @@ -84,7 +84,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | OutputKw 141..147 "output" | | | | | WhiteSpace 147..148 | | | | | | WhiteSpace 147..148 " " -| | | | SignalIdentifier 148..151 +| | | | ComplexIdentifier 148..151 | | | | | Identifier 148..151 | | | | | | Identifier 148..151 "out" | | | Semicolon 151..152 @@ -98,7 +98,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | ComponentKw 166..175 "component" | | | | WhiteSpace 175..176 | | | | | WhiteSpace 175..176 " " -| | | | ComponentIdentifier 176..185 +| | | | ComplexIdentifier 176..185 | | | | | Identifier 176..180 | | | | | | Identifier 176..180 "comp" | | | | | LBracket 180..181 @@ -141,7 +141,7 @@ expression: "crate :: view_syntax :: view_ast(& syntax)" | | | | | | VarKw 246..249 "var" | | | | | WhiteSpace 249..250 | | | | | | WhiteSpace 249..250 " " -| | | | | VarIdentifier 250..252 +| | | | | ComplexIdentifier 250..252 | | | | | | Identifier 250..251 | | | | | | | Identifier 250..251 "i" | | | | | | WhiteSpace 251..252