From 3593529c4d5062900e0d90e9c437f3132334705f Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 21 Jan 2022 12:32:09 -0800 Subject: [PATCH 01/14] migrate parser --- parser/Cargo.toml | 10 +- parser/README.md | 4 +- parser/benches/leo_ast.rs | 40 +- parser/examples/parser.rs | 18 +- parser/src/lib.rs | 71 +- parser/src/parser/context.rs | 150 +- parser/src/parser/expression.rs | 282 ++-- parser/src/parser/file.rs | 392 +++--- parser/src/parser/mod.rs | 23 +- parser/src/parser/statement.rs | 163 +-- parser/src/parser/type_.rs | 77 +- parser/src/test.rs | 186 ++- parser/src/tokenizer/lexer.rs | 12 +- parser/src/tokenizer/mod.rs | 104 +- parser/src/tokenizer/token.rs | 75 +- parser/tests/mod.rs | 17 - .../expected_leo_ast/linear_regression.json | 1162 ---------------- .../expected_leo_ast/one_plus_one.json | 100 -- .../expected_leo_ast/palindrome.json | 1189 ---------------- .../expected_leo_ast/pedersen_hash.json | 299 ---- .../expected_leo_ast/silly_sudoku.json | 1209 ----------------- parser/tests/serialization/json.rs | 6 +- .../serialization/leo/deprecated_error.leo | 7 - .../serialization/leo/linear_regression.leo | 65 - .../tests/serialization/leo/one_plus_one.leo | 3 - parser/tests/serialization/leo/palindrome.leo | 59 - .../tests/serialization/leo/parser_error.leo | 1 - .../tests/serialization/leo/pedersen_hash.leo | 25 - .../tests/serialization/leo/silly_sudoku.leo | 71 - parser/tests/serialization/mod.rs | 17 - 30 files changed, 921 insertions(+), 4916 deletions(-) delete mode 100644 parser/tests/mod.rs delete mode 100644 parser/tests/serialization/expected_leo_ast/linear_regression.json delete mode 100644 parser/tests/serialization/expected_leo_ast/one_plus_one.json delete mode 100644 parser/tests/serialization/expected_leo_ast/palindrome.json delete mode 100644 parser/tests/serialization/expected_leo_ast/pedersen_hash.json delete mode 100644 parser/tests/serialization/expected_leo_ast/silly_sudoku.json delete mode 100644 parser/tests/serialization/leo/deprecated_error.leo delete mode 100644 parser/tests/serialization/leo/linear_regression.leo delete mode 100644 parser/tests/serialization/leo/one_plus_one.leo delete mode 100644 parser/tests/serialization/leo/palindrome.leo delete mode 100644 parser/tests/serialization/leo/parser_error.leo delete mode 100644 parser/tests/serialization/leo/pedersen_hash.leo delete mode 100644 parser/tests/serialization/leo/silly_sudoku.leo delete mode 100644 parser/tests/serialization/mod.rs diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 560f072eb0..e16765ebcf 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -16,7 +16,7 @@ categories = [ "cryptography::cryptocurrencies", "web-programming" ] include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2021" -rust-version = "1.56.1" +rust-version = "1.56" [[bench]] name = "leo_ast" @@ -31,6 +31,14 @@ version = "1.5.3" path = "../errors" version = "1.5.3" +[dependencies.leo-input] +path = "../input" +version = "1.5.1" + +[dependencies.leo-span] +path = "../span" +version = "1.5.3" + [dependencies.lazy_static] version = "1.3.0" diff --git a/parser/README.md b/parser/README.md index c09aff1736..b683f9b4fb 100644 --- a/parser/README.md +++ b/parser/README.md @@ -30,7 +30,8 @@ Bolded ones are also keywords. #### Symbols - At - Not -- And +- And (`&&`) +- Ampersand (`&`) - Or - Eq - NotEq @@ -98,7 +99,6 @@ Bolded ones are also keywords. - **If** - **In** - **Let** -- **Mut** - **Return** - **Static** - **String** diff --git a/parser/benches/leo_ast.rs b/parser/benches/leo_ast.rs index 0777665e0d..9394de2b6b 100644 --- a/parser/benches/leo_ast.rs +++ b/parser/benches/leo_ast.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,55 +14,51 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use leo_ast::Ast; +use leo_errors::emitter::Handler; +use leo_span::symbol::create_session_if_not_set_then; + use criterion::{criterion_group, criterion_main, Criterion}; use std::time::Duration; -fn bench_big_if_else(c: &mut Criterion) { - let program_string = include_str!("./big_if_else.leo"); - let ast = leo_parser::parse_ast("./big_if_else.leo", program_string).expect("failed to parse benchmark"); +fn parse_ast(path: &str, input: &str) -> Ast { + create_session_if_not_set_then(|_| { + leo_parser::parse_ast(&Handler::default(), path, input).expect("failed to parse benchmark") + }) +} +fn bench_big_if_else(c: &mut Criterion) { + let ast = parse_ast("./big_if_else.leo", include_str!("./big_if_else.leo")); c.bench_function("Ast::big_if_else", |b| b.iter(|| &ast)); } fn bench_big_ternary(c: &mut Criterion) { - let program_string = include_str!("./big_ternary.leo"); - let ast = leo_parser::parse_ast("./big_ternary.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./big_ternary.leo", include_str!("./big_ternary.leo")); c.bench_function("Ast::big_ternary", |b| b.iter(|| &ast)); } fn bench_big_circuit(c: &mut Criterion) { - let program_string = include_str!("./big_circuit.leo"); - let ast = leo_parser::parse_ast("./big_circuit.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./big_circuit.leo", include_str!("./big_circuit.leo")); c.bench_function("Ast::big_circuit", |b| b.iter(|| &ast)); } fn bench_long_expr(c: &mut Criterion) { - let program_string = include_str!("./long_expr.leo"); - let ast = leo_parser::parse_ast("./long_expr.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./long_expr.leo", include_str!("./long_expr.leo")); c.bench_function("Ast::long_expr", |b| b.iter(|| &ast)); } fn bench_long_array(c: &mut Criterion) { - let program_string = include_str!("./long_array.leo"); - let ast = leo_parser::parse_ast("./long_array.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./long_array.leo", include_str!("./long_array.leo")); c.bench_function("Ast::long_array", |b| b.iter(|| &ast)); } fn bench_many_foos(c: &mut Criterion) { - let program_string = include_str!("./many_foos.leo"); - let ast = leo_parser::parse_ast("./many_foos.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./many_foos.leo", include_str!("./many_foos.leo")); c.bench_function("Ast::many_foos", |b| b.iter(|| &ast)); } fn bench_many_assigns(c: &mut Criterion) { - let program_string = include_str!("./many_assigns.leo"); - let ast = leo_parser::parse_ast("./many_assigns.leo", program_string).expect("failed to parse benchmark"); - + let ast = parse_ast("./many_assigns.leo", include_str!("./many_assigns.leo")); c.bench_function("Ast::many_assigns", |b| b.iter(|| &ast)); } diff --git a/parser/examples/parser.rs b/parser/examples/parser.rs index 04cb943625..801646f27f 100644 --- a/parser/examples/parser.rs +++ b/parser/examples/parser.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -15,7 +15,9 @@ // along with the Leo library. If not, see . use leo_ast::Ast; -use leo_errors::Result; +use leo_errors::{emitter::Handler, Result}; +use leo_span::symbol::create_session_if_not_set_then; + use std::{env, fs, path::Path}; fn to_leo_tree(filepath: &Path) -> Result { @@ -23,12 +25,12 @@ fn to_leo_tree(filepath: &Path) -> Result { let program_filepath = filepath.to_path_buf(); let program_string = fs::read_to_string(&program_filepath).expect("failed to open input file"); - // Parses the Leo file and constructs an ast. - let ast = leo_parser::parse_ast(filepath.to_str().unwrap(), &program_string)?; - - let serialized_leo_ast = Ast::to_json_string(&ast).expect("serialization failed"); - - Ok(serialized_leo_ast) + // Parses the Leo file constructing an ast which is then serialized. + create_session_if_not_set_then(|_| { + let handler = Handler::default(); + let ast = leo_parser::parse_ast(&handler, filepath.to_str().unwrap(), &program_string)?; + Ok(Ast::to_json_string(&ast).expect("serialization failed")) + }) } fn main() -> Result<()> { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 7b1a0d83aa..21a1001bde 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -23,19 +23,82 @@ #![doc = include_str!("../README.md")] pub(crate) mod tokenizer; +use leo_input::LeoInputParser; pub use tokenizer::KEYWORD_TOKENS; pub(crate) use tokenizer::*; pub mod parser; pub use parser::*; -use leo_ast::Ast; +use leo_ast::{Ast, Input}; +use leo_errors::emitter::Handler; use leo_errors::Result; #[cfg(test)] mod test; /// Creates a new AST from a given file path and source code text. -pub fn parse_ast, Y: AsRef>(path: T, source: Y) -> Result { - Ok(Ast::new(parser::parse(path.as_ref(), source.as_ref())?)) +pub fn parse_ast, Y: AsRef>(handler: &Handler, path: T, source: Y) -> Result { + Ok(Ast::new(parser::parse(handler, path.as_ref(), source.as_ref())?)) +} + +/// Parses program input from from the input file path and state file path +pub fn parse_program_input, Y: AsRef, T2: AsRef, Y2: AsRef>( + input_string: T, + input_path: Y, + state_string: T2, + state_path: Y2, +) -> Result { + let input_syntax_tree = LeoInputParser::parse_file(input_string.as_ref()).map_err(|mut e| { + e.set_path( + input_path.as_ref(), + &input_string + .as_ref() + .lines() + .map(|x| x.to_string()) + .collect::>()[..], + ); + + e + })?; + let state_syntax_tree = LeoInputParser::parse_file(state_string.as_ref()).map_err(|mut e| { + e.set_path( + state_path.as_ref(), + &state_string + .as_ref() + .lines() + .map(|x| x.to_string()) + .collect::>()[..], + ); + + e + })?; + + let mut input = Input::new(); + input.parse_input(input_syntax_tree).map_err(|mut e| { + e.set_path( + input_path.as_ref(), + &input_string + .as_ref() + .lines() + .map(|x| x.to_string()) + .collect::>()[..], + ); + + e + })?; + input.parse_state(state_syntax_tree).map_err(|mut e| { + e.set_path( + state_path.as_ref(), + &state_string + .as_ref() + .lines() + .map(|x| x.to_string()) + .collect::>()[..], + ); + + e + })?; + + Ok(input) } diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index af64bd9c43..c125e2a591 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,42 +14,48 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{borrow::Cow, unimplemented}; - use crate::{assert_no_whitespace, tokenizer::*, Token, KEYWORD_TOKENS}; + use leo_ast::*; -use leo_errors::{LeoError, ParserError, Result, Span}; +use leo_errors::emitter::Handler; +use leo_errors::{LeoError, ParserError, Result}; +use leo_span::{Span, Symbol}; + +use std::{borrow::Cow, unimplemented}; use tendril::format_tendril; /// Stores a program in tokenized format plus additional context. /// May be converted into a [`Program`] AST by parsing all tokens. -pub struct ParserContext { +pub struct ParserContext<'a> { + #[allow(dead_code)] + pub(crate) handler: &'a Handler, tokens: Vec, end_span: Span, // true if parsing an expression for an if statement -- means circuit inits are not legal pub(crate) fuzzy_struct_state: bool, } -impl Iterator for ParserContext { +impl Iterator for ParserContext<'_> { type Item = SpannedToken; fn next(&mut self) -> Option { - self.tokens.pop() + self.bump() } } -impl ParserContext { +impl<'a> ParserContext<'a> { /// /// Returns a new [`ParserContext`] type given a vector of tokens. /// - pub fn new(mut tokens: Vec) -> Self { + pub fn new(handler: &'a Handler, mut tokens: Vec) -> Self { tokens.reverse(); // todo: performance optimization here: drain filter tokens = tokens .into_iter() .filter(|x| !matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_))) .collect(); - ParserContext { + Self { + handler, end_span: tokens .iter() .find(|x| !x.span.content.trim().is_empty()) @@ -60,6 +66,16 @@ impl ParserContext { } } + /// Returns the current token if there is one. + pub fn curr(&self) -> Option<&SpannedToken> { + self.tokens.last() + } + + /// Emit the error `err`. + pub(crate) fn emit_err(&self, err: ParserError) { + self.handler.emit_err(err.into()); + } + /// /// Returns an unexpected end of function [`SyntaxError`]. /// @@ -75,12 +91,15 @@ impl ParserContext { } /// - /// Returns a reference to the next token or error if it does not exist. + /// Returns a reference to the next SpannedToken or error if it does not exist. /// pub fn peek(&self) -> Result<&SpannedToken> { - self.tokens.last().ok_or_else(|| self.eof()) + self.curr().ok_or_else(|| self.eof()) } + /// + /// Returns a reference to the next Token. + /// pub fn peek_token(&self) -> Cow<'_, Token> { self.tokens .last() @@ -112,14 +131,19 @@ impl ParserContext { !self.tokens.is_empty() } + /// Advances the current token. + pub fn bump(&mut self) -> Option { + self.tokens.pop() + } + /// /// Removes the next token if it exists and returns it, or [None] if /// the next token does not exist. /// pub fn eat(&mut self, token: Token) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.tokens.last() { + if let Some(SpannedToken { token: inner, .. }) = self.curr() { if &token == inner { - return self.tokens.pop(); + return self.bump(); } } None @@ -139,13 +163,12 @@ impl ParserContext { pub fn eat_identifier(&mut self) -> Option { if let Some(SpannedToken { token: Token::Ident(_), .. - }) = self.tokens.last() + }) = self.curr() { - let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Ident(name), span, - } = token + } = self.bump().unwrap() { return Some(Identifier { name, span }); } else { @@ -186,6 +209,21 @@ impl ParserContext { }) } + /// Returns `true` if the next token is Function or if it is a Const followed by Function. + /// Returns `false` otherwise. + pub fn peek_is_function(&self) -> Result { + let first = &self.peek()?.token; + let next = if self.tokens.len() >= 2 { + &self.peek_next()?.token + } else { + return Ok(false); + }; + Ok(matches!( + (first, next), + (Token::Function | Token::At, _) | (Token::Const, Token::Function) + )) + } + /// /// Removes the next two tokens if they are a pair of [`GroupCoordinate`] and returns them, /// or [None] if the next token is not a [`GroupCoordinate`]. @@ -263,13 +301,12 @@ impl ParserContext { pub fn eat_int(&mut self) -> Option<(PositiveNumber, Span)> { if let Some(SpannedToken { token: Token::Int(_), .. - }) = self.tokens.last() + }) = self.curr() { - let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Int(value), span, - } = token + } = self.bump().unwrap() { return Some((PositiveNumber { value }, span)); } else { @@ -284,9 +321,9 @@ impl ParserContext { /// the next token does not exist. /// pub fn eat_any(&mut self, token: &[Token]) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.tokens.last() { + if let Some(SpannedToken { token: inner, .. }) = self.curr() { if token.iter().any(|x| x == inner) { - return self.tokens.pop(); + return self.bump(); } } None @@ -296,9 +333,9 @@ impl ParserContext { /// Returns the span of the next token if it is equal to the given [`Token`], or error. /// pub fn expect(&mut self, token: Token) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { + if let Some(SpannedToken { token: inner, span }) = self.curr() { if &token == inner { - Ok(self.tokens.pop().unwrap().span) + Ok(self.bump().unwrap().span) } else { Err(ParserError::unexpected(inner, token, span).into()) } @@ -311,9 +348,9 @@ impl ParserContext { /// Returns the span of the next token if it is equal to one of the given [`Token`]s, or error. /// pub fn expect_oneof(&mut self, token: &[Token]) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { + if let Some(SpannedToken { token: inner, span }) = self.curr() { if token.iter().any(|x| x == inner) { - Ok(self.tokens.pop().unwrap()) + Ok(self.bump().unwrap()) } else { return Err(ParserError::unexpected( inner, @@ -334,27 +371,25 @@ impl ParserContext { pub fn expect_loose_identifier(&mut self) -> Result { if let Some(token) = self.eat_any(KEYWORD_TOKENS) { return Ok(Identifier { - name: token.token.to_string().into(), + name: token.token.keyword_to_symbol().unwrap(), span: token.span, }); } if let Some((int, span)) = self.eat_int() { - return Ok(Identifier { name: int.value, span }); + let name = Symbol::intern(&int.value); + return Ok(Identifier { name, span }); } self.expect_ident() } - /// /// Returns the [`Identifier`] of the next token if it is an [`Identifier`], or error. - /// pub fn expect_ident(&mut self) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { + if let Some(SpannedToken { token: inner, span }) = self.curr() { if let Token::Ident(_) = inner { - let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Ident(name), span, - } = token + } = self.bump().unwrap() { Ok(Identifier { name, span }) } else { @@ -378,4 +413,53 @@ impl ParserContext { Err(self.eof()) } } + + /// Parses a list of `T`s using `inner` + /// The opening and closing delimiters are `bra` and `ket`, + /// and elements in the list are separated by `sep`. + /// When `(list, true)` is returned, `sep` was a terminator. + pub(super) fn parse_list( + &mut self, + open: Token, + close: Token, + sep: Token, + mut inner: impl FnMut(&mut Self) -> Result>, + ) -> Result<(Vec, bool, Span)> { + let mut list = Vec::new(); + let mut trailing = false; + + // Parse opening delimiter. + let open_span = self.expect(open)?; + + while self.peek()?.token != close { + // Parse the element. We allow inner parser recovery through the `Option`. + if let Some(elem) = inner(self)? { + list.push(elem); + } + + // Parse the separator. + if self.eat(sep.clone()).is_none() { + trailing = false; + break; + } + } + + // Parse closing delimiter. + let close_span = self.expect(close)?; + + Ok((list, trailing, open_span + close_span)) + } + + /// Parse a list separated by `,` and delimited by parens. + pub(super) fn parse_paren_comma_list( + &mut self, + f: impl FnMut(&mut Self) -> Result>, + ) -> Result<(Vec, bool, Span)> { + self.parse_list(Token::LeftParen, Token::RightParen, Token::Comma, f) + } + + /// Returns true if the current token is `(`. + pub(super) fn peek_is_left_par(&self) -> bool { + matches!(self.curr().map(|t| &t.token), Some(Token::LeftParen)) + } } diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index eb07d5f4f0..0eec288b80 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use tendril::format_tendril; +use super::*; use leo_errors::{ParserError, Result}; +use leo_span::sym; -use super::*; +use tendril::format_tendril; const INT_TYPES: &[Token] = &[ Token::I8, @@ -35,7 +36,7 @@ const INT_TYPES: &[Token] = &[ Token::Group, ]; -impl ParserContext { +impl ParserContext<'_> { /// /// Returns an [`Expression`] AST node if the next token is an expression. /// Includes circuit init expressions. @@ -81,44 +82,45 @@ impl ParserContext { Ok(expr) } - /// - /// Returns an [`Expression`] AST node if the next tokens represent - /// a binary or expression. - /// - /// Otherwise, tries to parse the next token using [`parse_conjunctive_expression`]. - /// - pub fn parse_disjunctive_expression(&mut self) -> Result { - let mut expr = self.parse_conjunctive_expression()?; - while self.eat(Token::Or).is_some() { - let right = self.parse_conjunctive_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: BinaryOperation::Or, - left: Box::new(expr), - right: Box::new(right), - }) + /// Constructs a binary expression `left op right`. + fn bin_expr(left: Expression, right: Expression, op: BinaryOperation) -> Expression { + Expression::Binary(BinaryExpression { + span: left.span() + right.span(), + op, + left: Box::new(left), + right: Box::new(right), + }) + } + + /// Parses a left-associative binary expression ` token ` using `f` for left/right. + /// The `token` is translated to `op` in the AST. + fn parse_bin_expr( + &mut self, + token: Token, + op: BinaryOperation, + mut f: impl FnMut(&mut Self) -> Result, + ) -> Result { + let mut expr = f(self)?; + while self.eat(token.clone()).is_some() { + expr = Self::bin_expr(expr, f(self)?, op); } Ok(expr) } + /// Returns an [`Expression`] AST node if the next tokens represent + /// a binary or expression. /// + /// Otherwise, tries to parse the next token using [`parse_conjunctive_expression`]. + pub fn parse_disjunctive_expression(&mut self) -> Result { + self.parse_bin_expr(Token::Or, BinaryOperation::Or, Self::parse_conjunctive_expression) + } + /// Returns an [`Expression`] AST node if the next tokens represent a /// binary and expression. /// - /// Otherwise, tries to parse the next token using [`parse_bit_or_expression`]. - /// + /// Otherwise, tries to parse the next token using [`parse_equality_expression`]. pub fn parse_conjunctive_expression(&mut self) -> Result { - let mut expr = self.parse_equality_expression()?; - while self.eat(Token::And).is_some() { - let right = self.parse_equality_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: BinaryOperation::And, - left: Box::new(expr), - right: Box::new(right), - }) - } - Ok(expr) + self.parse_bin_expr(Token::And, BinaryOperation::And, Self::parse_equality_expression) } /// @@ -169,7 +171,7 @@ impl ParserContext { /// // pub fn parse_bit_and_expression(&mut self) -> Result { // let mut expr = self.parse_equality_expression()?; - // while self.eat(Token::BitAnd).is_some() { + // while self.eat(Token::Ampersand).is_some() { // let right = self.parse_equality_expression()?; // expr = Expression::Binary(BinaryExpression { // span: expr.span() + right.span(), @@ -181,53 +183,41 @@ impl ParserContext { // Ok(expr) // } - /// /// Returns an [`Expression`] AST node if the next tokens represent a /// binary equals or not equals expression. /// /// Otherwise, tries to parse the next token using [`parse_ordering_expression`]. - /// pub fn parse_equality_expression(&mut self) -> Result { let mut expr = self.parse_ordering_expression()?; if let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) { let right = self.parse_ordering_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: match op { - Token::Eq => BinaryOperation::Eq, - Token::NotEq => BinaryOperation::Ne, - _ => unimplemented!(), - }, - left: Box::new(expr), - right: Box::new(right), - }) + let op = match op { + Token::Eq => BinaryOperation::Eq, + Token::NotEq => BinaryOperation::Ne, + _ => unimplemented!(), + }; + expr = Self::bin_expr(expr, right, op); } Ok(expr) } - /// /// Returns an [`Expression`] AST node if the next tokens represent a /// binary relational expression: less than, less than or equals, greater than, greater than or equals. /// /// Otherwise, tries to parse the next token using [`parse_shift_expression`]. - /// pub fn parse_ordering_expression(&mut self) -> Result { let mut expr = self.parse_additive_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Lt, Token::LtEq, Token::Gt, Token::GtEq]) { let right = self.parse_additive_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: match op { - Token::Lt => BinaryOperation::Lt, - Token::LtEq => BinaryOperation::Le, - Token::Gt => BinaryOperation::Gt, - Token::GtEq => BinaryOperation::Ge, - _ => unimplemented!(), - }, - left: Box::new(expr), - right: Box::new(right), - }) + let op = match op { + Token::Lt => BinaryOperation::Lt, + Token::LtEq => BinaryOperation::Le, + Token::Gt => BinaryOperation::Gt, + Token::GtEq => BinaryOperation::Ge, + _ => unimplemented!(), + }; + expr = Self::bin_expr(expr, right, op); } Ok(expr) } @@ -257,76 +247,55 @@ impl ParserContext { // Ok(expr) // } - /// /// Returns an [`Expression`] AST node if the next tokens represent a /// binary addition or subtraction expression. /// /// Otherwise, tries to parse the next token using [`parse_mul_div_pow_expression`]. - /// pub fn parse_additive_expression(&mut self) -> Result { let mut expr = self.parse_multiplicative_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Add, Token::Minus]) { let right = self.parse_multiplicative_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: match op { - Token::Add => BinaryOperation::Add, - Token::Minus => BinaryOperation::Sub, - _ => unimplemented!(), - }, - left: Box::new(expr), - right: Box::new(right), - }) + let op = match op { + Token::Add => BinaryOperation::Add, + Token::Minus => BinaryOperation::Sub, + _ => unimplemented!(), + }; + expr = Self::bin_expr(expr, right, op); } Ok(expr) } - /// /// Returns an [`Expression`] AST node if the next tokens represent a /// binary multiplication, division, or modulus expression. /// /// Otherwise, tries to parse the next token using [`parse_exponential_expression`]. - /// pub fn parse_multiplicative_expression(&mut self) -> Result { let mut expr = self.parse_exponential_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Mul, Token::Div]) { let right = self.parse_exponential_expression()?; - expr = Expression::Binary(BinaryExpression { - span: expr.span() + right.span(), - op: match op { - Token::Mul => BinaryOperation::Mul, - Token::Div => BinaryOperation::Div, - // Token::Mod => BinaryOperation::Mod, - _ => unimplemented!(), - }, - left: Box::new(expr), - right: Box::new(right), - }) + let op = match op { + Token::Mul => BinaryOperation::Mul, + Token::Div => BinaryOperation::Div, + // Token::Mod => BinaryOperation::Mod, + _ => unimplemented!(), + }; + expr = Self::bin_expr(expr, right, op); } Ok(expr) } - /// /// Returns an [`Expression`] AST node if the next tokens represent a /// binary exponentiation expression. /// /// Otherwise, tries to parse the next token using [`parse_cast_expression`]. - /// pub fn parse_exponential_expression(&mut self) -> Result { - let mut exprs = vec![self.parse_cast_expression()?]; - while self.eat(Token::Exp).is_some() { - exprs.push(self.parse_cast_expression()?); - } - let mut expr = exprs.remove(exprs.len() - 1); - while !exprs.is_empty() { - let sub_expr = exprs.remove(exprs.len() - 1); - expr = Expression::Binary(BinaryExpression { - span: expr.span() + sub_expr.span(), - op: BinaryOperation::Pow, - left: Box::new(sub_expr), - right: Box::new(expr), - }) + let mut expr = self.parse_cast_expression()?; + + if self.eat(Token::Exp).is_some() { + let right = self.parse_exponential_expression()?; + expr = Self::bin_expr(expr, right, BinaryOperation::Pow); } + Ok(expr) } @@ -401,21 +370,12 @@ impl ParserContext { /// Otherwise, tries to parse the next token using [`parse_primary_expression`]. /// pub fn parse_postfix_expression(&mut self) -> Result { + // We don't directly parse named-type's and Identifier's here as + // the ABNF states. Rather the primary expression already + // handle those. The ABNF is more specific for language reasons. let mut expr = self.parse_primary_expression()?; - while let Some(token) = self.eat_any(&[ - Token::LeftSquare, - Token::Dot, - Token::LeftParen, - Token::DoubleColon, - Token::LengthOf, - ]) { + while let Some(token) = self.eat_any(&[Token::LeftSquare, Token::Dot, Token::LeftParen, Token::DoubleColon]) { match token.token { - Token::LengthOf => { - expr = Expression::LengthOf(LengthOfExpression { - span: expr.span().clone(), - inner: Box::new(expr), - }) - } Token::LeftSquare => { if self.eat(Token::DotDot).is_some() { let right = if self.peek_token().as_ref() != &Token::RightSquare { @@ -425,12 +385,12 @@ impl ParserContext { }; let end = self.expect(Token::RightSquare)?; - expr = Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + expr = Expression::Access(AccessExpression::ArrayRange(ArrayRangeAccess { span: expr.span() + &end, array: Box::new(expr), left: None, right, - }); + })); continue; } @@ -443,35 +403,35 @@ impl ParserContext { }; let end = self.expect(Token::RightSquare)?; - expr = Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + expr = Expression::Access(AccessExpression::ArrayRange(ArrayRangeAccess { span: expr.span() + &end, array: Box::new(expr), left: Some(Box::new(left)), right, - }); + })); } else { let end = self.expect(Token::RightSquare)?; - expr = Expression::ArrayAccess(ArrayAccessExpression { + expr = Expression::Access(AccessExpression::Array(ArrayAccess { span: expr.span() + &end, array: Box::new(expr), index: Box::new(left), - }); + })); } } Token::Dot => { if let Some(ident) = self.eat_identifier() { - expr = Expression::CircuitMemberAccess(CircuitMemberAccessExpression { + expr = Expression::Access(AccessExpression::Member(MemberAccess { span: expr.span() + &ident.span, - circuit: Box::new(expr), + inner: Box::new(expr), name: ident, type_: None, - }); + })); } else if let Some((num, span)) = self.eat_int() { - expr = Expression::TupleAccess(TupleAccessExpression { + expr = Expression::Access(AccessExpression::Tuple(TupleAccess { span: expr.span() + &span, tuple: Box::new(expr), index: num, - }); + })); } else { let next = self.peek()?; return Err(ParserError::unexpected_str(&next.token, "int or ident", &next.span).into()); @@ -481,8 +441,7 @@ impl ParserContext { let mut arguments = Vec::new(); let end_span; loop { - let end = self.eat(Token::RightParen); - if let Some(end) = end { + if let Some(end) = self.eat(Token::RightParen) { end_span = end.span; break; } @@ -500,11 +459,12 @@ impl ParserContext { } Token::DoubleColon => { let ident = self.expect_ident()?; - expr = Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { + expr = Expression::Access(AccessExpression::Static(StaticAccess { span: expr.span() + &ident.span, - circuit: Box::new(expr), + inner: Box::new(expr), + type_: None, name: ident, - }); + })); } _ => unimplemented!(), } @@ -526,39 +486,17 @@ impl ParserContext { }) } - /// - /// Returns an [`Expression`] AST node if the next tokens represent an + /// Returns an [`Expression`] AST node if the next tokens represent a /// circuit initialization expression. - /// pub fn parse_circuit_expression(&mut self, identifier: Identifier) -> Result { - self.expect(Token::LeftCurly)?; - let mut members = Vec::new(); - let end_span; - loop { - if let Some(end) = self.eat(Token::RightCurly) { - end_span = end.span; - break; - } - let name = self.expect_ident()?; - if self.eat(Token::Colon).is_some() { - let expression = self.parse_expression()?; - members.push(CircuitImpliedVariableDefinition { - identifier: name, - expression: Some(expression), - }); - } else { - members.push(CircuitImpliedVariableDefinition { - identifier: name.clone(), - expression: None, - }); - } - if self.eat(Token::Comma).is_none() { - end_span = self.expect(Token::RightCurly)?; - break; - } - } + let (members, _, span) = self.parse_list(Token::LeftCurly, Token::RightCurly, Token::Comma, |p| { + Ok(Some(CircuitImpliedVariableDefinition { + identifier: p.expect_ident()?, + expression: p.eat(Token::Colon).map(|_| p.parse_expression()).transpose()?, + })) + })?; Ok(Expression::CircuitInit(CircuitInitExpression { - span: &identifier.span + &end_span, + span: &identifier.span + &span, name: identifier, members, })) @@ -617,8 +555,8 @@ impl ParserContext { let first = self.parse_spread_or_expression()?; if self.eat(Token::Semicolon).is_some() { let dimensions = self - .parse_array_dimensions()? - .ok_or_else(|| ParserError::unable_to_parse_array_dimensions(span))?; + .parse_array_dimensions() + .map_err(|_| ParserError::unable_to_parse_array_dimensions(span))?; let end = self.expect(Token::RightSquare)?; let first = match first { SpreadOrExpression::Spread(first) => { @@ -723,7 +661,7 @@ impl ParserContext { } Token::BigSelf => { let ident = Identifier { - name: token.to_string().into(), + name: sym::SelfUpper, span, }; if !self.fuzzy_struct_state && self.peek_token().as_ref() == &Token::LeftCurly { @@ -732,17 +670,15 @@ impl ParserContext { Expression::Identifier(ident) } } - Token::Input | Token::LittleSelf => { - let ident = Identifier { - name: token.to_string().into(), - span, - }; - Expression::Identifier(ident) - } - // Token::LengthOf => Expression::LengthOf(LengthOfExpression { - // span, - // inner: Box::new(self.parse_primary_expression()?), - // }), + Token::LittleSelf => Expression::Identifier(Identifier { + name: sym::SelfLower, + span, + }), + Token::Input => Expression::Identifier(Identifier { name: sym::input, span }), + t if crate::type_::TYPE_TOKENS.contains(&t) => Expression::Identifier(Identifier { + name: t.keyword_to_symbol().unwrap(), + span, + }), token => { return Err(ParserError::unexpected_str(token, "expression", &span).into()); } diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 993c2200ed..7902ed5807 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use tendril::format_tendril; - -use leo_errors::{ParserError, Result, Span}; - +use super::*; use crate::KEYWORD_TOKENS; -use super::*; +use leo_errors::{ParserError, Result}; +use leo_span::{sym, Span}; -impl ParserContext { +impl ParserContext<'_> { /// /// Returns a [`Program`] AST if all tokens can be consumed and represent a valid Leo program. /// @@ -41,42 +39,38 @@ impl ParserContext { import_statements.push(self.parse_import_statement()?); } Token::Circuit => { + self.expect(Token::Circuit)?; let (id, circuit) = self.parse_circuit()?; circuits.insert(id, circuit); } - Token::Function | Token::At => { + Token::Ident(ident) => match *ident { + sym::test => return Err(ParserError::test_function(&token.span).into()), + kw @ (sym::Struct | sym::Class) => { + self.emit_err(ParserError::unexpected(kw, "circuit", &token.span)); + self.bump().unwrap(); + let (id, circuit) = self.parse_circuit()?; + circuits.insert(id, circuit); + } + _ => return Err(Self::unexpected_item(token).into()), + }, + // Const functions share the first token with the global Const. + Token::Const if self.peek_is_function()? => { let (id, function) = self.parse_function_declaration()?; functions.insert(id, function); } - Token::Ident(ident) if ident.as_ref() == "test" => { - return Err(ParserError::test_function(&token.span).into()); - } Token::Const => { let (name, global_const) = self.parse_global_const_declaration()?; global_consts.insert(name, global_const); } + Token::Function | Token::At => { + let (id, function) = self.parse_function_declaration()?; + functions.insert(id, function); + } Token::Type => { let (name, alias) = self.parse_type_alias()?; aliases.insert(name, alias); } - _ => { - return Err(ParserError::unexpected( - &token.token, - [ - Token::Import, - Token::Circuit, - Token::Function, - Token::Ident("test".into()), - Token::At, - ] - .iter() - .map(|x| format!("'{}'", x)) - .collect::>() - .join(", "), - &token.span, - ) - .into()); - } + _ => return Err(Self::unexpected_item(token).into()), } } Ok(Program { @@ -91,58 +85,46 @@ impl ParserContext { }) } - /// + fn unexpected_item(token: &SpannedToken) -> ParserError { + ParserError::unexpected( + &token.token, + [ + Token::Import, + Token::Circuit, + Token::Function, + Token::Ident(sym::test), + Token::At, + ] + .iter() + .map(|x| format!("'{}'", x)) + .collect::>() + .join(", "), + &token.span, + ) + } + /// Returns an [`Annotation`] AST node if the next tokens represent a supported annotation. - /// pub fn parse_annotation(&mut self) -> Result { let start = self.expect(Token::At)?; - let name = self.expect_ident()?; - if name.name.as_ref() == "context" { - return Err(ParserError::context_annotation(&name.span).into()); - } + let name = self.parse_annotation_name()?; - assert_no_whitespace(&start, &name.span, &name.name, "@")?; + assert_no_whitespace(&start, &name.span, &name.name.as_str(), "@")?; - let end_span; - let arguments = if self.eat(Token::LeftParen).is_some() { - let mut args = Vec::new(); - let mut comma = false; - loop { - if let Some(end) = self.eat(Token::RightParen) { - if comma { - return Err(ParserError::unexpected( - Token::RightParen, - [Token::Ident("identifier".into()), Token::Int("number".into())] - .iter() - .map(|x| format!("'{}'", x)) - .collect::>() - .join(", "), - &end.span, - ) - .into()); - } - end_span = end.span; - break; - } - comma = false; - if let Some(ident) = self.eat_identifier() { - args.push(ident.name); - } else if let Some((int, _)) = self.eat_int() { - args.push(int.value); + let (end_span, arguments) = if self.peek_is_left_par() { + let (args, _, span) = self.parse_paren_comma_list(|p| { + Ok(if let Some(ident) = p.eat_identifier() { + Some(ident.name) + } else if let Some((int, _)) = p.eat_int() { + Some(Symbol::intern(&int.value)) } else { - let token = self.peek()?; - return Err(ParserError::unexpected_str(&token.token, "ident or int", &token.span).into()); - } - if self.eat(Token::Comma).is_none() && !comma { - end_span = self.expect(Token::RightParen)?; - break; - } - comma = true; - } - args + let token = p.expect_any()?; + p.emit_err(ParserError::unexpected_str(&token.token, "ident or int", &token.span)); + None + }) + })?; + (span, args) } else { - end_span = name.span.clone(); - Vec::new() + (name.span.clone(), Vec::new()) }; Ok(Annotation { name, @@ -151,24 +133,26 @@ impl ParserContext { }) } - /// - /// Returns a vector of [`PackageAccess`] AST nodes if the next tokens represent package access - /// expressions within an import statement. - /// - pub fn parse_package_accesses(&mut self, span: &Span) -> Result> { - let mut out = Vec::new(); - self.expect(Token::LeftParen)?; - while self.eat(Token::RightParen).is_none() { - let access = self.parse_package_access()?; - out.push(access); - if self.eat(Token::Comma).is_none() { - self.expect(Token::RightParen)?; - break; - } + /// Parses `foo` in an annotation `@foo . That is, the name of the annotation. + fn parse_annotation_name(&mut self) -> Result { + let mut name = self.expect_ident()?; + + // Recover `context` instead of `test`. + if name.name == sym::context { + self.emit_err(ParserError::context_annotation(&name.span)); + name.name = sym::test; } + Ok(name) + } + + /// Returns a vector of [`PackageAccess`] AST nodes if the next tokens represent package access + /// expressions within an import statement. + pub fn parse_package_accesses(&mut self, span: &Span) -> Result> { + let (out, ..) = self.parse_paren_comma_list(|p| p.parse_package_access().map(Some))?; + if out.is_empty() { - return Err(ParserError::invalid_import_list(span).into()); + self.emit_err(ParserError::invalid_import_list(span)); } Ok(out) @@ -191,7 +175,7 @@ impl ParserContext { name.span = name.span + span; let next = self.expect_ident()?; name.span = name.span + next.span; - name.name = format_tendril!("{}-{}", name.name, next.name); + name.name = Symbol::intern(&format!("{}-{}", name.name, next.name)); } if self.peek_token().as_ref() == &Token::Dot { @@ -220,9 +204,7 @@ impl ParserContext { } } - /// /// Returns an [`Identifier`] AST node if the next tokens represent a valid package name. - /// pub fn parse_package_name(&mut self) -> Result { // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). let mut base = self.expect_loose_identifier()?; @@ -234,22 +216,22 @@ impl ParserContext { let span = self.expect(Token::Minus)?; base.span = base.span + span; let next = self.expect_loose_identifier()?; - base.name = format_tendril!("{}-{}", base.name, next.name); + base.name = Symbol::intern(&format!("{}-{}", base.name, next.name)); base.span = base.span + next.span; } Token::Int(_) => { let (num, span) = self.eat_int().unwrap(); - base.name = format_tendril!("{}{}", base.name, num.value); + base.name = Symbol::intern(&format!("{}{}", base.name, num.value)); base.span = base.span + span; } Token::Ident(_) => { let next = self.expect_ident()?; - base.name = format_tendril!("{}{}", base.name, next.name); + base.name = Symbol::intern(&format!("{}{}", base.name, next.name)); base.span = base.span + next.span; } x if KEYWORD_TOKENS.contains(x) => { let next = self.expect_loose_identifier()?; - base.name = format_tendril!("{}{}", base.name, next.name); + base.name = Symbol::intern(&format!("{}{}", base.name, next.name)); base.span = base.span + next.span; } _ => break, @@ -257,17 +239,18 @@ impl ParserContext { } // Return an error if the package name contains a keyword. - if let Some(token) = KEYWORD_TOKENS.iter().find(|x| x.to_string() == base.name.as_ref()) { - return Err(ParserError::unexpected_str(token, "package name", &base.span).into()); + if let Some(token) = KEYWORD_TOKENS.iter().find(|x| x.keyword_to_symbol() == Some(base.name)) { + self.emit_err(ParserError::unexpected_str(token, "package name", &base.span)); } // Return an error if the package name contains invalid characters. if !base .name + .as_str() .chars() .all(|x| x.is_ascii_lowercase() || x.is_ascii_digit() || x == '-' || x == '_') { - return Err(ParserError::invalid_package_name(&base.span).into()); + self.emit_err(ParserError::invalid_package_name(&base.span)); } // Return the package name. @@ -281,7 +264,7 @@ impl ParserContext { pub fn parse_package_path(&mut self) -> Result { let package_name = self.parse_package_name()?; self.expect(Token::Dot)?; - if self.peek()?.token == Token::LeftParen { + if self.peek_is_left_par() { let accesses = self.parse_package_accesses(&package_name.span)?; Ok(PackageOrPackages::Packages(Packages { span: &package_name.span + accesses.last().map(|x| x.span()).unwrap_or(&package_name.span), @@ -311,83 +294,112 @@ impl ParserContext { }) } - /// /// Returns a [`CircuitMember`] AST node if the next tokens represent a circuit member variable /// or circuit member function. - /// pub fn parse_circuit_declaration(&mut self) -> Result> { let mut members = Vec::new(); - let peeked = &self.peek()?.token; - let mut last_variable = peeked == &Token::Function || peeked == &Token::At; + let (mut semi_colons, mut commas) = (false, false); + while self.eat(Token::RightCurly).is_none() { - if !last_variable { - let (variable, last) = self.parse_member_variable_declaration()?; - - members.push(variable); - - let peeked = &self.peek()?; - if peeked.token == Token::Semicolon { - if commas { - return Err(ParserError::mixed_commas_and_semicolons(&peeked.span).into()); - } - - semi_colons = true; - self.expect(Token::Semicolon)?; - } else { - if semi_colons { - return Err(ParserError::mixed_commas_and_semicolons(&peeked.span).into()); - } - - commas = true; - self.eat(Token::Comma); - } - - if last { - last_variable = last; - } + members.push(if self.peek_is_function()? { + // function + self.parse_member_function_declaration()? + } else if *self.peek_token() == Token::Static { + // static const + self.parse_const_member_variable_declaration()? } else { - let function = self.parse_member_function_declaration()?; - members.push(function); - } + // variable + let variable = self.parse_member_variable_declaration()?; + + if let Some(semi) = self.eat(Token::Semicolon) { + if commas { + self.emit_err(ParserError::mixed_commas_and_semicolons(&semi.span)); + } + semi_colons = true; + } + + if let Some(comma) = self.eat(Token::Comma) { + if semi_colons { + self.emit_err(ParserError::mixed_commas_and_semicolons(&comma.span)); + } + commas = true; + } + + variable + }); } + self.ban_mixed_member_order(&members); + Ok(members) } + /// Emits errors if order isn't `consts variables functions`. + fn ban_mixed_member_order(&self, members: &[CircuitMember]) { + let mut had_var = false; + let mut had_fun = false; + for member in members { + match member { + CircuitMember::CircuitConst(id, _, e) if had_var => { + self.emit_err(ParserError::member_const_after_var(&(id.span() + e.span()))); + } + CircuitMember::CircuitConst(id, _, e) if had_fun => { + self.emit_err(ParserError::member_const_after_fun(&(id.span() + e.span()))); + } + CircuitMember::CircuitVariable(id, _) if had_fun => { + self.emit_err(ParserError::member_var_after_fun(id.span())); + } + CircuitMember::CircuitConst(..) => {} + CircuitMember::CircuitVariable(..) => had_var = true, + CircuitMember::CircuitFunction(..) => had_fun = true, + } + } + } + + /// Parses `IDENT: TYPE`. + fn parse_typed_field_name(&mut self) -> Result<(Identifier, Type)> { + let name = self.expect_ident()?; + self.expect(Token::Colon)?; + let type_ = self.parse_type()?.0; + + Ok((name, type_)) + } + + /// Returns a [`CircuitMember`] AST node if the next tokens represent a circuit member static constant. + pub fn parse_const_member_variable_declaration(&mut self) -> Result { + self.expect(Token::Static)?; + self.expect(Token::Const)?; + + // `IDENT: TYPE = EXPR`: + let (name, type_) = self.parse_typed_field_name()?; + self.expect(Token::Assign)?; + let literal = self.parse_primary_expression()?; + + self.expect(Token::Semicolon)?; + + Ok(CircuitMember::CircuitConst(name, type_, literal)) + } + /// /// Returns a [`CircuitMember`] AST node if the next tokens represent a circuit member variable. /// - pub fn parse_member_variable_declaration(&mut self) -> Result<(CircuitMember, bool)> { - let name = self.expect_ident()?; - self.expect(Token::Colon)?; - let type_ = self.parse_type()?.0; + pub fn parse_member_variable_declaration(&mut self) -> Result { + let (name, type_) = self.parse_typed_field_name()?; - let peeked = &self.peek()?.token; - if peeked == &Token::Function || peeked == &Token::At || peeked == &Token::RightCurly { - return Ok((CircuitMember::CircuitVariable(name, type_), true)); - } else if peeked == &Token::Comma || peeked == &Token::Semicolon { - let peeked = &self.peek_next()?.token; - if peeked == &Token::Function || peeked == &Token::At || peeked == &Token::RightCurly { - return Ok((CircuitMember::CircuitVariable(name, type_), true)); - } - } - - Ok((CircuitMember::CircuitVariable(name, type_), false)) + Ok(CircuitMember::CircuitVariable(name, type_)) } - /// /// Returns a [`CircuitMember`] AST node if the next tokens represent a circuit member function. - /// pub fn parse_member_function_declaration(&mut self) -> Result { let peeked = self.peek()?.clone(); - if peeked.token == Token::Function || peeked.token == Token::At { + if self.peek_is_function()? { let function = self.parse_function_declaration()?; - Ok(CircuitMember::CircuitFunction(function.1)) + Ok(CircuitMember::CircuitFunction(Box::new(function.1))) } else { return Err(ParserError::unexpected( &peeked.token, - [Token::Function, Token::At] + [Token::Function, Token::At, Token::Const] .iter() .map(|x| format!("'{}'", x)) .collect::>() @@ -403,8 +415,18 @@ impl ParserContext { /// circuit name and definition statement. /// pub fn parse_circuit(&mut self) -> Result<(Identifier, Circuit)> { - self.expect(Token::Circuit)?; - let name = self.expect_ident()?; + let name = if let Some(ident) = self.eat_identifier() { + ident + } else if let Some(scalar_type) = self.eat_any(crate::type_::TYPE_TOKENS) { + Identifier { + name: scalar_type.token.keyword_to_symbol().unwrap(), + span: scalar_type.span, + } + } else { + let next = self.peek()?; + return Err(ParserError::unexpected_str(&next.token, "ident", &next.span).into()); + }; + self.expect(Token::LeftCurly)?; let members = self.parse_circuit_declaration()?; @@ -412,7 +434,6 @@ impl ParserContext { name.clone(), Circuit { circuit_name: name, - core_mapping: std::cell::RefCell::new(None), members, }, )) @@ -424,24 +445,26 @@ impl ParserContext { pub fn parse_function_parameters(&mut self) -> Result { let const_ = self.eat(Token::Const); let mutable = self.eat(Token::Mut); + let reference = self.eat(Token::Ampersand); let mut name = if let Some(token) = self.eat(Token::LittleSelf) { Identifier { - name: token.token.to_string().into(), + name: sym::SelfLower, span: token.span, } } else { self.expect_ident()? }; - if name.name.as_ref() == "self" { + if name.name == sym::SelfLower { if let Some(mutable) = &mutable { - // Handle `mut self`. - name.span = &mutable.span + &name.span; - name.name = "mut self".to_string().into(); - return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { identifier: name })); + self.emit_err(ParserError::mut_self_parameter(&(&mutable.span + &name.span))); + return Ok(Self::build_ref_self(name, mutable)); + } else if let Some(reference) = &reference { + // Handle `&self`. + return Ok(Self::build_ref_self(name, reference)); } else if let Some(const_) = &const_ { // Handle `const self`. name.span = &const_.span + &name.span; - name.name = "const self".to_string().into(); + name.name = Symbol::intern("const self"); return Ok(FunctionInput::ConstSelfKeyword(ConstSelfKeyword { identifier: name })); } // Handle `self`. @@ -449,7 +472,7 @@ impl ParserContext { } if let Some(mutable) = &mutable { - return Err(ParserError::mut_function_input(&(&mutable.span + &name.span)).into()); + self.emit_err(ParserError::mut_function_input(&(&mutable.span + &name.span))); } self.expect(Token::Colon)?; @@ -463,42 +486,55 @@ impl ParserContext { })) } - /// + /// Builds a function parameter `&self`. + fn build_ref_self(mut name: Identifier, reference: &SpannedToken) -> FunctionInput { + name.span = &reference.span + &name.span; + // FIXME(Centril): This should be *two* tokens, NOT one! + name.name = Symbol::intern("&self"); + FunctionInput::RefSelfKeyword(RefSelfKeyword { identifier: name }) + } + /// Returns an [`(Identifier, Function)`] AST node if the next tokens represent a function name /// and function definition. - /// pub fn parse_function_declaration(&mut self) -> Result<(Identifier, Function)> { - let mut annotations = Vec::new(); + // Parse any annotations. + let mut annotations = IndexMap::new(); while self.peek_token().as_ref() == &Token::At { - annotations.push(self.parse_annotation()?); + let annotation = self.parse_annotation()?; + annotations.insert(annotation.name.name, annotation); } + + // Parse optional const modifier. + let const_ = self.eat(Token::Const).is_some(); + + // Parse `function IDENT`. let start = self.expect(Token::Function)?; let name = self.expect_ident()?; - self.expect(Token::LeftParen)?; - let mut inputs = Vec::new(); - while self.eat(Token::RightParen).is_none() { - let input = self.parse_function_parameters()?; - inputs.push(input); - if self.eat(Token::Comma).is_none() { - self.expect(Token::RightParen)?; - break; - } - } + + // Parse parameters. + let (inputs, ..) = self.parse_paren_comma_list(|p| p.parse_function_parameters().map(Some))?; + + // Parse return type. let output = if self.eat(Token::Arrow).is_some() { Some(self.parse_type()?.0) } else { None }; + + // Parse the function body. let block = self.parse_block()?; + Ok(( name.clone(), Function { annotations, identifier: name, input: inputs, + const_, output, span: start + block.span.clone(), block, + core_mapping: <_>::default(), }, )) } @@ -513,7 +549,7 @@ impl ParserContext { .variable_names .iter() .map(|variable_name| variable_name.identifier.clone()) - .collect::>(); + .collect(); Ok((variable_names, statement)) } diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index cf6ae0e5fc..6dbffe8ff3 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -19,6 +19,16 @@ //! This module contains the [`parse()`] method which calls the underlying [`tokenize()`] //! method to create a new program ast. +use crate::{tokenizer::*, Token}; + +use leo_ast::*; +use leo_errors::emitter::Handler; +use leo_errors::{ParserError, Result}; +use leo_span::{Span, Symbol}; + +use indexmap::IndexMap; +use std::unimplemented; + mod context; pub use context::*; @@ -27,13 +37,6 @@ pub mod file; pub mod statement; pub mod type_; -use std::unimplemented; - -use crate::{tokenizer::*, Token}; -use indexmap::IndexMap; -use leo_ast::*; -use leo_errors::{ParserError, Result, Span}; - pub(crate) fn assert_no_whitespace(left_span: &Span, right_span: &Span, left: &str, right: &str) -> Result<()> { if left_span.col_stop != right_span.col_start { let mut error_span = left_span + right_span; @@ -46,8 +49,8 @@ pub(crate) fn assert_no_whitespace(left_span: &Span, right_span: &Span, left: &s } /// Creates a new program from a given file path and source code text. -pub fn parse(path: &str, source: &str) -> Result { - let mut tokens = ParserContext::new(crate::tokenize(path, source.into())?); +pub fn parse(handler: &Handler, path: &str, source: &str) -> Result { + let mut tokens = ParserContext::new(handler, crate::tokenize(path, source.into())?); tokens.parse_program() } diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index c452549e62..afd5b96540 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -17,6 +17,7 @@ use super::*; use leo_errors::{ParserError, Result}; +use leo_span::sym; const ASSIGN_TOKENS: &[Token] = &[ Token::Assign, @@ -36,7 +37,7 @@ const ASSIGN_TOKENS: &[Token] = &[ // Token::AndEq, ]; -impl ParserContext { +impl ParserContext<'_> { /// /// Returns an [`Identifier`] AST node if the given [`Expression`] AST node evaluates to an /// identifier access. The access is stored in the given accesses. @@ -44,25 +45,29 @@ impl ParserContext { pub fn construct_assignee_access(expr: Expression, accesses: &mut Vec) -> Result { let identifier; match expr { - Expression::CircuitMemberAccess(expr) => { - identifier = Self::construct_assignee_access(*expr.circuit, accesses)?; - accesses.push(AssigneeAccess::Member(expr.name)); - } - Expression::TupleAccess(expr) => { - identifier = Self::construct_assignee_access(*expr.tuple, accesses)?; - accesses.push(AssigneeAccess::Tuple(expr.index, expr.span)); - } - Expression::ArrayRangeAccess(expr) => { - identifier = Self::construct_assignee_access(*expr.array, accesses)?; - accesses.push(AssigneeAccess::ArrayRange( - expr.left.map(|x| *x), - expr.right.map(|x| *x), - )); - } - Expression::ArrayAccess(expr) => { - identifier = Self::construct_assignee_access(*expr.array, accesses)?; - accesses.push(AssigneeAccess::ArrayIndex(*expr.index)); - } + Expression::Access(access) => match access { + AccessExpression::Member(expr) => { + identifier = Self::construct_assignee_access(*expr.inner, accesses)?; + accesses.push(AssigneeAccess::Member(expr.name)); + } + AccessExpression::Tuple(expr) => { + identifier = Self::construct_assignee_access(*expr.tuple, accesses)?; + accesses.push(AssigneeAccess::Tuple(expr.index, expr.span)); + } + AccessExpression::ArrayRange(expr) => { + identifier = Self::construct_assignee_access(*expr.array, accesses)?; + accesses.push(AssigneeAccess::ArrayRange( + expr.left.map(|x| *x), + expr.right.map(|x| *x), + )); + } + AccessExpression::Array(expr) => { + identifier = Self::construct_assignee_access(*expr.array, accesses)?; + accesses.push(AssigneeAccess::ArrayIndex(*expr.index)); + } + _ => return Err(ParserError::invalid_assignment_target(access.span()).into()), + }, + Expression::Identifier(id) => identifier = id, _ => return Err(ParserError::invalid_assignment_target(expr.span()).into()), } @@ -177,9 +182,7 @@ impl ParserContext { }) } - /// /// Returns a [`ConditionalStatement`] AST node if the next tokens represent a conditional statement. - /// pub fn parse_conditional_statement(&mut self) -> Result { let start = self.expect(Token::If)?; self.fuzzy_struct_state = true; @@ -188,12 +191,10 @@ impl ParserContext { let body = self.parse_block()?; let next = if self.eat(Token::Else).is_some() { let s = self.parse_statement()?; - match s { - Statement::Block(_) | Statement::Conditional(_) => Some(Box::new(s)), - s => { - return Err(ParserError::unexpected_statement(&s, "Block or Conditional", s.span()).into()); - } + if !matches!(s, Statement::Block(_) | Statement::Conditional(_)) { + self.emit_err(ParserError::unexpected_statement(&s, "Block or Conditional", s.span())); } + Some(Box::new(s)) } else { None }; @@ -206,19 +207,20 @@ impl ParserContext { }) } - /// /// Returns an [`IterationStatement`] AST node if the next tokens represent an iteration statement. - /// pub fn parse_loop_statement(&mut self) -> Result { let start_span = self.expect(Token::For)?; let ident = self.expect_ident()?; self.expect(Token::In)?; + + // Parse iteration range. let start = self.parse_expression()?; self.expect(Token::DotDot)?; let inclusive = self.eat(Token::Assign).is_some(); self.fuzzy_struct_state = true; let stop = self.parse_conditional_expression()?; self.fuzzy_struct_state = false; + let block = self.parse_block()?; Ok(IterationStatement { @@ -231,59 +233,56 @@ impl ParserContext { }) } - /// /// Returns a [`ConsoleArgs`] AST node if the next tokens represent a formatted string. - /// pub fn parse_console_args(&mut self) -> Result { - let start_span; - let string = match self.expect_any()? { - SpannedToken { - token: Token::StringLit(chars), - span, - } => { - start_span = span; - chars + let mut string = None; + let (parameters, _, span) = self.parse_paren_comma_list(|p| { + if string.is_none() { + let SpannedToken { token, span } = p.expect_any()?; + string = Some(match token { + Token::StringLit(chars) => chars, + _ => { + p.emit_err(ParserError::unexpected_str(token, "formatted string", &span)); + Vec::new() + } + }); + Ok(None) + } else { + p.parse_expression().map(Some) } - SpannedToken { token, span } => { - return Err(ParserError::unexpected_str(token, "formatted string", &span).into()); - } - }; - - // let parts = FormatStringPart::from_string(string); - - let mut parameters = Vec::new(); - while self.eat(Token::Comma).is_some() { - let param = self.parse_expression()?; - parameters.push(param); - } + })?; Ok(ConsoleArgs { - string, - span: &start_span + parameters.last().map(|x| x.span()).unwrap_or(&start_span), + string: string.unwrap_or_default(), + span, parameters, }) } - /// /// Returns a [`ConsoleStatement`] AST node if the next tokens represent a console statement. - /// pub fn parse_console_statement(&mut self) -> Result { let keyword = self.expect(Token::Console)?; self.expect(Token::Dot)?; let function = self.expect_ident()?; - self.expect(Token::LeftParen)?; - let function = match &*function.name { - "assert" => { + let function = match function.name { + sym::assert => { + self.expect(Token::LeftParen)?; let expr = self.parse_expression()?; + self.expect(Token::RightParen)?; ConsoleFunction::Assert(expr) } - "error" => ConsoleFunction::Error(self.parse_console_args()?), - "log" => ConsoleFunction::Log(self.parse_console_args()?), + sym::error => ConsoleFunction::Error(self.parse_console_args()?), + sym::log => ConsoleFunction::Log(self.parse_console_args()?), x => { - return Err(ParserError::unexpected_ident(x, &["assert", "error", "log"], &function.span).into()); + // Not sure what it is, assume it's `log`. + self.emit_err(ParserError::unexpected_ident( + x, + &["assert", "error", "log"], + &function.span, + )); + ConsoleFunction::Log(self.parse_console_args()?) } }; - self.expect(Token::RightParen)?; self.expect(Token::Semicolon)?; Ok(ConsoleStatement { @@ -292,14 +291,13 @@ impl ParserContext { }) } - /// /// Returns a [`VariableName`] AST node if the next tokens represent a variable name with /// valid keywords. - /// pub fn parse_variable_name(&mut self, span: &SpannedToken) -> Result { let mutable = self.eat(Token::Mut); + if let Some(mutable) = &mutable { - return Err(ParserError::let_mut_statement(&(&mutable.span + &span.span)).into()); + self.emit_err(ParserError::let_mut_statement(&(&mutable.span + &span.span))); } let name = self.expect_ident()?; @@ -310,35 +308,24 @@ impl ParserContext { }) } - /// /// Returns a [`DefinitionStatement`] AST node if the next tokens represent a definition statement. - /// pub fn parse_definition_statement(&mut self) -> Result { let declare = self.expect_oneof(&[Token::Let, Token::Const])?; - let mut variable_names = Vec::new(); - let next = self.eat(Token::LeftParen); - variable_names.push(self.parse_variable_name(&declare)?); - if next.is_some() { - let mut eaten_ending = false; - while self.eat(Token::Comma).is_some() { - if self.eat(Token::RightParen).is_some() { - eaten_ending = true; - break; - } - variable_names.push(self.parse_variable_name(&declare)?); - } - if !eaten_ending { - self.expect(Token::RightParen)?; - } - } - - let type_ = if self.eat(Token::Colon).is_some() { - Some(self.parse_type()?.0) + // Parse variable names. + let variable_names = if self.peek_is_left_par() { + self.parse_paren_comma_list(|p| p.parse_variable_name(&declare).map(Some)) + .map(|(vars, ..)| vars)? } else { - None + vec![self.parse_variable_name(&declare)?] }; + // Parse an optional type ascription. + let type_ = self + .eat(Token::Colon) + .map(|_| self.parse_type().map(|t| t.0)) + .transpose()?; + self.expect(Token::Assign)?; let expr = self.parse_expression()?; self.expect(Token::Semicolon)?; diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 0f7e3c4968..9c73c00a21 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -17,7 +17,7 @@ use super::*; use leo_errors::{ParserError, Result}; -const TYPE_TOKENS: &[Token] = &[ +pub(crate) const TYPE_TOKENS: &[Token] = &[ Token::I8, Token::I16, Token::I32, @@ -35,7 +35,7 @@ const TYPE_TOKENS: &[Token] = &[ Token::Char, ]; -impl ParserContext { +impl ParserContext<'_> { /// /// Returns a [`IntegerType`] AST node if the given token is a supported integer type, or [`None`]. /// @@ -55,58 +55,51 @@ impl ParserContext { }) } - /// /// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type. - /// - pub fn parse_array_dimensions(&mut self) -> Result> { - Ok(if let Some((int, _)) = self.eat_int() { - Some(ArrayDimensions(vec![int])) - } else if self.eat(Token::Underscore).is_some() { - None + pub fn parse_array_dimensions(&mut self) -> Result { + Ok(if let Some(dim) = self.parse_array_dimension() { + dim } else { - self.expect(Token::LeftParen)?; - let mut dimensions = Vec::new(); - loop { - if let Some((int, _)) = self.eat_int() { - dimensions.push(int); + let mut had_item_err = false; + let (dims, _, span) = self.parse_paren_comma_list(|p| { + Ok(if let Some(dim) = p.parse_array_dimension() { + Some(dim) } else { - let token = self.peek()?; - return Err(ParserError::unexpected_str(&token.token, "int", &token.span).into()); - } - if self.eat(Token::Comma).is_none() { - break; - } + let token = p.expect_any()?; + p.emit_err(ParserError::unexpected_str(&token.token, "int", &token.span)); + had_item_err = true; + None + }) + })?; + if dims.is_empty() && !had_item_err { + self.emit_err(ParserError::array_tuple_dimensions_empty(&span)); } - self.expect(Token::RightParen)?; - Some(ArrayDimensions(dimensions)) + ArrayDimensions::Multi(dims) }) } - /// - /// Returns a [`(Type, Span)`] tuple of AST nodes if the next token represents a type. Also - /// returns the span of the parsed token. - /// + /// Parses a basic array dimension, i.e., an integer or `_`. + fn parse_array_dimension(&mut self) -> Option { + if let Some((int, _)) = self.eat_int() { + Some(ArrayDimensions::Number(int)) + } else if self.eat(Token::Underscore).is_some() { + Some(ArrayDimensions::Unspecified) + } else { + None + } + } + + /// Returns a [`(Type, Span)`] tuple of AST nodes if the next token represents a type. + /// Also returns the span of the parsed token. pub fn parse_type(&mut self) -> Result<(Type, Span)> { Ok(if let Some(token) = self.eat(Token::BigSelf) { (Type::SelfType, token.span) } else if let Some(ident) = self.eat_identifier() { let span = ident.span.clone(); (Type::Identifier(ident), span) - } else if let Some(token) = self.eat(Token::LeftParen) { - let mut types = Vec::new(); - let end_span; - loop { - if let Some(end) = self.eat(Token::RightParen) { - end_span = end.span; - break; - } - types.push(self.parse_type()?.0); - if self.eat(Token::Comma).is_none() { - end_span = self.expect(Token::RightParen)?; - break; - } - } - (Type::Tuple(types), token.span + end_span) + } else if self.peek_is_left_par() { + let (types, _, span) = self.parse_paren_comma_list(|p| p.parse_type().map(|t| Some(t.0)))?; + (Type::Tuple(types), span) } else if let Some(token) = self.eat(Token::LeftSquare) { let (inner, _) = self.parse_type()?; self.expect(Token::Semicolon)?; diff --git a/parser/src/test.rs b/parser/src/test.rs index 74352bb573..5b0e71cd8e 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,17 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use crate::{tokenizer, ParserContext, SpannedToken}; use leo_ast::{Expression, ExpressionStatement, Statement, ValueExpression}; -use leo_errors::Span; +use leo_errors::{emitter::Handler, LeoError}; +use leo_span::{symbol::create_session_if_not_set_then, Span}; use leo_test_framework::{ runner::{Namespace, ParseType, Runner}, Test, }; +use serde::Serialize; use serde_yaml::Value; use tokenizer::Token; -use crate::{tokenizer, ParserContext}; - struct TokenNamespace; impl Namespace for TokenNamespace { @@ -33,18 +34,19 @@ impl Namespace for TokenNamespace { } fn run_test(&self, test: Test) -> Result { - let output = tokenizer::tokenize("test", test.content.into()); - output - .map(|tokens| { - Value::String( - tokens - .into_iter() - .map(|x| x.to_string()) - .collect::>() - .join(","), - ) - }) - .map_err(|x| x.to_string()) + create_session_if_not_set_then(|_| { + tokenizer::tokenize("test", test.content.into()) + .map(|tokens| { + Value::String( + tokens + .into_iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), + ) + }) + .map_err(|x| x.to_string()) + }) } } @@ -60,6 +62,37 @@ fn not_fully_consumed(tokens: &mut ParserContext) -> Result<(), String> { Err(out) } +fn with_handler( + tokens: Vec, + logic: impl FnOnce(&mut ParserContext<'_>) -> Result, +) -> Result { + let (handler, buf) = Handler::new_with_buf(); + let mut tokens = ParserContext::new(&handler, tokens); + let parsed = handler + .extend_if_error(logic(&mut tokens)) + .map_err(|_| buf.extract().to_string())?; + not_fully_consumed(&mut tokens)?; + Ok(parsed) +} + +fn implcit_value_expr() -> Expression { + Expression::Value(ValueExpression::Implicit("".into(), Span::default())) +} + +fn tokenize(test: Test) -> Result, String> { + tokenizer::tokenize("test", test.content.into()).map_err(|x| x.to_string()) +} + +fn all_are_comments(tokens: &[SpannedToken]) -> bool { + tokens + .iter() + .all(|x| matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_))) +} + +fn yaml_or_fail(value: T) -> Value { + serde_yaml::to_value(value).expect("serialization failed") +} + struct ParseExpressionNamespace; impl Namespace for ParseExpressionNamespace { @@ -68,23 +101,13 @@ impl Namespace for ParseExpressionNamespace { } fn run_test(&self, test: Test) -> Result { - let tokenizer = tokenizer::tokenize("test", test.content.into()).map_err(|x| x.to_string())?; - if tokenizer - .iter() - .all(|x| matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_))) - { - return Ok(serde_yaml::to_value(&Expression::Value(ValueExpression::Implicit( - "".into(), - Span::default(), - ))) - .expect("serialization failed")); - } - let mut tokens = ParserContext::new(tokenizer); - - let parsed = tokens.parse_expression().map_err(|x| x.to_string())?; - not_fully_consumed(&mut tokens)?; - - Ok(serde_yaml::to_value(&parsed).expect("serialization failed")) + create_session_if_not_set_then(|_| { + let tokenizer = tokenize(test)?; + if all_are_comments(&tokenizer) { + return Ok(yaml_or_fail(implcit_value_expr())); + } + with_handler(tokenizer, |p| p.parse_expression()).map(yaml_or_fail) + }) } } @@ -96,23 +119,16 @@ impl Namespace for ParseStatementNamespace { } fn run_test(&self, test: Test) -> Result { - let tokenizer = tokenizer::tokenize("test", test.content.into()).map_err(|x| x.to_string())?; - if tokenizer - .iter() - .all(|x| matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_))) - { - return Ok(serde_yaml::to_value(&Statement::Expression(ExpressionStatement { - expression: Expression::Value(ValueExpression::Implicit("".into(), Span::default())), - span: Span::default(), - })) - .expect("serialization failed")); - } - let mut tokens = ParserContext::new(tokenizer); - - let parsed = tokens.parse_statement().map_err(|x| x.to_string())?; - not_fully_consumed(&mut tokens)?; - - Ok(serde_yaml::to_value(&parsed).expect("serialization failed")) + create_session_if_not_set_then(|_| { + let tokenizer = tokenize(test)?; + if all_are_comments(&tokenizer) { + return Ok(yaml_or_fail(Statement::Expression(ExpressionStatement { + expression: implcit_value_expr(), + span: Span::default(), + }))); + } + with_handler(tokenizer, |p| p.parse_statement()).map(yaml_or_fail) + }) } } @@ -124,13 +140,72 @@ impl Namespace for ParseNamespace { } fn run_test(&self, test: Test) -> Result { - let tokenizer = tokenizer::tokenize("test", test.content.into()).map_err(|x| x.to_string())?; - let mut tokens = ParserContext::new(tokenizer); + create_session_if_not_set_then(|_| with_handler(tokenize(test)?, |p| p.parse_program()).map(yaml_or_fail)) + } +} - let parsed = tokens.parse_program().map_err(|x| x.to_string())?; - not_fully_consumed(&mut tokens)?; +struct SerializeNamespace; - Ok(serde_yaml::to_value(&parsed).expect("serialization failed")) +// Helper functions to recursively filter keys from AST JSON. +// Redeclaring here since we don't want to make this public. +fn remove_key_from_json(value: &mut serde_json::Value, key: &str) { + match value { + serde_json::value::Value::Object(map) => { + map.remove(key); + for val in map.values_mut() { + remove_key_from_json(val, key); + } + } + serde_json::value::Value::Array(values) => { + for val in values.iter_mut() { + remove_key_from_json(val, key); + } + } + _ => (), + } +} + +// Helper function to normalize AST +// Redeclaring here because we don't want to make this public +fn normalize_json_value(value: serde_json::Value) -> serde_json::Value { + match value { + serde_json::Value::Array(vec) => { + let orig_length = vec.len(); + let mut new_vec: Vec = vec + .into_iter() + .filter(|v| !matches!(v, serde_json::Value::Object(map) if map.is_empty())) + .map(normalize_json_value) + .collect(); + + if orig_length == 2 && new_vec.len() == 1 { + new_vec.pop().unwrap() + } else { + serde_json::Value::Array(new_vec) + } + } + serde_json::Value::Object(map) => { + serde_json::Value::Object(map.into_iter().map(|(k, v)| (k, normalize_json_value(v))).collect()) + } + _ => value, + } +} + +impl Namespace for SerializeNamespace { + fn parse_type(&self) -> ParseType { + ParseType::Whole + } + + fn run_test(&self, test: Test) -> Result { + create_session_if_not_set_then(|_| { + let tokenizer = tokenize(test)?; + let parsed = with_handler(tokenizer, |p| p.parse_program())?; + + let mut json = serde_json::to_value(parsed).expect("failed to convert to json value"); + remove_key_from_json(&mut json, "span"); + json = normalize_json_value(json); + + Ok(serde_json::from_value::(json).expect("failed serialization")) + }) } } @@ -143,6 +218,7 @@ impl Runner for TestRunner { "ParseStatement" => Box::new(ParseStatementNamespace), "ParseExpression" => Box::new(ParseExpressionNamespace), "Token" => Box::new(TokenNamespace), + "Serialize" => Box::new(SerializeNamespace), _ => return None, }) } diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 31407f5ce4..e2edc16995 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -15,7 +15,8 @@ // along with the Leo library. If not, see . use crate::tokenizer::{Char, Token}; -use leo_errors::Span; +use leo_span::{Span, Symbol}; + use serde::{Deserialize, Serialize}; use tendril::StrTendril; @@ -352,7 +353,7 @@ impl Token { // else if let Some(len) = eat(input, "&=") { // return (len, Some(Token::BitAndEq)); // } - // return (1, Some(Token::BitAnd)); + return (1, Some(Token::Ampersand)); } b'(' => return (1, Some(Token::LeftParen)), b')' => return (1, Some(Token::RightParen)), @@ -388,9 +389,6 @@ impl Token { return (len, Some(Token::DotDotDot)); } else if let Some(len) = eat(input, "..") { return (len, Some(Token::DotDot)); - } else if let Some(len) = eat(input, ".len()") { - // FIXME: remove this code once we allow method calls - return (len, Some(Token::LengthOf)); } return (1, Some(Token::Dot)); } @@ -526,7 +524,7 @@ impl Token { "u32" => Token::U32, "u64" => Token::U64, "u128" => Token::U128, - _ => Token::Ident(ident), + _ => Token::Ident(Symbol::intern(&ident)), }), ); } diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index 576254be1b..3e306dd0e7 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -28,7 +28,8 @@ pub(crate) use self::token::*; pub(crate) mod lexer; pub(crate) use self::lexer::*; -use leo_errors::{LeoError, ParserError, Span}; +use leo_errors::{LeoError, ParserError}; +use leo_span::Span; use tendril::StrTendril; @@ -112,30 +113,31 @@ pub(crate) fn tokenize(path: &str, input: StrTendril) -> Result> - // >>= - // >>> - // >>>= - // % - // %= - // ||= - // &&= + create_session_if_not_set_then(|_| { + // &= + // | + // |= + // ^ + // ^= + // ~ + // << + // <<= + // >> + // >>= + // >>> + // >>>= + // % + // %= + // ||= + // &&= - let tokens = tokenize( - "test_path", - r#" + let tokens = tokenize( + "test_path", + r#" "test" "test{}test" "test{}" @@ -170,6 +172,7 @@ mod tests { input let mut + & return static string @@ -223,25 +226,27 @@ mod tests { // test /* test */ //"# - .into(), - ) - .unwrap(); - let mut output = String::new(); - for SpannedToken { token, .. } in tokens.iter() { - output += &format!("{} ", token.to_string()); - } + .into(), + ) + .unwrap(); + let mut output = String::new(); + for SpannedToken { token, .. } in tokens.iter() { + output += &format!("{} ", token.to_string()); + } - // & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= - assert_eq!( - output, - r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> _ . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || ? // test + // & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= + assert_eq!( + output, + r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut & return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> _ . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || ? // test /* test */ // "# - ); + ); + }); } #[test] fn test_spans() { - let raw = r#" + create_session_if_not_set_then(|_| { + let raw = r#" test // test test @@ -251,20 +256,21 @@ mod tests { test */ test "#; - let tokens = tokenize("test_path", raw.into()).unwrap(); - let mut line_indicies = vec![0]; - for (i, c) in raw.chars().enumerate() { - if c == '\n' { - line_indicies.push(i + 1); + let tokens = tokenize("test_path", raw.into()).unwrap(); + let mut line_indicies = vec![0]; + for (i, c) in raw.chars().enumerate() { + if c == '\n' { + line_indicies.push(i + 1); + } } - } - for token in tokens.iter() { - let token_raw = token.token.to_string(); - let start = line_indicies.get(token.span.line_start - 1).unwrap(); - let stop = line_indicies.get(token.span.line_stop - 1).unwrap(); - let original = &raw[*start + token.span.col_start - 1..*stop + token.span.col_stop - 1]; - assert_eq!(original, &token_raw); - } - // println!("{}", serde_json::to_string_pretty(&tokens).unwrap()); + for token in tokens.iter() { + let token_raw = token.token.to_string(); + let start = line_indicies.get(token.span.line_start - 1).unwrap(); + let stop = line_indicies.get(token.span.line_stop - 1).unwrap(); + let original = &raw[*start + token.span.col_start - 1..*stop + token.span.col_stop - 1]; + assert_eq!(original, &token_raw); + } + // println!("{}", serde_json::to_string_pretty(&tokens).unwrap()); + }) } } diff --git a/parser/src/tokenizer/token.rs b/parser/src/tokenizer/token.rs index c031fa13a1..1601b8721f 100644 --- a/parser/src/tokenizer/token.rs +++ b/parser/src/tokenizer/token.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use leo_span::{sym, Symbol}; + use serde::{Deserialize, Serialize}; use std::fmt; use tendril::StrTendril; @@ -48,14 +50,14 @@ impl fmt::Display for Char { pub enum Token { // Lexical Grammar // Literals - CommentLine(#[serde(with = "leo_errors::common::tendril_json")] StrTendril), - CommentBlock(#[serde(with = "leo_errors::common::tendril_json")] StrTendril), + CommentLine(#[serde(with = "leo_span::tendril_json")] StrTendril), + CommentBlock(#[serde(with = "leo_span::tendril_json")] StrTendril), StringLit(Vec), - Ident(#[serde(with = "leo_errors::common::tendril_json")] StrTendril), - Int(#[serde(with = "leo_errors::common::tendril_json")] StrTendril), + Ident(Symbol), + Int(#[serde(with = "leo_span::tendril_json")] StrTendril), True, False, - AddressLit(#[serde(with = "leo_errors::common::tendril_json")] StrTendril), + AddressLit(#[serde(with = "leo_span::tendril_json")] StrTendril), CharLit(Char), // Symbols @@ -127,6 +129,7 @@ pub enum Token { As, Circuit, Console, + /// Const variable and a const function. Const, Else, For, @@ -135,16 +138,14 @@ pub enum Token { In, Let, Mut, + /// Represents `&`. + /// Used for `Reference` and `BitAnd`. + Ampersand, Return, Static, Type, // Not yet in ABNF - // arr.len() token - hacky zone - LengthOf, - - // Not yet in ABNF - // BitAnd, // BitAndEq, // BitOr, // BitOrEq, @@ -192,13 +193,13 @@ pub const KEYWORD_TOKENS: &[Token] = &[ Token::Input, Token::Let, Token::Mut, + Token::Ampersand, Token::Return, Token::BigSelf, Token::LittleSelf, Token::Static, Token::True, Token::Type, - Token::LengthOf, Token::U8, Token::U16, Token::U32, @@ -207,11 +208,52 @@ pub const KEYWORD_TOKENS: &[Token] = &[ ]; impl Token { - /// /// Returns `true` if the `self` token equals a Leo keyword. - /// pub fn is_keyword(&self) -> bool { - KEYWORD_TOKENS.iter().any(|x| x == self) + KEYWORD_TOKENS.contains(self) + } + + /// Converts `self` to the corresponding `Symbol` if it `is_keyword`. + pub fn keyword_to_symbol(&self) -> Option { + Some(match self { + Token::Address => sym::address, + Token::As => sym::As, + Token::Bool => sym::bool, + Token::Char => sym::char, + Token::Circuit => sym::circuit, + Token::Console => sym::console, + Token::Const => sym::Const, + Token::Else => sym::Else, + Token::False => sym::False, + Token::Field => sym::field, + Token::For => sym::For, + Token::Function => sym::function, + Token::Group => sym::group, + Token::I8 => sym::i8, + Token::I16 => sym::i16, + Token::I32 => sym::i32, + Token::I64 => sym::i64, + Token::I128 => sym::i128, + Token::If => sym::If, + Token::Import => sym::import, + Token::In => sym::In, + Token::Input => sym::input, + Token::Let => sym::Let, + Token::Mut => sym::Mut, + Token::Ampersand => sym::Ampersand, + Token::Return => sym::Return, + Token::BigSelf => sym::SelfUpper, + Token::LittleSelf => sym::SelfLower, + Token::Static => sym::Static, + Token::True => sym::True, + Token::Type => sym::Type, + Token::U8 => sym::u8, + Token::U16 => sym::u16, + Token::U32 => sym::u32, + Token::U64 => sym::u64, + Token::U128 => sym::u128, + _ => return None, + }) } } @@ -307,12 +349,11 @@ impl fmt::Display for Token { In => write!(f, "in"), Let => write!(f, "let"), Mut => write!(f, "mut"), + Ampersand => write!(f, "&"), // Used for `Reference` and `BitAnd` Return => write!(f, "return"), Static => write!(f, "static"), Type => write!(f, "type"), - LengthOf => write!(f, ".len()"), // FIXME Eof => write!(f, ""), - // BitAnd => write!(f, "&"), // BitAndEq => write!(f, "&="), // BitOr => write!(f, "|"), // BitOrEq => write!(f, "|="), diff --git a/parser/tests/mod.rs b/parser/tests/mod.rs deleted file mode 100644 index c2c2ddea35..0000000000 --- a/parser/tests/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -mod serialization; diff --git a/parser/tests/serialization/expected_leo_ast/linear_regression.json b/parser/tests/serialization/expected_leo_ast/linear_regression.json deleted file mode 100644 index f5e68ba903..0000000000 --- a/parser/tests/serialization/expected_leo_ast/linear_regression.json +++ /dev/null @@ -1,1162 +0,0 @@ -{ - "name": "", - "expected_input": [], - "import_statements": [], - "imports": {}, - "aliases": {}, - "circuits": { - "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Point {\\\"}\"}": { - "circuit_name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Point {\\\"}\"}", - "core_mapping": null, - "members": [ - { - "CircuitVariable": [ - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: i32,\\\"}\"}", - { - "IntegerType": "I32" - } - ] - }, - { - "CircuitVariable": [ - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: i32,\\\"}\"}", - { - "IntegerType": "I32" - } - ] - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "IntegerType": "I32" - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "IntegerType": "I32" - } - } - } - ], - "output": "SelfType", - "block": { - "statements": [ - { - "Return": { - "expression": { - "CircuitInit": { - "name": "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}", - "expression": null - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}", - "expression": null - } - ] - } - } - } - } - ] - } - } - } - ] - }, - "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":9,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit LinearRegression {\\\"}\"}": { - "circuit_name": "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":9,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit LinearRegression {\\\"}\"}", - "core_mapping": null, - "members": [ - { - "CircuitVariable": [ - "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" points: [Point; 5],\\\"}\"}", - { - "Array": [ - { - "Identifier": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":14,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" points: [Point; 5],\\\"}\"}" - }, - [ - { - "value": "5" - } - ] - ] - } - ] - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - { - "Identifier": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}" - }, - [ - { - "value": "5" - } - ] - ] - } - } - } - ], - "output": "SelfType", - "block": { - "statements": [ - { - "Return": { - "expression": { - "CircuitInit": { - "name": "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { points };\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { points };\\\"}\"}", - "expression": null - } - ] - } - } - } - } - ] - } - } - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":14,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function slope(self) -> i32 { \\\"}\"}", - "input": [ - { - "SelfKeyword": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":20,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function slope(self) -> i32 { \\\"}\"}" - } - ], - "output": { - "IntegerType": "I32" - }, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":13,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let num_points = 5i32;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "5" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x_sum = 0i32; \\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y_sum = 0i32; \\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let xy_sum = 0i32; \\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x2_sum = 0i32; \\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Iteration": { - "variable": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..5 {\\\"}\"}", - "start": { - "Value": { - "Implicit": "0" - } - }, - "stop": { - "Value": { - "Implicit": "5" - } - }, - "inclusive": false, - "block": { - "statements": [ - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "accesses": [] - }, - "value": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "type_": null - } - } - } - }, - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}", - "accesses": [] - }, - "value": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}", - "type_": null - } - } - } - }, - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":23,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":35,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":38,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}", - "type_": null - } - }, - "right": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":42,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":47,\\\"col_stop\\\":53,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":54,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":57,\\\"col_stop\\\":58,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}", - "type_": null - } - }, - "op": "Mul" - } - } - } - }, - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":23,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":35,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":38,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "right": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":42,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":47,\\\"col_stop\\\":53,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":54,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":57,\\\"col_stop\\\":58,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "op": "Mul" - } - } - } - } - ] - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"numerator\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":13,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" - } - ], - "type_": null, - "value": { - "Binary": { - "left": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":26,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":39,\\\"col_stop\\\":45,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" - }, - "op": "Mul" - } - }, - "right": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":50,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":58,\\\"col_stop\\\":63,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" - }, - "op": "Mul" - } - }, - "op": "Sub" - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"denominator\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":13,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Binary": { - "left": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":28,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":41,\\\"col_stop\\\":47,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" - }, - "op": "Mul" - } - }, - "right": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":52,\\\"col_stop\\\":57,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":60,\\\"col_stop\\\":65,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" - }, - "op": "Mul" - } - }, - "op": "Sub" - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"numerator\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":21,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"denominator\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":33,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" - }, - "op": "Div" - } - } - } - }, - { - "Return": { - "expression": { - "Identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":16,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return slope;\\\"}\"}" - } - } - } - ] - } - } - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":14,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}", - "input": [ - { - "SelfKeyword": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":21,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}" - }, - { - "Variable": { - "identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "IntegerType": "I32" - } - } - } - ], - "output": { - "IntegerType": "I32" - }, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":40,\\\"line_stop\\\":40,\\\"col_start\\\":13,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let num_points = 5i32; \\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "5" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":42,\\\"line_stop\\\":42,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x_sum = 0i32;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":43,\\\"line_stop\\\":43,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y_sum = 0i32;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "I32", - "0" - ] - } - } - } - }, - { - "Iteration": { - "variable": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":44,\\\"line_stop\\\":44,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..5 {\\\"}\"}", - "start": { - "Value": { - "Implicit": "0" - } - }, - "stop": { - "Value": { - "Implicit": "5" - } - }, - "inclusive": false, - "block": { - "statements": [ - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "accesses": [] - }, - "value": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" - } - } - }, - "name": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}", - "type_": null - } - } - } - }, - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}", - "accesses": [] - }, - "value": { - "CircuitMemberAccess": { - "circuit": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" - }, - "name": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" - } - } - }, - "name": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}", - "type_": null - } - } - } - } - ] - } - } - }, - { - "Return": { - "expression": { - "Binary": { - "left": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":17,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" - }, - "right": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":25,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":33,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" - }, - "op": "Mul" - } - }, - "op": "Sub" - } - }, - "right": { - "Identifier": "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":42,\\\"col_stop\\\":52,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" - }, - "op": "Div" - } - } - } - } - ] - } - } - } - ] - } - }, - "global_consts": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "IntegerType": "I32" - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":24,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "IntegerType": "I32" - } - } - } - ], - "output": { - "Array": [ - { - "IntegerType": "I32" - }, - [ - { - "value": "2" - } - ] - ] - }, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":7,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let points: [Point; 5] = [\\\"}\"}" - } - ], - "type_": { - "Array": [ - { - "Identifier": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":16,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let points: [Point; 5] = [\\\"}\"}" - }, - [ - { - "value": "5" - } - ] - ] - }, - "value": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "CircuitInit": { - "name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Add" - } - } - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Add" - } - } - } - ] - } - } - }, - { - "Expression": { - "CircuitInit": { - "name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "2" - } - }, - "op": "Add" - } - } - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "2" - } - }, - "op": "Add" - } - } - } - ] - } - } - }, - { - "Expression": { - "CircuitInit": { - "name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "3" - } - }, - "op": "Add" - } - } - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "3" - } - }, - "op": "Add" - } - } - } - ] - } - } - }, - { - "Expression": { - "CircuitInit": { - "name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "4" - } - }, - "op": "Add" - } - } - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "4" - } - }, - "op": "Add" - } - } - } - ] - } - } - }, - { - "Expression": { - "CircuitInit": { - "name": "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "5" - } - }, - "op": "Add" - } - } - }, - { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}", - "expression": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "5" - } - }, - "op": "Add" - } - } - } - ] - } - } - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "CircuitStaticFunctionAccess": { - "circuit": { - "Identifier": "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":13,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" - }, - "name": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":31,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" - } - }, - "arguments": [ - { - "Identifier": "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":35,\\\"col_stop\\\":41,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":15,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}" - }, - "name": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":19,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}", - "type_": null - } - }, - "arguments": [] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":7,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":16,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" - }, - "name": "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":20,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}", - "type_": null - } - }, - "arguments": [ - { - "Identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" - } - ] - } - } - } - }, - { - "Return": { - "expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Identifier": "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":11,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return [slope, offset];\\\"}\"}" - } - }, - { - "Expression": { - "Identifier": "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return [slope, offset];\\\"}\"}" - } - } - ] - } - } - } - } - ] - } - } - } -} \ No newline at end of file diff --git a/parser/tests/serialization/expected_leo_ast/one_plus_one.json b/parser/tests/serialization/expected_leo_ast/one_plus_one.json deleted file mode 100644 index 5865517126..0000000000 --- a/parser/tests/serialization/expected_leo_ast/one_plus_one.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "", - "expected_input": [], - "import_statements": [], - "imports": {}, - "aliases": {}, - "circuits": {}, - "global_consts": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}", - "input": [], - "output": { - "IntegerType": "U8" - }, - "block": { - "statements": [ - { - "Return": { - "expression": { - "Binary": { - "left": { - "Value": { - "Integer": [ - "U8", - "1", - { - "span" : { - "line_start": 2, - "line_stop": 2, - "col_start": 12, - "col_stop": 15, - "path": "", - "content": " return 1u8 + 1u8;" - } - } - ] - } - }, - "right": { - "Value": { - "Integer": [ - "U8", - "1", - { - "span": { - "line_start": 2, - "line_stop": 2, - "col_start": 18, - "col_stop": 21, - "path": "", - "content": " return 1u8 + 1u8;" - } - } - ] - } - }, - "op": "Add", - "span": { - "line_start": 2, - "line_stop": 2, - "col_start": 12, - "col_stop": 21, - "path": "", - "content": " return 1u8 + 1u8;" - } - } - }, - "span": { - "line_start": 2, - "line_stop": 2, - "col_start": 5, - "col_stop": 21, - "path": "", - "content": " return 1u8 + 1u8;" - } - } - } - ], - "span": { - "line_start": 1, - "line_stop": 3, - "col_start": 23, - "col_stop": 2, - "path": "", - "content": "function main() -> u8 {\n ...\n}" - } - }, - "span": { - "line_start": 1, - "line_stop": 3, - "col_start": 1, - "col_stop": 2, - "path": "", - "content": "function main() -> u8 {\n ...\n}" - } - } - } -} \ No newline at end of file diff --git a/parser/tests/serialization/expected_leo_ast/palindrome.json b/parser/tests/serialization/expected_leo_ast/palindrome.json deleted file mode 100644 index 32c7313219..0000000000 --- a/parser/tests/serialization/expected_leo_ast/palindrome.json +++ /dev/null @@ -1,1189 +0,0 @@ -{ - "name": "", - "expected_input": [], - "import_statements": [], - "imports": {}, - "aliases": {}, - "circuits": {}, - "global_consts": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":15,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - "Char", - [ - { - "value": "20" - } - ] - ] - } - } - } - ], - "output": "Boolean", - "block": { - "statements": [ - { - "Return": { - "expression": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":12,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return is_palindrome(str);\\\"}\"}" - }, - "arguments": [ - { - "Identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":26,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return is_palindrome(str);\\\"}\"}" - } - ] - } - } - } - } - ] - } - }, - "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":10,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":10,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - "Char", - [ - { - "value": "20" - } - ] - ] - } - } - } - ], - "output": "Boolean", - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Const", - "variable_names": [ - { - "mutable": false, - "identifier": "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":11,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const str_len = 20u32; // saving const for convenience\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "U32", - "20" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = true;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Boolean": "true" - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":9,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let processed = 0u8;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "U8", - "0" - ] - } - } - } - }, - { - "Iteration": { - "variable": "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for start in 0..(str_len / 2) {\\\"}\"}", - "start": { - "Value": { - "Implicit": "0" - } - }, - "stop": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":22,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for start in 0..(str_len / 2) {\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "2" - } - }, - "op": "Div" - } - }, - "inclusive": false, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":13,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" - } - ], - "type_": null, - "value": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":25,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" - }, - "index": { - "Identifier": "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":29,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" - } - } - } - } - }, - { - "Conditional": { - "condition": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":12,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if start_sym != ' ' {\\\"}\"}" - }, - "right": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - }, - "op": "Ne" - } - }, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":17,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let skipped = 0u8;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "U8", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":17,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let end_empty = 0u8;\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Integer": [ - "U8", - "0" - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":17,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let end_sym = ' ';\\\"}\"}" - } - ], - "type_": null, - "value": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - } - } - }, - { - "Iteration": { - "variable": "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":17,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}", - "start": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":25,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Sub" - } - }, - "stop": { - "Identifier": "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":39,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}" - }, - "inclusive": false, - "block": { - "statements": [ - { - "Conditional": { - "condition": { - "Binary": { - "left": { - "Binary": { - "left": { - "Binary": { - "left": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":20,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" - }, - "index": { - "Identifier": "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" - } - } - }, - "right": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - }, - "op": "Ne" - } - }, - "right": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":39,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":50,\\\"col_stop\\\":59,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" - }, - "op": "Eq" - } - }, - "op": "And" - } - }, - "right": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":63,\\\"col_stop\\\":70,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" - }, - "right": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - }, - "op": "Eq" - } - }, - "op": "And" - } - }, - "block": { - "statements": [ - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":21,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}", - "accesses": [] - }, - "value": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":31,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}" - }, - "index": { - "Identifier": "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":35,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}" - } - } - } - } - } - ] - }, - "next": { - "Block": { - "statements": [ - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":21,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_empty = end_empty + 1;\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":33,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_empty = end_empty + 1;\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Add" - } - } - } - }, - { - "Conditional": { - "condition": { - "Binary": { - "left": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' {\\\"}\"}" - }, - "index": { - "Identifier": "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":28,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' {\\\"}\"}" - } - } - }, - "right": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - }, - "op": "Ne" - } - }, - "block": { - "statements": [ - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":25,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" skipped = skipped + 1;\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":35,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" skipped = skipped + 1;\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Add" - } - } - } - } - ] - }, - "next": null - } - } - ] - } - } - } - } - ] - } - } - }, - { - "Conditional": { - "condition": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":16,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if end_sym != ' ' {\\\"}\"}" - }, - "right": { - "Value": { - "Char": { - "character": { - "Scalar": 32 - } - } - } - }, - "op": "Ne" - } - }, - "block": { - "statements": [ - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 67 - }, - { - "Scalar": 111 - }, - { - "Scalar": 109 - }, - { - "Scalar": 112 - }, - { - "Scalar": 97 - }, - { - "Scalar": 114 - }, - { - "Scalar": 105 - }, - { - "Scalar": 110 - }, - { - "Scalar": 103 - }, - { - "Scalar": 58 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - }, - { - "Scalar": 32 - }, - { - "Scalar": 63 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":51,\\\"col_stop\\\":60,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Comparing: {} ? {}\\\\\\\", start_sym, end_sym);\\\"}\"}" - }, - { - "Identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":62,\\\"col_stop\\\":69,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Comparing: {} ? {}\\\\\\\", start_sym, end_sym);\\\"}\"}" - } - ] - } - } - } - }, - { - "Conditional": { - "condition": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":20,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if result {\\\"}\"}" - }, - "block": { - "statements": [ - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":38,\\\"line_stop\\\":38,\\\"col_start\\\":21,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":38,\\\"line_stop\\\":38,\\\"col_start\\\":31,\\\"col_stop\\\":40,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":38,\\\"line_stop\\\":38,\\\"col_start\\\":44,\\\"col_stop\\\":51,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}" - }, - "op": "Eq" - } - } - } - } - ] - }, - "next": null - } - }, - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":17,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" processed = processed + 1;\\\"}\"}", - "accesses": [] - }, - "value": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":29,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" processed = processed + 1;\\\"}\"}" - }, - "right": { - "Value": { - "Implicit": "1" - } - }, - "op": "Add" - } - } - } - } - ] - }, - "next": null - } - } - ] - }, - "next": null - } - } - ] - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 82 - }, - { - "Scalar": 101 - }, - { - "Scalar": 115 - }, - { - "Scalar": 117 - }, - { - "Scalar": 108 - }, - { - "Scalar": 116 - }, - { - "Scalar": 32 - }, - { - "Scalar": 105 - }, - { - "Scalar": 115 - }, - { - "Scalar": 58 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":34,\\\"col_stop\\\":40,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Result is: {}\\\\\\\", result);\\\"}\"}" - } - ] - } - } - } - }, - { - "Return": { - "expression": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":12,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return result;\\\"}\"}" - } - } - } - ] - } - }, - "{\"name\":\"test_is_palindrome\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":10,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_is_palindrome() {\\\"}\"}": { - "annotations": [ - { - "arguments": [], - "name": "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":51,\\\"line_stop\\\":51,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" - } - ], - "identifier": "{\"name\":\"test_is_palindrome\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":10,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_is_palindrome() {\\\"}\"}", - "input": [], - "output": null, - "block": { - "statements": [ - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"a b a \\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 97 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 98 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 97 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - } - ] - } - } - ] - } - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"😀😀😀😀😀 😀😀😀😀😀\\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - }, - { - "Scalar": 128512 - } - ] - } - } - ] - } - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"borrow or rob \\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 98 - }, - { - "Scalar": 111 - }, - { - "Scalar": 114 - }, - { - "Scalar": 114 - }, - { - "Scalar": 111 - }, - { - "Scalar": 119 - }, - { - "Scalar": 32 - }, - { - "Scalar": 111 - }, - { - "Scalar": 114 - }, - { - "Scalar": 32 - }, - { - "Scalar": 114 - }, - { - "Scalar": 111 - }, - { - "Scalar": 98 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - } - ] - } - } - ] - } - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"bbbb aaaa aaaa bbbb\\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 98 - }, - { - "Scalar": 98 - }, - { - "Scalar": 98 - }, - { - "Scalar": 98 - }, - { - "Scalar": 32 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 32 - }, - { - "Scalar": 98 - }, - { - "Scalar": 98 - }, - { - "Scalar": 98 - }, - { - "Scalar": 98 - } - ] - } - } - ] - } - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"aaaaaaaaaaaaaaaaaaaa\\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - }, - { - "Scalar": 97 - } - ] - } - } - ] - } - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Call": { - "function": { - "Identifier": "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"taco cat \\\\\\\"));\\\"}\"}" - }, - "arguments": [ - { - "Value": { - "String": [ - { - "Scalar": 116 - }, - { - "Scalar": 97 - }, - { - "Scalar": 99 - }, - { - "Scalar": 111 - }, - { - "Scalar": 32 - }, - { - "Scalar": 99 - }, - { - "Scalar": 97 - }, - { - "Scalar": 116 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - }, - { - "Scalar": 32 - } - ] - } - } - ] - } - } - } - } - } - ] - } - } - } -} \ No newline at end of file diff --git a/parser/tests/serialization/expected_leo_ast/pedersen_hash.json b/parser/tests/serialization/expected_leo_ast/pedersen_hash.json deleted file mode 100644 index a74e50f4e9..0000000000 --- a/parser/tests/serialization/expected_leo_ast/pedersen_hash.json +++ /dev/null @@ -1,299 +0,0 @@ -{ - "name": "", - "expected_input": [], - "import_statements": [], - "imports": {}, - "aliases": {}, - "circuits": { - "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit PedersenHash {\\\"}\"}": { - "circuit_name": "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit PedersenHash {\\\"}\"}", - "core_mapping": null, - "members": [ - { - "CircuitVariable": [ - "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":5,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" parameters: [group; 256];\\\"}\"}", - { - "Array": [ - "Group", - [ - { - "value": "256" - } - ] - ] - } - ] - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(parameters: [group; 256]) -> Self {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":18,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(parameters: [group; 256]) -> Self {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - "Group", - [ - { - "value": "256" - } - ] - ] - } - } - } - ], - "output": "SelfType", - "block": { - "statements": [ - { - "Return": { - "expression": { - "CircuitInit": { - "name": "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":23,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}", - "expression": { - "Identifier": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":35,\\\"col_stop\\\":45,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}" - } - } - ] - } - } - } - } - ] - } - } - }, - { - "CircuitFunction": { - "annotations": [], - "identifier": "{\"name\":\"hash\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":14,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}", - "input": [ - { - "SelfKeyword": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":19,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}" - }, - { - "Variable": { - "identifier": "{\"name\":\"bits\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":25,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - "Boolean", - [ - { - "value": "256" - } - ] - ] - } - } - } - ], - "output": "Group", - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let digest: group = 0group;\\\"}\"}" - } - ], - "type_": "Group", - "value": { - "Value": { - "Group": { - "Single": "0" - } - } - } - } - }, - { - "Iteration": { - "variable": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..256 {\\\"}\"}", - "start": { - "Value": { - "Implicit": "0" - } - }, - "stop": { - "Value": { - "Implicit": "256" - } - }, - "inclusive": false, - "block": { - "statements": [ - { - "Conditional": { - "condition": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"bits\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if bits[i] {\\\"}\"}" - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if bits[i] {\\\"}\"}" - } - } - }, - "block": { - "statements": [ - { - "Assign": { - "operation": "Add", - "assignee": { - "identifier": "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":17,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}", - "accesses": [] - }, - "value": { - "ArrayAccess": { - "array": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":27,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" - }, - "name": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":32,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}", - "type_": null - } - }, - "index": { - "Identifier": "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":43,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" - } - } - } - } - } - ] - }, - "next": null - } - } - ] - } - } - }, - { - "Return": { - "expression": { - "Identifier": "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":16,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return digest;\\\"}\"}" - } - } - } - ] - } - } - } - ] - } - }, - "global_consts": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"hash_input\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":15,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - "Boolean", - [ - { - "value": "256" - } - ] - ] - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":46,\\\"col_stop\\\":56,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}", - "const_": true, - "mutable": false, - "type_": { - "Array": [ - "Group", - [ - { - "value": "256" - } - ] - ] - } - } - } - ], - "output": "Group", - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Const", - "variable_names": [ - { - "mutable": false, - "identifier": "{\"name\":\"pedersen\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":11,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "CircuitStaticFunctionAccess": { - "circuit": { - "Identifier": "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":22,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" - }, - "name": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":36,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" - } - }, - "arguments": [ - { - "Identifier": "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":40,\\\"col_stop\\\":50,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" - } - ] - } - } - } - }, - { - "Return": { - "expression": { - "Call": { - "function": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"pedersen\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":12,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}" - }, - "name": "{\"name\":\"hash\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":21,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}", - "type_": null - } - }, - "arguments": [ - { - "Identifier": "{\"name\":\"hash_input\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":26,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}" - } - ] - } - } - } - } - ] - } - } - } -} \ No newline at end of file diff --git a/parser/tests/serialization/expected_leo_ast/silly_sudoku.json b/parser/tests/serialization/expected_leo_ast/silly_sudoku.json deleted file mode 100644 index 167a3faddb..0000000000 --- a/parser/tests/serialization/expected_leo_ast/silly_sudoku.json +++ /dev/null @@ -1,1209 +0,0 @@ -{ - "name": "", - "expected_input": [], - "import_statements": [ - { - "package_or_packages": { - "Package": { - "name": "{\"name\":\"lib\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"import lib.SillySudoku;\\\"}\"}", - "access": { - "Symbol": { - "symbol": "{\"name\":\"SillySudoku\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":12,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"import lib.SillySudoku;\\\"}\"}", - "alias": null - } - } - } - } - } - ], - "imports": {}, - "aliases": {}, - "circuits": {}, - "global_consts": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}": { - "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":15,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":37,\\\"col_stop\\\":43,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - } - } - } - ], - "output": "Boolean", - "block": { - "statements": [ - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 83 - }, - { - "Scalar": 116 - }, - { - "Scalar": 97 - }, - { - "Scalar": 114 - }, - { - "Scalar": 116 - }, - { - "Scalar": 105 - }, - { - "Scalar": 110 - }, - { - "Scalar": 103 - }, - { - "Scalar": 32 - }, - { - "Scalar": 83 - }, - { - "Scalar": 117 - }, - { - "Scalar": 100 - }, - { - "Scalar": 111 - }, - { - "Scalar": 107 - }, - { - "Scalar": 117 - }, - { - "Scalar": 32 - }, - { - "Scalar": 115 - }, - { - "Scalar": 111 - }, - { - "Scalar": 108 - }, - { - "Scalar": 118 - }, - { - "Scalar": 101 - }, - { - "Scalar": 114 - }, - { - "Scalar": 46 - }, - { - "Scalar": 46 - }, - { - "Scalar": 46 - } - ], - "parameters": [] - } - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 123 - }, - { - "Scalar": 125 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"{}\\\\\\\", puzzle);\\\"}\"}" - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"sudoku\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" - } - ], - "type_": null, - "value": { - "CircuitInit": { - "name": "{\"name\":\"SillySudoku\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":18,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}", - "members": [ - { - "identifier": "{\"name\":\"puzzle_grid\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":32,\\\"col_stop\\\":43,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}", - "expression": { - "Identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":45,\\\"col_stop\\\":51,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" - } - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 67 - }, - { - "Scalar": 104 - }, - { - "Scalar": 101 - }, - { - "Scalar": 99 - }, - { - "Scalar": 107 - }, - { - "Scalar": 105 - }, - { - "Scalar": 110 - }, - { - "Scalar": 103 - }, - { - "Scalar": 32 - }, - { - "Scalar": 83 - }, - { - "Scalar": 117 - }, - { - "Scalar": 100 - }, - { - "Scalar": 111 - }, - { - "Scalar": 107 - }, - { - "Scalar": 117 - }, - { - "Scalar": 32 - }, - { - "Scalar": 97 - }, - { - "Scalar": 110 - }, - { - "Scalar": 115 - }, - { - "Scalar": 119 - }, - { - "Scalar": 101 - }, - { - "Scalar": 114 - }, - { - "Scalar": 46 - }, - { - "Scalar": 46 - }, - { - "Scalar": 46 - } - ], - "parameters": [] - } - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 123 - }, - { - "Scalar": 125 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"{}\\\\\\\", answer);\\\"}\"}" - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "CircuitMemberAccess": { - "circuit": { - "Identifier": "{\"name\":\"sudoku\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" - }, - "name": "{\"name\":\"solve\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":25,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}", - "type_": null - } - }, - "arguments": [ - { - "Identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 84 - }, - { - "Scalar": 104 - }, - { - "Scalar": 101 - }, - { - "Scalar": 32 - }, - { - "Scalar": 97 - }, - { - "Scalar": 110 - }, - { - "Scalar": 115 - }, - { - "Scalar": 119 - }, - { - "Scalar": 101 - }, - { - "Scalar": 114 - }, - { - "Scalar": 32 - }, - { - "Scalar": 105 - }, - { - "Scalar": 115 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - }, - { - "Scalar": 46 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":38,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"The answer is {}.\\\\\\\", result);\\\"}\"}" - } - ] - } - } - } - }, - { - "Return": { - "expression": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":12,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return result;\\\"}\"}" - } - } - } - ] - } - }, - "{\"name\":\"test_solve_pass\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_pass() {\\\"}\"}": { - "annotations": [ - { - "arguments": [], - "name": "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" - } - ], - "identifier": "{\"name\":\"test_solve_pass\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_pass() {\\\"}\"}", - "input": [], - "output": null, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let puzzle: [u8; (3, 3)] = [[0, 2, 0],\\\"}\"}" - } - ], - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - }, - "value": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "2" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "6" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "8" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "9" - } - } - } - ] - } - } - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let answer: [u8; (3, 3)] = [[1, 2, 3],\\\"}\"}" - } - ], - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - }, - "value": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "1" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "2" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "3" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "4" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "5" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "6" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "7" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "8" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "9" - } - } - } - ] - } - } - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "Identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - "arguments": [ - { - "Identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - { - "Identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Binary": { - "left": { - "Value": { - "Boolean": "true" - } - }, - "right": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(true == result);\\\"}\"}" - }, - "op": "Eq" - } - } - } - } - } - ] - } - }, - "{\"name\":\"test_solve_fail\",\"span\":\"{\\\"line_start\\\":42,\\\"line_stop\\\":42,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_fail() {\\\"}\"}": { - "annotations": [ - { - "arguments": [], - "name": "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" - } - ], - "identifier": "{\"name\":\"test_solve_fail\",\"span\":\"{\\\"line_start\\\":42,\\\"line_stop\\\":42,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_fail() {\\\"}\"}", - "input": [], - "output": null, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":43,\\\"line_stop\\\":43,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let puzzle: [u8; (3, 3)] = [[0, 2, 0],\\\"}\"}" - } - ], - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - }, - "value": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "2" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "6" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "8" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "0" - } - } - } - ] - } - } - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let answer: [u8; (3, 3)] = [[1, 2, 3],\\\"}\"}" - } - ], - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - }, - "value": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "1" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "2" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "3" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "4" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "5" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "6" - } - } - } - ] - } - } - }, - { - "Expression": { - "ArrayInline": { - "elements": [ - { - "Expression": { - "Value": { - "Implicit": "7" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "8" - } - } - }, - { - "Expression": { - "Value": { - "Implicit": "8" - } - } - } - ] - } - } - } - ] - } - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "Identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - "arguments": [ - { - "Identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - { - "Identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":52,\\\"line_stop\\\":52,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Binary": { - "left": { - "Value": { - "Boolean": "false" - } - }, - "right": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":29,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(false == result);\\\"}\"}" - }, - "op": "Eq" - } - } - } - } - } - ] - } - }, - "{\"name\":\"test_solve_with_input\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":10,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_with_input(\\\"}\"}": { - "annotations": [ - { - "arguments": [ - "test_input" - ], - "name": "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test(test_input)\\\"}\"}" - } - ], - "identifier": "{\"name\":\"test_solve_with_input\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":10,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_with_input(\\\"}\"}", - "input": [ - { - "Variable": { - "identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" puzzle: [u8; (3, 3)],\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" answer: [u8; (3, 3)],\\\"}\"}", - "const_": false, - "mutable": true, - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "3" - }, - { - "value": "3" - } - ] - ] - } - } - }, - { - "Variable": { - "identifier": "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":5,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" expected: bool\\\"}\"}", - "const_": false, - "mutable": true, - "type_": "Boolean" - } - } - ], - "output": null, - "block": { - "statements": [ - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ], - "type_": null, - "value": { - "Call": { - "function": { - "Identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - "arguments": [ - { - "Identifier": "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - }, - { - "Identifier": "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Log": { - "string": [ - { - "Scalar": 101 - }, - { - "Scalar": 120 - }, - { - "Scalar": 112 - }, - { - "Scalar": 101 - }, - { - "Scalar": 99 - }, - { - "Scalar": 116 - }, - { - "Scalar": 101 - }, - { - "Scalar": 100 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - }, - { - "Scalar": 44 - }, - { - "Scalar": 32 - }, - { - "Scalar": 103 - }, - { - "Scalar": 111 - }, - { - "Scalar": 116 - }, - { - "Scalar": 32 - }, - { - "Scalar": 123 - }, - { - "Scalar": 125 - } - ], - "parameters": [ - { - "Identifier": "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":40,\\\"col_stop\\\":48,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"expected {}, got {}\\\\\\\", expected, result);\\\"}\"}" - }, - { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":50,\\\"col_stop\\\":56,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"expected {}, got {}\\\\\\\", expected, result);\\\"}\"}" - } - ] - } - } - } - }, - { - "Console": { - "function": { - "Assert": { - "Binary": { - "left": { - "Identifier": "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":70,\\\"line_stop\\\":70,\\\"col_start\\\":20,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(expected == result);\\\"}\"}" - }, - "right": { - "Identifier": "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":70,\\\"line_stop\\\":70,\\\"col_start\\\":32,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(expected == result);\\\"}\"}" - }, - "op": "Eq" - } - } - } - } - } - ] - } - } - } -} \ No newline at end of file diff --git a/parser/tests/serialization/json.rs b/parser/tests/serialization/json.rs index 0d95bd699a..b0fcd85eef 100644 --- a/parser/tests/serialization/json.rs +++ b/parser/tests/serialization/json.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. +// Copyright (C) 2019-2022 Aleo Systems Inc. // This file is part of the Leo library. // The Leo library is free software: you can redistribute it and/or modify @@ -17,7 +17,7 @@ use leo_ast::Ast; #[cfg(not(feature = "ci_skip"))] use leo_ast::Program; -use leo_errors::{LeoError, Result}; +use leo_errors::{emitter::Handler, LeoError, Result}; use std::fs::File; use std::io::BufReader; @@ -28,7 +28,7 @@ fn to_ast(program_filepath: &Path) -> Result { let program_string = std::fs::read_to_string(program_filepath).expect("failed to open test"); // Parses the Leo file and constructs a leo ast. - leo_parser::parse_ast("", &program_string) + leo_parser::parse_ast(&Handler::default(), "", &program_string) } fn setup() { diff --git a/parser/tests/serialization/leo/deprecated_error.leo b/parser/tests/serialization/leo/deprecated_error.leo deleted file mode 100644 index d1ce342312..0000000000 --- a/parser/tests/serialization/leo/deprecated_error.leo +++ /dev/null @@ -1,7 +0,0 @@ -function main() { - return 1 + 1; -} - -test function old { - console.log("old"); -} \ No newline at end of file diff --git a/parser/tests/serialization/leo/linear_regression.leo b/parser/tests/serialization/leo/linear_regression.leo deleted file mode 100644 index 51dc4dd908..0000000000 --- a/parser/tests/serialization/leo/linear_regression.leo +++ /dev/null @@ -1,65 +0,0 @@ -circuit Point { - x: i32, - y: i32, - - function new(x: i32, y: i32) -> Self { - return Self { x, y }; - } -} - -circuit LinearRegression { - points: [Point; 5], - - // Instantiates a linear regression circuit. - function new(points: [Point; 5]) -> Self { - return Self { points }; - } - - // Return the slope of the linear regression. - function slope(self) -> i32 { - - let num_points = 5i32; - // Calculate the sums. - let x_sum = 0i32; - let y_sum = 0i32; - let xy_sum = 0i32; - let x2_sum = 0i32; - for i in 0..5 { - x_sum += self.points[i].x; - y_sum += self.points[i].y; - xy_sum += self.points[i].x * self.points[i].y; - x2_sum += self.points[i].x * self.points[i].x; - } - let numerator = (num_points * xy_sum) - (x_sum * y_sum); - let denominator = (num_points * x2_sum) - (x_sum * x_sum); - let slope = numerator / denominator; - return slope; - } - // Return the offset of the linear regression. - function offset(self, slope: i32) -> i32 { - let num_points = 5i32; - // Calculate the sum. - let x_sum = 0i32; - let y_sum = 0i32; - for i in 0..5 { - x_sum += self.points[i].x; - y_sum += self.points[i].y; - } - return (y_sum - slope * x_sum) / num_points; - } -} - - -function main (x: i32, y: i32) -> [i32; 2] { - let points: [Point; 5] = [ - Point{x: x + 1, y: y + 1}, - Point{x: x + 2, y: y + 2}, - Point{x: x + 3, y: y + 3}, - Point{x: x + 4, y: y + 4}, - Point{x: x + 5, y: y + 5} - ]; - let reg = LinearRegression::new(points); - let slope = reg.slope(); - let offset = reg.offset(slope); - return [slope, offset]; -} diff --git a/parser/tests/serialization/leo/one_plus_one.leo b/parser/tests/serialization/leo/one_plus_one.leo deleted file mode 100644 index 8e4fdc5a44..0000000000 --- a/parser/tests/serialization/leo/one_plus_one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() -> u8 { - return 1u8 + 1u8; -} diff --git a/parser/tests/serialization/leo/palindrome.leo b/parser/tests/serialization/leo/palindrome.leo deleted file mode 100644 index f2b1872733..0000000000 --- a/parser/tests/serialization/leo/palindrome.leo +++ /dev/null @@ -1,59 +0,0 @@ -// This Program takes in any 20-byte low register string and tells -// whether a string is a palindrome ignoring any spaces. - -function main(str: [char; 20]) -> bool { - return is_palindrome(str); -} - -function is_palindrome(str: [char; 20]) -> bool { - const str_len = 20u32; // saving const for convenience - - // By default we assume that input is a palindrome. - let result = true; - let processed = 0u8; - - for start in 0..(str_len / 2) { - let start_sym = str[start]; - if start_sym != ' ' { - let skipped = 0u8; - let end_empty = 0u8; - let end_sym = ' '; - - for end in (str_len - 1)..start { - if str[end] != ' ' && skipped == processed && end_sym == ' ' { - end_sym = str[end]; - } else { - end_empty = end_empty + 1; - if str[end] != ' ' { - skipped = skipped + 1; - } - } - } - - // If there are symbols left to the right from the start. - if end_sym != ' ' { - console.log("Comparing: {} ? {}", start_sym, end_sym); - - if result { - result = (start_sym == end_sym); - } - - processed = processed + 1; - } - } - } - - console.log("Result is: {}", result); - - return result; -} - -@test -function test_is_palindrome() { - console.assert(is_palindrome("a b a ")); - console.assert(is_palindrome("😀😀😀😀😀 😀😀😀😀😀")); - console.assert(is_palindrome("borrow or rob ")); - console.assert(is_palindrome("bbbb aaaa aaaa bbbb")); - console.assert(is_palindrome("aaaaaaaaaaaaaaaaaaaa")); - console.assert(is_palindrome("taco cat ")); -} diff --git a/parser/tests/serialization/leo/parser_error.leo b/parser/tests/serialization/leo/parser_error.leo deleted file mode 100644 index e466dcbd8e..0000000000 --- a/parser/tests/serialization/leo/parser_error.leo +++ /dev/null @@ -1 +0,0 @@ -invalid \ No newline at end of file diff --git a/parser/tests/serialization/leo/pedersen_hash.leo b/parser/tests/serialization/leo/pedersen_hash.leo deleted file mode 100644 index ab6474c4e4..0000000000 --- a/parser/tests/serialization/leo/pedersen_hash.leo +++ /dev/null @@ -1,25 +0,0 @@ -circuit PedersenHash { - parameters: [group; 256]; - - // Instantiates a Pedersen hash circuit - function new(parameters: [group; 256]) -> Self { - return Self { parameters: parameters }; - } - - function hash(self, bits: [bool; 256]) -> group { - let digest: group = 0group; - for i in 0..256 { - if bits[i] { - digest += self.parameters[i]; - } - } - return digest; - } -} - -// The 'pedersen-hash' main function. -function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group { - const pedersen = PedersenHash::new(parameters); - return pedersen.hash(hash_input); -} - diff --git a/parser/tests/serialization/leo/silly_sudoku.leo b/parser/tests/serialization/leo/silly_sudoku.leo deleted file mode 100644 index 856bd8892a..0000000000 --- a/parser/tests/serialization/leo/silly_sudoku.leo +++ /dev/null @@ -1,71 +0,0 @@ -import lib.SillySudoku; - -// The `silly-sudoku` main function -function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool { - console.log("Starting Sudoku solver..."); - console.log("{}", puzzle); - - // Instantiate the Sudoku puzzle. - let sudoku = SillySudoku { puzzle_grid: puzzle }; - - console.log("Checking Sudoku answer..."); - console.log("{}", answer); - - // Evaluate the Sudoku puzzle with the given answer. - let result = sudoku.solve(answer); - - console.log("The answer is {}.", result); - - return result; -} - -// Tests that the `silly-sudoku` circuit outputs true on a correct answer. -@test -function test_solve_pass() { - let puzzle: [u8; (3, 3)] = [[0, 2, 0], - [0, 0, 6], - [0, 8, 9]]; - - let answer: [u8; (3, 3)] = [[1, 2, 3], - [4, 5, 6], - [7, 8, 9]]; - - // Runs the Sudoku checker. - let result = main(puzzle, answer); - - // Expects the result to be true. - console.assert(true == result); -} - -// Tests that the `silly-sudoku` circuit outputs false on an incorrect answer. -@test -function test_solve_fail() { - let puzzle: [u8; (3, 3)] = [[0, 2, 0], - [0, 0, 6], - [0, 8, 0]]; - - let answer: [u8; (3, 3)] = [[1, 2, 3], - [4, 5, 6], - [7, 8, 8]]; // We have an extra `8` in this column! - - // Runs the Sudoku checker. - let result = main(puzzle, answer); - - // Expects the result to be false. - console.assert(false == result); -} - -// Test that the `silly-sudoku` circuit outputs the expected value on a custom test input. -@test(test_input) -function test_solve_with_input( - puzzle: [u8; (3, 3)], - answer: [u8; (3, 3)], - expected: bool -) { - // Runs the Sudoku checker. - let result = main(puzzle, answer); - - console.log("expected {}, got {}", expected, result); - - console.assert(expected == result); -} diff --git a/parser/tests/serialization/mod.rs b/parser/tests/serialization/mod.rs deleted file mode 100644 index 5096607ede..0000000000 --- a/parser/tests/serialization/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -mod json; From 0a525fc04f5afe24fd4c4d51252ae8f1a61416ee Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 21 Jan 2022 12:44:41 -0800 Subject: [PATCH 02/14] clean up commented out code --- parser/src/parser/context.rs | 16 ------- parser/src/parser/expression.rs | 85 --------------------------------- parser/src/parser/statement.rs | 18 ------- parser/src/tokenizer/lexer.rs | 43 ----------------- parser/src/tokenizer/mod.rs | 19 -------- parser/src/tokenizer/token.rs | 34 ------------- 6 files changed, 215 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index c125e2a591..d0949a74b6 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -108,22 +108,6 @@ impl<'a> ParserContext<'a> { .unwrap_or_else(|| Cow::Owned(Token::Eof)) } - // pub fn peek_oneof(&self, token: &[Token]) -> Result<&SpannedToken> { - // if let Some(spanned_token) = self.inner.last() { - // if token.iter().any(|x| x == &spanned_token.token) { - // Ok(spanned_token) - // } else { - // Err(SyntaxError::unexpected( - // &spanned_token.token, - // token, - // &spanned_token.span, - // )) - // } - // } else { - // Err(self.eof()) - // } - // } - /// /// Returns true if the next token exists. /// diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 0eec288b80..821ac3d71b 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -123,66 +123,6 @@ impl ParserContext<'_> { self.parse_bin_expr(Token::And, BinaryOperation::And, Self::parse_equality_expression) } - /// - /// Returns an [`Expression`] AST node if the next tokens represent a - /// binary bitwise or expression. - /// - /// Otherwise, tries to parse the next token using [`parse_bit_xor_expression`]. - /// - // pub fn parse_bit_or_expression(&mut self) -> Result { - // let mut expr = self.parse_bit_xor_expression()?; - // while self.eat(Token::BitOr).is_some() { - // let right = self.parse_bit_xor_expression()?; - // expr = Expression::Binary(BinaryExpression { - // span: expr.span() + right.span(), - // op: BinaryOperation::BitOr, - // left: Box::new(expr), - // right: Box::new(right), - // }) - // } - // Ok(expr) - // } - - /// - /// Returns an [`Expression`] AST node if the next tokens represent a - /// binary bitwise xor expression. - /// - /// Otherwise, tries to parse the next token using [`parse_bit_and_expression`]. - /// - // pub fn parse_bit_xor_expression(&mut self) -> Result { - // let mut expr = self.parse_bit_and_expression()?; - // while self.eat(Token::BitXor).is_some() { - // let right = self.parse_bit_and_expression()?; - // expr = Expression::Binary(BinaryExpression { - // span: expr.span() + right.span(), - // op: BinaryOperation::BitXor, - // left: Box::new(expr), - // right: Box::new(right), - // }) - // } - // Ok(expr) - // } - - /// - /// Returns an [`Expression`] AST node if the next tokens represent a - /// binary bitwise and expression. - /// - /// Otherwise, tries to parse the next token using [`parse_equality_expression`]. - /// - // pub fn parse_bit_and_expression(&mut self) -> Result { - // let mut expr = self.parse_equality_expression()?; - // while self.eat(Token::Ampersand).is_some() { - // let right = self.parse_equality_expression()?; - // expr = Expression::Binary(BinaryExpression { - // span: expr.span() + right.span(), - // op: BinaryOperation::BitAnd, - // left: Box::new(expr), - // right: Box::new(right), - // }) - // } - // Ok(expr) - // } - /// Returns an [`Expression`] AST node if the next tokens represent a /// binary equals or not equals expression. /// @@ -222,31 +162,6 @@ impl ParserContext<'_> { Ok(expr) } - /// - /// Returns an [`Expression`] AST node if the next tokens represent a - /// binary shift expression. - /// - /// Otherwise, tries to parse the next token using [`parse_additive_expression`]. - /// - // pub fn parse_shift_expression(&mut self) -> Result { - // let mut expr = self.parse_additive_expression()?; - // while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Shl, Token::Shr, Token::ShrSigned]) { - // let right = self.parse_additive_expression()?; - // expr = Expression::Binary(BinaryExpression { - // span: expr.span() + right.span(), - // op: match op { - // Token::Shl => BinaryOperation::Shl, - // Token::Shr => BinaryOperation::Shr, - // Token::ShrSigned => BinaryOperation::ShrSigned, - // _ => unimplemented!(), - // }, - // left: Box::new(expr), - // right: Box::new(right), - // }) - // } - // Ok(expr) - // } - /// Returns an [`Expression`] AST node if the next tokens represent a /// binary addition or subtraction expression. /// diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index afd5b96540..0b40d48a19 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -26,15 +26,6 @@ const ASSIGN_TOKENS: &[Token] = &[ Token::MulEq, Token::DivEq, Token::ExpEq, - // Token::BitAndEq, - // Token::BitOrEq, - // Token::BitXorEq, - // Token::ShlEq, - // Token::ShrEq, - // Token::ShrSignedEq, - // Token::ModEq, - // Token::OrEq, - // Token::AndEq, ]; impl ParserContext<'_> { @@ -124,15 +115,6 @@ impl ParserContext<'_> { Token::MulEq => AssignOperation::Mul, Token::DivEq => AssignOperation::Div, Token::ExpEq => AssignOperation::Pow, - // Token::OrEq => AssignOperation::Or, - // Token::AndEq => AssignOperation::And, - // Token::BitOrEq => AssignOperation::BitOr, - // Token::BitAndEq => AssignOperation::BitAnd, - // Token::BitXorEq => AssignOperation::BitXor, - // Token::ShrEq => AssignOperation::Shr, - // Token::ShrSignedEq => AssignOperation::ShrSigned, - // Token::ShlEq => AssignOperation::Shl, - // Token::ModEq => AssignOperation::Mod, _ => unimplemented!(), }, value, diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index e2edc16995..93ce3a49bf 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -345,14 +345,8 @@ impl Token { } b'&' => { if let Some(len) = eat(input, "&&") { - // if let Some(inner_len) = eat(&input[len..], "=") { - // return (len + inner_len, Some(Token::AndEq)); - // } return (len, Some(Token::And)); } - // else if let Some(len) = eat(input, "&=") { - // return (len, Some(Token::BitAndEq)); - // } return (1, Some(Token::Ampersand)); } b'(' => return (1, Some(Token::LeftParen)), @@ -421,29 +415,12 @@ impl Token { if let Some(len) = eat(input, "<=") { return (len, Some(Token::LtEq)); } - // else if let Some(len) = eat(input, "<<") { - // if let Some(inner_len) = eat(&input[len..], "=") { - // return (len + inner_len, Some(Token::ShlEq)); - // } - // return (len, Some(Token::Shl)); - // } return (1, Some(Token::Lt)); } b'>' => { if let Some(len) = eat(input, ">=") { return (len, Some(Token::GtEq)); } - // else if let Some(len) = eat(input, ">>") { - // if let Some(inner_len) = eat(&input[len..], "=") { - // return (len + inner_len, Some(Token::ShrEq)); - // } else if let Some(inner_len) = eat(&input[len..], ">") { - // if let Some(eq_len) = eat(&input[len + inner_len..], "=") { - // return (len + inner_len + eq_len, Some(Token::ShrSignedEq)); - // } - // return (len + inner_len, Some(Token::ShrSigned)); - // } - // return (len, Some(Token::Shr)); - // } return (1, Some(Token::Gt)); } b'=' => { @@ -459,29 +436,9 @@ impl Token { b'}' => return (1, Some(Token::RightCurly)), b'|' => { if let Some(len) = eat(input, "||") { - // if let Some(inner_len) = eat(&input[len..], "=") { - // return (len + inner_len, Some(Token::OrEq)); - // } return (len, Some(Token::Or)); } - // else if let Some(len) = eat(input, "|=") { - // return (len, Some(Token::BitOrEq)); - // } - // return (1, Some(Token::BitOr)); } - // b'^' => { - // if let Some(len) = eat(input, "^=") { - // return (len, Some(Token::BitXorEq)); - // } - // return (1, Some(Token::BitXor)); - // } - // b'~' => return (1, Some(Token::BitNot)), - // b'%' => { - // if let Some(len) = eat(input, "%=") { - // return (len, Some(Token::ModEq)); - // } - // return (1, Some(Token::Mod)); - // } _ => (), } if let Some(ident) = eat_identifier(&input_tendril) { diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index 3e306dd0e7..6177973939 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -118,23 +118,6 @@ mod tests { #[test] fn test_tokenizer() { create_session_if_not_set_then(|_| { - // &= - // | - // |= - // ^ - // ^= - // ~ - // << - // <<= - // >> - // >>= - // >>> - // >>>= - // % - // %= - // ||= - // &&= - let tokens = tokenize( "test_path", r#" @@ -234,7 +217,6 @@ mod tests { output += &format!("{} ", token.to_string()); } - // & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= assert_eq!( output, r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut & return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> _ . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || ? // test @@ -270,7 +252,6 @@ mod tests { let original = &raw[*start + token.span.col_start - 1..*stop + token.span.col_stop - 1]; assert_eq!(original, &token_raw); } - // println!("{}", serde_json::to_string_pretty(&tokens).unwrap()); }) } } diff --git a/parser/src/tokenizer/token.rs b/parser/src/tokenizer/token.rs index 1601b8721f..ce3347beb0 100644 --- a/parser/src/tokenizer/token.rs +++ b/parser/src/tokenizer/token.rs @@ -145,24 +145,6 @@ pub enum Token { Static, Type, - // Not yet in ABNF - // BitAndEq, - // BitOr, - // BitOrEq, - // BitXor, - // BitXorEq, - // BitNot, - // Shl, - // ShlEq, - // Shr, - // ShrEq, - // ShrSigned, - // ShrSignedEq, - // Mod, - // ModEq, - // OrEq, - // AndEq, - // Meta Tokens Eof, } @@ -354,22 +336,6 @@ impl fmt::Display for Token { Static => write!(f, "static"), Type => write!(f, "type"), Eof => write!(f, ""), - // BitAndEq => write!(f, "&="), - // BitOr => write!(f, "|"), - // BitOrEq => write!(f, "|="), - // BitXor => write!(f, "^"), - // BitXorEq => write!(f, "^="), - // BitNot => write!(f, "~"), - // Shl => write!(f, "<<"), - // ShlEq => write!(f, "<<="), - // Shr => write!(f, ">>"), - // ShrEq => write!(f, ">>="), - // ShrSigned => write!(f, ">>>"), - // ShrSignedEq => write!(f, ">>>="), - // Mod => write!(f, "%"), - // ModEq => write!(f, "%="), - // OrEq => write!(f, "||="), - // AndEq => write!(f, "&&="), } } } From 6a91f5d9a8d7f383d76361c33a3161ad709a8abe Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 21 Jan 2022 12:57:07 -0800 Subject: [PATCH 03/14] forgot to push lockfile --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7692ae0562..0bc5e71451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1531,6 +1531,8 @@ dependencies = [ "lazy_static", "leo-ast", "leo-errors", + "leo-input", + "leo-span", "leo-test-framework", "serde", "serde_json", From 06a6fd9598bc54ef8c75a37cf65710121f18c81b Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 26 Jan 2022 11:45:47 -0800 Subject: [PATCH 04/14] unimplemented to unreachable --- parser/src/parser/context.rs | 8 ++++---- parser/src/parser/expression.rs | 13 ++++++------- parser/src/parser/mod.rs | 2 +- parser/src/parser/statement.rs | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index d0949a74b6..17c11e76f4 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -21,7 +21,7 @@ use leo_errors::emitter::Handler; use leo_errors::{LeoError, ParserError, Result}; use leo_span::{Span, Symbol}; -use std::{borrow::Cow, unimplemented}; +use std::{borrow::Cow, unreachable}; use tendril::format_tendril; /// Stores a program in tokenized format plus additional context. @@ -156,7 +156,7 @@ impl<'a> ParserContext<'a> { { return Some(Identifier { name, span }); } else { - unimplemented!() + unreachable!() } } None @@ -294,7 +294,7 @@ impl<'a> ParserContext<'a> { { return Some((PositiveNumber { value }, span)); } else { - unimplemented!() + unreachable!() } } None @@ -377,7 +377,7 @@ impl<'a> ParserContext<'a> { { Ok(Identifier { name, span }) } else { - unimplemented!() + unreachable!() } } else { Err(ParserError::unexpected_str(inner, "ident", span).into()) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 821ac3d71b..ff3a81b91d 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -134,7 +134,7 @@ impl ParserContext<'_> { let op = match op { Token::Eq => BinaryOperation::Eq, Token::NotEq => BinaryOperation::Ne, - _ => unimplemented!(), + _ => unreachable!(), }; expr = Self::bin_expr(expr, right, op); } @@ -155,7 +155,7 @@ impl ParserContext<'_> { Token::LtEq => BinaryOperation::Le, Token::Gt => BinaryOperation::Gt, Token::GtEq => BinaryOperation::Ge, - _ => unimplemented!(), + _ => unreachable!(), }; expr = Self::bin_expr(expr, right, op); } @@ -173,7 +173,7 @@ impl ParserContext<'_> { let op = match op { Token::Add => BinaryOperation::Add, Token::Minus => BinaryOperation::Sub, - _ => unimplemented!(), + _ => unreachable!(), }; expr = Self::bin_expr(expr, right, op); } @@ -191,8 +191,7 @@ impl ParserContext<'_> { let op = match op { Token::Mul => BinaryOperation::Mul, Token::Div => BinaryOperation::Div, - // Token::Mod => BinaryOperation::Mod, - _ => unimplemented!(), + _ => unreachable!(), }; expr = Self::bin_expr(expr, right, op); } @@ -250,7 +249,7 @@ impl ParserContext<'_> { Token::Not => UnaryOperation::Not, Token::Minus => UnaryOperation::Negate, // Token::BitNot => UnaryOperation::BitNot, - _ => unimplemented!(), + _ => unreachable!(), }; // hack for const signed integer overflow issues if matches!(operation, UnaryOperation::Negate) { @@ -381,7 +380,7 @@ impl ParserContext<'_> { name: ident, })); } - _ => unimplemented!(), + _ => unreachable!(), } } Ok(expr) diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index 6dbffe8ff3..429d28bbf3 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -27,7 +27,7 @@ use leo_errors::{ParserError, Result}; use leo_span::{Span, Symbol}; use indexmap::IndexMap; -use std::unimplemented; +use std::unreachable; mod context; pub use context::*; diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 0b40d48a19..55fdfb4fb1 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -115,7 +115,7 @@ impl ParserContext<'_> { Token::MulEq => AssignOperation::Mul, Token::DivEq => AssignOperation::Div, Token::ExpEq => AssignOperation::Pow, - _ => unimplemented!(), + _ => unreachable!(), }, value, }))) @@ -317,7 +317,7 @@ impl ParserContext<'_> { declaration_type: match declare.token { Token::Let => Declare::Let, Token::Const => Declare::Const, - _ => unimplemented!(), + _ => unreachable!(), }, variable_names, type_, From daafe940c98a156a663789385813ec53c69ae16d Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 26 Jan 2022 11:49:51 -0800 Subject: [PATCH 05/14] unimplemented to unreachable --- parser/src/parser/context.rs | 6 +++--- parser/src/parser/expression.rs | 13 ++++++------- parser/src/parser/statement.rs | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index 17c11e76f4..fe5b03683e 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -156,7 +156,7 @@ impl<'a> ParserContext<'a> { { return Some(Identifier { name, span }); } else { - unreachable!() + unreachable!("Impossible to reach area, unless a change broke the parser.") } } None @@ -294,7 +294,7 @@ impl<'a> ParserContext<'a> { { return Some((PositiveNumber { value }, span)); } else { - unreachable!() + unreachable!("Impossible to reach area, unless a change broke the parser.") } } None @@ -377,7 +377,7 @@ impl<'a> ParserContext<'a> { { Ok(Identifier { name, span }) } else { - unreachable!() + unreachable!("Impossible to reach area, unless a change broke the parser.") } } else { Err(ParserError::unexpected_str(inner, "ident", span).into()) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index ff3a81b91d..79c6e020d0 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -134,7 +134,7 @@ impl ParserContext<'_> { let op = match op { Token::Eq => BinaryOperation::Eq, Token::NotEq => BinaryOperation::Ne, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }; expr = Self::bin_expr(expr, right, op); } @@ -155,7 +155,7 @@ impl ParserContext<'_> { Token::LtEq => BinaryOperation::Le, Token::Gt => BinaryOperation::Gt, Token::GtEq => BinaryOperation::Ge, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }; expr = Self::bin_expr(expr, right, op); } @@ -173,7 +173,7 @@ impl ParserContext<'_> { let op = match op { Token::Add => BinaryOperation::Add, Token::Minus => BinaryOperation::Sub, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }; expr = Self::bin_expr(expr, right, op); } @@ -191,7 +191,7 @@ impl ParserContext<'_> { let op = match op { Token::Mul => BinaryOperation::Mul, Token::Div => BinaryOperation::Div, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }; expr = Self::bin_expr(expr, right, op); } @@ -248,8 +248,7 @@ impl ParserContext<'_> { let operation = match op.token { Token::Not => UnaryOperation::Not, Token::Minus => UnaryOperation::Negate, - // Token::BitNot => UnaryOperation::BitNot, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }; // hack for const signed integer overflow issues if matches!(operation, UnaryOperation::Negate) { @@ -380,7 +379,7 @@ impl ParserContext<'_> { name: ident, })); } - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), } } Ok(expr) diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 55fdfb4fb1..3ebdfa693e 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -115,7 +115,7 @@ impl ParserContext<'_> { Token::MulEq => AssignOperation::Mul, Token::DivEq => AssignOperation::Div, Token::ExpEq => AssignOperation::Pow, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }, value, }))) @@ -317,7 +317,7 @@ impl ParserContext<'_> { declaration_type: match declare.token { Token::Let => Declare::Let, Token::Const => Declare::Const, - _ => unreachable!(), + _ => unreachable!("Impossible to reach area, unless a change broke the parser."), }, variable_names, type_, From 5b7daa7b106c737517838d6719090923082fbf8a Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 10:26:42 -0800 Subject: [PATCH 06/14] disable tgc binary for now --- Cargo.lock | 6 ---- test-framework/Cargo.toml | 38 +++++++++++++------------- tests/parser/unreachable/eat_ident.leo | 18 ++++++++++++ tests/parser/unreachable/eat_int.leo | 19 +++++++++++++ 4 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 tests/parser/unreachable/eat_ident.leo create mode 100644 tests/parser/unreachable/eat_int.leo diff --git a/Cargo.lock b/Cargo.lock index 0bc5e71451..a9370767f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1585,13 +1585,7 @@ dependencies = [ name = "leo-test-framework" version = "1.5.3" dependencies = [ - "leo-asg", - "leo-ast", - "leo-ast-passes", - "leo-compiler", "leo-errors", - "leo-imports", - "leo-parser", "regex", "serde", "serde_json", diff --git a/test-framework/Cargo.toml b/test-framework/Cargo.toml index 508f8997d9..4a312dcbf1 100644 --- a/test-framework/Cargo.toml +++ b/test-framework/Cargo.toml @@ -29,30 +29,30 @@ features = [ "preserve_order" ] version = "0.8" # List of dependencies for tgc binary; +# disabled for now while porting modules from staging +# [dependencies.leo-ast] +# path = "../ast" +# version = "1.5.2" -[dependencies.leo-ast] -path = "../ast" -version = "1.5.2" +# [dependencies.leo-ast-passes] +# path = "../ast-passes" +# version = "1.5.2" -[dependencies.leo-ast-passes] -path = "../ast-passes" -version = "1.5.2" +# [dependencies.leo-parser] +# path = "../parser" +# version = "1.5.2" -[dependencies.leo-parser] -path = "../parser" -version = "1.5.2" +# [dependencies.leo-imports] +# path = "../imports" +# version = "1.5.2" -[dependencies.leo-imports] -path = "../imports" -version = "1.5.2" +# [dependencies.leo-asg] +# path = "../asg" +# version = "1.5.2" -[dependencies.leo-asg] -path = "../asg" -version = "1.5.2" - -[dependencies.leo-compiler] -path = "../compiler" -version = "1.5.2" +# [dependencies.leo-compiler] +# path = "../compiler" +# version = "1.5.2" [dependencies.structopt] version = "0.3" diff --git a/tests/parser/unreachable/eat_ident.leo b/tests/parser/unreachable/eat_ident.leo new file mode 100644 index 0000000000..dfd7f1aadf --- /dev/null +++ b/tests/parser/unreachable/eat_ident.leo @@ -0,0 +1,18 @@ +/* +namespace: Parse +expectation: Fail +*/ + +circuit try_to_hit_eat_ident_unreachable +circuit ; +circuit . +circuit import +circuit , +circuit * +circuit + +circuit - +circuit / +circuit [ +circuit ] +circuit { +circuit } diff --git a/tests/parser/unreachable/eat_int.leo b/tests/parser/unreachable/eat_int.leo new file mode 100644 index 0000000000..7748be8ab5 --- /dev/null +++ b/tests/parser/unreachable/eat_int.leo @@ -0,0 +1,19 @@ +/* +namespace: ParseExpression +expectation: Fail +*/ + +x.0_try_to_hit_hit_eat_int_unreachable +x.; +x.a +x., +x.. +x+ +x- +x* +x/ +x.import +x.[ +x.] +x.{ +x.} \ No newline at end of file From 2bb1d8f8d60a8d994e919a267527edd16ea1e0dc Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 10:34:02 -0800 Subject: [PATCH 07/14] migrate parser tests from staging --- .../parser/parser/circuits/big_self.leo.out | 5 +- .../parser/circuits/const_functions.leo.out | 253 +++++ .../parser/parser/circuits/consts.leo.out | 41 + .../parser/parser/circuits/empty.leo.out | 1 - .../circuits/field_and_functions.leo.out | 62 +- .../parser/parser/circuits/fields.leo.out | 1 - .../parser/circuits/fields_fail.leo.out | 2 +- .../parser/parser/circuits/functions.leo.out | 50 +- .../parser/circuits/mixed_order_fail.leo.out | 5 + .../parser/circuits/mut_self_fail.leo.out | 5 + .../parser/parser/circuits/ref_self.leo.out | 57 ++ .../parser/parser/circuits/self.leo.out | 5 +- .../parser/circuits/struct_fail.leo.out | 5 + .../expression/access/array_access.leo.out | 483 ++++----- .../access/array_range_access.leo.out | 771 +++++++------- .../parser/expression/access/call.leo.out | 116 ++- .../parser/expression/access/circuit.leo.out | 229 +++-- .../expression/access/circuit_static.leo.out | 222 ++-- .../parser/expression/access/tuple.leo.out | 219 ++-- .../parser/expression/array_init.leo.out | 22 + .../parser/expression/array_init_fail.leo.out | 1 + .../parser/expression/array_len.leo.out | 466 +++++---- .../parser/expression/literal/access.leo.out | 963 ++++++++++++++++++ .../expression/literal/group_fail.leo.out | 1 - .../parser/expression/unary/negate.leo.out | 49 +- .../parser/expression/unary/not.leo.out | 49 +- .../parser/parser/functions/annotated.leo.out | 168 ++- .../annotated_arg_not_ident_int.leo.out | 5 + .../functions/annotated_context_fail.leo.out | 5 + .../parser/functions/annotated_param.leo.out | 5 +- .../parser/functions/annotated_twice.leo.out | 8 +- .../functions/bounded_recursion.leo.out | 208 ++++ .../functions/bounded_recursion_fail.leo.out | 208 ++++ .../parser/functions/const_function.leo.out | 53 + .../parser/functions/const_param.leo.out | 8 +- .../parser/functions/const_self_bad.leo.out | 4 +- .../parser/parser/functions/empty.leo.out | 4 +- .../parser/parser/functions/empty2.leo.out | 4 +- .../functions/infinite_recursion_fail.leo.out | 120 +++ .../parser/functions/param_array.leo.out | 4 +- .../functions/param_array_unsized.leo.out | 4 +- .../parser/functions/param_circuit.leo.out | 4 +- .../parser/functions/param_tuple.leo.out | 4 +- .../parser/parser/functions/params.leo.out | 4 +- .../parser/functions/params_return.leo.out | 4 +- .../parser/parser/functions/return.leo.out | 4 +- .../parser/functions/return_tuple.leo.out | 4 +- .../import/import_empty_list_fail.leo.out | 2 +- .../parser/import/invalid_chars_fail.leo.out | 5 + .../parser/parser/import/keyword_fail.leo.out | 5 + .../serialize/linear_regression.leo.out | 677 ++++++++++++ .../parser/serialize/one_plus_one.leo.out | 36 + .../parser/serialize/palindrome.leo.out | 554 ++++++++++ .../parser/serialize/parser_error.leo.out | 5 + .../parser/serialize/pedersen_hash.leo.out | 169 +++ .../parser/serialize/silly_sudoku.leo.out | 528 ++++++++++ .../parser/parser/statement/console.leo.out | 36 +- .../parser/statement/let_mut_recover.leo.out | 5 + .../parser/unreachable/eat_ident.leo.out | 5 + .../parser/parser/unreachable/eat_int.leo.out | 5 + tests/parser/circuits/const_functions.leo | 23 + tests/parser/circuits/consts.leo | 9 + tests/parser/circuits/field_and_functions.leo | 1 + tests/parser/circuits/fields_fail.leo | 3 +- tests/parser/circuits/functions.leo | 5 +- tests/parser/circuits/mixed_order_fail.leo | 19 + .../{mut_self.leo => mut_self_fail.leo} | 2 +- tests/parser/circuits/ref_self.leo | 10 + tests/parser/circuits/struct_fail.leo | 9 + tests/parser/expression/array_init.leo | 4 +- tests/parser/expression/array_init_fail.leo | 2 + tests/parser/expression/literal/access.leo | 51 + .../parser/expression/literal/group_fail.leo | 2 - tests/parser/functions/annotated.leo | 19 +- .../functions/annotated_arg_not_ident_int.leo | 14 + .../functions/annotated_context_fail.leo | 14 + tests/parser/functions/annotated_fail.leo | 9 - tests/parser/functions/bounded_recursion.leo | 15 + .../functions/bounded_recursion_fail.leo | 15 + tests/parser/functions/const_function.leo | 8 + .../functions/infinite_recursion_fail.leo | 13 + .../parser/import/import_empty_list_fail.leo | 4 +- tests/parser/import/invalid_chars_fail.leo | 8 + tests/parser/import/keyword_fail.leo | 8 + tests/parser/serialize/linear_regression.leo | 70 ++ tests/parser/serialize/one_plus_one.leo | 8 + tests/parser/serialize/palindrome.leo | 64 ++ tests/parser/serialize/parser_error.leo | 6 + tests/parser/serialize/pedersen_hash.leo | 30 + tests/parser/serialize/silly_sudoku.leo | 76 ++ tests/parser/statement/definition_fail.leo | 2 +- tests/parser/statement/let_mut_recover.leo | 9 + tests/parser/unreachable/eat_int.leo | 2 +- 93 files changed, 6167 insertions(+), 1314 deletions(-) create mode 100644 tests/expectations/parser/parser/circuits/const_functions.leo.out create mode 100644 tests/expectations/parser/parser/circuits/consts.leo.out create mode 100644 tests/expectations/parser/parser/circuits/mixed_order_fail.leo.out create mode 100644 tests/expectations/parser/parser/circuits/mut_self_fail.leo.out create mode 100644 tests/expectations/parser/parser/circuits/ref_self.leo.out create mode 100644 tests/expectations/parser/parser/circuits/struct_fail.leo.out create mode 100644 tests/expectations/parser/parser/expression/literal/access.leo.out create mode 100644 tests/expectations/parser/parser/functions/annotated_arg_not_ident_int.leo.out create mode 100644 tests/expectations/parser/parser/functions/annotated_context_fail.leo.out create mode 100644 tests/expectations/parser/parser/functions/bounded_recursion.leo.out create mode 100644 tests/expectations/parser/parser/functions/bounded_recursion_fail.leo.out create mode 100644 tests/expectations/parser/parser/functions/const_function.leo.out create mode 100644 tests/expectations/parser/parser/functions/infinite_recursion_fail.leo.out create mode 100644 tests/expectations/parser/parser/import/invalid_chars_fail.leo.out create mode 100644 tests/expectations/parser/parser/import/keyword_fail.leo.out create mode 100644 tests/expectations/parser/parser/serialize/linear_regression.leo.out create mode 100644 tests/expectations/parser/parser/serialize/one_plus_one.leo.out create mode 100644 tests/expectations/parser/parser/serialize/palindrome.leo.out create mode 100644 tests/expectations/parser/parser/serialize/parser_error.leo.out create mode 100644 tests/expectations/parser/parser/serialize/pedersen_hash.leo.out create mode 100644 tests/expectations/parser/parser/serialize/silly_sudoku.leo.out create mode 100644 tests/expectations/parser/parser/statement/let_mut_recover.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/eat_ident.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/eat_int.leo.out create mode 100644 tests/parser/circuits/const_functions.leo create mode 100644 tests/parser/circuits/consts.leo create mode 100644 tests/parser/circuits/mixed_order_fail.leo rename tests/parser/circuits/{mut_self.leo => mut_self_fail.leo} (83%) create mode 100644 tests/parser/circuits/ref_self.leo create mode 100644 tests/parser/circuits/struct_fail.leo create mode 100644 tests/parser/expression/literal/access.leo create mode 100644 tests/parser/functions/annotated_arg_not_ident_int.leo create mode 100644 tests/parser/functions/annotated_context_fail.leo delete mode 100644 tests/parser/functions/annotated_fail.leo create mode 100644 tests/parser/functions/bounded_recursion.leo create mode 100644 tests/parser/functions/bounded_recursion_fail.leo create mode 100644 tests/parser/functions/const_function.leo create mode 100644 tests/parser/functions/infinite_recursion_fail.leo create mode 100644 tests/parser/import/invalid_chars_fail.leo create mode 100644 tests/parser/import/keyword_fail.leo create mode 100644 tests/parser/serialize/linear_regression.leo create mode 100644 tests/parser/serialize/one_plus_one.leo create mode 100644 tests/parser/serialize/palindrome.leo create mode 100644 tests/parser/serialize/parser_error.leo create mode 100644 tests/parser/serialize/pedersen_hash.leo create mode 100644 tests/parser/serialize/silly_sudoku.leo create mode 100644 tests/parser/statement/let_mut_recover.leo diff --git a/tests/expectations/parser/parser/circuits/big_self.leo.out b/tests/expectations/parser/parser/circuits/big_self.leo.out index 285482cf47..8d6223649f 100644 --- a/tests/expectations/parser/parser/circuits/big_self.leo.out +++ b/tests/expectations/parser/parser/circuits/big_self.leo.out @@ -10,13 +10,14 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: - CircuitFunction: - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x() -> Self {\\\"}\"}" input: [] + const_: false output: SelfType + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/circuits/const_functions.leo.out b/tests/expectations/parser/parser/circuits/const_functions.leo.out new file mode 100644 index 0000000000..0cd2d5e744 --- /dev/null +++ b/tests/expectations/parser/parser/circuits/const_functions.leo.out @@ -0,0 +1,253 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: + "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": + circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" + members: + - CircuitVariable: + - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: u32\\\"}\"}" + - IntegerType: U32 + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function x() { \\\"}\"}" + input: [] + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 6 + line_stop: 6 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 6 + line_stop: 6 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 5 + line_stop: 7 + col_start: 24 + col_stop: 6 + path: "" + content: " const function x() { \n ...\n }" + span: + line_start: 5 + line_stop: 7 + col_start: 11 + col_stop: 6 + path: "" + content: " const function x() { \n ...\n }" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function x(self) { \\\"}\"}" + input: + - SelfKeyword: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function x(self) { \\\"}\"}" + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 9 + line_stop: 9 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 9 + line_stop: 9 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 8 + line_stop: 10 + col_start: 28 + col_stop: 6 + path: "" + content: " const function x(self) { \n ...\n }" + span: + line_start: 8 + line_stop: 10 + col_start: 11 + col_stop: 6 + path: "" + content: " const function x(self) { \n ...\n }" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function c(const self) { \\\"}\"}" + input: + - ConstSelfKeyword: "{\"name\":\"const self\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":22,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function c(const self) { \\\"}\"}" + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 12 + line_stop: 12 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 12 + line_stop: 12 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 11 + line_stop: 13 + col_start: 34 + col_stop: 6 + path: "" + content: " const function c(const self) { \n ...\n }" + span: + line_start: 11 + line_stop: 13 + col_start: 11 + col_stop: 6 + path: "" + content: " const function c(const self) { \n ...\n }" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, x: u32) {\\\"}\"}" + input: + - ConstSelfKeyword: "{\"name\":\"const self\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":22,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, x: u32) {\\\"}\"}" + - Variable: + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, x: u32) {\\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: U32 + span: + line_start: 14 + line_stop: 14 + col_start: 34 + col_stop: 35 + path: "" + content: " const function b(const self, x: u32) {" + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 15 + line_stop: 15 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 15 + line_stop: 15 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 14 + line_stop: 16 + col_start: 42 + col_stop: 6 + path: "" + content: " const function b(const self, x: u32) {\n ...\n }" + span: + line_start: 14 + line_stop: 16 + col_start: 11 + col_stop: 6 + path: "" + content: " const function b(const self, x: u32) {\n ...\n }" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, const x: u32) {\\\"}\"}" + input: + - ConstSelfKeyword: "{\"name\":\"const self\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":22,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, const x: u32) {\\\"}\"}" + - Variable: + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":40,\\\"col_stop\\\":41,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function b(const self, const x: u32) {\\\"}\"}" + const_: true + mutable: false + type_: + IntegerType: U32 + span: + line_start: 17 + line_stop: 17 + col_start: 40 + col_stop: 41 + path: "" + content: " const function b(const self, const x: u32) {" + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 18 + line_stop: 18 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 18 + line_stop: 18 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 17 + line_stop: 19 + col_start: 48 + col_stop: 6 + path: "" + content: " const function b(const self, const x: u32) {\n ...\n }" + span: + line_start: 17 + line_stop: 19 + col_start: 11 + col_stop: 6 + path: "" + content: " const function b(const self, const x: u32) {\n ...\n }" + global_consts: {} + functions: {} diff --git a/tests/expectations/parser/parser/circuits/consts.leo.out b/tests/expectations/parser/parser/circuits/consts.leo.out new file mode 100644 index 0000000000..84c302700b --- /dev/null +++ b/tests/expectations/parser/parser/circuits/consts.leo.out @@ -0,0 +1,41 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: + "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": + circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" + members: + - CircuitConst: + - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" static const x: u32 = 2;\\\"}\"}" + - IntegerType: U32 + - Value: + Implicit: + - "2" + - span: + line_start: 4 + line_stop: 4 + col_start: 27 + col_stop: 28 + path: "" + content: " static const x: u32 = 2;" + - CircuitConst: + - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" static const y: u32 = 5;\\\"}\"}" + - IntegerType: U32 + - Value: + Implicit: + - "5" + - span: + line_start: 5 + line_stop: 5 + col_start: 27 + col_stop: 28 + path: "" + content: " static const y: u32 = 5;" + global_consts: {} + functions: {} diff --git a/tests/expectations/parser/parser/circuits/empty.leo.out b/tests/expectations/parser/parser/circuits/empty.leo.out index a5ceaec155..eb759bfecd 100644 --- a/tests/expectations/parser/parser/circuits/empty.leo.out +++ b/tests/expectations/parser/parser/circuits/empty.leo.out @@ -10,7 +10,6 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: [] global_consts: {} functions: {} diff --git a/tests/expectations/parser/parser/circuits/field_and_functions.leo.out b/tests/expectations/parser/parser/circuits/field_and_functions.leo.out index bf637c4ed0..db42615815 100644 --- a/tests/expectations/parser/parser/circuits/field_and_functions.leo.out +++ b/tests/expectations/parser/parser/circuits/field_and_functions.leo.out @@ -10,19 +10,33 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: + - CircuitConst: + - "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" static const a: u8 = 10;\\\"}\"}" + - IntegerType: U8 + - Value: + Implicit: + - "10" + - span: + line_start: 4 + line_stop: 4 + col_start: 26 + col_stop: 28 + path: "" + content: " static const a: u8 = 10;" - CircuitVariable: - - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: u32,\\\"}\"}" + - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: u32,\\\"}\"}" - IntegerType: U32 - CircuitVariable: - - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: u32\\\"}\"}" + - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: u32\\\"}\"}" - IntegerType: U32 - CircuitFunction: - annotations: [] - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x() {\\\"}\"}" + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -30,38 +44,40 @@ outputs: TupleInit: elements: [] span: - line_start: 7 - line_stop: 7 + line_start: 8 + line_stop: 8 col_start: 16 col_stop: 18 path: "" content: " return ();" span: - line_start: 7 - line_stop: 7 + line_start: 8 + line_stop: 8 col_start: 9 col_stop: 18 path: "" content: " return ();" span: - line_start: 6 - line_stop: 8 + line_start: 7 + line_stop: 9 col_start: 18 col_stop: 6 path: "" content: " function x() {\n ...\n }" span: - line_start: 6 - line_stop: 8 + line_start: 7 + line_stop: 9 col_start: 5 col_stop: 6 path: "" content: " function x() {\n ...\n }" - CircuitFunction: - annotations: [] - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function y() {\\\"}\"}" + annotations: {} + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function y() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -69,29 +85,29 @@ outputs: TupleInit: elements: [] span: - line_start: 10 - line_stop: 10 + line_start: 11 + line_stop: 11 col_start: 16 col_stop: 18 path: "" content: " return ();" span: - line_start: 10 - line_stop: 10 + line_start: 11 + line_stop: 11 col_start: 9 col_stop: 18 path: "" content: " return ();" span: - line_start: 9 - line_stop: 11 + line_start: 10 + line_stop: 12 col_start: 18 col_stop: 6 path: "" content: " function y() {\n ...\n }" span: - line_start: 9 - line_stop: 11 + line_start: 10 + line_stop: 12 col_start: 5 col_stop: 6 path: "" diff --git a/tests/expectations/parser/parser/circuits/fields.leo.out b/tests/expectations/parser/parser/circuits/fields.leo.out index 7464095aaa..7f5a0460a1 100644 --- a/tests/expectations/parser/parser/circuits/fields.leo.out +++ b/tests/expectations/parser/parser/circuits/fields.leo.out @@ -10,7 +10,6 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: - CircuitVariable: - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: u32;\\\"}\"}" diff --git a/tests/expectations/parser/parser/circuits/fields_fail.leo.out b/tests/expectations/parser/parser/circuits/fields_fail.leo.out index 8c4dbaf736..2225346003 100644 --- a/tests/expectations/parser/parser/circuits/fields_fail.leo.out +++ b/tests/expectations/parser/parser/circuits/fields_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370006]: Cannot mix use of commas and semi-colons for circuit member variable declarations.\n --> test:10:11\n |\n 10 | y: u32;\n | ^" + - "Error [EPAR0370006]: Cannot mix use of commas and semi-colons for circuit member variable declarations.\n --> test:10:11\n |\n 10 | y: u32;\n | ^\nError [EPAR0370006]: Cannot mix use of commas and semi-colons for circuit member variable declarations.\n --> test:11:5\n |\n 11 | , // recovery witness\n | ^" diff --git a/tests/expectations/parser/parser/circuits/functions.leo.out b/tests/expectations/parser/parser/circuits/functions.leo.out index 48a6234f16..c6db22f69c 100644 --- a/tests/expectations/parser/parser/circuits/functions.leo.out +++ b/tests/expectations/parser/parser/circuits/functions.leo.out @@ -10,13 +10,14 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: - CircuitFunction: - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -52,10 +53,12 @@ outputs: path: "" content: " function x() {\n ...\n }" - CircuitFunction: - annotations: [] + annotations: {} identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function y() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -90,5 +93,46 @@ outputs: col_stop: 6 path: "" content: " function y() {\n ...\n }" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":20,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const function z() {\\\"}\"}" + input: [] + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 11 + line_stop: 11 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 11 + line_stop: 11 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 10 + line_stop: 12 + col_start: 24 + col_stop: 6 + path: "" + content: " const function z() {\n ...\n }" + span: + line_start: 10 + line_stop: 12 + col_start: 11 + col_stop: 6 + path: "" + content: " const function z() {\n ...\n }" global_consts: {} functions: {} diff --git a/tests/expectations/parser/parser/circuits/mixed_order_fail.leo.out b/tests/expectations/parser/parser/circuits/mixed_order_fail.leo.out new file mode 100644 index 0000000000..7ef15bf91e --- /dev/null +++ b/tests/expectations/parser/parser/circuits/mixed_order_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370022]: Member functions must come after member variables.\n --> test:7:5\n |\n 7 | foo: u8,\n | ^^^\nError [EPAR0370021]: Member functions must come after member consts.\n --> test:9:18\n |\n 9 | static const BAR: u8 = 0u8;\n | ^^^^^^^^^^^^^\nError [EPAR0370020]: Member variables must come after member consts.\n --> test:15:18\n |\n 15 | static const BAR: u8 = 0u8;\n | ^^^^^^^^^^^^^" diff --git a/tests/expectations/parser/parser/circuits/mut_self_fail.leo.out b/tests/expectations/parser/parser/circuits/mut_self_fail.leo.out new file mode 100644 index 0000000000..7a1b004381 --- /dev/null +++ b/tests/expectations/parser/parser/circuits/mut_self_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370019]: `mut self` is no longer accepted. Use `&self` if you would like to pass in a mutable reference to `self`\n --> test:4:16\n |\n 4 | function x(mut self) {\n | ^^^^^^^^" diff --git a/tests/expectations/parser/parser/circuits/ref_self.leo.out b/tests/expectations/parser/parser/circuits/ref_self.leo.out new file mode 100644 index 0000000000..36a7f97eae --- /dev/null +++ b/tests/expectations/parser/parser/circuits/ref_self.leo.out @@ -0,0 +1,57 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: + "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": + circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" + members: + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x(&self) {\\\"}\"}" + input: + - RefSelfKeyword: "{\"name\":\"&self\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":16,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x(&self) {\\\"}\"}" + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 5 + line_stop: 5 + col_start: 16 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 5 + line_stop: 5 + col_start: 9 + col_stop: 18 + path: "" + content: " return ();" + span: + line_start: 4 + line_stop: 6 + col_start: 23 + col_stop: 6 + path: "" + content: " function x(&self) {\n ...\n }" + span: + line_start: 4 + line_stop: 6 + col_start: 5 + col_stop: 6 + path: "" + content: " function x(&self) {\n ...\n }" + global_consts: {} + functions: {} diff --git a/tests/expectations/parser/parser/circuits/self.leo.out b/tests/expectations/parser/parser/circuits/self.leo.out index 913f60dad1..ab817ab360 100644 --- a/tests/expectations/parser/parser/circuits/self.leo.out +++ b/tests/expectations/parser/parser/circuits/self.leo.out @@ -10,14 +10,15 @@ outputs: circuits: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}": circuit_name: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit X {\\\"}\"}" - core_mapping: ~ members: - CircuitFunction: - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x(self) {\\\"}\"}" input: - SelfKeyword: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function x(self) {\\\"}\"}" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/circuits/struct_fail.leo.out b/tests/expectations/parser/parser/circuits/struct_fail.leo.out new file mode 100644 index 0000000000..aee38799dc --- /dev/null +++ b/tests/expectations/parser/parser/circuits/struct_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected circuit -- got 'struct'\n --> test:3:1\n |\n 3 | struct A {}\n | ^^^^^^\nError [EPAR0370005]: expected circuit -- got 'class'\n --> test:5:1\n |\n 5 | class C {}\n | ^^^^^" diff --git a/tests/expectations/parser/parser/expression/access/array_access.leo.out b/tests/expectations/parser/parser/expression/access/array_access.leo.out index 1ab093eebc..045d403df6 100644 --- a/tests/expectations/parser/parser/expression/access/array_access.leo.out +++ b/tests/expectations/parser/parser/expression/access/array_access.leo.out @@ -2,170 +2,179 @@ namespace: ParseExpression expectation: Pass outputs: - - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0]\\\"}\"}" - index: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "x[0]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x[0]" - - ArrayAccess: - array: - Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X[1]\\\"}\"}" - index: - Value: - Implicit: - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "X[1]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "X[1]" - - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8]\\\"}\"}" - index: - Value: - Integer: - - U8 - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 6 - path: "" - content: "x[0u8]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x[0u8]" - - ArrayAccess: - array: - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1u8][2u8]\\\"}\"}" - index: - Value: - Integer: - - U8 - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 6 - path: "" - content: "x[1u8][2u8]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x[1u8][2u8]" - index: - Value: - Integer: - - U8 - - "2" - - span: - line_start: 1 - line_stop: 1 - col_start: 8 - col_stop: 11 - path: "" - content: "x[1u8][2u8]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 12 - path: "" - content: "x[1u8][2u8]" - - ArrayAccess: - array: - ArrayAccess: - array: - ArrayAccess: + - Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0]\\\"}\"}" + index: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[0]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x[0]" + - Access: + Array: + array: + Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X[1]\\\"}\"}" + index: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "X[1]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "X[1]" + - Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8]\\\"}\"}" + index: + Value: + Integer: + - U8 + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 6 + path: "" + content: "x[0u8]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x[0u8]" + - Access: + Array: + array: + Access: + Array: array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1u8][2u8]\\\"}\"}" index: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + Value: + Integer: + - U8 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 6 + path: "" + content: "x[1u8][2u8]" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 5 + col_stop: 7 + path: "" + content: "x[1u8][2u8]" + index: + Value: + Integer: + - U8 + - "2" + - span: + line_start: 1 + line_stop: 1 + col_start: 8 + col_stop: 11 + path: "" + content: "x[1u8][2u8]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "x[1u8][2u8]" + - Access: + Array: + array: + Access: + Array: + array: + Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + index: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x[x][y][z]" + index: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":7,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 8 path: "" content: "x[x][y][z]" - index: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":7,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 8 - path: "" - content: "x[x][y][z]" - index: - Identifier: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 11 - path: "" - content: "x[x][y][z]" + index: + Identifier: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x][y][z]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "x[x][y][z]" - Call: function: - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0]()\\\"}\"}" - index: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "x[0]()" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x[0]()" + Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0]()\\\"}\"}" + index: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[0]()" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x[0]()" arguments: [] span: line_start: 1 @@ -174,61 +183,64 @@ outputs: col_stop: 7 path: "" content: "x[0]()" - - ArrayAccess: - array: - Call: - function: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x()[0]\\\"}\"}" - arguments: [] - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: "x()[0]" - index: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 5 - col_stop: 6 - path: "" - content: "x()[0]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x()[0]" + - Access: + Array: + array: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x()[0]\\\"}\"}" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: "x()[0]" + index: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 5 + col_stop: 6 + path: "" + content: "x()[0]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x()[0]" - Call: function: - CircuitStaticFunctionAccess: - circuit: - Call: - function: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" - arguments: - - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x(y)::y(x)" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 8 - path: "" - content: "x(y)::y(x)" + Access: + Static: + inner: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" + arguments: + - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x(y)::y(x)" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 8 + path: "" + content: "x(y)::y(x)" arguments: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x(y)::y(x)\\\"}\"}" span: @@ -238,37 +250,40 @@ outputs: col_stop: 11 path: "" content: "x(y)::y(x)" - - ArrayAccess: - array: - TupleAccess: - tuple: - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" + - Access: + Array: + array: + Access: + Tuple: + tuple: + Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" + index: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x[x].0[x]" index: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" + value: "0" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 5 + col_stop: 7 path: "" content: "x[x].0[x]" - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x[x].0[x]" - index: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 10 - path: "" - content: "x[x].0[x]" + index: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x].0[x]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "x[x].0[x]" diff --git a/tests/expectations/parser/parser/expression/access/array_range_access.leo.out b/tests/expectations/parser/parser/expression/access/array_range_access.leo.out index ecaf1054ae..d930ff5e17 100644 --- a/tests/expectations/parser/parser/expression/access/array_range_access.leo.out +++ b/tests/expectations/parser/parser/expression/access/array_range_access.leo.out @@ -2,133 +2,171 @@ namespace: ParseExpression expectation: Pass outputs: - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..]\\\"}\"}" - left: ~ - right: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: "x[..]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1..]\\\"}\"}" - left: - Value: - Implicit: - - "1" - - span: + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..]\\\"}\"}" + left: ~ + right: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: "x[..]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1..]\\\"}\"}" + left: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[1..]" + right: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x[1..]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..1]\\\"}\"}" + left: ~ + right: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 5 + col_stop: 6 + path: "" + content: "x[..1]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x[..1]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1..1]\\\"}\"}" + left: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[1..1]" + right: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 6 + col_stop: 7 + path: "" + content: "x[1..1]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 8 + path: "" + content: "x[1..1]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0..100]\\\"}\"}" + left: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[0..100]" + right: + Value: + Implicit: + - "100" + - span: + line_start: 1 + line_stop: 1 + col_start: 6 + col_stop: 9 + path: "" + content: "x[0..100]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "x[0..100]" + - Access: + Array: + array: + Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[323452345.2345234523453453][323452345.2345234523453453]\\\"}\"}" + index: + Access: + Tuple: + tuple: + Value: + Implicit: + - "323452345" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 12 + path: "" + content: "x[323452345.2345234523453453][323452345.2345234523453453]" + index: + value: "2345234523453453" + span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 29 + path: "" + content: "x[323452345.2345234523453453][323452345.2345234523453453]" + span: line_start: 1 line_stop: 1 - col_start: 3 - col_stop: 4 + col_start: 1 + col_stop: 30 path: "" - content: "x[1..]" - right: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x[1..]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..1]\\\"}\"}" - left: ~ - right: - Value: - Implicit: - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 5 - col_stop: 6 - path: "" - content: "x[..1]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x[..1]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[1..1]\\\"}\"}" - left: - Value: - Implicit: - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "x[1..1]" - right: - Value: - Implicit: - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 6 - col_stop: 7 - path: "" - content: "x[1..1]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 8 - path: "" - content: "x[1..1]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0..100]\\\"}\"}" - left: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "x[0..100]" - right: - Value: - Implicit: - - "100" - - span: - line_start: 1 - line_stop: 1 - col_start: 6 - col_stop: 9 - path: "" - content: "x[0..100]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 10 - path: "" - content: "x[0..100]" - - ArrayAccess: - array: - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[323452345.2345234523453453][323452345.2345234523453453]\\\"}\"}" - index: - TupleAccess: + content: "x[323452345.2345234523453453][323452345.2345234523453453]" + index: + Access: + Tuple: tuple: Value: Implicit: @@ -136,8 +174,8 @@ outputs: - span: line_start: 1 line_stop: 1 - col_start: 3 - col_stop: 12 + col_start: 31 + col_stop: 40 path: "" content: "x[323452345.2345234523453453][323452345.2345234523453453]" index: @@ -145,277 +183,264 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 3 - col_stop: 29 + col_start: 31 + col_stop: 57 path: "" content: "x[323452345.2345234523453453][323452345.2345234523453453]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 30 - path: "" - content: "x[323452345.2345234523453453][323452345.2345234523453453]" - index: - TupleAccess: - tuple: - Value: - Implicit: - - "323452345" - - span: - line_start: 1 - line_stop: 1 - col_start: 31 - col_stop: 40 - path: "" - content: "x[323452345.2345234523453453][323452345.2345234523453453]" - index: - value: "2345234523453453" - span: - line_start: 1 - line_stop: 1 - col_start: 31 - col_stop: 57 - path: "" - content: "x[323452345.2345234523453453][323452345.2345234523453453]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 58 - path: "" - content: "x[323452345.2345234523453453][323452345.2345234523453453]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8..1u8]\\\"}\"}" - left: - Value: - Integer: - - U8 - - "0" - - span: + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 58 + path: "" + content: "x[323452345.2345234523453453][323452345.2345234523453453]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8..1u8]\\\"}\"}" + left: + Value: + Integer: + - U8 + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 6 + path: "" + content: "x[0u8..1u8]" + right: + Value: + Integer: + - U8 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 8 + col_stop: 11 + path: "" + content: "x[0u8..1u8]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "x[0u8..1u8]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8..]\\\"}\"}" + left: + Value: + Integer: + - U8 + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 6 + path: "" + content: "x[0u8..]" + right: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "x[0u8..]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..0u8]\\\"}\"}" + left: ~ + right: + Value: + Integer: + - U8 + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 5 + col_stop: 8 + path: "" + content: "x[..0u8]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "x[..0u8]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..]\\\"}\"}" + left: ~ + right: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: "x[..]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" + left: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" + span: line_start: 1 line_stop: 1 col_start: 3 col_stop: 6 path: "" - content: "x[0u8..1u8]" - right: - Value: - Integer: - - U8 - - "1" - - span: - line_start: 1 - line_stop: 1 - col_start: 8 - col_stop: 11 - path: "" - content: "x[0u8..1u8]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 12 - path: "" - content: "x[0u8..1u8]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0u8..]\\\"}\"}" - left: - Value: - Integer: - - U8 - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 6 - path: "" - content: "x[0u8..]" - right: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "x[0u8..]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..0u8]\\\"}\"}" - left: ~ - right: - Value: - Integer: - - U8 - - "0" - - span: + content: "x[x.y..]" + type_: ~ + right: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "x[x.y..]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" + left: ~ + right: + Access: + Member: + inner: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" + span: line_start: 1 line_stop: 1 col_start: 5 col_stop: 8 path: "" - content: "x[..0u8]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "x[..0u8]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..]\\\"}\"}" - left: ~ - right: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: "x[..]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" - left: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 6 - path: "" - content: "x[x.y..]" - type_: ~ - right: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "x[x.y..]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" - left: ~ - right: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" - name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[..y.x]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 5 - col_stop: 8 - path: "" - content: "x[..y.x]" - type_: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "x[..y.x]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" - left: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 6 - path: "" - content: "x[x.y..y.x]" - type_: ~ - right: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" - name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 8 - col_stop: 11 - path: "" - content: "x[x.y..y.x]" - type_: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 12 - path: "" - content: "x[x.y..y.x]" - - ArrayRangeAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" - left: - CircuitMemberAccess: - circuit: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + content: "x[..y.x]" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "x[..y.x]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" + left: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" span: line_start: 1 line_stop: 1 col_start: 3 col_stop: 6 path: "" + content: "x[x.y..y.x]" + type_: ~ + right: + Access: + Member: + inner: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y..y.x]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 8 + col_stop: 11 + path: "" + content: "x[x.y..y.x]" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "x[x.y..y.x]" + - Access: + ArrayRange: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + left: + Access: + Member: + inner: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 6 + path: "" + content: "x[x.y.x..y.x.y]" + type_: ~ + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 8 + path: "" content: "x[x.y.x..y.x.y]" type_: ~ - name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 8 - path: "" - content: "x[x.y.x..y.x.y]" - type_: ~ - right: - CircuitMemberAccess: - circuit: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" - name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + right: + Access: + Member: + inner: + Access: + Member: + inner: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 10 + col_stop: 13 + path: "" + content: "x[x.y.x..y.x.y]" + type_: ~ + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" span: line_start: 1 line_stop: 1 col_start: 10 - col_stop: 13 + col_stop: 15 path: "" content: "x[x.y.x..y.x.y]" type_: ~ - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":14,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[x.y.x..y.x.y]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 10 - col_stop: 15 - path: "" - content: "x[x.y.x..y.x.y]" - type_: ~ - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 16 - path: "" - content: "x[x.y.x..y.x.y]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 16 + path: "" + content: "x[x.y.x..y.x.y]" diff --git a/tests/expectations/parser/parser/expression/access/call.leo.out b/tests/expectations/parser/parser/expression/access/call.leo.out index 56ad6d5493..eb541b94a7 100644 --- a/tests/expectations/parser/parser/expression/access/call.leo.out +++ b/tests/expectations/parser/parser/expression/access/call.leo.out @@ -65,17 +65,19 @@ outputs: content: "x(x, y, z)" - Call: function: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y()" + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y()" arguments: [] span: line_start: 1 @@ -86,17 +88,19 @@ outputs: content: "x::y()" - Call: function: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y(x)\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y(x)\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y(x)" + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y(x)\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y(x)\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y(x)" arguments: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":7,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y(x)\\\"}\"}" span: @@ -108,18 +112,19 @@ outputs: content: "x::y(x)" - Call: function: - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0(x)\\\"}\"}" - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.0(x) + Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0(x)\\\"}\"}" + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.0(x) arguments: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0(x)\\\"}\"}" span: @@ -131,27 +136,28 @@ outputs: content: x.0(x) - Call: function: - ArrayAccess: - array: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0](x)\\\"}\"}" - index: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 4 - path: "" - content: "x[0](x)" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x[0](x)" + Access: + Array: + array: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0](x)\\\"}\"}" + index: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 4 + path: "" + content: "x[0](x)" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x[0](x)" arguments: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":7,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x[0](x)\\\"}\"}" span: diff --git a/tests/expectations/parser/parser/expression/access/circuit.leo.out b/tests/expectations/parser/parser/expression/access/circuit.leo.out index e84068ed71..19b5bb9c4a 100644 --- a/tests/expectations/parser/parser/expression/access/circuit.leo.out +++ b/tests/expectations/parser/parser/expression/access/circuit.leo.out @@ -2,67 +2,72 @@ namespace: ParseExpression expectation: Pass outputs: - - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.y - type_: ~ - - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X.Y\\\"}\"}" - name: "{\"name\":\"Y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X.Y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: X.Y - type_: ~ - - CircuitMemberAccess: - circuit: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.y.z - type_: ~ - name: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: x.y.z - type_: ~ + - Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.y + type_: ~ + - Access: + Member: + inner: + Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X.Y\\\"}\"}" + name: "{\"name\":\"Y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X.Y\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: X.Y + type_: ~ + - Access: + Member: + inner: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.y.z + type_: ~ + name: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.z\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: x.y.z + type_: ~ - Call: function: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y()\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y()\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.y() - type_: ~ + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y()\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.y() + type_: ~ arguments: [] span: line_start: 1 @@ -71,58 +76,62 @@ outputs: col_stop: 6 path: "" content: x.y() - - TupleAccess: - tuple: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.0\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.0\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.y.0 - type_: ~ - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: x.y.0 - - ArrayAccess: - array: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y[1]\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y[1]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: "x.y[1]" - type_: ~ - index: - Value: - Implicit: - - "1" - - span: + - Access: + Tuple: + tuple: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.0\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y.0\\\"}\"}" + span: line_start: 1 line_stop: 1 - col_start: 5 - col_stop: 6 + col_start: 1 + col_stop: 4 + path: "" + content: x.y.0 + type_: ~ + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: x.y.0 + - Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y[1]\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.y[1]\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 path: "" content: "x.y[1]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x.y[1]" + type_: ~ + index: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 5 + col_stop: 6 + path: "" + content: "x.y[1]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x.y[1]" diff --git a/tests/expectations/parser/parser/expression/access/circuit_static.leo.out b/tests/expectations/parser/parser/expression/access/circuit_static.leo.out index e0d20d272f..f01ebb1773 100644 --- a/tests/expectations/parser/parser/expression/access/circuit_static.leo.out +++ b/tests/expectations/parser/parser/expression/access/circuit_static.leo.out @@ -2,62 +2,72 @@ namespace: ParseExpression expectation: Pass outputs: - - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y" - - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X::Y\\\"}\"}" - name: "{\"name\":\"Y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X::Y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "X::Y" - - CircuitStaticFunctionAccess: - circuit: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y::z" - name: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 8 - path: "" - content: "x::y::z" + - Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y" + - Access: + Static: + inner: + Identifier: "{\"name\":\"X\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X::Y\\\"}\"}" + name: "{\"name\":\"Y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"X::Y\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "X::Y" + - Access: + Static: + inner: + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y::z" + name: "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y::z\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 8 + path: "" + content: "x::y::z" - Call: function: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y()" + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y()" arguments: [] span: line_start: 1 @@ -66,56 +76,62 @@ outputs: col_stop: 7 path: "" content: "x::y()" - - TupleAccess: - tuple: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y.0\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y.0\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y.0" - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "x::y.0" - - ArrayAccess: - array: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y[1]\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y[1]\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 5 - path: "" - content: "x::y[1]" - index: - Value: - Implicit: - - "1" - - span: + - Access: + Tuple: + tuple: + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y.0\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y.0\\\"}\"}" + type_: ~ + span: line_start: 1 line_stop: 1 - col_start: 6 - col_stop: 7 + col_start: 1 + col_stop: 5 + path: "" + content: "x::y.0" + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "x::y.0" + - Access: + Array: + array: + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y[1]\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x::y[1]\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 path: "" content: "x::y[1]" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 8 - path: "" - content: "x::y[1]" + index: + Value: + Implicit: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 6 + col_stop: 7 + path: "" + content: "x::y[1]" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 8 + path: "" + content: "x::y[1]" diff --git a/tests/expectations/parser/parser/expression/access/tuple.leo.out b/tests/expectations/parser/parser/expression/access/tuple.leo.out index 5a9b570777..e904278a34 100644 --- a/tests/expectations/parser/parser/expression/access/tuple.leo.out +++ b/tests/expectations/parser/parser/expression/access/tuple.leo.out @@ -2,108 +2,117 @@ namespace: ParseExpression expectation: Pass outputs: - - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0\\\"}\"}" - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.0 - - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.1\\\"}\"}" - index: - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.1 - - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.2\\\"}\"}" - index: - value: "2" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.2 - - TupleAccess: - tuple: - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0.0\\\"}\"}" - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.0.0 - index: - value: "0" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: x.0.0 - - TupleAccess: - tuple: - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.1.1\\\"}\"}" - index: - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.1.1 - index: - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: x.1.1 - - TupleAccess: - tuple: - TupleAccess: - tuple: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.2.2\\\"}\"}" - index: - value: "2" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 4 - path: "" - content: x.2.2 - index: - value: "2" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 6 - path: "" - content: x.2.2 + - Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0\\\"}\"}" + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.0 + - Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.1\\\"}\"}" + index: + value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.1 + - Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.2\\\"}\"}" + index: + value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.2 + - Access: + Tuple: + tuple: + Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.0.0\\\"}\"}" + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.0.0 + index: + value: "0" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: x.0.0 + - Access: + Tuple: + tuple: + Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.1.1\\\"}\"}" + index: + value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.1.1 + index: + value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: x.1.1 + - Access: + Tuple: + tuple: + Access: + Tuple: + tuple: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":2,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"x.2.2\\\"}\"}" + index: + value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: x.2.2 + index: + value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: x.2.2 diff --git a/tests/expectations/parser/parser/expression/array_init.leo.out b/tests/expectations/parser/parser/expression/array_init.leo.out index 00b738d2cb..bf542ace05 100644 --- a/tests/expectations/parser/parser/expression/array_init.leo.out +++ b/tests/expectations/parser/parser/expression/array_init.leo.out @@ -88,6 +88,28 @@ outputs: col_stop: 12 path: "" content: "[0; (1, 2)]" + - ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "[0; (1, 2,)]" + dimensions: + - value: "1" + - value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "[0; (1, 2,)]" - ArrayInit: element: Value: diff --git a/tests/expectations/parser/parser/expression/array_init_fail.leo.out b/tests/expectations/parser/parser/expression/array_init_fail.leo.out index 0eacb46895..d8a72305fd 100644 --- a/tests/expectations/parser/parser/expression/array_init_fail.leo.out +++ b/tests/expectations/parser/parser/expression/array_init_fail.leo.out @@ -4,3 +4,4 @@ expectation: Fail outputs: - "Error [EPAR0370010]: illegal spread in array initializer\n --> test:1:1\n |\n 1 | [...0u8; 1]\n | ^^^^^^^" - "Error [EPAR0370010]: illegal spread in array initializer\n --> test:1:1\n |\n 1 | [...0; 1]\n | ^^^^^" + - "Error [EPAR0370023]: Array dimensions specified as a tuple cannot be empty.\n --> test:1:5\n |\n 1 | [0; ()]\n | ^^" diff --git a/tests/expectations/parser/parser/expression/array_len.leo.out b/tests/expectations/parser/parser/expression/array_len.leo.out index 42b12f37b3..5d31cbeb55 100644 --- a/tests/expectations/parser/parser/expression/array_len.leo.out +++ b/tests/expectations/parser/parser/expression/array_len.leo.out @@ -2,209 +2,287 @@ namespace: ParseExpression expectation: Pass outputs: - - LengthOf: - inner: - ArrayInit: - element: - Value: - Integer: - - U8 - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 5 - path: "" - content: "[0u8; 1].len()" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0u8; 1].len()" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0u8; 1].len()" - - LengthOf: - inner: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; 1].len()" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "[0; 1].len()" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 7 - path: "" - content: "[0; 1].len()" - - LengthOf: - inner: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; (1)].len()" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0; (1)].len()" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 9 - path: "" - content: "[0; (1)].len()" - - LengthOf: - inner: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; (1, 2)].len()" - dimensions: - - value: "1" - - value: "2" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 12 - path: "" - content: "[0; (1, 2)].len()" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 12 - path: "" - content: "[0; (1, 2)].len()" - - LengthOf: - inner: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 3 - path: "" - content: "[0; (1, 2, 3)].len()" - dimensions: - - value: "1" - - value: "2" - - value: "3" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 15 - path: "" - content: "[0; (1, 2, 3)].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + Value: + Integer: + - U8 + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 5 + path: "" + content: "[0u8; 1].len()" + dimensions: + - value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "[0u8; 1].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0u8; 1].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "[0u8; 1].len()" + type_: ~ + arguments: [] span: line_start: 1 line_stop: 1 col_start: 1 col_stop: 15 path: "" - content: "[0; (1, 2, 3)].len()" - - LengthOf: - inner: - ArrayInit: - element: - ArrayInit: - element: - ArrayInit: - element: - Value: - Implicit: - - "0" - - span: - line_start: 1 - line_stop: 1 - col_start: 4 - col_stop: 5 - path: "" - content: "[[[0; 3]; 2]; 1].len()" - dimensions: - - value: "3" - span: - line_start: 1 - line_stop: 1 - col_start: 3 - col_stop: 9 - path: "" - content: "[[[0; 3]; 2]; 1].len()" - dimensions: - - value: "2" - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 13 - path: "" - content: "[[[0; 3]; 2]; 1].len()" - dimensions: - - value: "1" - span: - line_start: 1 - line_stop: 1 - col_start: 1 - col_stop: 17 - path: "" - content: "[[[0; 3]; 2]; 1].len()" + content: "[0u8; 1].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "[0; 1].len()" + dimensions: + - value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: "[0; 1].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0; 1].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "[0; 1].len()" + type_: ~ + arguments: [] span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 17 + col_stop: 13 + path: "" + content: "[0; 1].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "[0; (1)].len()" + dimensions: + - value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "[0; (1)].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0; (1)].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "[0; (1)].len()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 15 + path: "" + content: "[0; (1)].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "[0; (1, 2)].len()" + dimensions: + - value: "1" + - value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "[0; (1, 2)].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":13,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0; (1, 2)].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 16 + path: "" + content: "[0; (1, 2)].len()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 18 + path: "" + content: "[0; (1, 2)].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "[0; (1, 2, 3)].len()" + dimensions: + - value: "1" + - value: "2" + - value: "3" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 15 + path: "" + content: "[0; (1, 2, 3)].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":16,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[0; (1, 2, 3)].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 19 + path: "" + content: "[0; (1, 2, 3)].len()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 21 + path: "" + content: "[0; (1, 2, 3)].len()" + - Call: + function: + Access: + Member: + inner: + ArrayInit: + element: + ArrayInit: + element: + ArrayInit: + element: + Value: + Implicit: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 4 + col_stop: 5 + path: "" + content: "[[[0; 3]; 2]; 1].len()" + dimensions: + - value: "3" + span: + line_start: 1 + line_stop: 1 + col_start: 3 + col_stop: 9 + path: "" + content: "[[[0; 3]; 2]; 1].len()" + dimensions: + - value: "2" + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 13 + path: "" + content: "[[[0; 3]; 2]; 1].len()" + dimensions: + - value: "1" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 17 + path: "" + content: "[[[0; 3]; 2]; 1].len()" + name: "{\"name\":\"len\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"[[[0; 3]; 2]; 1].len()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 21 + path: "" + content: "[[[0; 3]; 2]; 1].len()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 23 path: "" content: "[[[0; 3]; 2]; 1].len()" diff --git a/tests/expectations/parser/parser/expression/literal/access.leo.out b/tests/expectations/parser/parser/expression/literal/access.leo.out new file mode 100644 index 0000000000..e2dbf60e24 --- /dev/null +++ b/tests/expectations/parser/parser/expression/literal/access.leo.out @@ -0,0 +1,963 @@ +--- +namespace: ParseExpression +expectation: Pass +outputs: + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Address: + - aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 64 + path: "" + content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":65,\\\"col_stop\\\":69,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 69 + path: "" + content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 71 + path: "" + content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8.call() + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"address\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"address::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"address::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 14 + path: "" + content: "address::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 16 + path: "" + content: "address::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Boolean: + - "true" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: true.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"true.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: true.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: true.call() + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"bool\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"bool::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"bool::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "bool::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "bool::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Char: + character: + Scalar: 97 + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: "'a'.call()" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"'a'.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "'a'.call()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "'a'.call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"char\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"char::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"char::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "char::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "char::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Field: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: 1field.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1field.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1field.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 14 + path: "" + content: 1field.call() + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"field\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"field::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"field::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "field::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 14 + path: "" + content: "field::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Group: + Single: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 7 + path: "" + content: 0group.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"0group.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 0group.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 14 + path: "" + content: 0group.call() + - Call: + function: + Access: + Member: + inner: + Value: + Group: + Tuple: + x: + Number: + - "0" + - span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 3 + path: "" + content: "(0, 1)group.call()" + y: + Number: + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 5 + col_stop: 6 + path: "" + content: "(0, 1)group.call()" + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 12 + path: "" + content: "(0, 1)group.call()" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":13,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"(0, 1)group.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 17 + path: "" + content: "(0, 1)group.call()" + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 19 + path: "" + content: "(0, 1)group.call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"group\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"group::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":8,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"group::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "group::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 14 + path: "" + content: "group::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - I8 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: 1i8.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1i8.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: 1i8.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: 1i8.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - I16 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1i16.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1i16.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1i16.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1i16.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - I32 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1i32.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1i32.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1i32.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1i32.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - I64 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1i64.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1i64.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1i64.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1i64.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - I128 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: 1i128.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1i128.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: 1i128.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: 1i128.call() + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"i8\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i8::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i8::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "i8::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "i8::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"i16\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i16::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i16::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "i16::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "i16::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"i32\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i32::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i32::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "i32::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "i32::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"i64\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i64::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i64::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "i64::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "i64::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"i128\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i128::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"i128::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "i128::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "i128::call()" + - Value: + Implicit: + - "" + - span: + line_start: 0 + line_stop: 0 + col_start: 0 + col_stop: 0 + path: "" + content: "" + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - U8 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 4 + path: "" + content: 1u8.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1u8.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: 1u8.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: 1u8.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - U16 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1u16.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1u16.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1u16.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1u16.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - U32 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1u32.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1u32.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1u32.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1u32.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - U64 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 5 + path: "" + content: 1u64.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1u64.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: 1u64.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: 1u64.call() + - Call: + function: + Access: + Member: + inner: + Value: + Integer: + - U128 + - "1" + - span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 6 + path: "" + content: 1u128.call() + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"1u128.call()\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: 1u128.call() + type_: ~ + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: 1u128.call() + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"u8\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u8::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u8::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 9 + path: "" + content: "u8::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "u8::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"u16\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u16::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u16::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "u16::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "u16::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"u32\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u32::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u32::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "u32::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "u32::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"u64\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u64::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":6,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u64::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 10 + path: "" + content: "u64::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 12 + path: "" + content: "u64::call()" + - Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"u128\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":1,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u128::call()\\\"}\"}" + name: "{\"name\":\"call\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":7,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"u128::call()\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "u128::call()" + arguments: [] + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 13 + path: "" + content: "u128::call()" diff --git a/tests/expectations/parser/parser/expression/literal/group_fail.leo.out b/tests/expectations/parser/parser/expression/literal/group_fail.leo.out index 8816fb7773..e9076add85 100644 --- a/tests/expectations/parser/parser/expression/literal/group_fail.leo.out +++ b/tests/expectations/parser/parser/expression/literal/group_fail.leo.out @@ -2,7 +2,6 @@ namespace: ParseExpression expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'group'\n --> test:1:1\n |\n 1 | group\n | ^^^^^" - "did not consume all input: 'group' @ 1:3-8\n" - "did not consume all input: 'group' @ 1:6-11\n" - "Error [EPAR0370009]: unexpected string: expected 'expression', got ','\n --> test:1:2\n |\n 1 | (,)group\n | ^" diff --git a/tests/expectations/parser/parser/expression/unary/negate.leo.out b/tests/expectations/parser/parser/expression/unary/negate.leo.out index 9fe8865d44..649b722072 100644 --- a/tests/expectations/parser/parser/expression/unary/negate.leo.out +++ b/tests/expectations/parser/parser/expression/unary/negate.leo.out @@ -15,18 +15,19 @@ outputs: content: "-x" - Unary: inner: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x.y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x.y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 5 - path: "" - content: "-x.y" - type_: ~ + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x.y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x.y\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 5 + path: "" + content: "-x.y" + type_: ~ op: Negate span: line_start: 1 @@ -37,17 +38,19 @@ outputs: content: "-x.y" - Unary: inner: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x::y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x::y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 6 - path: "" - content: "-x::y" + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x::y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"-x::y\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 6 + path: "" + content: "-x::y" op: Negate span: line_start: 1 diff --git a/tests/expectations/parser/parser/expression/unary/not.leo.out b/tests/expectations/parser/parser/expression/unary/not.leo.out index 04de6a3e4c..71716da156 100644 --- a/tests/expectations/parser/parser/expression/unary/not.leo.out +++ b/tests/expectations/parser/parser/expression/unary/not.leo.out @@ -15,18 +15,19 @@ outputs: content: "!x" - Unary: inner: - CircuitMemberAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x.y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x.y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 5 - path: "" - content: "!x.y" - type_: ~ + Access: + Member: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x.y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":4,\\\"col_stop\\\":5,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x.y\\\"}\"}" + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 5 + path: "" + content: "!x.y" + type_: ~ op: Not span: line_start: 1 @@ -37,17 +38,19 @@ outputs: content: "!x.y" - Unary: inner: - CircuitStaticFunctionAccess: - circuit: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x::y\\\"}\"}" - name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x::y\\\"}\"}" - span: - line_start: 1 - line_stop: 1 - col_start: 2 - col_stop: 6 - path: "" - content: "!x::y" + Access: + Static: + inner: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":2,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x::y\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"!x::y\\\"}\"}" + type_: ~ + span: + line_start: 1 + line_stop: 1 + col_start: 2 + col_stop: 6 + path: "" + content: "!x::y" op: Not span: line_start: 1 diff --git a/tests/expectations/parser/parser/functions/annotated.leo.out b/tests/expectations/parser/parser/functions/annotated.leo.out index 67fcef91c6..d9e264e6cf 100644 --- a/tests/expectations/parser/parser/functions/annotated.leo.out +++ b/tests/expectations/parser/parser/functions/annotated.leo.out @@ -10,9 +10,10 @@ outputs: circuits: {} global_consts: {} functions: - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}": + "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function a() {\\\"}\"}": annotations: - - span: + test: + span: line_start: 3 line_stop: 3 col_start: 1 @@ -21,9 +22,11 @@ outputs: content: "@test" name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" arguments: [] - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}" + identifier: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function a() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -50,11 +53,166 @@ outputs: col_start: 14 col_stop: 2 path: "" - content: "function x() {\n ...\n}" + content: "function a() {\n ...\n}" span: line_start: 4 line_stop: 6 col_start: 1 col_stop: 2 path: "" - content: "function x() {\n ...\n}" + content: "function a() {\n ...\n}" + "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function b() {\\\"}\"}": + annotations: + test: + span: + line_start: 8 + line_stop: 8 + col_start: 1 + col_stop: 12 + path: "" + content: "@test(test)" + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test(test)\\\"}\"}" + arguments: + - test + identifier: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function b() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 10 + line_stop: 10 + col_start: 12 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 10 + line_stop: 10 + col_start: 5 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 9 + line_stop: 11 + col_start: 14 + col_stop: 2 + path: "" + content: "function b() {\n ...\n}" + span: + line_start: 9 + line_stop: 11 + col_start: 1 + col_stop: 2 + path: "" + content: "function b() {\n ...\n}" + "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function c() {\\\"}\"}": + annotations: + test: + span: + line_start: 13 + line_stop: 13 + col_start: 1 + col_stop: 13 + path: "" + content: "@test(test,)" + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test(test,)\\\"}\"}" + arguments: + - test + identifier: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function c() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 15 + line_stop: 15 + col_start: 12 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 15 + line_stop: 15 + col_start: 5 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 14 + line_stop: 16 + col_start: 14 + col_stop: 2 + path: "" + content: "function c() {\n ...\n}" + span: + line_start: 14 + line_stop: 16 + col_start: 1 + col_stop: 2 + path: "" + content: "function c() {\n ...\n}" + "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function d() {\\\"}\"}": + annotations: + test: + span: + line_start: 18 + line_stop: 18 + col_start: 1 + col_stop: 8 + path: "" + content: "@test()" + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test()\\\"}\"}" + arguments: [] + identifier: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function d() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 20 + line_stop: 20 + col_start: 12 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 20 + line_stop: 20 + col_start: 5 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 19 + line_stop: 21 + col_start: 14 + col_stop: 2 + path: "" + content: "function d() {\n ...\n}" + span: + line_start: 19 + line_stop: 21 + col_start: 1 + col_stop: 2 + path: "" + content: "function d() {\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/annotated_arg_not_ident_int.leo.out b/tests/expectations/parser/parser/functions/annotated_arg_not_ident_int.leo.out new file mode 100644 index 0000000000..34585e8f24 --- /dev/null +++ b/tests/expectations/parser/parser/functions/annotated_arg_not_ident_int.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'ident or int', got '?'\n --> test:3:6\n |\n 3 | @foo(?, bar, ?)\n | ^\nError [EPAR0370009]: unexpected string: expected 'ident or int', got '?'\n --> test:3:14\n |\n 3 | @foo(?, bar, ?)\n | ^\nError [EPAR0370017]: \"@context(...)\" is deprecated. Did you mean @test annotation?\n --> test:8:2\n |\n 8 | @context // recovery witness\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/functions/annotated_context_fail.leo.out b/tests/expectations/parser/parser/functions/annotated_context_fail.leo.out new file mode 100644 index 0000000000..15e47e1265 --- /dev/null +++ b/tests/expectations/parser/parser/functions/annotated_context_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370017]: \"@context(...)\" is deprecated. Did you mean @test annotation?\n --> test:3:2\n |\n 3 | @context\n | ^^^^^^^\nError [EPAR0370017]: \"@context(...)\" is deprecated. Did you mean @test annotation?\n --> test:8:2\n |\n 8 | @context // recovery witness\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/functions/annotated_param.leo.out b/tests/expectations/parser/parser/functions/annotated_param.leo.out index 9d5acf38e5..5e5e8b0796 100644 --- a/tests/expectations/parser/parser/functions/annotated_param.leo.out +++ b/tests/expectations/parser/parser/functions/annotated_param.leo.out @@ -12,7 +12,8 @@ outputs: functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}": annotations: - - span: + test: + span: line_start: 3 line_stop: 3 col_start: 1 @@ -24,7 +25,9 @@ outputs: - test identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/annotated_twice.leo.out b/tests/expectations/parser/parser/functions/annotated_twice.leo.out index 5b3bda5319..7afe638d67 100644 --- a/tests/expectations/parser/parser/functions/annotated_twice.leo.out +++ b/tests/expectations/parser/parser/functions/annotated_twice.leo.out @@ -12,7 +12,8 @@ outputs: functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}": annotations: - - span: + test: + span: line_start: 3 line_stop: 3 col_start: 1 @@ -21,7 +22,8 @@ outputs: content: "@test @test2" name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test @test2\\\"}\"}" arguments: [] - - span: + test2: + span: line_start: 3 line_stop: 3 col_start: 7 @@ -32,7 +34,9 @@ outputs: arguments: [] identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out new file mode 100644 index 0000000000..53e1ab419b --- /dev/null +++ b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out @@ -0,0 +1,208 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" + const_: true + mutable: false + type_: + IntegerType: U32 + span: + line_start: 3 + line_stop: 3 + col_start: 18 + col_stop: 19 + path: "" + content: "function x(const y: u32) {" + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Conditional: + condition: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if y < 5u32 {\\\"}\"}" + right: + Value: + Integer: + - U32 + - "5" + - span: + line_start: 4 + line_stop: 4 + col_start: 12 + col_stop: 16 + path: "" + content: " if y < 5u32 {" + op: Lt + span: + line_start: 4 + line_stop: 4 + col_start: 8 + col_stop: 16 + path: "" + content: " if y < 5u32 {" + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(y+1);\\\"}\"}" + arguments: + - Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":11,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(y+1);\\\"}\"}" + right: + Value: + Implicit: + - "1" + - span: + line_start: 5 + line_stop: 5 + col_start: 13 + col_stop: 14 + path: "" + content: " x(y+1);" + op: Add + span: + line_start: 5 + line_stop: 5 + col_start: 11 + col_stop: 14 + path: "" + content: " x(y+1);" + span: + line_start: 5 + line_stop: 5 + col_start: 9 + col_stop: 15 + path: "" + content: " x(y+1);" + span: + line_start: 5 + line_stop: 5 + col_start: 9 + col_stop: 15 + path: "" + content: " x(y+1);" + span: + line_start: 4 + line_stop: 6 + col_start: 17 + col_stop: 6 + path: "" + content: " if y < 5u32 {\n ...\n }" + next: ~ + span: + line_start: 4 + line_stop: 6 + col_start: 5 + col_stop: 6 + path: "" + content: " if y < 5u32 {\n ...\n }" + span: + line_start: 3 + line_stop: 7 + col_start: 26 + col_stop: 2 + path: "" + content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + span: + line_start: 3 + line_stop: 7 + col_start: 1 + col_stop: 2 + path: "" + content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: Boolean + span: + line_start: 9 + line_stop: 9 + col_start: 15 + col_stop: 16 + path: "" + content: "function main(y: bool) -> bool {" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(1u32);\\\"}\"}" + arguments: + - Value: + Integer: + - U32 + - "1" + - span: + line_start: 10 + line_stop: 10 + col_start: 7 + col_stop: 11 + path: "" + content: " x(1u32);" + span: + line_start: 10 + line_stop: 10 + col_start: 5 + col_stop: 12 + path: "" + content: " x(1u32);" + span: + line_start: 10 + line_stop: 10 + col_start: 5 + col_stop: 12 + path: "" + content: " x(1u32);" + - Return: + expression: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return y;\\\"}\"}" + span: + line_start: 11 + line_stop: 11 + col_start: 5 + col_stop: 13 + path: "" + content: " return y;" + span: + line_start: 9 + line_stop: 12 + col_start: 32 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" + span: + line_start: 9 + line_stop: 12 + col_start: 1 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/bounded_recursion_fail.leo.out b/tests/expectations/parser/parser/functions/bounded_recursion_fail.leo.out new file mode 100644 index 0000000000..aed18632e6 --- /dev/null +++ b/tests/expectations/parser/parser/functions/bounded_recursion_fail.leo.out @@ -0,0 +1,208 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const y: u32) {\\\"}\"}" + const_: true + mutable: false + type_: + IntegerType: U32 + span: + line_start: 3 + line_stop: 3 + col_start: 18 + col_stop: 19 + path: "" + content: "function x(const y: u32) {" + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Conditional: + condition: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if y < 999u32 {\\\"}\"}" + right: + Value: + Integer: + - U32 + - "999" + - span: + line_start: 4 + line_stop: 4 + col_start: 12 + col_stop: 18 + path: "" + content: " if y < 999u32 {" + op: Lt + span: + line_start: 4 + line_stop: 4 + col_start: 8 + col_stop: 18 + path: "" + content: " if y < 999u32 {" + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(y+1);\\\"}\"}" + arguments: + - Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":11,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(y+1);\\\"}\"}" + right: + Value: + Implicit: + - "1" + - span: + line_start: 5 + line_stop: 5 + col_start: 13 + col_stop: 14 + path: "" + content: " x(y+1);" + op: Add + span: + line_start: 5 + line_stop: 5 + col_start: 11 + col_stop: 14 + path: "" + content: " x(y+1);" + span: + line_start: 5 + line_stop: 5 + col_start: 9 + col_stop: 15 + path: "" + content: " x(y+1);" + span: + line_start: 5 + line_stop: 5 + col_start: 9 + col_stop: 15 + path: "" + content: " x(y+1);" + span: + line_start: 4 + line_stop: 6 + col_start: 19 + col_stop: 6 + path: "" + content: " if y < 999u32 {\n ...\n }" + next: ~ + span: + line_start: 4 + line_stop: 6 + col_start: 5 + col_stop: 6 + path: "" + content: " if y < 999u32 {\n ...\n }" + span: + line_start: 3 + line_stop: 7 + col_start: 26 + col_stop: 2 + path: "" + content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + span: + line_start: 3 + line_stop: 7 + col_start: 1 + col_stop: 2 + path: "" + content: "function x(const y: u32) {\n ...\n ...\n ...\n}" + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: Boolean + span: + line_start: 9 + line_stop: 9 + col_start: 15 + col_stop: 16 + path: "" + content: "function main(y: bool) -> bool {" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x(1u32);\\\"}\"}" + arguments: + - Value: + Integer: + - U32 + - "1" + - span: + line_start: 10 + line_stop: 10 + col_start: 7 + col_stop: 11 + path: "" + content: " x(1u32);" + span: + line_start: 10 + line_stop: 10 + col_start: 5 + col_stop: 12 + path: "" + content: " x(1u32);" + span: + line_start: 10 + line_stop: 10 + col_start: 5 + col_stop: 12 + path: "" + content: " x(1u32);" + - Return: + expression: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return y;\\\"}\"}" + span: + line_start: 11 + line_stop: 11 + col_start: 5 + col_stop: 13 + path: "" + content: " return y;" + span: + line_start: 9 + line_stop: 12 + col_start: 32 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" + span: + line_start: 9 + line_stop: 12 + col_start: 1 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/const_function.leo.out b/tests/expectations/parser/parser/functions/const_function.leo.out new file mode 100644 index 0000000000..142f12dfb9 --- /dev/null +++ b/tests/expectations/parser/parser/functions/const_function.leo.out @@ -0,0 +1,53 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const function x() {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const function x() {\\\"}\"}" + input: [] + const_: true + output: ~ + core_mapping: ~ + block: + statements: + - Return: + expression: + TupleInit: + elements: [] + span: + line_start: 4 + line_stop: 4 + col_start: 12 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 4 + line_stop: 4 + col_start: 5 + col_stop: 14 + path: "" + content: " return ();" + span: + line_start: 3 + line_stop: 5 + col_start: 20 + col_stop: 2 + path: "" + content: "const function x() {\n ...\n}" + span: + line_start: 3 + line_stop: 5 + col_start: 7 + col_stop: 2 + path: "" + content: "const function x() {\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/const_param.leo.out b/tests/expectations/parser/parser/functions/const_param.leo.out index 974b0032ef..f1302d128d 100644 --- a/tests/expectations/parser/parser/functions/const_param.leo.out +++ b/tests/expectations/parser/parser/functions/const_param.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, const y: i32) {\\\"}\"}" input: - Variable: @@ -40,7 +40,9 @@ outputs: col_stop: 27 path: "" content: "function x(x: u32, const y: i32) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: @@ -76,7 +78,7 @@ outputs: path: "" content: "function x(x: u32, const y: i32) {\n ...\n}" "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u32, y: i32) {\\\"}\"}" input: - Variable: @@ -105,7 +107,9 @@ outputs: col_stop: 27 path: "" content: "function x(const x: u32, y: i32) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/const_self_bad.leo.out b/tests/expectations/parser/parser/functions/const_self_bad.leo.out index 13de7c2191..3b02d74ff3 100644 --- a/tests/expectations/parser/parser/functions/const_self_bad.leo.out +++ b/tests/expectations/parser/parser/functions/const_self_bad.leo.out @@ -11,11 +11,13 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const self) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const self) {\\\"}\"}" input: - ConstSelfKeyword: "{\"name\":\"const self\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const self) {\\\"}\"}" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/empty.leo.out b/tests/expectations/parser/parser/functions/empty.leo.out index 319f4a6f56..4bd3bfbc1a 100644 --- a/tests/expectations/parser/parser/functions/empty.leo.out +++ b/tests/expectations/parser/parser/functions/empty.leo.out @@ -11,10 +11,12 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/empty2.leo.out b/tests/expectations/parser/parser/functions/empty2.leo.out index 31558387f6..60c3f10b1c 100644 --- a/tests/expectations/parser/parser/functions/empty2.leo.out +++ b/tests/expectations/parser/parser/functions/empty2.leo.out @@ -11,10 +11,12 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {}\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() {}\\\"}\"}" input: [] + const_: false output: ~ + core_mapping: ~ block: statements: [] span: diff --git a/tests/expectations/parser/parser/functions/infinite_recursion_fail.leo.out b/tests/expectations/parser/parser/functions/infinite_recursion_fail.leo.out new file mode 100644 index 0000000000..93a823f907 --- /dev/null +++ b/tests/expectations/parser/parser/functions/infinite_recursion_fail.leo.out @@ -0,0 +1,120 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" inf();\\\"}\"}" + arguments: [] + span: + line_start: 4 + line_stop: 4 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 4 + line_stop: 4 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 3 + line_stop: 5 + col_start: 16 + col_stop: 2 + path: "" + content: "function inf() {\n ...\n}" + span: + line_start: 3 + line_stop: 5 + col_start: 1 + col_stop: 2 + path: "" + content: "function inf() {\n ...\n}" + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: Boolean + span: + line_start: 7 + line_stop: 7 + col_start: 15 + col_stop: 16 + path: "" + content: "function main(y: bool) -> bool {" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":5,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" inf();\\\"}\"}" + arguments: [] + span: + line_start: 8 + line_stop: 8 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 8 + line_stop: 8 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + - Return: + expression: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return y;\\\"}\"}" + span: + line_start: 9 + line_stop: 9 + col_start: 5 + col_stop: 13 + path: "" + content: " return y;" + span: + line_start: 7 + line_stop: 10 + col_start: 32 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" + span: + line_start: 7 + line_stop: 10 + col_start: 1 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" diff --git a/tests/expectations/parser/parser/functions/param_array.leo.out b/tests/expectations/parser/parser/functions/param_array.leo.out index 02d219333a..b648d79414 100644 --- a/tests/expectations/parser/parser/functions/param_array.leo.out +++ b/tests/expectations/parser/parser/functions/param_array.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: [u8; 12]) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: [u8; 12]) {\\\"}\"}" input: - Variable: @@ -29,7 +29,9 @@ outputs: col_stop: 13 path: "" content: "function x(x: [u8; 12]) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/param_array_unsized.leo.out b/tests/expectations/parser/parser/functions/param_array_unsized.leo.out index e34bccbcb2..41594cf508 100644 --- a/tests/expectations/parser/parser/functions/param_array_unsized.leo.out +++ b/tests/expectations/parser/parser/functions/param_array_unsized.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: [u8; _]) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: [u8; _]) {\\\"}\"}" input: - Variable: @@ -29,7 +29,9 @@ outputs: col_stop: 13 path: "" content: "function x(x: [u8; _]) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/param_circuit.leo.out b/tests/expectations/parser/parser/functions/param_circuit.leo.out index 41aa2496ab..2d18f67ce0 100644 --- a/tests/expectations/parser/parser/functions/param_circuit.leo.out +++ b/tests/expectations/parser/parser/functions/param_circuit.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: MyCircuit) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: MyCircuit) {\\\"}\"}" input: - Variable: @@ -27,7 +27,9 @@ outputs: col_stop: 13 path: "" content: "function x(x: MyCircuit) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/param_tuple.leo.out b/tests/expectations/parser/parser/functions/param_tuple.leo.out index 1b81592a70..17e104a53a 100644 --- a/tests/expectations/parser/parser/functions/param_tuple.leo.out +++ b/tests/expectations/parser/parser/functions/param_tuple.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: (u32, i32)) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: (u32, i32)) {\\\"}\"}" input: - Variable: @@ -29,7 +29,9 @@ outputs: col_stop: 13 path: "" content: "function x(x: (u32, i32)) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/params.leo.out b/tests/expectations/parser/parser/functions/params.leo.out index 6f84f7488c..26c4fe8b37 100644 --- a/tests/expectations/parser/parser/functions/params.leo.out +++ b/tests/expectations/parser/parser/functions/params.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) {\\\"}\"}" input: - Variable: @@ -40,7 +40,9 @@ outputs: col_stop: 21 path: "" content: "function x(x: u32, y: i32) {" + const_: false output: ~ + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/params_return.leo.out b/tests/expectations/parser/parser/functions/params_return.leo.out index 0ceb91e0d2..681070bf9c 100644 --- a/tests/expectations/parser/parser/functions/params_return.leo.out +++ b/tests/expectations/parser/parser/functions/params_return.leo.out @@ -11,7 +11,7 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(x: u32, y: i32) -> u32 {\\\"}\"}" input: - Variable: @@ -40,8 +40,10 @@ outputs: col_stop: 21 path: "" content: "function x(x: u32, y: i32) -> u32 {" + const_: false output: IntegerType: U32 + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/return.leo.out b/tests/expectations/parser/parser/functions/return.leo.out index e2b451091d..abaabd9585 100644 --- a/tests/expectations/parser/parser/functions/return.leo.out +++ b/tests/expectations/parser/parser/functions/return.leo.out @@ -11,11 +11,13 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> u32 {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> u32 {\\\"}\"}" input: [] + const_: false output: IntegerType: U32 + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/functions/return_tuple.leo.out b/tests/expectations/parser/parser/functions/return_tuple.leo.out index 054adbbf0c..0fa5721ff3 100644 --- a/tests/expectations/parser/parser/functions/return_tuple.leo.out +++ b/tests/expectations/parser/parser/functions/return_tuple.leo.out @@ -11,13 +11,15 @@ outputs: global_consts: {} functions: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> (u32, u32) {\\\"}\"}": - annotations: [] + annotations: {} identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x() -> (u32, u32) {\\\"}\"}" input: [] + const_: false output: Tuple: - IntegerType: U32 - IntegerType: U32 + core_mapping: ~ block: statements: - Return: diff --git a/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out b/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out index e9201ce299..0436fedf95 100644 --- a/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out +++ b/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370002]: Cannot import empty list\n --> test:3:8\n |\n 3 | import a.();\n | ^" + - "Error [EPAR0370002]: Cannot import empty list\n --> test:3:8\n |\n 3 | import a.();\n | ^\nError [EPAR0370002]: Cannot import empty list\n --> test:5:8\n |\n 5 | import a.();\n | ^" diff --git a/tests/expectations/parser/parser/import/invalid_chars_fail.leo.out b/tests/expectations/parser/parser/import/invalid_chars_fail.leo.out new file mode 100644 index 0000000000..e44abfa775 --- /dev/null +++ b/tests/expectations/parser/parser/import/invalid_chars_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370012]: package names must be lowercase alphanumeric ascii with underscores and singular dashes\n --> test:3:8\n |\n 3 | import AB.c;\n | ^^\nError [EPAR0370012]: package names must be lowercase alphanumeric ascii with underscores and singular dashes\n --> test:5:8\n |\n 5 | import AB.c;\n | ^^" diff --git a/tests/expectations/parser/parser/import/keyword_fail.leo.out b/tests/expectations/parser/parser/import/keyword_fail.leo.out new file mode 100644 index 0000000000..c229c8167f --- /dev/null +++ b/tests/expectations/parser/parser/import/keyword_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'package name', got 'function'\n --> test:3:8\n |\n 3 | import function.a;\n | ^^^^^^^^\nError [EPAR0370009]: unexpected string: expected 'package name', got 'import'\n --> test:5:8\n |\n 5 | import import.a;\n | ^^^^^^" diff --git a/tests/expectations/parser/parser/serialize/linear_regression.leo.out b/tests/expectations/parser/parser/serialize/linear_regression.leo.out new file mode 100644 index 0000000000..91a060a842 --- /dev/null +++ b/tests/expectations/parser/parser/serialize/linear_regression.leo.out @@ -0,0 +1,677 @@ +--- +namespace: Serialize +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: + "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Point {\\\"}\"}": + circuit_name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Point {\\\"}\"}" + members: + - CircuitVariable: + - "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x: i32,\\\"}\"}" + - IntegerType: I32 + - CircuitVariable: + - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: i32,\\\"}\"}" + - IntegerType: I32 + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: I32 + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(x: i32, y: i32) -> Self { \\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: I32 + const_: false + output: SelfType + core_mapping: ~ + block: + statements: + - Return: + expression: + CircuitInit: + name: "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}" + expression: ~ + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { x, y };\\\"}\"}" + expression: ~ + "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":9,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit LinearRegression {\\\"}\"}": + circuit_name: "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":9,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit LinearRegression {\\\"}\"}" + members: + - CircuitVariable: + - "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" points: [Point; 5],\\\"}\"}" + - Array: + - Identifier: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":14,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" points: [Point; 5],\\\"}\"}" + - - value: "5" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Identifier: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(points: [Point; 5]) -> Self { \\\"}\"}" + - - value: "5" + const_: false + output: SelfType + core_mapping: ~ + block: + statements: + - Return: + expression: + CircuitInit: + name: "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { points };\\\"}\"}" + members: + - identifier: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { points };\\\"}\"}" + expression: ~ + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":14,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function slope(self) -> i32 { \\\"}\"}" + input: + - SelfKeyword: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":20,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function slope(self) -> i32 { \\\"}\"}" + const_: false + output: + IntegerType: I32 + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":13,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let num_points = 5i32;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "5" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x_sum = 0i32; \\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y_sum = 0i32; \\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let xy_sum = 0i32; \\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x2_sum = 0i32; \\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Iteration: + variable: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..5 {\\\"}\"}" + start: + Value: + Implicit: "0" + stop: + Value: + Implicit: "5" + inclusive: false + block: + statements: + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + accesses: [] + value: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + type_: ~ + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" + accesses: [] + value: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y;\\\"}\"}" + type_: ~ + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + accesses: [] + value: + Binary: + left: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":23,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":35,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":38,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + type_: ~ + right: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":42,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":47,\\\"col_stop\\\":53,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":54,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":57,\\\"col_stop\\\":58,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" xy_sum += self.points[i].x * self.points[i].y;\\\"}\"}" + type_: ~ + op: Mul + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + accesses: [] + value: + Binary: + left: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":23,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":35,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":38,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + type_: ~ + right: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":42,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":47,\\\"col_stop\\\":53,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":54,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":57,\\\"col_stop\\\":58,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x2_sum += self.points[i].x * self.points[i].x;\\\"}\"}" + type_: ~ + op: Mul + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"numerator\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":13,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" + type_: ~ + value: + Binary: + left: + Binary: + left: + Identifier: "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":26,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" + right: + Identifier: "{\"name\":\"xy_sum\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":39,\\\"col_stop\\\":45,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" + op: Mul + right: + Binary: + left: + Identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":50,\\\"col_stop\\\":55,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" + right: + Identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":58,\\\"col_stop\\\":63,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let numerator = (num_points * xy_sum) - (x_sum * y_sum); \\\"}\"}" + op: Mul + op: Sub + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"denominator\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":13,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" + type_: ~ + value: + Binary: + left: + Binary: + left: + Identifier: "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":28,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" + right: + Identifier: "{\"name\":\"x2_sum\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":41,\\\"col_stop\\\":47,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" + op: Mul + right: + Binary: + left: + Identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":52,\\\"col_stop\\\":57,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" + right: + Identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":60,\\\"col_stop\\\":65,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let denominator = (num_points * x2_sum) - (x_sum * x_sum);\\\"}\"}" + op: Mul + op: Sub + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" + type_: ~ + value: + Binary: + left: + Identifier: "{\"name\":\"numerator\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":21,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" + right: + Identifier: "{\"name\":\"denominator\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":33,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = numerator / denominator;\\\"}\"}" + op: Div + - Return: + expression: + Identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":38,\\\"line_stop\\\":38,\\\"col_start\\\":16,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return slope;\\\"}\"}" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":14,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}" + input: + - SelfKeyword: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":21,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}" + - Variable: + identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":41,\\\"line_stop\\\":41,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function offset(self, slope: i32) -> i32 {\\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: I32 + const_: false + output: + IntegerType: I32 + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":42,\\\"line_stop\\\":42,\\\"col_start\\\":13,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let num_points = 5i32; \\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "5" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":44,\\\"line_stop\\\":44,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x_sum = 0i32;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y_sum = 0i32;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - I32 + - "0" + - Iteration: + variable: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":46,\\\"line_stop\\\":46,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..5 {\\\"}\"}" + start: + Value: + Implicit: "0" + stop: + Value: + Implicit: "5" + inclusive: false + block: + statements: + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + accesses: [] + value: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + name: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":47,\\\"line_stop\\\":47,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x_sum += self.points[i].x;\\\"}\"}" + type_: ~ + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":13,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" + accesses: [] + value: + Access: + Member: + inner: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":22,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" + name: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":27,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":34,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" + name: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y_sum += self.points[i].y; \\\"}\"}" + type_: ~ + - Return: + expression: + Binary: + left: + Binary: + left: + Identifier: "{\"name\":\"y_sum\",\"span\":\"{\\\"line_start\\\":50,\\\"line_stop\\\":50,\\\"col_start\\\":17,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" + right: + Binary: + left: + Identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":50,\\\"line_stop\\\":50,\\\"col_start\\\":25,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" + right: + Identifier: "{\"name\":\"x_sum\",\"span\":\"{\\\"line_start\\\":50,\\\"line_stop\\\":50,\\\"col_start\\\":33,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" + op: Mul + op: Sub + right: + Identifier: "{\"name\":\"num_points\",\"span\":\"{\\\"line_start\\\":50,\\\"line_stop\\\":50,\\\"col_start\\\":42,\\\"col_stop\\\":52,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return (y_sum - slope * x_sum) / num_points;\\\"}\"}" + op: Div + global_consts: {} + functions: + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: I32 + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":24,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main (x: i32, y: i32) -> [i32; 2] {\\\"}\"}" + const_: false + mutable: true + type_: + IntegerType: I32 + const_: false + output: + Array: + - IntegerType: I32 + - - value: "2" + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":7,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let points: [Point; 5] = [\\\"}\"}" + type_: + Array: + - Identifier: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":16,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let points: [Point; 5] = [\\\"}\"}" + - - value: "5" + value: + ArrayInline: + elements: + - Expression: + CircuitInit: + name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" + right: + Value: + Implicit: "1" + op: Add + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 1, y: y + 1},\\\"}\"}" + right: + Value: + Implicit: "1" + op: Add + - Expression: + CircuitInit: + name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" + right: + Value: + Implicit: "2" + op: Add + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 2, y: y + 2},\\\"}\"}" + right: + Value: + Implicit: "2" + op: Add + - Expression: + CircuitInit: + name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" + right: + Value: + Implicit: "3" + op: Add + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 3, y: y + 3},\\\"}\"}" + right: + Value: + Implicit: "3" + op: Add + - Expression: + CircuitInit: + name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" + right: + Value: + Implicit: "4" + op: Add + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 4, y: y + 4},\\\"}\"}" + right: + Value: + Implicit: "4" + op: Add + - Expression: + CircuitInit: + name: "{\"name\":\"Point\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" + members: + - identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":16,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" + right: + Value: + Implicit: "5" + op: Add + - identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" + expression: + Binary: + left: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" Point{x: x + 5, y: y + 5}\\\"}\"}" + right: + Value: + Implicit: "5" + op: Add + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" + type_: ~ + value: + Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"LinearRegression\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":13,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" + name: "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":31,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" + type_: ~ + arguments: + - Identifier: "{\"name\":\"points\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":35,\\\"col_stop\\\":41,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let reg = LinearRegression::new(points);\\\"}\"}" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":7,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}" + type_: ~ + value: + Call: + function: + Access: + Member: + inner: + Identifier: "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":15,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}" + name: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":19,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let slope = reg.slope();\\\"}\"}" + type_: ~ + arguments: [] + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":65,\\\"line_stop\\\":65,\\\"col_start\\\":7,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" + type_: ~ + value: + Call: + function: + Access: + Member: + inner: + Identifier: "{\"name\":\"reg\",\"span\":\"{\\\"line_start\\\":65,\\\"line_stop\\\":65,\\\"col_start\\\":16,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" + name: "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":65,\\\"line_stop\\\":65,\\\"col_start\\\":20,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" + type_: ~ + arguments: + - Identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":65,\\\"line_stop\\\":65,\\\"col_start\\\":27,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let offset = reg.offset(slope);\\\"}\"}" + - Return: + expression: + ArrayInline: + elements: + - Expression: + Identifier: "{\"name\":\"slope\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":11,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return [slope, offset];\\\"}\"}" + - Expression: + Identifier: "{\"name\":\"offset\",\"span\":\"{\\\"line_start\\\":66,\\\"line_stop\\\":66,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return [slope, offset];\\\"}\"}" diff --git a/tests/expectations/parser/parser/serialize/one_plus_one.leo.out b/tests/expectations/parser/parser/serialize/one_plus_one.leo.out new file mode 100644 index 0000000000..e417be3b50 --- /dev/null +++ b/tests/expectations/parser/parser/serialize/one_plus_one.leo.out @@ -0,0 +1,36 @@ +--- +namespace: Serialize +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() -> u8 {\\\"}\"}" + input: [] + const_: false + output: + IntegerType: U8 + core_mapping: ~ + block: + statements: + - Return: + expression: + Binary: + left: + Value: + Integer: + - U8 + - "1" + right: + Value: + Integer: + - U8 + - "1" + op: Add diff --git a/tests/expectations/parser/parser/serialize/palindrome.leo.out b/tests/expectations/parser/parser/serialize/palindrome.leo.out new file mode 100644 index 0000000000..6ecc69d502 --- /dev/null +++ b/tests/expectations/parser/parser/serialize/palindrome.leo.out @@ -0,0 +1,554 @@ +--- +namespace: Serialize +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":15,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(str: [char; 20]) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Char + - - value: "20" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Return: + expression: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":12,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return is_palindrome(str);\\\"}\"}" + arguments: + - Identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":26,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return is_palindrome(str);\\\"}\"}" + "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":10,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":10,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function is_palindrome(str: [char; 20]) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Char + - - value: "20" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Const + variable_names: + - mutable: false + identifier: "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":11,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const str_len = 20u32; // saving const for convenience\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - U32 + - "20" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = true;\\\"}\"}" + type_: ~ + value: + Value: + Boolean: "true" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":9,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let processed = 0u8;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - U8 + - "0" + - Iteration: + variable: "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":9,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for start in 0..(str_len / 2) {\\\"}\"}" + start: + Value: + Implicit: "0" + stop: + Binary: + left: + Identifier: "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":22,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for start in 0..(str_len / 2) {\\\"}\"}" + right: + Value: + Implicit: "2" + op: Div + inclusive: false + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":13,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" + type_: ~ + value: + Access: + Array: + array: + Identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":25,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" + index: + Identifier: "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":29,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let start_sym = str[start];\\\"}\"}" + - Conditional: + condition: + Binary: + left: + Identifier: "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":12,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if start_sym != ' ' {\\\"}\"}" + right: + Value: + Char: + character: + Scalar: 32 + op: Ne + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":17,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let skipped = 0u8;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - U8 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":17,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let end_empty = 0u8;\\\"}\"}" + type_: ~ + value: + Value: + Integer: + - U8 + - "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":22,\\\"line_stop\\\":22,\\\"col_start\\\":17,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let end_sym = ' ';\\\"}\"}" + type_: ~ + value: + Value: + Char: + character: + Scalar: 32 + - Iteration: + variable: "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":17,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}" + start: + Binary: + left: + Identifier: "{\"name\":\"str_len\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":25,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}" + right: + Value: + Implicit: "1" + op: Sub + stop: + Identifier: "{\"name\":\"start\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":39,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for end in (str_len - 1)..start {\\\"}\"}" + inclusive: false + block: + statements: + - Conditional: + condition: + Binary: + left: + Binary: + left: + Binary: + left: + Access: + Array: + array: + Identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":20,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" + index: + Identifier: "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" + right: + Value: + Char: + character: + Scalar: 32 + op: Ne + right: + Binary: + left: + Identifier: "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":39,\\\"col_stop\\\":46,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" + right: + Identifier: "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":50,\\\"col_stop\\\":59,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" + op: Eq + op: And + right: + Binary: + left: + Identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":63,\\\"col_stop\\\":70,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' && skipped == processed && end_sym == ' ' {\\\"}\"}" + right: + Value: + Char: + character: + Scalar: 32 + op: Eq + op: And + block: + statements: + - Assign: + operation: Assign + assignee: + identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":21,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}" + accesses: [] + value: + Access: + Array: + array: + Identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":31,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}" + index: + Identifier: "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":35,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_sym = str[end];\\\"}\"}" + next: + Block: + statements: + - Assign: + operation: Assign + assignee: + identifier: "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":21,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_empty = end_empty + 1;\\\"}\"}" + accesses: [] + value: + Binary: + left: + Identifier: "{\"name\":\"end_empty\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":33,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" end_empty = end_empty + 1;\\\"}\"}" + right: + Value: + Implicit: "1" + op: Add + - Conditional: + condition: + Binary: + left: + Access: + Array: + array: + Identifier: "{\"name\":\"str\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":24,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' {\\\"}\"}" + index: + Identifier: "{\"name\":\"end\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":28,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if str[end] != ' ' {\\\"}\"}" + right: + Value: + Char: + character: + Scalar: 32 + op: Ne + block: + statements: + - Assign: + operation: Assign + assignee: + identifier: "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":25,\\\"col_stop\\\":32,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" skipped = skipped + 1;\\\"}\"}" + accesses: [] + value: + Binary: + left: + Identifier: "{\"name\":\"skipped\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":35,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" skipped = skipped + 1;\\\"}\"}" + right: + Value: + Implicit: "1" + op: Add + next: ~ + - Conditional: + condition: + Binary: + left: + Identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":16,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if end_sym != ' ' {\\\"}\"}" + right: + Value: + Char: + character: + Scalar: 32 + op: Ne + block: + statements: + - Console: + function: + Log: + string: + - Scalar: 67 + - Scalar: 111 + - Scalar: 109 + - Scalar: 112 + - Scalar: 97 + - Scalar: 114 + - Scalar: 105 + - Scalar: 110 + - Scalar: 103 + - Scalar: 58 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + - Scalar: 32 + - Scalar: 63 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + parameters: + - Identifier: "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":51,\\\"col_stop\\\":60,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Comparing: {} ? {}\\\\\\\", start_sym, end_sym);\\\"}\"}" + - Identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":37,\\\"line_stop\\\":37,\\\"col_start\\\":62,\\\"col_stop\\\":69,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Comparing: {} ? {}\\\\\\\", start_sym, end_sym);\\\"}\"}" + - Conditional: + condition: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":20,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if result {\\\"}\"}" + block: + statements: + - Assign: + operation: Assign + assignee: + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":40,\\\"line_stop\\\":40,\\\"col_start\\\":21,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}" + accesses: [] + value: + Binary: + left: + Identifier: "{\"name\":\"start_sym\",\"span\":\"{\\\"line_start\\\":40,\\\"line_stop\\\":40,\\\"col_start\\\":31,\\\"col_stop\\\":40,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}" + right: + Identifier: "{\"name\":\"end_sym\",\"span\":\"{\\\"line_start\\\":40,\\\"line_stop\\\":40,\\\"col_start\\\":44,\\\"col_stop\\\":51,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" result = (start_sym == end_sym);\\\"}\"}" + op: Eq + next: ~ + - Assign: + operation: Assign + assignee: + identifier: "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":43,\\\"line_stop\\\":43,\\\"col_start\\\":17,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" processed = processed + 1;\\\"}\"}" + accesses: [] + value: + Binary: + left: + Identifier: "{\"name\":\"processed\",\"span\":\"{\\\"line_start\\\":43,\\\"line_stop\\\":43,\\\"col_start\\\":29,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" processed = processed + 1;\\\"}\"}" + right: + Value: + Implicit: "1" + op: Add + next: ~ + next: ~ + - Console: + function: + Log: + string: + - Scalar: 82 + - Scalar: 101 + - Scalar: 115 + - Scalar: 117 + - Scalar: 108 + - Scalar: 116 + - Scalar: 32 + - Scalar: 105 + - Scalar: 115 + - Scalar: 58 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + parameters: + - Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":48,\\\"line_stop\\\":48,\\\"col_start\\\":34,\\\"col_stop\\\":40,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"Result is: {}\\\\\\\", result);\\\"}\"}" + - Return: + expression: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":50,\\\"line_stop\\\":50,\\\"col_start\\\":12,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return result;\\\"}\"}" + "{\"name\":\"test_is_palindrome\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":10,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_is_palindrome() {\\\"}\"}": + annotations: + test: + arguments: [] + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":53,\\\"line_stop\\\":53,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" + identifier: "{\"name\":\"test_is_palindrome\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":10,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_is_palindrome() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":55,\\\"line_stop\\\":55,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"a b a \\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 97 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 98 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 97 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":56,\\\"line_stop\\\":56,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"😀😀😀😀😀 😀😀😀😀😀\\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Scalar: 128512 + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"borrow or rob \\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 98 + - Scalar: 111 + - Scalar: 114 + - Scalar: 114 + - Scalar: 111 + - Scalar: 119 + - Scalar: 32 + - Scalar: 111 + - Scalar: 114 + - Scalar: 32 + - Scalar: 114 + - Scalar: 111 + - Scalar: 98 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":58,\\\"line_stop\\\":58,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"bbbb aaaa aaaa bbbb\\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 98 + - Scalar: 98 + - Scalar: 98 + - Scalar: 98 + - Scalar: 32 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 32 + - Scalar: 32 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 32 + - Scalar: 98 + - Scalar: 98 + - Scalar: 98 + - Scalar: 98 + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":59,\\\"line_stop\\\":59,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"aaaaaaaaaaaaaaaaaaaa\\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Scalar: 97 + - Console: + function: + Assert: + Call: + function: + Identifier: "{\"name\":\"is_palindrome\",\"span\":\"{\\\"line_start\\\":60,\\\"line_stop\\\":60,\\\"col_start\\\":20,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(is_palindrome(\\\\\\\"taco cat \\\\\\\"));\\\"}\"}" + arguments: + - Value: + String: + - Scalar: 116 + - Scalar: 97 + - Scalar: 99 + - Scalar: 111 + - Scalar: 32 + - Scalar: 99 + - Scalar: 97 + - Scalar: 116 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 + - Scalar: 32 diff --git a/tests/expectations/parser/parser/serialize/parser_error.leo.out b/tests/expectations/parser/parser/serialize/parser_error.leo.out new file mode 100644 index 0000000000..716c636e1b --- /dev/null +++ b/tests/expectations/parser/parser/serialize/parser_error.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Serialize +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected 'import', 'circuit', 'function', 'test', '@' -- got 'invalid'\n --> test:3:1\n |\n 3 | invalid\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/serialize/pedersen_hash.leo.out b/tests/expectations/parser/parser/serialize/pedersen_hash.leo.out new file mode 100644 index 0000000000..9ac6f544ab --- /dev/null +++ b/tests/expectations/parser/parser/serialize/pedersen_hash.leo.out @@ -0,0 +1,169 @@ +--- +namespace: Serialize +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: + "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit PedersenHash {\\\"}\"}": + circuit_name: "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":9,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit PedersenHash {\\\"}\"}" + members: + - CircuitVariable: + - "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" parameters: [group; 256];\\\"}\"}" + - Array: + - Group + - - value: "256" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":14,\\\"col_stop\\\":17,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(parameters: [group; 256]) -> Self {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":18,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function new(parameters: [group; 256]) -> Self {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Group + - - value: "256" + const_: false + output: SelfType + core_mapping: ~ + block: + statements: + - Return: + expression: + CircuitInit: + name: "{\"name\":\"Self\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}" + members: + - identifier: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":23,\\\"col_stop\\\":33,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}" + expression: + Identifier: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":35,\\\"col_stop\\\":45,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return Self { parameters: parameters };\\\"}\"}" + - CircuitFunction: + annotations: {} + identifier: "{\"name\":\"hash\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":14,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}" + input: + - SelfKeyword: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":19,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}" + - Variable: + identifier: "{\"name\":\"bits\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":25,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function hash(self, bits: [bool; 256]) -> group {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Boolean + - - value: "256" + const_: false + output: Group + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":13,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let digest: group = 0group;\\\"}\"}" + type_: Group + value: + Value: + Group: + Single: "0" + - Iteration: + variable: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":13,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" for i in 0..256 {\\\"}\"}" + start: + Value: + Implicit: "0" + stop: + Value: + Implicit: "256" + inclusive: false + block: + statements: + - Conditional: + condition: + Access: + Array: + array: + Identifier: "{\"name\":\"bits\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":16,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if bits[i] {\\\"}\"}" + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" if bits[i] {\\\"}\"}" + block: + statements: + - Assign: + operation: Add + assignee: + identifier: "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":17,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" + accesses: [] + value: + Access: + Array: + array: + Access: + Member: + inner: + Identifier: "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":27,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" + name: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":32,\\\"col_stop\\\":42,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" + type_: ~ + index: + Identifier: "{\"name\":\"i\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":43,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" digest += self.parameters[i];\\\"}\"}" + next: ~ + - Return: + expression: + Identifier: "{\"name\":\"digest\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":16,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return digest;\\\"}\"}" + global_consts: {} + functions: + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"hash_input\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":15,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - Boolean + - - value: "256" + - Variable: + identifier: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":46,\\\"col_stop\\\":56,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {\\\"}\"}" + const_: true + mutable: false + type_: + Array: + - Group + - - value: "256" + const_: false + output: Group + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Const + variable_names: + - mutable: false + identifier: "{\"name\":\"pedersen\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":11,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" + type_: ~ + value: + Call: + function: + Access: + Static: + inner: + Identifier: "{\"name\":\"PedersenHash\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":22,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" + name: "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":36,\\\"col_stop\\\":39,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" + type_: ~ + arguments: + - Identifier: "{\"name\":\"parameters\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":40,\\\"col_stop\\\":50,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const pedersen = PedersenHash::new(parameters);\\\"}\"}" + - Return: + expression: + Call: + function: + Access: + Member: + inner: + Identifier: "{\"name\":\"pedersen\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":12,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}" + name: "{\"name\":\"hash\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":21,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}" + type_: ~ + arguments: + - Identifier: "{\"name\":\"hash_input\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":26,\\\"col_stop\\\":36,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return pedersen.hash(hash_input);\\\"}\"}" diff --git a/tests/expectations/parser/parser/serialize/silly_sudoku.leo.out b/tests/expectations/parser/parser/serialize/silly_sudoku.leo.out new file mode 100644 index 0000000000..f0c7db8212 --- /dev/null +++ b/tests/expectations/parser/parser/serialize/silly_sudoku.leo.out @@ -0,0 +1,528 @@ +--- +namespace: Serialize +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: + - package_or_packages: + Package: + name: "{\"name\":\"lib\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":8,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"import lib.SillySudoku;\\\"}\"}" + access: + Symbol: + symbol: "{\"name\":\"SillySudoku\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":12,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"import lib.SillySudoku;\\\"}\"}" + alias: ~ + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":15,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + - Variable: + identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":37,\\\"col_stop\\\":43,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Console: + function: + Log: + string: + - Scalar: 83 + - Scalar: 116 + - Scalar: 97 + - Scalar: 114 + - Scalar: 116 + - Scalar: 105 + - Scalar: 110 + - Scalar: 103 + - Scalar: 32 + - Scalar: 83 + - Scalar: 117 + - Scalar: 100 + - Scalar: 111 + - Scalar: 107 + - Scalar: 117 + - Scalar: 32 + - Scalar: 115 + - Scalar: 111 + - Scalar: 108 + - Scalar: 118 + - Scalar: 101 + - Scalar: 114 + - Scalar: 46 + - Scalar: 46 + - Scalar: 46 + parameters: [] + - Console: + function: + Log: + string: + - Scalar: 123 + - Scalar: 125 + parameters: + - Identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"{}\\\\\\\", puzzle);\\\"}\"}" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"sudoku\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" + type_: ~ + value: + CircuitInit: + name: "{\"name\":\"SillySudoku\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":18,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" + members: + - identifier: "{\"name\":\"puzzle_grid\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":32,\\\"col_stop\\\":43,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" + expression: + Identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":45,\\\"col_stop\\\":51,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let sudoku = SillySudoku { puzzle_grid: puzzle };\\\"}\"}" + - Console: + function: + Log: + string: + - Scalar: 67 + - Scalar: 104 + - Scalar: 101 + - Scalar: 99 + - Scalar: 107 + - Scalar: 105 + - Scalar: 110 + - Scalar: 103 + - Scalar: 32 + - Scalar: 83 + - Scalar: 117 + - Scalar: 100 + - Scalar: 111 + - Scalar: 107 + - Scalar: 117 + - Scalar: 32 + - Scalar: 97 + - Scalar: 110 + - Scalar: 115 + - Scalar: 119 + - Scalar: 101 + - Scalar: 114 + - Scalar: 46 + - Scalar: 46 + - Scalar: 46 + parameters: [] + - Console: + function: + Log: + string: + - Scalar: 123 + - Scalar: 125 + parameters: + - Identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"{}\\\\\\\", answer);\\\"}\"}" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" + type_: ~ + value: + Call: + function: + Access: + Member: + inner: + Identifier: "{\"name\":\"sudoku\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":18,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" + name: "{\"name\":\"solve\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":25,\\\"col_stop\\\":30,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" + type_: ~ + arguments: + - Identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = sudoku.solve(answer);\\\"}\"}" + - Console: + function: + Log: + string: + - Scalar: 84 + - Scalar: 104 + - Scalar: 101 + - Scalar: 32 + - Scalar: 97 + - Scalar: 110 + - Scalar: 115 + - Scalar: 119 + - Scalar: 101 + - Scalar: 114 + - Scalar: 32 + - Scalar: 105 + - Scalar: 115 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + - Scalar: 46 + parameters: + - Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":38,\\\"col_stop\\\":44,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"The answer is {}.\\\\\\\", result);\\\"}\"}" + - Return: + expression: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":12,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return result;\\\"}\"}" + "{\"name\":\"test_solve_pass\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_pass() {\\\"}\"}": + annotations: + test: + arguments: [] + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" + identifier: "{\"name\":\"test_solve_pass\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_pass() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let puzzle: [u8; (3, 3)] = [[0, 2, 0],\\\"}\"}" + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + value: + ArrayInline: + elements: + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "2" + - Expression: + Value: + Implicit: "0" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "6" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "8" + - Expression: + Value: + Implicit: "9" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let answer: [u8; (3, 3)] = [[1, 2, 3],\\\"}\"}" + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + value: + ArrayInline: + elements: + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "1" + - Expression: + Value: + Implicit: "2" + - Expression: + Value: + Implicit: "3" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "4" + - Expression: + Value: + Implicit: "5" + - Expression: + Value: + Implicit: "6" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "7" + - Expression: + Value: + Implicit: "8" + - Expression: + Value: + Implicit: "9" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + type_: ~ + value: + Call: + function: + Identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + arguments: + - Identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":36,\\\"line_stop\\\":36,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Console: + function: + Assert: + Binary: + left: + Value: + Boolean: "true" + right: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":28,\\\"col_stop\\\":34,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(true == result);\\\"}\"}" + op: Eq + "{\"name\":\"test_solve_fail\",\"span\":\"{\\\"line_start\\\":44,\\\"line_stop\\\":44,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_fail() {\\\"}\"}": + annotations: + test: + arguments: [] + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":43,\\\"line_stop\\\":43,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test\\\"}\"}" + identifier: "{\"name\":\"test_solve_fail\",\"span\":\"{\\\"line_start\\\":44,\\\"line_stop\\\":44,\\\"col_start\\\":10,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_fail() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":45,\\\"line_stop\\\":45,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let puzzle: [u8; (3, 3)] = [[0, 2, 0],\\\"}\"}" + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + value: + ArrayInline: + elements: + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "2" + - Expression: + Value: + Implicit: "0" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "6" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "0" + - Expression: + Value: + Implicit: "8" + - Expression: + Value: + Implicit: "0" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":49,\\\"line_stop\\\":49,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let answer: [u8; (3, 3)] = [[1, 2, 3],\\\"}\"}" + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + value: + ArrayInline: + elements: + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "1" + - Expression: + Value: + Implicit: "2" + - Expression: + Value: + Implicit: "3" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "4" + - Expression: + Value: + Implicit: "5" + - Expression: + Value: + Implicit: "6" + - Expression: + ArrayInline: + elements: + - Expression: + Value: + Implicit: "7" + - Expression: + Value: + Implicit: "8" + - Expression: + Value: + Implicit: "8" + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + type_: ~ + value: + Call: + function: + Identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + arguments: + - Identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":54,\\\"line_stop\\\":54,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Console: + function: + Assert: + Binary: + left: + Value: + Boolean: "false" + right: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":57,\\\"line_stop\\\":57,\\\"col_start\\\":29,\\\"col_stop\\\":35,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(false == result);\\\"}\"}" + op: Eq + "{\"name\":\"test_solve_with_input\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":10,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_with_input(\\\"}\"}": + annotations: + test: + arguments: + - test_input + name: "{\"name\":\"test\",\"span\":\"{\\\"line_start\\\":61,\\\"line_stop\\\":61,\\\"col_start\\\":2,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"@test(test_input)\\\"}\"}" + identifier: "{\"name\":\"test_solve_with_input\",\"span\":\"{\\\"line_start\\\":62,\\\"line_stop\\\":62,\\\"col_start\\\":10,\\\"col_stop\\\":31,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function test_solve_with_input(\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":63,\\\"line_stop\\\":63,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" puzzle: [u8; (3, 3)],\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + - Variable: + identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":64,\\\"line_stop\\\":64,\\\"col_start\\\":5,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" answer: [u8; (3, 3)],\\\"}\"}" + const_: false + mutable: true + type_: + Array: + - IntegerType: U8 + - - value: "3" + - value: "3" + - Variable: + identifier: "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":65,\\\"line_stop\\\":65,\\\"col_start\\\":5,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" expected: bool\\\"}\"}" + const_: false + mutable: true + type_: Boolean + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Definition: + declaration_type: Let + variable_names: + - mutable: true + identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":9,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + type_: ~ + value: + Call: + function: + Identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":18,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + arguments: + - Identifier: "{\"name\":\"puzzle\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":23,\\\"col_stop\\\":29,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Identifier: "{\"name\":\"answer\",\"span\":\"{\\\"line_start\\\":68,\\\"line_stop\\\":68,\\\"col_start\\\":31,\\\"col_stop\\\":37,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let result = main(puzzle, answer);\\\"}\"}" + - Console: + function: + Log: + string: + - Scalar: 101 + - Scalar: 120 + - Scalar: 112 + - Scalar: 101 + - Scalar: 99 + - Scalar: 116 + - Scalar: 101 + - Scalar: 100 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + - Scalar: 44 + - Scalar: 32 + - Scalar: 103 + - Scalar: 111 + - Scalar: 116 + - Scalar: 32 + - Scalar: 123 + - Scalar: 125 + parameters: + - Identifier: "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":70,\\\"line_stop\\\":70,\\\"col_start\\\":40,\\\"col_stop\\\":48,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"expected {}, got {}\\\\\\\", expected, result);\\\"}\"}" + - Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":70,\\\"line_stop\\\":70,\\\"col_start\\\":50,\\\"col_stop\\\":56,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.log(\\\\\\\"expected {}, got {}\\\\\\\", expected, result);\\\"}\"}" + - Console: + function: + Assert: + Binary: + left: + Identifier: "{\"name\":\"expected\",\"span\":\"{\\\"line_start\\\":72,\\\"line_stop\\\":72,\\\"col_start\\\":20,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(expected == result);\\\"}\"}" + right: + Identifier: "{\"name\":\"result\",\"span\":\"{\\\"line_start\\\":72,\\\"line_stop\\\":72,\\\"col_start\\\":32,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(expected == result);\\\"}\"}" + op: Eq diff --git a/tests/expectations/parser/parser/statement/console.leo.out b/tests/expectations/parser/parser/statement/console.leo.out index f8bb2b4c7d..ac03e47b00 100644 --- a/tests/expectations/parser/parser/statement/console.leo.out +++ b/tests/expectations/parser/parser/statement/console.leo.out @@ -24,15 +24,15 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 15 - col_stop: 22 + col_start: 14 + col_stop: 23 path: "" content: "console.error(\"{}\", x);" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 22 + col_stop: 23 path: "" content: "console.error(\"{}\", x);" - Console: @@ -49,15 +49,15 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 15 - col_stop: 27 + col_start: 14 + col_stop: 28 path: "" content: "console.error(\"{}{}\", x, y);" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 27 + col_stop: 28 path: "" content: "console.error(\"{}{}\", x, y);" - Console: @@ -69,15 +69,15 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 15 - col_stop: 18 + col_start: 14 + col_stop: 19 path: "" content: "console.error(\"x\");" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 18 + col_stop: 19 path: "" content: "console.error(\"x\");" - Console: @@ -91,15 +91,15 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 13 - col_stop: 20 + col_start: 12 + col_stop: 21 path: "" content: "console.log(\"{}\", x);" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 20 + col_stop: 21 path: "" content: "console.log(\"{}\", x);" - Console: @@ -116,15 +116,15 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 13 - col_stop: 25 + col_start: 12 + col_stop: 26 path: "" content: "console.log(\"{}{}\", x, y);" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 25 + col_stop: 26 path: "" content: "console.log(\"{}{}\", x, y);" - Console: @@ -136,14 +136,14 @@ outputs: span: line_start: 1 line_stop: 1 - col_start: 13 - col_stop: 16 + col_start: 12 + col_stop: 17 path: "" content: "console.log(\"x\");" span: line_start: 1 line_stop: 1 col_start: 1 - col_stop: 16 + col_stop: 17 path: "" content: "console.log(\"x\");" diff --git a/tests/expectations/parser/parser/statement/let_mut_recover.leo.out b/tests/expectations/parser/parser/statement/let_mut_recover.leo.out new file mode 100644 index 0000000000..6e6b2f1418 --- /dev/null +++ b/tests/expectations/parser/parser/statement/let_mut_recover.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370015]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:4:5\n |\n 4 | let mut x = 0;\n | ^^^^^^^\nError [EPAR0370015]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:5:5\n |\n 5 | let mut y = 0; // recovery witness\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/unreachable/eat_ident.leo.out b/tests/expectations/parser/parser/unreachable/eat_ident.leo.out new file mode 100644 index 0000000000..a979c804ac --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/eat_ident.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected { -- got 'circuit'\n --> test:4:1\n |\n 4 | circuit ;\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/unreachable/eat_int.leo.out b/tests/expectations/parser/parser/unreachable/eat_int.leo.out new file mode 100644 index 0000000000..f4b4c369d8 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/eat_int.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected 'import', 'circuit', 'function', 'test', '@' -- got 'x'\n --> test:3:1\n |\n 3 | x.0_try_to_hit_hit_eat_int_unreachable\n | ^" diff --git a/tests/parser/circuits/const_functions.leo b/tests/parser/circuits/const_functions.leo new file mode 100644 index 0000000000..21fb9d5e12 --- /dev/null +++ b/tests/parser/circuits/const_functions.leo @@ -0,0 +1,23 @@ +/* +namespace: Parse +expectation: Pass +*/ + +circuit X { + x: u32 + const function x() { + return (); + } + const function x(self) { + return (); + } + const function c(const self) { + return (); + } + const function b(const self, x: u32) { + return (); + } + const function b(const self, const x: u32) { + return (); + } +} diff --git a/tests/parser/circuits/consts.leo b/tests/parser/circuits/consts.leo new file mode 100644 index 0000000000..e50b3829a7 --- /dev/null +++ b/tests/parser/circuits/consts.leo @@ -0,0 +1,9 @@ +/* +namespace: Parse +expectation: Pass +*/ + +circuit X { + static const x: u32 = 2; + static const y: u32 = 5; +} \ No newline at end of file diff --git a/tests/parser/circuits/field_and_functions.leo b/tests/parser/circuits/field_and_functions.leo index 51d09324ec..99ce46e134 100644 --- a/tests/parser/circuits/field_and_functions.leo +++ b/tests/parser/circuits/field_and_functions.leo @@ -4,6 +4,7 @@ expectation: Pass */ circuit X { + static const a: u8 = 10; x: u32, y: u32 function x() { diff --git a/tests/parser/circuits/fields_fail.leo b/tests/parser/circuits/fields_fail.leo index a56bdb1a6e..6ebc22b0b1 100644 --- a/tests/parser/circuits/fields_fail.leo +++ b/tests/parser/circuits/fields_fail.leo @@ -11,4 +11,5 @@ circuit X { circuit X { x: u32, y: u32; -} \ No newline at end of file + , // recovery witness +} diff --git a/tests/parser/circuits/functions.leo b/tests/parser/circuits/functions.leo index 4eff256a0a..511bb48aa0 100644 --- a/tests/parser/circuits/functions.leo +++ b/tests/parser/circuits/functions.leo @@ -10,4 +10,7 @@ circuit X { function y() { return (); } -} \ No newline at end of file + const function z() { + return (); + } +} diff --git a/tests/parser/circuits/mixed_order_fail.leo b/tests/parser/circuits/mixed_order_fail.leo new file mode 100644 index 0000000000..7267cf0465 --- /dev/null +++ b/tests/parser/circuits/mixed_order_fail.leo @@ -0,0 +1,19 @@ +/* +namespace: Parse +expectation: Fail +*/ + +circuit A { + function a() {} + const function z() {} + + foo: u8, + + static const BAR: u8 = 0u8; +} + +circuit B { + foo: u8, + + static const BAR: u8 = 0u8; +} diff --git a/tests/parser/circuits/mut_self.leo b/tests/parser/circuits/mut_self_fail.leo similarity index 83% rename from tests/parser/circuits/mut_self.leo rename to tests/parser/circuits/mut_self_fail.leo index 952f73a236..dff6af2db1 100644 --- a/tests/parser/circuits/mut_self.leo +++ b/tests/parser/circuits/mut_self_fail.leo @@ -1,6 +1,6 @@ /* namespace: Parse -expectation: Pass +expectation: Fail */ circuit X { diff --git a/tests/parser/circuits/ref_self.leo b/tests/parser/circuits/ref_self.leo new file mode 100644 index 0000000000..8e5c19f820 --- /dev/null +++ b/tests/parser/circuits/ref_self.leo @@ -0,0 +1,10 @@ +/* +namespace: Parse +expectation: Pass +*/ + +circuit X { + function x(&self) { + return (); + } +} \ No newline at end of file diff --git a/tests/parser/circuits/struct_fail.leo b/tests/parser/circuits/struct_fail.leo new file mode 100644 index 0000000000..582b508aab --- /dev/null +++ b/tests/parser/circuits/struct_fail.leo @@ -0,0 +1,9 @@ +/* +namespace: Parse +expectation: Fail +*/ + +struct A {} +circuit B {} +class C {} +circuit D {} diff --git a/tests/parser/expression/array_init.leo b/tests/parser/expression/array_init.leo index 8efc49b5d6..343be881e7 100644 --- a/tests/parser/expression/array_init.leo +++ b/tests/parser/expression/array_init.leo @@ -11,6 +11,8 @@ expectation: Pass [0; (1, 2)] +[0; (1, 2,)] + [0; (1, 2, 3)] -[[[0; 3]; 2]; 1] \ No newline at end of file +[[[0; 3]; 2]; 1] diff --git a/tests/parser/expression/array_init_fail.leo b/tests/parser/expression/array_init_fail.leo index b9ff1835f8..8cd5b5eb0b 100644 --- a/tests/parser/expression/array_init_fail.leo +++ b/tests/parser/expression/array_init_fail.leo @@ -7,3 +7,5 @@ expectation: Fail [...0u8; 1] [...0; 1] + +[0; ()] diff --git a/tests/parser/expression/literal/access.leo b/tests/parser/expression/literal/access.leo new file mode 100644 index 0000000000..bb30728808 --- /dev/null +++ b/tests/parser/expression/literal/access.leo @@ -0,0 +1,51 @@ +/* +namespace: ParseExpression +expectation: Pass +*/ + +// address +aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8.call() +address::call() + +// bool +true.call() +bool::call() + +// char +'a'.call() +char::call() + +// field +1field.call() +field::call() + +//group +0group.call() +(0, 1)group.call() +group::call() + +// ints +1i8.call() +1i16.call() +1i32.call() +1i64.call() +1i128.call() + +i8::call() +i16::call() +i32::call() +i64::call() +i128::call() + +// uints +1u8.call() +1u16.call() +1u32.call() +1u64.call() +1u128.call() + +u8::call() +u16::call() +u32::call() +u64::call() +u128::call() \ No newline at end of file diff --git a/tests/parser/expression/literal/group_fail.leo b/tests/parser/expression/literal/group_fail.leo index 6a5651d9c0..1b0ecd1de2 100644 --- a/tests/parser/expression/literal/group_fail.leo +++ b/tests/parser/expression/literal/group_fail.leo @@ -3,8 +3,6 @@ namespace: ParseExpression expectation: Fail */ -group - ()group (123)group diff --git a/tests/parser/functions/annotated.leo b/tests/parser/functions/annotated.leo index 39a1686dd7..56568b959a 100644 --- a/tests/parser/functions/annotated.leo +++ b/tests/parser/functions/annotated.leo @@ -4,6 +4,21 @@ expectation: Pass */ @test -function x() { +function a() { return (); -} \ No newline at end of file +} + +@test(test) +function b() { + return (); +} + +@test(test,) +function c() { + return (); +} + +@test() +function d() { + return (); +} diff --git a/tests/parser/functions/annotated_arg_not_ident_int.leo b/tests/parser/functions/annotated_arg_not_ident_int.leo new file mode 100644 index 0000000000..20780213f0 --- /dev/null +++ b/tests/parser/functions/annotated_arg_not_ident_int.leo @@ -0,0 +1,14 @@ +/* +namespace: Parse +expectation: Fail +*/ + +@foo(?, bar, ?) +function x() { + return (); +} + +@context // recovery witness +function x() { + return (); +} diff --git a/tests/parser/functions/annotated_context_fail.leo b/tests/parser/functions/annotated_context_fail.leo new file mode 100644 index 0000000000..1daef2c25c --- /dev/null +++ b/tests/parser/functions/annotated_context_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: Parse +expectation: Fail +*/ + +@context +function f() { + return (); +} + +@context // recovery witness +function g() { + return (); +} diff --git a/tests/parser/functions/annotated_fail.leo b/tests/parser/functions/annotated_fail.leo deleted file mode 100644 index 2f21d6171c..0000000000 --- a/tests/parser/functions/annotated_fail.leo +++ /dev/null @@ -1,9 +0,0 @@ -/* -namespace: Parse -expectation: Fail -*/ - -@test(test,) -function x() { - return (); -} \ No newline at end of file diff --git a/tests/parser/functions/bounded_recursion.leo b/tests/parser/functions/bounded_recursion.leo new file mode 100644 index 0000000000..6ca5a10f4e --- /dev/null +++ b/tests/parser/functions/bounded_recursion.leo @@ -0,0 +1,15 @@ +/* +namespace: Parse +expectation: Pass +*/ + +function x(const y: u32) { + if y < 5u32 { + x(y+1); + } +} + +function main(y: bool) -> bool { + x(1u32); + return y; +} \ No newline at end of file diff --git a/tests/parser/functions/bounded_recursion_fail.leo b/tests/parser/functions/bounded_recursion_fail.leo new file mode 100644 index 0000000000..96c93779d4 --- /dev/null +++ b/tests/parser/functions/bounded_recursion_fail.leo @@ -0,0 +1,15 @@ +/* +namespace: Parse +expectation: Pass +*/ + +function x(const y: u32) { + if y < 999u32 { + x(y+1); + } +} + +function main(y: bool) -> bool { + x(1u32); + return y; +} \ No newline at end of file diff --git a/tests/parser/functions/const_function.leo b/tests/parser/functions/const_function.leo new file mode 100644 index 0000000000..fd8703b9fc --- /dev/null +++ b/tests/parser/functions/const_function.leo @@ -0,0 +1,8 @@ +/* +namespace: Parse +expectation: Pass +*/ + +const function x() { + return (); +} diff --git a/tests/parser/functions/infinite_recursion_fail.leo b/tests/parser/functions/infinite_recursion_fail.leo new file mode 100644 index 0000000000..b1660ba188 --- /dev/null +++ b/tests/parser/functions/infinite_recursion_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Parse +expectation: Pass +*/ + +function inf() { + inf(); +} + +function main(y: bool) -> bool { + inf(); + return y; +} \ No newline at end of file diff --git a/tests/parser/import/import_empty_list_fail.leo b/tests/parser/import/import_empty_list_fail.leo index 536a91d51a..4e8bbe7b80 100644 --- a/tests/parser/import/import_empty_list_fail.leo +++ b/tests/parser/import/import_empty_list_fail.leo @@ -3,4 +3,6 @@ namespace: Parse expectation: Fail */ -import a.(); \ No newline at end of file +import a.(); + +import a.(); diff --git a/tests/parser/import/invalid_chars_fail.leo b/tests/parser/import/invalid_chars_fail.leo new file mode 100644 index 0000000000..47cf2bcb72 --- /dev/null +++ b/tests/parser/import/invalid_chars_fail.leo @@ -0,0 +1,8 @@ +/* +namespace: Parse +expectation: Fail +*/ + +import AB.c; + +import AB.c; diff --git a/tests/parser/import/keyword_fail.leo b/tests/parser/import/keyword_fail.leo new file mode 100644 index 0000000000..11b5456b79 --- /dev/null +++ b/tests/parser/import/keyword_fail.leo @@ -0,0 +1,8 @@ +/* +namespace: Parse +expectation: Fail +*/ + +import function.a; + +import import.a; diff --git a/tests/parser/serialize/linear_regression.leo b/tests/parser/serialize/linear_regression.leo new file mode 100644 index 0000000000..b64dd2cbac --- /dev/null +++ b/tests/parser/serialize/linear_regression.leo @@ -0,0 +1,70 @@ +/* +namespace: Serialize +expectation: Pass +*/ + +circuit Point { + x: i32, + y: i32, + + function new(x: i32, y: i32) -> Self { + return Self { x, y }; + } +} + +circuit LinearRegression { + points: [Point; 5], + + // Instantiates a linear regression circuit. + function new(points: [Point; 5]) -> Self { + return Self { points }; + } + + // Return the slope of the linear regression. + function slope(self) -> i32 { + + let num_points = 5i32; + // Calculate the sums. + let x_sum = 0i32; + let y_sum = 0i32; + let xy_sum = 0i32; + let x2_sum = 0i32; + for i in 0..5 { + x_sum += self.points[i].x; + y_sum += self.points[i].y; + xy_sum += self.points[i].x * self.points[i].y; + x2_sum += self.points[i].x * self.points[i].x; + } + let numerator = (num_points * xy_sum) - (x_sum * y_sum); + let denominator = (num_points * x2_sum) - (x_sum * x_sum); + let slope = numerator / denominator; + return slope; + } + // Return the offset of the linear regression. + function offset(self, slope: i32) -> i32 { + let num_points = 5i32; + // Calculate the sum. + let x_sum = 0i32; + let y_sum = 0i32; + for i in 0..5 { + x_sum += self.points[i].x; + y_sum += self.points[i].y; + } + return (y_sum - slope * x_sum) / num_points; + } +} + + +function main (x: i32, y: i32) -> [i32; 2] { + let points: [Point; 5] = [ + Point{x: x + 1, y: y + 1}, + Point{x: x + 2, y: y + 2}, + Point{x: x + 3, y: y + 3}, + Point{x: x + 4, y: y + 4}, + Point{x: x + 5, y: y + 5} + ]; + let reg = LinearRegression::new(points); + let slope = reg.slope(); + let offset = reg.offset(slope); + return [slope, offset]; +} diff --git a/tests/parser/serialize/one_plus_one.leo b/tests/parser/serialize/one_plus_one.leo new file mode 100644 index 0000000000..46862774c2 --- /dev/null +++ b/tests/parser/serialize/one_plus_one.leo @@ -0,0 +1,8 @@ +/* +namespace: Serialize +expectation: Pass +*/ + +function main() -> u8 { + return 1u8 + 1u8; +} diff --git a/tests/parser/serialize/palindrome.leo b/tests/parser/serialize/palindrome.leo new file mode 100644 index 0000000000..ebc9bb7e11 --- /dev/null +++ b/tests/parser/serialize/palindrome.leo @@ -0,0 +1,64 @@ +/* +namespace: Serialize +expectation: Pass +*/ + +// This Program takes in any 20-byte low register string and tells +// whether a string is a palindrome ignoring any spaces. + +function main(str: [char; 20]) -> bool { + return is_palindrome(str); +} + +function is_palindrome(str: [char; 20]) -> bool { + const str_len = 20u32; // saving const for convenience + + // By default we assume that input is a palindrome. + let result = true; + let processed = 0u8; + + for start in 0..(str_len / 2) { + let start_sym = str[start]; + if start_sym != ' ' { + let skipped = 0u8; + let end_empty = 0u8; + let end_sym = ' '; + + for end in (str_len - 1)..start { + if str[end] != ' ' && skipped == processed && end_sym == ' ' { + end_sym = str[end]; + } else { + end_empty = end_empty + 1; + if str[end] != ' ' { + skipped = skipped + 1; + } + } + } + + // If there are symbols left to the right from the start. + if end_sym != ' ' { + console.log("Comparing: {} ? {}", start_sym, end_sym); + + if result { + result = (start_sym == end_sym); + } + + processed = processed + 1; + } + } + } + + console.log("Result is: {}", result); + + return result; +} + +@test +function test_is_palindrome() { + console.assert(is_palindrome("a b a ")); + console.assert(is_palindrome("😀😀😀😀😀 😀😀😀😀😀")); + console.assert(is_palindrome("borrow or rob ")); + console.assert(is_palindrome("bbbb aaaa aaaa bbbb")); + console.assert(is_palindrome("aaaaaaaaaaaaaaaaaaaa")); + console.assert(is_palindrome("taco cat ")); +} diff --git a/tests/parser/serialize/parser_error.leo b/tests/parser/serialize/parser_error.leo new file mode 100644 index 0000000000..91be4d8733 --- /dev/null +++ b/tests/parser/serialize/parser_error.leo @@ -0,0 +1,6 @@ +/* +namespace: Serialize +expectation: Fail +*/ + +invalid \ No newline at end of file diff --git a/tests/parser/serialize/pedersen_hash.leo b/tests/parser/serialize/pedersen_hash.leo new file mode 100644 index 0000000000..b8520a9be4 --- /dev/null +++ b/tests/parser/serialize/pedersen_hash.leo @@ -0,0 +1,30 @@ +/* +namespace: Serialize +expectation: Pass +*/ + +circuit PedersenHash { + parameters: [group; 256]; + + // Instantiates a Pedersen hash circuit + function new(parameters: [group; 256]) -> Self { + return Self { parameters: parameters }; + } + + function hash(self, bits: [bool; 256]) -> group { + let digest: group = 0group; + for i in 0..256 { + if bits[i] { + digest += self.parameters[i]; + } + } + return digest; + } +} + +// The 'pedersen-hash' main function. +function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group { + const pedersen = PedersenHash::new(parameters); + return pedersen.hash(hash_input); +} + diff --git a/tests/parser/serialize/silly_sudoku.leo b/tests/parser/serialize/silly_sudoku.leo new file mode 100644 index 0000000000..1b940e2689 --- /dev/null +++ b/tests/parser/serialize/silly_sudoku.leo @@ -0,0 +1,76 @@ +/* +namespace: Serialize +expectation: Pass +*/ + +import lib.SillySudoku; + +// The `silly-sudoku` main function +function main(puzzle: [u8; (3, 3)], answer: [u8; (3, 3)]) -> bool { + console.log("Starting Sudoku solver..."); + console.log("{}", puzzle); + + // Instantiate the Sudoku puzzle. + let sudoku = SillySudoku { puzzle_grid: puzzle }; + + console.log("Checking Sudoku answer..."); + console.log("{}", answer); + + // Evaluate the Sudoku puzzle with the given answer. + let result = sudoku.solve(answer); + + console.log("The answer is {}.", result); + + return result; +} + +// Tests that the `silly-sudoku` circuit outputs true on a correct answer. +@test +function test_solve_pass() { + let puzzle: [u8; (3, 3)] = [[0, 2, 0], + [0, 0, 6], + [0, 8, 9]]; + + let answer: [u8; (3, 3)] = [[1, 2, 3], + [4, 5, 6], + [7, 8, 9]]; + + // Runs the Sudoku checker. + let result = main(puzzle, answer); + + // Expects the result to be true. + console.assert(true == result); +} + +// Tests that the `silly-sudoku` circuit outputs false on an incorrect answer. +@test +function test_solve_fail() { + let puzzle: [u8; (3, 3)] = [[0, 2, 0], + [0, 0, 6], + [0, 8, 0]]; + + let answer: [u8; (3, 3)] = [[1, 2, 3], + [4, 5, 6], + [7, 8, 8]]; // We have an extra `8` in this column! + + // Runs the Sudoku checker. + let result = main(puzzle, answer); + + // Expects the result to be false. + console.assert(false == result); +} + +// Test that the `silly-sudoku` circuit outputs the expected value on a custom test input. +@test(test_input) +function test_solve_with_input( + puzzle: [u8; (3, 3)], + answer: [u8; (3, 3)], + expected: bool +) { + // Runs the Sudoku checker. + let result = main(puzzle, answer); + + console.log("expected {}, got {}", expected, result); + + console.assert(expected == result); +} diff --git a/tests/parser/statement/definition_fail.leo b/tests/parser/statement/definition_fail.leo index 7e3fd0d28b..7bdfc14af2 100644 --- a/tests/parser/statement/definition_fail.leo +++ b/tests/parser/statement/definition_fail.leo @@ -51,4 +51,4 @@ let (x,y,,) = (); let (,x,y) = (); -let (x,,y) = (); \ No newline at end of file +let (x,,y) = (); diff --git a/tests/parser/statement/let_mut_recover.leo b/tests/parser/statement/let_mut_recover.leo new file mode 100644 index 0000000000..cc3fa19096 --- /dev/null +++ b/tests/parser/statement/let_mut_recover.leo @@ -0,0 +1,9 @@ +/* +namespace: Parse +expectation: Fail +*/ + +function foo() { + let mut x = 0; + let mut y = 0; // recovery witness +} diff --git a/tests/parser/unreachable/eat_int.leo b/tests/parser/unreachable/eat_int.leo index 7748be8ab5..b8bd8aa886 100644 --- a/tests/parser/unreachable/eat_int.leo +++ b/tests/parser/unreachable/eat_int.leo @@ -1,5 +1,5 @@ /* -namespace: ParseExpression +namespace: Parse expectation: Fail */ From 22d24411b724d274f4c0d1c11121edb60ac0dffd Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 10:57:13 -0800 Subject: [PATCH 08/14] test unreachable contexts --- .../parser/unreachable/expect_ident.leo.out | 5 ++ tests/parser/unreachable/eat_ident.leo | 36 +++++++++++ tests/parser/unreachable/eat_int.leo | 61 +++++++++++++++---- tests/parser/unreachable/expect_ident.leo | 54 ++++++++++++++++ 4 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 tests/expectations/parser/parser/unreachable/expect_ident.leo.out create mode 100644 tests/parser/unreachable/expect_ident.leo diff --git a/tests/expectations/parser/parser/unreachable/expect_ident.leo.out b/tests/expectations/parser/parser/unreachable/expect_ident.leo.out new file mode 100644 index 0000000000..45e22e2125 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/expect_ident.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected 'import', 'circuit', 'function', 'test', '@' -- got 'x'\n --> test:3:1\n |\n 3 | x::try_to_hit_expect_ident_unreachable\n | ^" diff --git a/tests/parser/unreachable/eat_ident.leo b/tests/parser/unreachable/eat_ident.leo index dfd7f1aadf..7fd93c6200 100644 --- a/tests/parser/unreachable/eat_ident.leo +++ b/tests/parser/unreachable/eat_ident.leo @@ -16,3 +16,39 @@ circuit [ circuit ] circuit { circuit } +circuit - +circuit _ +circuit = +circuit == +circuit ! +circuit != +circuit > +circuit >= +circuit < +circuit <= +circuit > +circuit .. +circuit as +circuit console +circuit const +circuit let +circuit for +circuit if +circuit else +circuit i8 +circuit i16 +circuit i32 +circuit i64 +circuit i128 +circuit u8 +circuit u16 +circuit u32 +circuit u64 +circuit u128 +circuit & +circuit return +circuit self +circuit self +circuit true +circuit false +circuit 0 \ No newline at end of file diff --git a/tests/parser/unreachable/eat_int.leo b/tests/parser/unreachable/eat_int.leo index b8bd8aa886..5117dd9aa9 100644 --- a/tests/parser/unreachable/eat_int.leo +++ b/tests/parser/unreachable/eat_int.leo @@ -4,16 +4,51 @@ expectation: Fail */ x.0_try_to_hit_hit_eat_int_unreachable -x.; -x.a -x., -x.. -x+ -x- -x* -x/ -x.import -x.[ -x.] -x.{ -x.} \ No newline at end of file +x.-12 +x.0_; +x.0_. +x.0_import +x.0_, +x.0_* +x.0_+ +x.0_- +x.0_/ +x.0_[ +x.0_] +x.0_{ +x.0_} +x.0_- +x.0__ +x.0_= +x.0_== +x.0_! +x.0_!= +x.0_> +x.0_>= +x.0_< +x.0_<= +x.0_> +x.0_.. +x.0_as +x.0_console +x.0_const +x.0_let +x.0_for +x.0_if +x.0_else +x.0_i8 +x.0_i16 +x.0_i32 +x.0_i64 +x.0_i128 +x.0_u8 +x.0_u16 +x.0_u32 +x.0_u64 +x.0_u128 +x.0_& +x.0_return +x.0_self +x.0_self +x.0_true +x.0_false diff --git a/tests/parser/unreachable/expect_ident.leo b/tests/parser/unreachable/expect_ident.leo new file mode 100644 index 0000000000..70e6f5bfad --- /dev/null +++ b/tests/parser/unreachable/expect_ident.leo @@ -0,0 +1,54 @@ +/* +namespace: Parse +expectation: Fail +*/ + +x::try_to_hit_expect_ident_unreachable +x::; +x::. +x::import +x::, +x::* +x::+ +x::- +x::/ +x::[ +x::] +x::{ +x::} +x::- +x::_ +x::= +x::== +x::! +x::!= +x::> +x::>= +x::< +x::<= +x::> +x::.. +x::as +x::console +x::const +x::let +x::for +x::if +x::else +x::i8 +x::i16 +x::i32 +x::i64 +x::i128 +x::u8 +x::u16 +x::u32 +x::u64 +x::u128 +x::& +x::return +x::self +x::self +x::true +x::false +x::0 \ No newline at end of file From 9cb1f3632d78cce5d58b2a8428e3a1f6a543f111 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 11:28:19 -0800 Subject: [PATCH 09/14] add missed cases, test unreachable exprs --- .../functions/infinite_recursion.leo.out | 120 ++++++++++++++++++ .../parser/unreachable/eat_ident.leo.out | 2 +- .../unreachable/eat_ident_bad_ident.leo.out | 5 + .../parser/unreachable/eat_ident_semi.leo.out | 5 + .../parser/parser/unreachable/eat_int.leo.out | 4 +- .../equality_and_order_expression.leo.out | 56 ++++++++ .../unreachable/equality_expression.leo.out | 52 ++++++++ .../parser/unreachable/expect_ident.leo.out | 4 +- .../parser/parser/unreachable/math_op.leo.out | 6 + .../parser/parser/unreachable/postfix.leo.out | 5 + .../functions/bounded_recursion_fail.leo | 15 --- ...ursion_fail.leo => infinite_recursion.leo} | 0 tests/parser/unreachable/eat_ident.leo | 9 +- tests/parser/unreachable/eat_int.leo | 11 +- .../equality_and_order_expression.leo | 57 +++++++++ tests/parser/unreachable/expect_ident.leo | 11 +- tests/parser/unreachable/math_op.leo | 102 +++++++++++++++ tests/parser/unreachable/postfix.leo | 51 ++++++++ 18 files changed, 484 insertions(+), 31 deletions(-) create mode 100644 tests/expectations/parser/parser/functions/infinite_recursion.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/eat_ident_bad_ident.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/eat_ident_semi.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/equality_and_order_expression.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/equality_expression.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/math_op.leo.out create mode 100644 tests/expectations/parser/parser/unreachable/postfix.leo.out delete mode 100644 tests/parser/functions/bounded_recursion_fail.leo rename tests/parser/functions/{infinite_recursion_fail.leo => infinite_recursion.leo} (100%) create mode 100644 tests/parser/unreachable/equality_and_order_expression.leo create mode 100644 tests/parser/unreachable/math_op.leo create mode 100644 tests/parser/unreachable/postfix.leo diff --git a/tests/expectations/parser/parser/functions/infinite_recursion.leo.out b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out new file mode 100644 index 0000000000..93a823f907 --- /dev/null +++ b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out @@ -0,0 +1,120 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + expected_input: [] + import_statements: [] + imports: {} + aliases: {} + circuits: {} + global_consts: {} + functions: + "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function inf() {\\\"}\"}" + input: [] + const_: false + output: ~ + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":5,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" inf();\\\"}\"}" + arguments: [] + span: + line_start: 4 + line_stop: 4 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 4 + line_stop: 4 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 3 + line_stop: 5 + col_start: 16 + col_stop: 2 + path: "" + content: "function inf() {\n ...\n}" + span: + line_start: 3 + line_stop: 5 + col_start: 1 + col_stop: 2 + path: "" + content: "function inf() {\n ...\n}" + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}": + annotations: {} + identifier: "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + input: + - Variable: + identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main(y: bool) -> bool {\\\"}\"}" + const_: false + mutable: true + type_: Boolean + span: + line_start: 7 + line_stop: 7 + col_start: 15 + col_stop: 16 + path: "" + content: "function main(y: bool) -> bool {" + const_: false + output: Boolean + core_mapping: ~ + block: + statements: + - Expression: + expression: + Call: + function: + Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":5,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" inf();\\\"}\"}" + arguments: [] + span: + line_start: 8 + line_stop: 8 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + span: + line_start: 8 + line_stop: 8 + col_start: 5 + col_stop: 10 + path: "" + content: " inf();" + - Return: + expression: + Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" return y;\\\"}\"}" + span: + line_start: 9 + line_stop: 9 + col_start: 5 + col_stop: 13 + path: "" + content: " return y;" + span: + line_start: 7 + line_stop: 10 + col_start: 32 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" + span: + line_start: 7 + line_stop: 10 + col_start: 1 + col_stop: 2 + path: "" + content: "function main(y: bool) -> bool {\n ...\n ...\n}" diff --git a/tests/expectations/parser/parser/unreachable/eat_ident.leo.out b/tests/expectations/parser/parser/unreachable/eat_ident.leo.out index a979c804ac..cb16998106 100644 --- a/tests/expectations/parser/parser/unreachable/eat_ident.leo.out +++ b/tests/expectations/parser/parser/unreachable/eat_ident.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370005]: expected { -- got 'circuit'\n --> test:4:1\n |\n 4 | circuit ;\n | ^^^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got ';'\n --> test:3:9\n |\n 3 | circuit ;\n | ^" diff --git a/tests/expectations/parser/parser/unreachable/eat_ident_bad_ident.leo.out b/tests/expectations/parser/parser/unreachable/eat_ident_bad_ident.leo.out new file mode 100644 index 0000000000..cb16998106 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/eat_ident_bad_ident.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'ident', got ';'\n --> test:3:9\n |\n 3 | circuit ;\n | ^" diff --git a/tests/expectations/parser/parser/unreachable/eat_ident_semi.leo.out b/tests/expectations/parser/parser/unreachable/eat_ident_semi.leo.out new file mode 100644 index 0000000000..a979c804ac --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/eat_ident_semi.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected { -- got 'circuit'\n --> test:4:1\n |\n 4 | circuit ;\n | ^^^^^^^" diff --git a/tests/expectations/parser/parser/unreachable/eat_int.leo.out b/tests/expectations/parser/parser/unreachable/eat_int.leo.out index f4b4c369d8..1afeaebce3 100644 --- a/tests/expectations/parser/parser/unreachable/eat_int.leo.out +++ b/tests/expectations/parser/parser/unreachable/eat_int.leo.out @@ -1,5 +1,5 @@ --- -namespace: Parse +namespace: ParseStatement expectation: Fail outputs: - - "Error [EPAR0370005]: expected 'import', 'circuit', 'function', 'test', '@' -- got 'x'\n --> test:3:1\n |\n 3 | x.0_try_to_hit_hit_eat_int_unreachable\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'int or ident', got '-'\n --> test:1:3\n |\n 1 | x.-12\n | ^" diff --git a/tests/expectations/parser/parser/unreachable/equality_and_order_expression.leo.out b/tests/expectations/parser/parser/unreachable/equality_and_order_expression.leo.out new file mode 100644 index 0000000000..23a140dc16 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/equality_and_order_expression.leo.out @@ -0,0 +1,56 @@ +--- +namespace: ParseExpression +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ; {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 . {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 import {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 , {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 * {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 + {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 - {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 / {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 [ {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ] {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 { {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 } {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ( {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ) {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 : {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 :: {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ? {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 _ {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 = {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 == {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ! {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 != {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 > {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 >= {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 < {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 <= {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 > {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 .. {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 as {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 console {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 const {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 let {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 for {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 if {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 else {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i8 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i16 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i32 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i64 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i128 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u8 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u16 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u32 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u64 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u128 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 & {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 return {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 self {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 Self {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 true {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 false {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 0 {}\n | ^^" diff --git a/tests/expectations/parser/parser/unreachable/equality_expression.leo.out b/tests/expectations/parser/parser/unreachable/equality_expression.leo.out new file mode 100644 index 0000000000..3a65a32f09 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/equality_expression.leo.out @@ -0,0 +1,52 @@ +--- +namespace: ParseExpression +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ; {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 . {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 import {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 , {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 * {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 + {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 - {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 / {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 [ {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ] {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 { {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 } {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ? {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 _ {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 = {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 == {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 ! {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 != {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 > {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 >= {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 < {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 <= {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 > {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 .. {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 as {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 console {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 const {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 let {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 for {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 if {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 else {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i8 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i16 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i32 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i64 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 i128 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u8 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u16 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u32 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u64 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 u128 {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 & {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 return {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 self {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 Self {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 true {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 false {}\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if 10 0 {}\n | ^^" diff --git a/tests/expectations/parser/parser/unreachable/expect_ident.leo.out b/tests/expectations/parser/parser/unreachable/expect_ident.leo.out index 45e22e2125..7589b17985 100644 --- a/tests/expectations/parser/parser/unreachable/expect_ident.leo.out +++ b/tests/expectations/parser/parser/unreachable/expect_ident.leo.out @@ -1,5 +1,5 @@ --- -namespace: Parse +namespace: ParseStatement expectation: Fail outputs: - - "Error [EPAR0370005]: expected 'import', 'circuit', 'function', 'test', '@' -- got 'x'\n --> test:3:1\n |\n 3 | x::try_to_hit_expect_ident_unreachable\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'ident', got ';'\n --> test:1:4\n |\n 1 | x::;\n | ^" diff --git a/tests/expectations/parser/parser/unreachable/math_op.leo.out b/tests/expectations/parser/parser/unreachable/math_op.leo.out new file mode 100644 index 0000000000..d2d7bfdec0 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/math_op.leo.out @@ -0,0 +1,6 @@ +--- +namespace: ParseStatement +expectation: Fail +outputs: + - "did not consume all input: 'b' @ 1:13-14\n';' @ 1:14-15\n'let' @ 2:1-4\n'x' @ 2:5-6\n'=' @ 2:7-8\n'a' @ 2:9-10\n'.' @ 2:11-12\n'b' @ 2:13-14\n';' @ 2:14-15\n'let' @ 3:1-4\n'x' @ 3:5-6\n'=' @ 3:7-8\n'a' @ 3:9-10\n'import' @ 3:11-17\n'b' @ 3:18-19\n';' @ 3:19-20\n'let' @ 4:1-4\n'x' @ 4:5-6\n'=' @ 4:7-8\n'a' @ 4:9-10\n',' @ 4:11-12\n'b' @ 4:13-14\n';' @ 4:14-15\n'let' @ 5:1-4\n'x' @ 5:5-6\n'=' @ 5:7-8\n'a' @ 5:9-10\n'[' @ 5:11-12\n'b' @ 5:13-14\n';' @ 5:14-15\n'let' @ 6:1-4\n'x' @ 6:5-6\n'=' @ 6:7-8\n'a' @ 6:9-10\n']' @ 6:11-12\n'b' @ 6:13-14\n';' @ 6:14-15\n'let' @ 7:1-4\n'x' @ 7:5-6\n'=' @ 7:7-8\n'a' @ 7:9-10\n'{' @ 7:11-12\n'b' @ 7:13-14\n';' @ 7:14-15\n'let' @ 8:1-4\n'x' @ 8:5-6\n'=' @ 8:7-8\n'a' @ 8:9-10\n'}' @ 8:11-12\n'b' @ 8:13-14\n';' @ 8:14-15\n'let' @ 9:1-4\n'x' @ 9:5-6\n'=' @ 9:7-8\n'a' @ 9:9-10\n'(' @ 9:11-12\n'b' @ 9:13-14\n';' @ 9:14-15\n'let' @ 10:1-4\n'x' @ 10:5-6\n'=' @ 10:7-8\n'a' @ 10:9-10\n')' @ 10:11-12\n'b' @ 10:13-14\n';' @ 10:14-15\n'let' @ 11:1-4\n'x' @ 11:5-6\n'=' @ 11:7-8\n'a' @ 11:9-10\n':' @ 11:11-12\n'b' @ 11:13-14\n';' @ 11:14-15\n'let' @ 12:1-4\n'x' @ 12:5-6\n'=' @ 12:7-8\n'a' @ 12:9-10\n'::' @ 12:11-13\n'b' @ 12:14-15\n';' @ 12:15-16\n'let' @ 13:1-4\n'x' @ 13:5-6\n'=' @ 13:7-8\n'a' @ 13:9-10\n'?' @ 13:11-12\n'b' @ 13:13-14\n';' @ 13:14-15\n'let' @ 14:1-4\n'x' @ 14:5-6\n'=' @ 14:7-8\n'a' @ 14:9-10\n'_' @ 14:11-12\n'b' @ 14:13-14\n';' @ 14:14-15\n'let' @ 15:1-4\n'x' @ 15:5-6\n'=' @ 15:7-8\n'a' @ 15:9-10\n'=' @ 15:11-12\n'b' @ 15:13-14\n';' @ 15:14-15\n'let' @ 16:1-4\n'x' @ 16:5-6\n'=' @ 16:7-8\n'a' @ 16:9-10\n'==' @ 16:11-13\n'b' @ 16:14-15\n';' @ 16:15-16\n'let' @ 17:1-4\n'x' @ 17:5-6\n'=' @ 17:7-8\n'a' @ 17:9-10\n'!' @ 17:11-12\n'b' @ 17:13-14\n';' @ 17:14-15\n'let' @ 18:1-4\n'x' @ 18:5-6\n'=' @ 18:7-8\n'a' @ 18:9-10\n'!=' @ 18:11-13\n'b' @ 18:14-15\n';' @ 18:15-16\n'let' @ 19:1-4\n'x' @ 19:5-6\n'=' @ 19:7-8\n'a' @ 19:9-10\n'>' @ 19:11-12\n'b' @ 19:13-14\n';' @ 19:14-15\n'let' @ 20:1-4\n'x' @ 20:5-6\n'=' @ 20:7-8\n'a' @ 20:9-10\n'>=' @ 20:11-13\n'b' @ 20:14-15\n';' @ 20:15-16\n'let' @ 21:1-4\n'x' @ 21:5-6\n'=' @ 21:7-8\n'a' @ 21:9-10\n'<' @ 21:11-12\n'b' @ 21:13-14\n';' @ 21:14-15\n'let' @ 22:1-4\n'x' @ 22:5-6\n'=' @ 22:7-8\n'a' @ 22:9-10\n'<=' @ 22:11-13\n'b' @ 22:14-15\n';' @ 22:15-16\n'let' @ 23:1-4\n'x' @ 23:5-6\n'=' @ 23:7-8\n'a' @ 23:9-10\n'>' @ 23:11-12\n'b' @ 23:13-14\n';' @ 23:14-15\n'let' @ 24:1-4\n'x' @ 24:5-6\n'=' @ 24:7-8\n'a' @ 24:9-10\n'..' @ 24:11-13\n'b' @ 24:14-15\n';' @ 24:15-16\n'let' @ 25:1-4\n'x' @ 25:5-6\n'=' @ 25:7-8\n'a' @ 25:9-10\n'as' @ 25:11-13\n'b' @ 25:14-15\n';' @ 25:15-16\n'let' @ 26:1-4\n'x' @ 26:5-6\n'=' @ 26:7-8\n'a' @ 26:9-10\n'console' @ 26:11-18\n'b' @ 26:19-20\n';' @ 26:20-21\n'let' @ 27:1-4\n'x' @ 27:5-6\n'=' @ 27:7-8\n'a' @ 27:9-10\n'const' @ 27:11-16\n'b' @ 27:17-18\n';' @ 27:18-19\n'let' @ 28:1-4\n'x' @ 28:5-6\n'=' @ 28:7-8\n'a' @ 28:9-10\n'let' @ 28:11-14\n'b' @ 28:15-16\n';' @ 28:16-17\n'let' @ 29:1-4\n'x' @ 29:5-6\n'=' @ 29:7-8\n'a' @ 29:9-10\n'for' @ 29:11-14\n'b' @ 29:15-16\n';' @ 29:16-17\n'let' @ 30:1-4\n'x' @ 30:5-6\n'=' @ 30:7-8\n'a' @ 30:9-10\n'if' @ 30:11-13\n'b' @ 30:14-15\n';' @ 30:15-16\n'let' @ 31:1-4\n'x' @ 31:5-6\n'=' @ 31:7-8\n'a' @ 31:9-10\n'else' @ 31:11-15\n'b' @ 31:16-17\n';' @ 31:17-18\n'let' @ 32:1-4\n'x' @ 32:5-6\n'=' @ 32:7-8\n'a' @ 32:9-10\n'i8' @ 32:11-13\n'b' @ 32:14-15\n';' @ 32:15-16\n'let' @ 33:1-4\n'x' @ 33:5-6\n'=' @ 33:7-8\n'a' @ 33:9-10\n'i16' @ 33:11-14\n'b' @ 33:15-16\n';' @ 33:16-17\n'let' @ 34:1-4\n'x' @ 34:5-6\n'=' @ 34:7-8\n'a' @ 34:9-10\n'i32' @ 34:11-14\n'b' @ 34:15-16\n';' @ 34:16-17\n'let' @ 35:1-4\n'x' @ 35:5-6\n'=' @ 35:7-8\n'a' @ 35:9-10\n'i64' @ 35:11-14\n'b' @ 35:15-16\n';' @ 35:16-17\n'let' @ 36:1-4\n'x' @ 36:5-6\n'=' @ 36:7-8\n'a' @ 36:9-10\n'i128' @ 36:11-15\n'b' @ 36:16-17\n';' @ 36:17-18\n'let' @ 37:1-4\n'x' @ 37:5-6\n'=' @ 37:7-8\n'a' @ 37:9-10\n'u8' @ 37:11-13\n'b' @ 37:14-15\n';' @ 37:15-16\n'let' @ 38:1-4\n'x' @ 38:5-6\n'=' @ 38:7-8\n'a' @ 38:9-10\n'u16' @ 38:11-14\n'b' @ 38:15-16\n';' @ 38:16-17\n'let' @ 39:1-4\n'x' @ 39:5-6\n'=' @ 39:7-8\n'a' @ 39:9-10\n'u32' @ 39:11-14\n'b' @ 39:15-16\n';' @ 39:16-17\n'let' @ 40:1-4\n'x' @ 40:5-6\n'=' @ 40:7-8\n'a' @ 40:9-10\n'u64' @ 40:11-14\n'b' @ 40:15-16\n';' @ 40:16-17\n'let' @ 41:1-4\n'x' @ 41:5-6\n'=' @ 41:7-8\n'a' @ 41:9-10\n'u128' @ 41:11-15\n'b' @ 41:16-17\n';' @ 41:17-18\n'let' @ 42:1-4\n'x' @ 42:5-6\n'=' @ 42:7-8\n'a' @ 42:9-10\n'&' @ 42:11-12\n'b' @ 42:13-14\n';' @ 42:14-15\n'let' @ 43:1-4\n'x' @ 43:5-6\n'=' @ 43:7-8\n'a' @ 43:9-10\n'return' @ 43:11-17\n'b' @ 43:18-19\n';' @ 43:19-20\n'let' @ 44:1-4\n'x' @ 44:5-6\n'=' @ 44:7-8\n'a' @ 44:9-10\n'self' @ 44:11-15\n'b' @ 44:16-17\n';' @ 44:17-18\n'let' @ 45:1-4\n'x' @ 45:5-6\n'=' @ 45:7-8\n'a' @ 45:9-10\n'Self' @ 45:11-15\n'b' @ 45:16-17\n';' @ 45:17-18\n'let' @ 46:1-4\n'x' @ 46:5-6\n'=' @ 46:7-8\n'a' @ 46:9-10\n'true' @ 46:11-15\n'b' @ 46:16-17\n';' @ 46:17-18\n'let' @ 47:1-4\n'x' @ 47:5-6\n'=' @ 47:7-8\n'a' @ 47:9-10\n'false' @ 47:11-16\n'b' @ 47:17-18\n';' @ 47:18-19\n'let' @ 48:1-4\n'x' @ 48:5-6\n'=' @ 48:7-8\n'a' @ 48:9-10\n'0' @ 48:11-12\n'b' @ 48:13-14\n';' @ 48:14-15\n" + - "did not consume all input: '=' @ 1:3-4\n'b' @ 1:4-5\n';' @ 1:5-6\n'x' @ 2:1-2\n'.' @ 2:2-3\n'=' @ 2:3-4\n'b' @ 2:4-5\n';' @ 2:5-6\n'ximport' @ 3:1-8\n'=' @ 3:8-9\n'b' @ 3:9-10\n';' @ 3:10-11\n'x' @ 4:1-2\n',' @ 4:2-3\n'=' @ 4:3-4\n'b' @ 4:4-5\n';' @ 4:5-6\n'x' @ 5:1-2\n'[' @ 5:2-3\n'=' @ 5:3-4\n'b' @ 5:4-5\n';' @ 5:5-6\n'x' @ 6:1-2\n']' @ 6:2-3\n'=' @ 6:3-4\n'b' @ 6:4-5\n';' @ 6:5-6\n'x' @ 7:1-2\n'{' @ 7:2-3\n'=' @ 7:3-4\n'b' @ 7:4-5\n';' @ 7:5-6\n'x' @ 8:1-2\n'}' @ 8:2-3\n'=' @ 8:3-4\n'b' @ 8:4-5\n';' @ 8:5-6\n'x' @ 9:1-2\n'=' @ 9:2-3\n'(' @ 9:3-4\n';' @ 9:4-5\n'x' @ 10:1-2\n'=' @ 10:2-3\n')' @ 10:3-4\n';' @ 10:4-5\n'x' @ 11:1-2\n'=' @ 11:2-3\n':' @ 11:3-4\n';' @ 11:4-5\n'x' @ 12:1-2\n'=' @ 12:2-3\n'::' @ 12:3-5\n';' @ 12:5-6\n'x' @ 13:1-2\n'?' @ 13:2-3\n'=' @ 13:3-4\n'b' @ 13:4-5\n';' @ 13:5-6\n'x_' @ 14:1-3\n'=' @ 14:3-4\n'b' @ 14:4-5\n';' @ 14:5-6\n'x' @ 15:1-2\n'==' @ 15:2-4\n'b' @ 15:4-5\n';' @ 15:5-6\n'x' @ 16:1-2\n'==' @ 16:2-4\n'b' @ 16:4-5\n';' @ 16:5-6\n'x' @ 17:1-2\n'!=' @ 17:2-4\n'b' @ 17:4-5\n';' @ 17:5-6\n'x' @ 18:1-2\n'!=' @ 18:2-4\n'=' @ 18:4-5\n'b' @ 18:5-6\n';' @ 18:6-7\n'x' @ 19:1-2\n'>=' @ 19:2-4\n'b' @ 19:4-5\n';' @ 19:5-6\n'x' @ 20:1-2\n'>=' @ 20:2-4\n'=' @ 20:4-5\n'b' @ 20:5-6\n';' @ 20:6-7\n'x' @ 21:1-2\n'<=' @ 21:2-4\n'b' @ 21:4-5\n';' @ 21:5-6\n'x' @ 22:1-2\n'<=' @ 22:2-4\n'=' @ 22:4-5\n'b' @ 22:5-6\n';' @ 22:6-7\n'x' @ 23:1-2\n'>=' @ 23:2-4\n'b' @ 23:4-5\n';' @ 23:5-6\n'x' @ 24:1-2\n'..' @ 24:2-4\n'=' @ 24:4-5\n'b' @ 24:5-6\n';' @ 24:6-7\n'xas' @ 25:1-4\n'=' @ 25:4-5\n'b' @ 25:5-6\n';' @ 25:6-7\n'xconsole' @ 26:1-9\n'=' @ 26:9-10\n'b' @ 26:10-11\n';' @ 26:11-12\n'xconst' @ 27:1-7\n'=' @ 27:7-8\n'b' @ 27:8-9\n';' @ 27:9-10\n'xlet' @ 28:1-5\n'=' @ 28:5-6\n'b' @ 28:6-7\n';' @ 28:7-8\n'xfor' @ 29:1-5\n'=' @ 29:5-6\n'b' @ 29:6-7\n';' @ 29:7-8\n'xif' @ 30:1-4\n'=' @ 30:4-5\n'b' @ 30:5-6\n';' @ 30:6-7\n'xelse' @ 31:1-6\n'=' @ 31:6-7\n'b' @ 31:7-8\n';' @ 31:8-9\n'xi8' @ 32:1-4\n'=' @ 32:4-5\n'b' @ 32:5-6\n';' @ 32:6-7\n'xi16' @ 33:1-5\n'=' @ 33:5-6\n'b' @ 33:6-7\n';' @ 33:7-8\n'xi32' @ 34:1-5\n'=' @ 34:5-6\n'b' @ 34:6-7\n';' @ 34:7-8\n'xi64' @ 35:1-5\n'=' @ 35:5-6\n'b' @ 35:6-7\n';' @ 35:7-8\n'xi128' @ 36:1-6\n'=' @ 36:6-7\n'b' @ 36:7-8\n';' @ 36:8-9\n'xu8' @ 37:1-4\n'=' @ 37:4-5\n'b' @ 37:5-6\n';' @ 37:6-7\n'xu16' @ 38:1-5\n'=' @ 38:5-6\n'b' @ 38:6-7\n';' @ 38:7-8\n'xu32' @ 39:1-5\n'=' @ 39:5-6\n'b' @ 39:6-7\n';' @ 39:7-8\n'xu64' @ 40:1-5\n'=' @ 40:5-6\n'b' @ 40:6-7\n';' @ 40:7-8\n'xu128' @ 41:1-6\n'=' @ 41:6-7\n'b' @ 41:7-8\n';' @ 41:8-9\n'x' @ 42:1-2\n'&' @ 42:2-3\n'=' @ 42:3-4\n'b' @ 42:4-5\n';' @ 42:5-6\n'xreturn' @ 43:1-8\n'=' @ 43:8-9\n'b' @ 43:9-10\n';' @ 43:10-11\n'xself' @ 44:1-6\n'=' @ 44:6-7\n'b' @ 44:7-8\n';' @ 44:8-9\n'xSelf' @ 45:1-6\n'=' @ 45:6-7\n'b' @ 45:7-8\n';' @ 45:8-9\n'xtrue' @ 46:1-6\n'=' @ 46:6-7\n'b' @ 46:7-8\n';' @ 46:8-9\n'xfalse' @ 47:1-7\n'=' @ 47:7-8\n'b' @ 47:8-9\n';' @ 47:9-10\n'x0' @ 48:1-3\n'=' @ 48:3-4\n'b' @ 48:4-5\n';' @ 48:5-6\n" diff --git a/tests/expectations/parser/parser/unreachable/postfix.leo.out b/tests/expectations/parser/parser/unreachable/postfix.leo.out new file mode 100644 index 0000000000..d55371f772 --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/postfix.leo.out @@ -0,0 +1,5 @@ +--- +namespace: ParseStatement +expectation: Fail +outputs: + - "did not consume all input: ';' @ 1:11-12\n'let' @ 2:1-4\n'x' @ 2:5-6\n'=' @ 2:7-8\n'a' @ 2:9-10\n'.' @ 2:10-11\n';' @ 2:11-12\n'let' @ 3:1-4\n'x' @ 3:5-6\n'=' @ 3:7-8\n'aimport' @ 3:9-16\n';' @ 3:16-17\n'let' @ 4:1-4\n'x' @ 4:5-6\n'=' @ 4:7-8\n'a' @ 4:9-10\n',' @ 4:10-11\n';' @ 4:11-12\n'let' @ 5:1-4\n'x' @ 5:5-6\n'=' @ 5:7-8\n'a' @ 5:9-10\n'[' @ 5:10-11\n';' @ 5:11-12\n'let' @ 6:1-4\n'x' @ 6:5-6\n'=' @ 6:7-8\n'a' @ 6:9-10\n']' @ 6:10-11\n';' @ 6:11-12\n'let' @ 7:1-4\n'x' @ 7:5-6\n'=' @ 7:7-8\n'a' @ 7:9-10\n'{' @ 7:10-11\n';' @ 7:11-12\n'let' @ 8:1-4\n'x' @ 8:5-6\n'=' @ 8:7-8\n'a' @ 8:9-10\n'}' @ 8:10-11\n';' @ 8:11-12\n'let' @ 9:1-4\n'x' @ 9:5-6\n'=' @ 9:7-8\n'a' @ 9:9-10\n')' @ 9:10-11\n';' @ 9:11-12\n'let' @ 10:1-4\n'x' @ 10:5-6\n'=' @ 10:7-8\n'a' @ 10:9-10\n':' @ 10:10-11\n';' @ 10:11-12\n'let' @ 11:1-4\n'x' @ 11:5-6\n'=' @ 11:7-8\n'a' @ 11:9-10\n'?' @ 11:10-11\n';' @ 11:11-12\n'let' @ 12:1-4\n'x' @ 12:5-6\n'=' @ 12:7-8\n'a_' @ 12:9-11\n';' @ 12:11-12\n'let' @ 13:1-4\n'x' @ 13:5-6\n'=' @ 13:7-8\n'a' @ 13:9-10\n'=' @ 13:10-11\n';' @ 13:11-12\n'let' @ 14:1-4\n'x' @ 14:5-6\n'=' @ 14:7-8\n'a' @ 14:9-10\n'==' @ 14:10-12\n';' @ 14:12-13\n'let' @ 15:1-4\n'x' @ 15:5-6\n'=' @ 15:7-8\n'a' @ 15:9-10\n'!' @ 15:10-11\n';' @ 15:11-12\n'let' @ 16:1-4\n'x' @ 16:5-6\n'=' @ 16:7-8\n'a' @ 16:9-10\n'!=' @ 16:10-12\n';' @ 16:12-13\n'let' @ 17:1-4\n'x' @ 17:5-6\n'=' @ 17:7-8\n'a' @ 17:9-10\n'>' @ 17:10-11\n';' @ 17:11-12\n'let' @ 18:1-4\n'x' @ 18:5-6\n'=' @ 18:7-8\n'a' @ 18:9-10\n'>=' @ 18:10-12\n';' @ 18:12-13\n'let' @ 19:1-4\n'x' @ 19:5-6\n'=' @ 19:7-8\n'a' @ 19:9-10\n'<' @ 19:10-11\n';' @ 19:11-12\n'let' @ 20:1-4\n'x' @ 20:5-6\n'=' @ 20:7-8\n'a' @ 20:9-10\n'<=' @ 20:10-12\n';' @ 20:12-13\n'let' @ 21:1-4\n'x' @ 21:5-6\n'=' @ 21:7-8\n'a' @ 21:9-10\n'>' @ 21:10-11\n';' @ 21:11-12\n'let' @ 22:1-4\n'x' @ 22:5-6\n'=' @ 22:7-8\n'a' @ 22:9-10\n'..' @ 22:10-12\n';' @ 22:12-13\n'let' @ 23:1-4\n'x' @ 23:5-6\n'=' @ 23:7-8\n'aas' @ 23:9-12\n';' @ 23:12-13\n'let' @ 24:1-4\n'x' @ 24:5-6\n'=' @ 24:7-8\n'aconsole' @ 24:9-17\n';' @ 24:17-18\n'let' @ 25:1-4\n'x' @ 25:5-6\n'=' @ 25:7-8\n'aconst' @ 25:9-15\n';' @ 25:15-16\n'let' @ 26:1-4\n'x' @ 26:5-6\n'=' @ 26:7-8\n'alet' @ 26:9-13\n';' @ 26:13-14\n'let' @ 27:1-4\n'x' @ 27:5-6\n'=' @ 27:7-8\n'afor' @ 27:9-13\n';' @ 27:13-14\n'let' @ 28:1-4\n'x' @ 28:5-6\n'=' @ 28:7-8\n'aif' @ 28:9-12\n';' @ 28:12-13\n'let' @ 29:1-4\n'x' @ 29:5-6\n'=' @ 29:7-8\n'aelse' @ 29:9-14\n';' @ 29:14-15\n'let' @ 30:1-4\n'x' @ 30:5-6\n'=' @ 30:7-8\n'ai8' @ 30:9-12\n';' @ 30:12-13\n'let' @ 31:1-4\n'x' @ 31:5-6\n'=' @ 31:7-8\n'ai16' @ 31:9-13\n';' @ 31:13-14\n'let' @ 32:1-4\n'x' @ 32:5-6\n'=' @ 32:7-8\n'ai32' @ 32:9-13\n';' @ 32:13-14\n'let' @ 33:1-4\n'x' @ 33:5-6\n'=' @ 33:7-8\n'ai64' @ 33:9-13\n';' @ 33:13-14\n'let' @ 34:1-4\n'x' @ 34:5-6\n'=' @ 34:7-8\n'ai128' @ 34:9-14\n';' @ 34:14-15\n'let' @ 35:1-4\n'x' @ 35:5-6\n'=' @ 35:7-8\n'au8' @ 35:9-12\n';' @ 35:12-13\n'let' @ 36:1-4\n'x' @ 36:5-6\n'=' @ 36:7-8\n'au16' @ 36:9-13\n';' @ 36:13-14\n'let' @ 37:1-4\n'x' @ 37:5-6\n'=' @ 37:7-8\n'au32' @ 37:9-13\n';' @ 37:13-14\n'let' @ 38:1-4\n'x' @ 38:5-6\n'=' @ 38:7-8\n'au64' @ 38:9-13\n';' @ 38:13-14\n'let' @ 39:1-4\n'x' @ 39:5-6\n'=' @ 39:7-8\n'au128' @ 39:9-14\n';' @ 39:14-15\n'let' @ 40:1-4\n'x' @ 40:5-6\n'=' @ 40:7-8\n'a' @ 40:9-10\n'&' @ 40:10-11\n';' @ 40:11-12\n'let' @ 41:1-4\n'x' @ 41:5-6\n'=' @ 41:7-8\n'areturn' @ 41:9-16\n';' @ 41:16-17\n'let' @ 42:1-4\n'x' @ 42:5-6\n'=' @ 42:7-8\n'aself' @ 42:9-14\n';' @ 42:14-15\n'let' @ 43:1-4\n'x' @ 43:5-6\n'=' @ 43:7-8\n'aSelf' @ 43:9-14\n';' @ 43:14-15\n'let' @ 44:1-4\n'x' @ 44:5-6\n'=' @ 44:7-8\n'atrue' @ 44:9-14\n';' @ 44:14-15\n'let' @ 45:1-4\n'x' @ 45:5-6\n'=' @ 45:7-8\n'afalse' @ 45:9-15\n';' @ 45:15-16\n'let' @ 46:1-4\n'x' @ 46:5-6\n'=' @ 46:7-8\n'a0' @ 46:9-11\n';' @ 46:11-12\n" diff --git a/tests/parser/functions/bounded_recursion_fail.leo b/tests/parser/functions/bounded_recursion_fail.leo deleted file mode 100644 index 96c93779d4..0000000000 --- a/tests/parser/functions/bounded_recursion_fail.leo +++ /dev/null @@ -1,15 +0,0 @@ -/* -namespace: Parse -expectation: Pass -*/ - -function x(const y: u32) { - if y < 999u32 { - x(y+1); - } -} - -function main(y: bool) -> bool { - x(1u32); - return y; -} \ No newline at end of file diff --git a/tests/parser/functions/infinite_recursion_fail.leo b/tests/parser/functions/infinite_recursion.leo similarity index 100% rename from tests/parser/functions/infinite_recursion_fail.leo rename to tests/parser/functions/infinite_recursion.leo diff --git a/tests/parser/unreachable/eat_ident.leo b/tests/parser/unreachable/eat_ident.leo index 7fd93c6200..83f080b4d1 100644 --- a/tests/parser/unreachable/eat_ident.leo +++ b/tests/parser/unreachable/eat_ident.leo @@ -3,7 +3,6 @@ namespace: Parse expectation: Fail */ -circuit try_to_hit_eat_ident_unreachable circuit ; circuit . circuit import @@ -16,7 +15,11 @@ circuit [ circuit ] circuit { circuit } -circuit - +circuit ( +circuit ) +circuit : +circuit :: +circuit ? circuit _ circuit = circuit == @@ -48,7 +51,7 @@ circuit u128 circuit & circuit return circuit self -circuit self +circuit Self circuit true circuit false circuit 0 \ No newline at end of file diff --git a/tests/parser/unreachable/eat_int.leo b/tests/parser/unreachable/eat_int.leo index 5117dd9aa9..4ad7af074f 100644 --- a/tests/parser/unreachable/eat_int.leo +++ b/tests/parser/unreachable/eat_int.leo @@ -1,9 +1,8 @@ /* -namespace: Parse +namespace: ParseStatement expectation: Fail */ -x.0_try_to_hit_hit_eat_int_unreachable x.-12 x.0_; x.0_. @@ -17,7 +16,11 @@ x.0_[ x.0_] x.0_{ x.0_} -x.0_- +x.0_( +x.0_) +x.0_: +x.0_:: +x.0_? x.0__ x.0_= x.0_== @@ -49,6 +52,6 @@ x.0_u128 x.0_& x.0_return x.0_self -x.0_self +x.0_Self x.0_true x.0_false diff --git a/tests/parser/unreachable/equality_and_order_expression.leo b/tests/parser/unreachable/equality_and_order_expression.leo new file mode 100644 index 0000000000..f032d1e1af --- /dev/null +++ b/tests/parser/unreachable/equality_and_order_expression.leo @@ -0,0 +1,57 @@ +/* +namespace: ParseExpression +expectation: Fail +*/ + +if 10 ; {} +if 10 . {} +if 10 import {} +if 10 , {} +if 10 * {} +if 10 + {} +if 10 - {} +if 10 / {} +if 10 [ {} +if 10 ] {} +if 10 { {} +if 10 } {} +if 10 ( {} +if 10 ) {} +if 10 : {} +if 10 :: {} +if 10 ? {} +if 10 _ {} +if 10 = {} +if 10 == {} +if 10 ! {} +if 10 != {} +if 10 > {} +if 10 >= {} +if 10 < {} +if 10 <= {} +if 10 > {} +if 10 .. {} +if 10 as {} +if 10 console {} +if 10 const {} +if 10 let {} +if 10 for {} +if 10 if {} +if 10 else {} +if 10 i8 {} +if 10 i16 {} +if 10 i32 {} +if 10 i64 {} +if 10 i128 {} +if 10 u8 {} +if 10 u16 {} +if 10 u32 {} +if 10 u64 {} +if 10 u128 {} +if 10 & {} +if 10 return {} +if 10 self {} +if 10 Self {} +if 10 true {} +if 10 false {} +if 10 0 {} \ No newline at end of file diff --git a/tests/parser/unreachable/expect_ident.leo b/tests/parser/unreachable/expect_ident.leo index 70e6f5bfad..b3cd3abfd5 100644 --- a/tests/parser/unreachable/expect_ident.leo +++ b/tests/parser/unreachable/expect_ident.leo @@ -1,9 +1,8 @@ /* -namespace: Parse +namespace: ParseStatement expectation: Fail */ -x::try_to_hit_expect_ident_unreachable x::; x::. x::import @@ -16,7 +15,11 @@ x::[ x::] x::{ x::} -x::- +x::( +x::) +x::: +x:::: +x::? x::_ x::= x::== @@ -48,7 +51,7 @@ x::u128 x::& x::return x::self -x::self +x::Self x::true x::false x::0 \ No newline at end of file diff --git a/tests/parser/unreachable/math_op.leo b/tests/parser/unreachable/math_op.leo new file mode 100644 index 0000000000..5d3ce66b0f --- /dev/null +++ b/tests/parser/unreachable/math_op.leo @@ -0,0 +1,102 @@ +/* +namespace: ParseStatement +expectation: Fail +*/ + +let x = a ; b; +let x = a . b; +let x = a import b; +let x = a , b; +let x = a [ b; +let x = a ] b; +let x = a { b; +let x = a } b; +let x = a ( b; +let x = a ) b; +let x = a : b; +let x = a :: b; +let x = a ? b; +let x = a _ b; +let x = a = b; +let x = a == b; +let x = a ! b; +let x = a != b; +let x = a > b; +let x = a >= b; +let x = a < b; +let x = a <= b; +let x = a > b; +let x = a .. b; +let x = a as b; +let x = a console b; +let x = a const b; +let x = a let b; +let x = a for b; +let x = a if b; +let x = a else b; +let x = a i8 b; +let x = a i16 b; +let x = a i32 b; +let x = a i64 b; +let x = a i128 b; +let x = a u8 b; +let x = a u16 b; +let x = a u32 b; +let x = a u64 b; +let x = a u128 b; +let x = a & b; +let x = a return b; +let x = a self b; +let x = a Self b; +let x = a true b; +let x = a false b; +let x = a 0 b; + +x;=b; +x.=b; +ximport=b; +x,=b; +x[=b; +x]=b; +x{=b; +x}=b; +x=(; +x=); +x=:; +x=::; +x?=b; +x_=b; +x==b; +x==b; +x!=b; +x!==b; +x>=b; +x>==b; +x<=b; +x<==b; +x>=b; +x..=b; +xas=b; +xconsole=b; +xconst=b; +xlet=b; +xfor=b; +xif=b; +xelse=b; +xi8=b; +xi16=b; +xi32=b; +xi64=b; +xi128=b; +xu8=b; +xu16=b; +xu32=b; +xu64=b; +xu128=b; +x&=b; +xreturn=b; +xself=b; +xSelf=b; +xtrue=b; +xfalse=b; +x0=b; \ No newline at end of file diff --git a/tests/parser/unreachable/postfix.leo b/tests/parser/unreachable/postfix.leo new file mode 100644 index 0000000000..2a3533e1d4 --- /dev/null +++ b/tests/parser/unreachable/postfix.leo @@ -0,0 +1,51 @@ +/* +namespace: ParseStatement +expectation: Fail +*/ + +let x = a;; +let x = a.; +let x = aimport; +let x = a,; +let x = a[; +let x = a]; +let x = a{; +let x = a}; +let x = a); +let x = a:; +let x = a?; +let x = a_; +let x = a=; +let x = a==; +let x = a!; +let x = a!=; +let x = a>; +let x = a>=; +let x = a<; +let x = a<=; +let x = a>; +let x = a..; +let x = aas; +let x = aconsole; +let x = aconst; +let x = alet; +let x = afor; +let x = aif; +let x = aelse; +let x = ai8; +let x = ai16; +let x = ai32; +let x = ai64; +let x = ai128; +let x = au8; +let x = au16; +let x = au32; +let x = au64; +let x = au128; +let x = a&; +let x = areturn; +let x = aself; +let x = aSelf; +let x = atrue; +let x = afalse; +let x = a0; \ No newline at end of file From 09818747870ab4bba90ea9dd080b739bd5c6fa88 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 11:30:45 -0800 Subject: [PATCH 10/14] tested all unreachables --- .../parser/parser/unreachable/define.leo.out | 5 ++ tests/parser/unreachable/define.leo | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/expectations/parser/parser/unreachable/define.leo.out create mode 100644 tests/parser/unreachable/define.leo diff --git a/tests/expectations/parser/parser/unreachable/define.leo.out b/tests/expectations/parser/parser/unreachable/define.leo.out new file mode 100644 index 0000000000..bf28b4b9ea --- /dev/null +++ b/tests/expectations/parser/parser/unreachable/define.leo.out @@ -0,0 +1,5 @@ +--- +namespace: ParseStatement +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'expression', got ';'\n --> test:1:1\n |\n 1 | ; x = 10u8;\n | ^" diff --git a/tests/parser/unreachable/define.leo b/tests/parser/unreachable/define.leo new file mode 100644 index 0000000000..dcef3aeb31 --- /dev/null +++ b/tests/parser/unreachable/define.leo @@ -0,0 +1,53 @@ +/* +namespace: ParseStatement +expectation: Fail +*/ + +; x = 10u8; +. x = 10u8; +import x = 10u8; +, x = 10u8; +[ x = 10u8; +] x = 10u8; +{ x = 10u8; +} x = 10u8; +( x = 10u8; +) x = 10u8; +: x = 10u8; +:: x = 10u8; +? x = 10u8; +_ x = 10u8; += x = 10u8; +== x = 10u8; +! x = 10u8; +!= x = 10u8; +> x = 10u8; +>= x = 10u8; +< x = 10u8; +<= x = 10u8; +> x = 10u8; +.. x = 10u8; +as x = 10u8; +console x = 10u8; +const x = 10u8; +let x = 10u8; +for x = 10u8; +if x = 10u8; +else x = 10u8; +i8 x = 10u8; +i16 x = 10u8; +i32 x = 10u8; +i64 x = 10u8; +i128 x = 10u8; +u8 x = 10u8; +u16 x = 10u8; +u32 x = 10u8; +u64 x = 10u8; +u128 x = 10u8; +& x = 10u8; +return x = 10u8; +self x = 10u8; +Self x = 10u8; +true x = 10u8; +false x = 10u8; +0 x = 10u8; \ No newline at end of file From e8ffe7ff9d9c68873418176fc85cf368d4eda7c3 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Fri, 28 Jan 2022 15:06:00 -0800 Subject: [PATCH 11/14] merge upstream changes from ast and staging --- Cargo.lock | 1 + parser/Cargo.toml | 3 +++ parser/src/parser/expression.rs | 2 +- parser/src/parser/file.rs | 15 ++++----------- parser/src/parser/type_.rs | 12 +++++++----- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea45669892..c8a5345bd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1538,6 +1538,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "smallvec", "tendril", "tracing", ] diff --git a/parser/Cargo.toml b/parser/Cargo.toml index e16765ebcf..e96457c567 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -23,6 +23,9 @@ name = "leo_ast" path = "benches/leo_ast.rs" harness = false +[dependencies] +smallvec = "1.8" + [dependencies.leo-ast] path = "../ast" version = "1.5.3" diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 79c6e020d0..137e171ac3 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -403,7 +403,7 @@ impl ParserContext<'_> { /// circuit initialization expression. pub fn parse_circuit_expression(&mut self, identifier: Identifier) -> Result { let (members, _, span) = self.parse_list(Token::LeftCurly, Token::RightCurly, Token::Comma, |p| { - Ok(Some(CircuitImpliedVariableDefinition { + Ok(Some(CircuitVariableInitializer { identifier: p.expect_ident()?, expression: p.eat(Token::Colon).map(|_| p.parse_expression()).transpose()?, })) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 7902ed5807..4e740a3fba 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -559,19 +559,12 @@ impl ParserContext<'_> { /// const definition statement and assignment. /// pub fn parse_type_alias(&mut self) -> Result<(Identifier, Alias)> { - self.expect(Token::Type)?; + let start = self.expect(Token::Type)?; let name = self.expect_ident()?; self.expect(Token::Assign)?; - let (type_, _) = self.parse_type()?; - self.expect(Token::Semicolon)?; + let (represents, _) = self.parse_type()?; + let span = start + self.expect(Token::Semicolon)?; - Ok(( - name.clone(), - Alias { - represents: type_, - span: name.span.clone(), - name, - }, - )) + Ok((name.clone(), Alias { represents, span, name })) } } diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 9c73c00a21..37470530ce 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -17,6 +17,8 @@ use super::*; use leo_errors::{ParserError, Result}; +use smallvec::smallvec; + pub(crate) const TYPE_TOKENS: &[Token] = &[ Token::I8, Token::I16, @@ -58,7 +60,7 @@ impl ParserContext<'_> { /// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type. pub fn parse_array_dimensions(&mut self) -> Result { Ok(if let Some(dim) = self.parse_array_dimension() { - dim + ArrayDimensions(smallvec![dim]) } else { let mut had_item_err = false; let (dims, _, span) = self.parse_paren_comma_list(|p| { @@ -74,16 +76,16 @@ impl ParserContext<'_> { if dims.is_empty() && !had_item_err { self.emit_err(ParserError::array_tuple_dimensions_empty(&span)); } - ArrayDimensions::Multi(dims) + ArrayDimensions(dims.into()) }) } /// Parses a basic array dimension, i.e., an integer or `_`. - fn parse_array_dimension(&mut self) -> Option { + fn parse_array_dimension(&mut self) -> Option { if let Some((int, _)) = self.eat_int() { - Some(ArrayDimensions::Number(int)) + Some(Dimension::Number(int)) } else if self.eat(Token::Underscore).is_some() { - Some(ArrayDimensions::Unspecified) + Some(Dimension::Unspecified) } else { None } From 437e06d0d33f2965d76bb619053b49e8e84e6884 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Mon, 31 Jan 2022 14:13:15 -0800 Subject: [PATCH 12/14] make some changes to semantics of function names --- parser/src/parser/context.rs | 33 ++++++++++++++++----------------- parser/src/parser/expression.rs | 12 ++++++------ parser/src/parser/statement.rs | 4 ++-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index fe5b03683e..b338216cd1 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -67,7 +67,7 @@ impl<'a> ParserContext<'a> { } /// Returns the current token if there is one. - pub fn curr(&self) -> Option<&SpannedToken> { + pub fn peek_option(&self) -> Option<&SpannedToken> { self.tokens.last() } @@ -84,25 +84,24 @@ impl<'a> ParserContext<'a> { } /// - /// Returns a reference to the next next token or error if it does not exist. + /// Returns a reference to the next SpannedToken or error if it does not exist. /// pub fn peek_next(&self) -> Result<&SpannedToken> { self.tokens.get(self.tokens.len() - 2).ok_or_else(|| self.eof()) } /// - /// Returns a reference to the next SpannedToken or error if it does not exist. + /// Returns a reference to the current SpannedToken or error if it does not exist. /// pub fn peek(&self) -> Result<&SpannedToken> { - self.curr().ok_or_else(|| self.eof()) + self.tokens.last().ok_or_else(|| self.eof()) } /// /// Returns a reference to the next Token. /// pub fn peek_token(&self) -> Cow<'_, Token> { - self.tokens - .last() + self.peek_option() .map(|x| &x.token) .map(Cow::Borrowed) .unwrap_or_else(|| Cow::Owned(Token::Eof)) @@ -125,7 +124,7 @@ impl<'a> ParserContext<'a> { /// the next token does not exist. /// pub fn eat(&mut self, token: Token) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.curr() { + if let Some(SpannedToken { token: inner, .. }) = self.peek_option() { if &token == inner { return self.bump(); } @@ -147,7 +146,7 @@ impl<'a> ParserContext<'a> { pub fn eat_identifier(&mut self) -> Option { if let Some(SpannedToken { token: Token::Ident(_), .. - }) = self.curr() + }) = self.peek_option() { if let SpannedToken { token: Token::Ident(name), @@ -156,7 +155,7 @@ impl<'a> ParserContext<'a> { { return Some(Identifier { name, span }); } else { - unreachable!("Impossible to reach area, unless a change broke the parser.") + unreachable!("eat_identifier_ shouldn't produce this") } } None @@ -285,7 +284,7 @@ impl<'a> ParserContext<'a> { pub fn eat_int(&mut self) -> Option<(PositiveNumber, Span)> { if let Some(SpannedToken { token: Token::Int(_), .. - }) = self.curr() + }) = self.peek_option() { if let SpannedToken { token: Token::Int(value), @@ -294,7 +293,7 @@ impl<'a> ParserContext<'a> { { return Some((PositiveNumber { value }, span)); } else { - unreachable!("Impossible to reach area, unless a change broke the parser.") + unreachable!("eat_int_ shouldn't produce this") } } None @@ -305,7 +304,7 @@ impl<'a> ParserContext<'a> { /// the next token does not exist. /// pub fn eat_any(&mut self, token: &[Token]) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.curr() { + if let Some(SpannedToken { token: inner, .. }) = self.peek_option() { if token.iter().any(|x| x == inner) { return self.bump(); } @@ -317,7 +316,7 @@ impl<'a> ParserContext<'a> { /// Returns the span of the next token if it is equal to the given [`Token`], or error. /// pub fn expect(&mut self, token: Token) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.curr() { + if let Some(SpannedToken { token: inner, span }) = self.peek_option() { if &token == inner { Ok(self.bump().unwrap().span) } else { @@ -332,7 +331,7 @@ impl<'a> ParserContext<'a> { /// Returns the span of the next token if it is equal to one of the given [`Token`]s, or error. /// pub fn expect_oneof(&mut self, token: &[Token]) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.curr() { + if let Some(SpannedToken { token: inner, span }) = self.peek_option() { if token.iter().any(|x| x == inner) { Ok(self.bump().unwrap()) } else { @@ -368,7 +367,7 @@ impl<'a> ParserContext<'a> { /// Returns the [`Identifier`] of the next token if it is an [`Identifier`], or error. pub fn expect_ident(&mut self) -> Result { - if let Some(SpannedToken { token: inner, span }) = self.curr() { + if let Some(SpannedToken { token: inner, span }) = self.peek_option() { if let Token::Ident(_) = inner { if let SpannedToken { token: Token::Ident(name), @@ -377,7 +376,7 @@ impl<'a> ParserContext<'a> { { Ok(Identifier { name, span }) } else { - unreachable!("Impossible to reach area, unless a change broke the parser.") + unreachable!("expect_ident_ shouldn't produce this") } } else { Err(ParserError::unexpected_str(inner, "ident", span).into()) @@ -444,6 +443,6 @@ impl<'a> ParserContext<'a> { /// Returns true if the current token is `(`. pub(super) fn peek_is_left_par(&self) -> bool { - matches!(self.curr().map(|t| &t.token), Some(Token::LeftParen)) + matches!(self.peek_option().map(|t| &t.token), Some(Token::LeftParen)) } } diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 137e171ac3..c7d977a490 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -134,7 +134,7 @@ impl ParserContext<'_> { let op = match op { Token::Eq => BinaryOperation::Eq, Token::NotEq => BinaryOperation::Ne, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_equality_expression_ shouldn't produce this"), }; expr = Self::bin_expr(expr, right, op); } @@ -155,7 +155,7 @@ impl ParserContext<'_> { Token::LtEq => BinaryOperation::Le, Token::Gt => BinaryOperation::Gt, Token::GtEq => BinaryOperation::Ge, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_ordering_expression_ shouldn't produce this"), }; expr = Self::bin_expr(expr, right, op); } @@ -173,7 +173,7 @@ impl ParserContext<'_> { let op = match op { Token::Add => BinaryOperation::Add, Token::Minus => BinaryOperation::Sub, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_additive_expression_ shouldn't produce this"), }; expr = Self::bin_expr(expr, right, op); } @@ -191,7 +191,7 @@ impl ParserContext<'_> { let op = match op { Token::Mul => BinaryOperation::Mul, Token::Div => BinaryOperation::Div, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_multiplicative_expression_ shouldn't produce this"), }; expr = Self::bin_expr(expr, right, op); } @@ -248,7 +248,7 @@ impl ParserContext<'_> { let operation = match op.token { Token::Not => UnaryOperation::Not, Token::Minus => UnaryOperation::Negate, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_unary_expression_ shouldn't produce this"), }; // hack for const signed integer overflow issues if matches!(operation, UnaryOperation::Negate) { @@ -379,7 +379,7 @@ impl ParserContext<'_> { name: ident, })); } - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_postfix_expression_ shouldn't produce this"), } } Ok(expr) diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 3ebdfa693e..91c1d2a21c 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -115,7 +115,7 @@ impl ParserContext<'_> { Token::MulEq => AssignOperation::Mul, Token::DivEq => AssignOperation::Div, Token::ExpEq => AssignOperation::Pow, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_assign_statement_ shouldn't produce this"), }, value, }))) @@ -317,7 +317,7 @@ impl ParserContext<'_> { declaration_type: match declare.token { Token::Let => Declare::Let, Token::Const => Declare::Const, - _ => unreachable!("Impossible to reach area, unless a change broke the parser."), + _ => unreachable!("parse_definition_statement_ shouldn't produce this"), }, variable_names, type_, From d6d23f938b77b3da29262a38e2206ff3fbcc8c78 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 1 Feb 2022 13:51:02 +0100 Subject: [PATCH 13/14] cherry pick ast-docs commit --- ast/src/annotation.rs | 6 +++ ast/src/common/array_dimensions.rs | 1 + ast/src/common/const_self_keyword.rs | 1 + ast/src/common/identifier.rs | 7 +++- ast/src/common/mut_self_keyword.rs | 1 + ast/src/common/positive_number.rs | 4 +- ast/src/common/self_keyword.rs | 1 + ast/src/common/spread_or_expression.rs | 4 +- ast/src/expression/accesses.rs | 6 +++ ast/src/expression/array_init.rs | 8 ++++ ast/src/expression/array_inline.rs | 5 +++ ast/src/expression/binary.rs | 34 ++++++++++++++++ ast/src/expression/call.rs | 5 +++ ast/src/expression/cast.rs | 4 ++ ast/src/expression/err.rs | 2 + ast/src/expression/from_bits.rs | 40 ------------------- ast/src/expression/from_bytes.rs | 40 ------------------- ast/src/expression/mod.rs | 20 +++++++--- ast/src/expression/ternary.rs | 5 +++ ast/src/expression/to_bits.rs | 39 ------------------ ast/src/expression/to_bytes.rs | 39 ------------------ ast/src/expression/tuple_init.rs | 4 ++ ast/src/expression/unary.rs | 10 +++++ ast/src/expression/value.rs | 11 +++++ ast/src/functions/function.rs | 10 +++++ ast/src/functions/input/function_input.rs | 6 +++ ast/src/functions/input/input_variable.rs | 5 +++ ast/src/groups/group_coordinate.rs | 5 +++ ast/src/groups/group_value.rs | 7 ++++ ast/src/imports/import.rs | 2 + ast/src/imports/import_symbol.rs | 9 +++++ ast/src/imports/package.rs | 5 +++ ast/src/imports/package_access.rs | 13 +++++- ast/src/imports/package_or_packages.rs | 4 ++ ast/src/imports/packages.rs | 5 +++ ast/src/node.rs | 3 ++ ast/src/pass.rs | 1 + ast/src/program.rs | 14 +++++++ ast/src/statements/assign/assignee.rs | 11 ++++- ast/src/statements/assign/mod.rs | 22 ++++++++++ ast/src/statements/block.rs | 3 ++ ast/src/statements/conditional.rs | 5 +++ ast/src/statements/console/console_args.rs | 4 ++ .../statements/console/console_function.rs | 7 ++++ .../statements/console/console_statement.rs | 3 ++ ast/src/statements/definition/declare.rs | 3 ++ ast/src/statements/definition/mod.rs | 6 +++ ast/src/statements/expression.rs | 3 ++ ast/src/statements/iteration.rs | 8 ++++ ast/src/statements/return_statement.rs | 3 ++ ast/src/statements/statement.rs | 9 +++++ ast/src/types/integer_type.rs | 2 + ast/src/types/type_.rs | 15 ++++++- parser/src/parser/file.rs | 25 +++++------- .../import/import_empty_list_fail.leo.out | 2 +- .../parser/parser/import/many_import.leo.out | 26 ++++++------ 56 files changed, 340 insertions(+), 203 deletions(-) delete mode 100644 ast/src/expression/from_bits.rs delete mode 100644 ast/src/expression/from_bytes.rs delete mode 100644 ast/src/expression/to_bits.rs delete mode 100644 ast/src/expression/to_bytes.rs diff --git a/ast/src/annotation.rs b/ast/src/annotation.rs index 6362c745aa..572c1191d3 100644 --- a/ast/src/annotation.rs +++ b/ast/src/annotation.rs @@ -20,16 +20,22 @@ use leo_span::{sym, Span, Symbol}; use serde::{Deserialize, Serialize}; use std::fmt; +/// An annotation `@name (arguments)?`. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Annotation { + /// The span including `name ( arguments )`. pub span: Span, + /// The name of the annotation. pub name: Identifier, + /// Arguments for the annotation, if any. pub arguments: Vec, } +/// The set of allowed annotations. const ALLOWED_ANNOTATIONS: &[Symbol] = &[sym::test]; impl Annotation { + /// Is the annotation valid? pub fn is_valid_annotation(&self) -> bool { ALLOWED_ANNOTATIONS.iter().any(|name| self.name.name == *name) } diff --git a/ast/src/common/array_dimensions.rs b/ast/src/common/array_dimensions.rs index 11ca7e82c6..811c862225 100644 --- a/ast/src/common/array_dimensions.rs +++ b/ast/src/common/array_dimensions.rs @@ -67,6 +67,7 @@ impl Deref for ArrayDimensions { } impl ArrayDimensions { + /// Construct a single-dimensional array-dimension. pub fn single(dim: Dimension) -> Self { Self(smallvec![dim]) } diff --git a/ast/src/common/const_self_keyword.rs b/ast/src/common/const_self_keyword.rs index 576e65c0ec..1adbfbcdc7 100644 --- a/ast/src/common/const_self_keyword.rs +++ b/ast/src/common/const_self_keyword.rs @@ -25,6 +25,7 @@ use std::fmt; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(transparent)] pub struct ConstSelfKeyword { + /// Always `const self`. pub identifier: Identifier, } diff --git a/ast/src/common/identifier.rs b/ast/src/common/identifier.rs index ab8ae7e54c..7273012d44 100644 --- a/ast/src/common/identifier.rs +++ b/ast/src/common/identifier.rs @@ -37,7 +37,9 @@ use std::{ /// to reflect the new struct instantiation. #[derive(Clone)] pub struct Identifier { + /// The symbol that the user wrote, e.g., `foo`. pub name: Symbol, + /// A span locating where the identifier occured in the source. pub span: Span, } @@ -52,6 +54,7 @@ impl Node for Identifier { } impl Identifier { + /// Constructs a new identifier with `name` and a default span. pub fn new(name: Symbol) -> Self { Self { name, @@ -59,7 +62,7 @@ impl Identifier { } } - /// Check if the Identifier name matches the other name + /// Check if the Identifier name matches the other name. pub fn matches(&self, other: &Self) -> bool { self.name == other.name } @@ -121,7 +124,7 @@ impl<'de> Deserialize<'de> for Identifier { fn deserialize>(deserializer: D) -> Result { struct IdentifierVisitor; - impl<'de> Visitor<'de> for IdentifierVisitor { + impl Visitor<'_> for IdentifierVisitor { type Value = Identifier; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/ast/src/common/mut_self_keyword.rs b/ast/src/common/mut_self_keyword.rs index 2c5bf0a78f..633482d89f 100644 --- a/ast/src/common/mut_self_keyword.rs +++ b/ast/src/common/mut_self_keyword.rs @@ -24,6 +24,7 @@ use std::fmt; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(transparent)] pub struct RefSelfKeyword { + /// Always `&self`. pub identifier: Identifier, } diff --git a/ast/src/common/positive_number.rs b/ast/src/common/positive_number.rs index 55241ecb23..1ecc719398 100644 --- a/ast/src/common/positive_number.rs +++ b/ast/src/common/positive_number.rs @@ -23,14 +23,14 @@ use tendril::StrTendril; /// A number string guaranteed to be positive by the pest grammar. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] pub struct PositiveNumber { + /// The string representation of the positive number. + // FIXME(Centril): This should become an `u128`. #[serde(with = "leo_span::tendril_json")] pub value: StrTendril, } impl PositiveNumber { - /// /// Returns `true` if this number is zero. - /// pub fn is_zero(&self) -> bool { self.value.as_ref().eq("0") } diff --git a/ast/src/common/self_keyword.rs b/ast/src/common/self_keyword.rs index f70dd2c408..17a41e45c6 100644 --- a/ast/src/common/self_keyword.rs +++ b/ast/src/common/self_keyword.rs @@ -25,6 +25,7 @@ use std::fmt; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(transparent)] pub struct SelfKeyword { + /// Always just `self`. pub identifier: Identifier, } diff --git a/ast/src/common/spread_or_expression.rs b/ast/src/common/spread_or_expression.rs index 91ed617134..fa6d6d9c1b 100644 --- a/ast/src/common/spread_or_expression.rs +++ b/ast/src/common/spread_or_expression.rs @@ -20,10 +20,12 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; -/// Spread or expression +/// Either a spread expression or a normal expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum SpreadOrExpression { + /// A spread expression, i.e., `...other_array`. Spread(Expression), + /// A normal element expression. Expression(Expression), } diff --git a/ast/src/expression/accesses.rs b/ast/src/expression/accesses.rs index 00f3b6ff00..2bef95ce46 100644 --- a/ast/src/expression/accesses.rs +++ b/ast/src/expression/accesses.rs @@ -17,12 +17,18 @@ use super::*; use crate::accesses::*; +/// An access expressions, extracting a smaller part out of a whole. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum AccessExpression { + /// An `array[index]` expression. Array(ArrayAccess), + /// An expression accessing a range of an array. ArrayRange(ArrayRangeAccess), + /// An expression accessing a field in a structure, e.g., `circuit_var.field`. Member(MemberAccess), + /// Access to a tuple field using its position, e.g., `tuple.1`. Tuple(TupleAccess), + /// Access to a member constant or a static function of a circuit. Static(StaticAccess), } diff --git a/ast/src/expression/array_init.rs b/ast/src/expression/array_init.rs index d5b81a5c18..5437757e51 100644 --- a/ast/src/expression/array_init.rs +++ b/ast/src/expression/array_init.rs @@ -16,10 +16,18 @@ use super::*; +/// An array initializer expression, e.g., `[42; 5]`. +/// constructing an array of `element` repeated according to `dimensions`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ArrayInitExpression { + /// The expression that all elements in the array will evaluate to. pub element: Box, + /// The dimensions of the array. + /// + /// This could be a multi-dimensional array, + /// e.g., `[42; (2, 2)]`, giving you a matrix `[[2, 2], [2, 2]]`. pub dimensions: ArrayDimensions, + /// The span of the entire expression from `[` to `]`. pub span: Span, } diff --git a/ast/src/expression/array_inline.rs b/ast/src/expression/array_inline.rs index a7da2b1f01..4e03912a4f 100644 --- a/ast/src/expression/array_inline.rs +++ b/ast/src/expression/array_inline.rs @@ -16,9 +16,14 @@ use super::*; +/// An expression constructing an array by listing the individual elements inline, +/// for example `[4, 6, 5, 2]`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ArrayInlineExpression { + /// A list, where a part can be either an element, + /// or list of elements to construct the array with. pub elements: Vec, + /// The span of the entire expression from `[` to `]`. pub span: Span, } diff --git a/ast/src/expression/binary.rs b/ast/src/expression/binary.rs index faf0c06802..0a829fe193 100644 --- a/ast/src/expression/binary.rs +++ b/ast/src/expression/binary.rs @@ -16,33 +16,59 @@ use super::*; +/// A binary operator. +/// +/// Precedence is defined in the parser. #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum BinaryOperation { + /// Addition, i.e. `+`. Add, + /// Subtraction, i.e. `-`. Sub, + /// Multiplication, i.e. `*`. Mul, + /// Division, i.e. `/`. Div, + /// Exponentiation, i.e. `**` in `a ** b`. Pow, + /// Logical-or, i.e., `||`. Or, + /// Logical-and, i.e., `&&`. And, + /// Equality relation, i.e., `==`. Eq, + /// In-equality relation, i.e. `!=`. Ne, + /// Greater-or-equal relation, i.e. `>=`. Ge, + /// Greater-than relation, i.e. `>=`. Gt, + /// Lesser-or-equal relation, i.e. `<=`. Le, + /// Lesser-than relation, i.e. `<`. Lt, + /// Bitwise-or, i.e., `|`. BitOr, + /// Bitwise-and, i.e., `&`. BitAnd, + /// Bitwise-or, i.e., `^`. BitXor, + /// Shift-right, i.e `>>`. Shr, + /// Unsigned shift-right, i.e `>>>`. ShrSigned, + /// Shift-left, i.e `<<`. Shl, + /// Modulus or remainder operation, i.e., `%`. Mod, } +/// The category a binary operation belongs to. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum BinaryOperationClass { + /// A numeric one, that is, the result is numeric. Numeric, + /// A boolean one, meaning the result is of type `bool`. Boolean, } @@ -74,6 +100,8 @@ impl AsRef for BinaryOperation { } impl BinaryOperation { + /// The class ("category") that the binary operation belongs to. + /// For example, the `+` operator is numeric and `==` results in a boolean value. pub fn class(&self) -> BinaryOperationClass { match self { BinaryOperation::Add @@ -100,11 +128,17 @@ impl BinaryOperation { } } +/// A binary expression `left op right` of two operands separated by some operator. +/// For example, `foo + bar`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct BinaryExpression { + /// The left operand of the expression. pub left: Box, + /// The right operand of the expression. pub right: Box, + /// The operand defining the meaning of the resulting binary expression. pub op: BinaryOperation, + /// The span from `left` to `right`. pub span: Span, } diff --git a/ast/src/expression/call.rs b/ast/src/expression/call.rs index 5405a1c20a..2670141391 100644 --- a/ast/src/expression/call.rs +++ b/ast/src/expression/call.rs @@ -16,10 +16,15 @@ use super::*; +/// A function call expression, e.g., `foo(args)` or `Foo::bar(args)`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CallExpression { + /// An expression evaluating to a callable function, + /// either a member of a structure or a free function. pub function: Box, // todo: make this identifier? + /// Expressions for the arguments passed to the functions parameters. pub arguments: Vec, + /// Span of the entire call `function(arguments)`. pub span: Span, } diff --git a/ast/src/expression/cast.rs b/ast/src/expression/cast.rs index fce0add1d8..525618996c 100644 --- a/ast/src/expression/cast.rs +++ b/ast/src/expression/cast.rs @@ -18,10 +18,14 @@ use crate::Type; use super::*; +/// A cast expression `e as U`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CastExpression { + /// The expression `e` of a type `T` that is being cast to `U`. pub inner: Box, + /// The type `U` to cast `e` to. pub target_type: Type, + /// Span for the entire expression `e as U` to. pub span: Span, } diff --git a/ast/src/expression/err.rs b/ast/src/expression/err.rs index 7d25725fa4..23c94eeeeb 100644 --- a/ast/src/expression/err.rs +++ b/ast/src/expression/err.rs @@ -16,8 +16,10 @@ use super::*; +/// Represents a syntactically invalid expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ErrExpression { + /// The span of the invalid expression. pub span: Span, } diff --git a/ast/src/expression/from_bits.rs b/ast/src/expression/from_bits.rs deleted file mode 100644 index 2a034781c0..0000000000 --- a/ast/src/expression/from_bits.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -use super::*; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct FromBitsExpression { - pub named_type: Box, - pub arg: Box, - pub span: Span, -} - -impl fmt::Display for FromBitsExpression { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}.from_bits({})", self.named_type, self.arg) - } -} - -impl Node for FromBitsExpression { - fn span(&self) -> &Span { - &self.span - } - - fn set_span(&mut self, span: Span) { - self.span = span; - } -} diff --git a/ast/src/expression/from_bytes.rs b/ast/src/expression/from_bytes.rs deleted file mode 100644 index ae5ad3a60f..0000000000 --- a/ast/src/expression/from_bytes.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -use super::*; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct FromBytesExpression { - pub named_type: Box, - pub arg: Box, - pub span: Span, -} - -impl fmt::Display for FromBytesExpression { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}.from_bytes({})", self.named_type, self.arg) - } -} - -impl Node for FromBytesExpression { - fn span(&self) -> &Span { - &self.span - } - - fn set_span(&mut self, span: Span) { - self.span = span; - } -} diff --git a/ast/src/expression/mod.rs b/ast/src/expression/mod.rs index 3134ab280c..d5c473954f 100644 --- a/ast/src/expression/mod.rs +++ b/ast/src/expression/mod.rs @@ -46,26 +46,34 @@ pub use cast::*; mod err; pub use err::*; -/// Expression that evaluates to a value +/// Expression that evaluates to a value. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Expression { + /// An identifier expression. Identifier(Identifier), + /// A literal expression. Value(ValueExpression), + /// A binary expression, e.g., `42 + 24`. Binary(BinaryExpression), + /// An unary expression. Unary(UnaryExpression), + /// A ternary conditional expression `cond ? if_expr : else_expr`. Ternary(TernaryExpression), + /// A cast expression `expr as type`. Cast(CastExpression), + /// An access expression of some sort, e.g., `array[idx]` or `foo.bar`. Access(AccessExpression), - + /// An array expression where individual elements are listed inline, + /// for example `[4, 6, ...[5, 7], 2]`. ArrayInline(ArrayInlineExpression), + /// An array-repeat expression, e.g., `[42; 3]` yielding `[42, 42, 42]`. ArrayInit(ArrayInitExpression), - + /// A tuple expression e.g., `(foo, 42, true)`. TupleInit(TupleInitExpression), - + /// An expression constructing a structure like `Foo { bar: 42, baz }`. CircuitInit(CircuitInitExpression), - + /// A call expression like `my_fun(args)`. Call(CallExpression), - /// An expression of type "error". /// Will result in a compile error eventually. Err(ErrExpression), diff --git a/ast/src/expression/ternary.rs b/ast/src/expression/ternary.rs index b2ace68333..55b17a0630 100644 --- a/ast/src/expression/ternary.rs +++ b/ast/src/expression/ternary.rs @@ -16,11 +16,16 @@ use super::*; +/// A ternary conditional expression, that is, `condition ? if_true : if_false`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct TernaryExpression { + /// The condition determining which branch to pick. pub condition: Box, + /// The branch the expression evaluates to if `condition` evaluates to true. pub if_true: Box, + /// The branch the expression evaluates to if `condition` evaluates to false. pub if_false: Box, + /// The span from `condition` to `if_false`. pub span: Span, } diff --git a/ast/src/expression/to_bits.rs b/ast/src/expression/to_bits.rs deleted file mode 100644 index b10a7e20d2..0000000000 --- a/ast/src/expression/to_bits.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -use super::*; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ToBitsExpression { - pub value: Box, - pub span: Span, -} - -impl fmt::Display for ToBitsExpression { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}.to_bits()", self.value) - } -} - -impl Node for ToBitsExpression { - fn span(&self) -> &Span { - &self.span - } - - fn set_span(&mut self, span: Span) { - self.span = span; - } -} diff --git a/ast/src/expression/to_bytes.rs b/ast/src/expression/to_bytes.rs deleted file mode 100644 index c79e0bb60c..0000000000 --- a/ast/src/expression/to_bytes.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is 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. - -// The Leo library 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 the Leo library. If not, see . - -use super::*; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ToBytesExpression { - pub value: Box, - pub span: Span, -} - -impl fmt::Display for ToBytesExpression { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}.to_bytes()", self.value) - } -} - -impl Node for ToBytesExpression { - fn span(&self) -> &Span { - &self.span - } - - fn set_span(&mut self, span: Span) { - self.span = span; - } -} diff --git a/ast/src/expression/tuple_init.rs b/ast/src/expression/tuple_init.rs index bfc966e2e7..7167b63300 100644 --- a/ast/src/expression/tuple_init.rs +++ b/ast/src/expression/tuple_init.rs @@ -16,9 +16,13 @@ use super::*; +/// A tuple construction expression, e.g., `(foo, false, 42)`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct TupleInitExpression { + /// The elements of the tuple. + /// In the example above, it would be `foo`, `false`, and `42`. pub elements: Vec, + /// The span from `(` to `)`. pub span: Span, } diff --git a/ast/src/expression/unary.rs b/ast/src/expression/unary.rs index 436894146b..7b3193529b 100644 --- a/ast/src/expression/unary.rs +++ b/ast/src/expression/unary.rs @@ -16,10 +16,16 @@ use super::*; +/// The unary operator for an unary expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UnaryOperation { + /// The logical not operator, i.e., `!`. + /// For example, it transforms `true` to `false`. Not, + /// The negation operator, i.e., `-`. Negate, + /// The bitwise not operator, i.e., `~`. + /// For example, it transforms `1010` to `0101`. BitNot, } @@ -33,10 +39,14 @@ impl AsRef for UnaryOperation { } } +/// An unary expression applying an operator to an inner expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct UnaryExpression { + /// The inner expression `op` is applied to. pub inner: Box, + /// The unary operator to apply to `inner`. pub op: UnaryOperation, + /// The span covering `op inner`. pub span: Span, } diff --git a/ast/src/expression/value.rs b/ast/src/expression/value.rs index d6c75972dc..89c5960779 100644 --- a/ast/src/expression/value.rs +++ b/ast/src/expression/value.rs @@ -19,32 +19,43 @@ use tendril::StrTendril; use super::*; use crate::{Char, CharValue}; +/// A literal expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ValueExpression { // todo: deserialize values here + /// An address literal, e.g., `aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8`. Address( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A boolean literal, either `true` or `false`. Boolean( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A char literal, e.g., `'a'`, representing a single unicode code point. Char(CharValue), + /// A field literal, e.g., `42field`. + /// That is, an unsigned number followed by the keyword `field`. Field( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A group literal, either single or tuple. + /// For example, `42group` or `(12, 52)group`. Group(Box), + /// A negated non-integer literal, e.g., `-4.2`. Implicit( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// An integer literal, e.g., `42`. Integer( IntegerType, #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A string literal, e.g., `"foobar"`. String(Vec, #[serde(with = "leo_span::span_json")] Span), } diff --git a/ast/src/functions/function.rs b/ast/src/functions/function.rs index 89fd89ece9..3dac34440c 100644 --- a/ast/src/functions/function.rs +++ b/ast/src/functions/function.rs @@ -22,15 +22,25 @@ use serde::{Deserialize, Serialize}; use std::cell::Cell; use std::fmt; +/// A function definition. #[derive(Clone, Serialize, Deserialize)] pub struct Function { + /// A map of all the annotations from their base names to the whole. pub annotations: IndexMap, + /// The function identifier, e.g., `foo` in `function foo(...) { ... }`. pub identifier: Identifier, + /// The function's parameters. pub input: Vec, + /// WHether the function is `const`. pub const_: bool, + /// The function return type, if explicitly specified, or `()` if not. pub output: Option, + /// Any mapping to the core library. + /// Always `None` when initially parsed. pub core_mapping: Cell>, + /// The body of the function. pub block: Block, + /// The entire span of the function definition. pub span: Span, } diff --git a/ast/src/functions/input/function_input.rs b/ast/src/functions/input/function_input.rs index 5ead43d586..1e7c46895c 100644 --- a/ast/src/functions/input/function_input.rs +++ b/ast/src/functions/input/function_input.rs @@ -20,12 +20,18 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A function parameter. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FunctionInputVariable { + /// The name the parameter is accessible as in the function's body. pub identifier: Identifier, + /// Is it a const parameter? pub const_: bool, + /// Is it a mutable parameter? pub mutable: bool, + /// What's the parameter's type? pub type_: Type, + /// The parameters span from any annotations to its type. pub span: Span, } diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index f2298fe44d..0d92c41240 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -23,9 +23,13 @@ use std::fmt; /// Enumerates the possible inputs to a function. #[derive(Clone, Serialize, Deserialize)] pub enum FunctionInput { + /// A `self` parameter. SelfKeyword(SelfKeyword), + /// A `const self` parameter. ConstSelfKeyword(ConstSelfKeyword), + /// A `&self` parameter. RefSelfKeyword(RefSelfKeyword), + /// A normal function parameter. Variable(FunctionInputVariable), } @@ -81,6 +85,7 @@ impl FunctionInput { } } + /// Formats the parameter to `f`. fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { FunctionInput::SelfKeyword(keyword) => write!(f, "{}", keyword), diff --git a/ast/src/groups/group_coordinate.rs b/ast/src/groups/group_coordinate.rs index 896c400e62..4187daed19 100644 --- a/ast/src/groups/group_coordinate.rs +++ b/ast/src/groups/group_coordinate.rs @@ -24,14 +24,19 @@ use serde::{Deserialize, Serialize}; use std::fmt; use tendril::StrTendril; +/// A coordinate in a tuple group literal. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GroupCoordinate { + /// A number, e.g., `42`. Number( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A sign high recovery, i.e. `+`. SignHigh, + /// A sign low recovery, i.e., `-`. SignLow, + /// Recovery with an inferred value. Inferred, } diff --git a/ast/src/groups/group_value.rs b/ast/src/groups/group_value.rs index 65d8b7a259..22ec31757d 100644 --- a/ast/src/groups/group_value.rs +++ b/ast/src/groups/group_value.rs @@ -24,12 +24,15 @@ use serde::{Deserialize, Serialize}; use std::fmt; use tendril::StrTendril; +/// A group literal. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GroupValue { + /// Single group literal, e.g., `42group`. Single( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), + /// A tuple group literal with (x, y) coordinates. Tuple(GroupTuple), } @@ -69,10 +72,14 @@ impl fmt::Display for GroupValue { } } +/// A group tuple literal, e.g., `(42, 24)group`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct GroupTuple { + /// The left component of the type, e.g., `42` in the case above. pub x: GroupCoordinate, + /// The right component of the type, e.g., `24` in the case above. pub y: GroupCoordinate, + /// The span from `(` to `)`. pub span: Span, } diff --git a/ast/src/imports/import.rs b/ast/src/imports/import.rs index 5a7e7f35cb..a3819e8621 100644 --- a/ast/src/imports/import.rs +++ b/ast/src/imports/import.rs @@ -23,7 +23,9 @@ use std::fmt; /// Represents an import statement in a Leo program. #[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct ImportStatement { + /// The package or packages to import. pub package_or_packages: PackageOrPackages, + /// The span, excluding the `;`. pub span: Span, } diff --git a/ast/src/imports/import_symbol.rs b/ast/src/imports/import_symbol.rs index e59a4d6c0e..c0b4de7443 100644 --- a/ast/src/imports/import_symbol.rs +++ b/ast/src/imports/import_symbol.rs @@ -21,10 +21,17 @@ use leo_span::{sym, Span}; use serde::{Deserialize, Serialize}; use std::fmt; +/// An import of `symbol` possibly renamed to `alias`, +/// e.g., `symbol` or `symbol as alias`. +/// +/// This is the leaf of an import tree. #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct ImportSymbol { pub symbol: Identifier, + /// The name, if any, to import `symbol` as. + /// If not specified, `symbol` is the name it is imported under. pub alias: Option, + /// The span including `symbol` and possibly `as alias`. pub span: Span, } @@ -50,6 +57,7 @@ impl fmt::Debug for ImportSymbol { } impl ImportSymbol { + /// Creates a glob `*` import. pub fn star(span: &Span) -> Self { Self { symbol: Identifier { @@ -61,6 +69,7 @@ impl ImportSymbol { } } + /// Is this a glob import? pub fn is_star(&self) -> bool { self.symbol.name == sym::Star } diff --git a/ast/src/imports/package.rs b/ast/src/imports/package.rs index f135682435..ce693f604d 100644 --- a/ast/src/imports/package.rs +++ b/ast/src/imports/package.rs @@ -20,14 +20,19 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A package import specification. #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Package { + /// The base package to import `access` from. pub name: Identifier, + /// A specification of what to import from `name`. pub access: PackageAccess, + /// The span including the `name` and the `access`. pub span: Span, } impl Package { + /// Formats `self` to `f`. fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}.{}", self.name, self.access) } diff --git a/ast/src/imports/package_access.rs b/ast/src/imports/package_access.rs index 06751b6269..28745f6921 100644 --- a/ast/src/imports/package_access.rs +++ b/ast/src/imports/package_access.rs @@ -22,9 +22,19 @@ use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub enum PackageAccess { - Star { span: Span }, + /// A glob import `*`. + Star { + /// The span for the `*`. + span: Span, + }, + /// A subpackage to import. SubPackage(Box), + /// A leaf package to import. Symbol(ImportSymbol), + /// Several subpackages to import. + // FIXME(Centril): This structure seems convoluted and unclear. + // Refactor and simplify the types to: + // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/struct.UseTree.html. Multiple(Packages), } @@ -49,6 +59,7 @@ impl Node for PackageAccess { } impl PackageAccess { + /// Formats `self` to `f`. fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { PackageAccess::Star { .. } => write!(f, "*"), diff --git a/ast/src/imports/package_or_packages.rs b/ast/src/imports/package_or_packages.rs index df895db027..780f99f1e5 100644 --- a/ast/src/imports/package_or_packages.rs +++ b/ast/src/imports/package_or_packages.rs @@ -20,13 +20,17 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A specification of what packages to import. #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub enum PackageOrPackages { + /// Instruction to import a single package or item. Package(Package), + /// Instruction to import a packages or items with a common prefix. Packages(Packages), } impl PackageOrPackages { + /// Formats `self` to `f`. fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { PackageOrPackages::Package(ref package) => write!(f, "{}", package), diff --git a/ast/src/imports/packages.rs b/ast/src/imports/packages.rs index 73e965fc50..dafe4cae9d 100644 --- a/ast/src/imports/packages.rs +++ b/ast/src/imports/packages.rs @@ -20,14 +20,19 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// Import of `name.(accesses)`, that is, several sub-packages or items within `name`. #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Packages { + /// The common package that `accesses` are contained within. pub name: Identifier, + /// The packages or items to import within the package `name`. pub accesses: Vec, + /// The entire span for `name.(accesses)`. pub span: Span, } impl Packages { + /// Formats `self` to `f`. fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}.(", self.name)?; for (i, access) in self.accesses.iter().enumerate() { diff --git a/ast/src/node.rs b/ast/src/node.rs index 046ae2a04c..be0c100b9c 100644 --- a/ast/src/node.rs +++ b/ast/src/node.rs @@ -16,10 +16,13 @@ use leo_span::Span; +/// A node in the AST. pub trait Node: std::fmt::Debug + std::fmt::Display + Clone + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned { + /// Returns the span of the node. fn span(&self) -> &Span; + /// Sets the span of the node. fn set_span(&mut self, span: Span); } diff --git a/ast/src/pass.rs b/ast/src/pass.rs index aff6e641e7..2ac35621b9 100644 --- a/ast/src/pass.rs +++ b/ast/src/pass.rs @@ -17,6 +17,7 @@ use crate::{Ast, Program}; use leo_errors::Result; +/// A pass consuming a `Program` and possibly returning an `Ast`. pub trait AstPass { fn do_pass(self, ast: Program) -> Result; } diff --git a/ast/src/program.rs b/ast/src/program.rs index 5d7a3244c2..0ea6c27179 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -28,15 +28,25 @@ use std::fmt; /// Stores the Leo program abstract syntax tree. #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct Program { + /// The name of the program. + /// Empty after parsing. pub name: String, + /// Expected function inputs. + /// Empty after parsing. pub expected_input: Vec, + /// The collected import statements. pub import_statements: Vec, #[serde(with = "crate::common::imported_modules")] + /// A map from paths to injected programs. pub imports: IndexMap, Program>, + /// A map from alias names to type aliases. pub aliases: IndexMap, + /// A map from circuit names to circuit definitions. pub circuits: IndexMap, + /// A map from constant names to their definitions. #[serde(with = "crate::common::global_consts_json")] pub global_consts: IndexMap, DefinitionStatement>, + /// A map from function names to their definitions. pub functions: IndexMap, } @@ -77,6 +87,7 @@ impl fmt::Display for Program { } impl Program { + /// Constructs an empty program with `name`. pub fn new(name: String) -> Self { Self { name, @@ -90,6 +101,7 @@ impl Program { } } + /// Handles all internal annotations like `@CoreFunction` and `@AlwaysConst`. pub fn handle_internal_annotations(&mut self) { self.circuits .iter_mut() @@ -121,10 +133,12 @@ impl Program { }); } + /// Extract the name of the program. pub fn get_name(&self) -> String { self.name.to_string() } + /// Sets the name of the program. pub fn name(mut self, name: String) -> Self { self.name = name; self diff --git a/ast/src/statements/assign/assignee.rs b/ast/src/statements/assign/assignee.rs index e55ff82237..3e8e26c14e 100644 --- a/ast/src/statements/assign/assignee.rs +++ b/ast/src/statements/assign/assignee.rs @@ -21,24 +21,31 @@ use serde::{Deserialize, Serialize}; use std::fmt; #[allow(clippy::large_enum_variant)] +/// A sub-place in a variable to assign to. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum AssigneeAccess { + /// Assignment to a range in an array. ArrayRange(Option, Option), + /// Assignment to an element of an array identified by its index. ArrayIndex(Expression), + /// Assignment to a tuple field by its position, e.g., `2`. Tuple(PositiveNumber, #[serde(with = "leo_span::span_json")] Span), + /// Assignment to a field in a structure. Member(Identifier), } -/// Definition assignee: v, arr[0..2], Point p.x +/// Definition assignee, e.g., `v`, `arr[0..2]`, `p.x`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Assignee { + /// The base variable to assign to. pub identifier: Identifier, + /// Sub-places within `identifier` to assign to, if any. pub accesses: Vec, pub span: Span, } impl Assignee { - /// Returns the name of the variable being assigned to + /// Returns the name of the variable being assigned to. pub fn identifier(&self) -> &Identifier { &self.identifier } diff --git a/ast/src/statements/assign/mod.rs b/ast/src/statements/assign/mod.rs index b6cea744eb..839b894116 100644 --- a/ast/src/statements/assign/mod.rs +++ b/ast/src/statements/assign/mod.rs @@ -24,22 +24,38 @@ use std::fmt; mod assignee; pub use assignee::*; +/// The assignment operator. #[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum AssignOperation { + /// Plain assignment, `=`. Assign, + /// Add-assignment, `+=`. Add, + /// Subtracting assignment, `-=`. Sub, + /// Multiplicating assignment, `*=`. Mul, + /// Divising-assignment, `/=`. Div, + /// Exponentating assignment `**=`. Pow, + /// Logical or assignment. Or, + /// Logical and assignment. And, + /// Bitwise or assignment. BitOr, + /// Bitwise and assignment. BitAnd, + /// Bitwise xor assignment. BitXor, + /// Shift right assignment. Shr, + /// Signed shift right assignment. ShrSigned, + /// Shift left assignment. Shl, + /// Modulus / remainder assignment. Mod, } @@ -65,11 +81,17 @@ impl AsRef for AssignOperation { } } +/// An assignment statement, `assignee operation? = value`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct AssignStatement { + /// The assignment operation. + /// For plain assignment, use `AssignOperation::Assign`. pub operation: AssignOperation, + /// The place to assign to. pub assignee: Assignee, + /// The value to assign to the `assignee`. pub value: Expression, + /// The span, excluding the semicolon. pub span: Span, } diff --git a/ast/src/statements/block.rs b/ast/src/statements/block.rs index 6447667341..e54a4a6ba5 100644 --- a/ast/src/statements/block.rs +++ b/ast/src/statements/block.rs @@ -20,9 +20,12 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A block `{ [stmt]* }` consisting of a list of statements to execute in order. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct Block { + /// The list of statements to execute. pub statements: Vec, + /// The span from `{` to `}`. pub span: Span, } diff --git a/ast/src/statements/conditional.rs b/ast/src/statements/conditional.rs index dbfdf42185..2e4adf6b65 100644 --- a/ast/src/statements/conditional.rs +++ b/ast/src/statements/conditional.rs @@ -20,11 +20,16 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// An `if condition block (else next)?` statement. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct ConditionalStatement { + /// The `bool`-typed condition deciding what to evaluate. pub condition: Expression, + /// The block to evaluate in case `condition` yields `true`. pub block: Block, + /// The statement, if any, to evaluate when `condition` yields `false`. pub next: Option>, + /// The span from `if` to `next` or to `block`. pub span: Span, } diff --git a/ast/src/statements/console/console_args.rs b/ast/src/statements/console/console_args.rs index c45d14ba1d..4c03aa26df 100644 --- a/ast/src/statements/console/console_args.rs +++ b/ast/src/statements/console/console_args.rs @@ -20,10 +20,14 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// The arguments `args` passed to `console.log(args)` or `console.error(args)`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct ConsoleArgs { + /// The formatting string with `parameters` interpolated into it. pub string: Vec, + /// Parameters to interpolate in `string`. pub parameters: Vec, + /// The span from `(` to `)`. pub span: Span, } diff --git a/ast/src/statements/console/console_function.rs b/ast/src/statements/console/console_function.rs index be184c92ee..dc7a2baf08 100644 --- a/ast/src/statements/console/console_function.rs +++ b/ast/src/statements/console/console_function.rs @@ -20,10 +20,17 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A console logging function to invoke. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum ConsoleFunction { + /// A `console.assert(expr)` call to invoke, + /// asserting that the expression evaluates to `true`. Assert(Expression), + /// A `console.error(args)` call to invoke, + /// resulting in an error at runtime. Error(ConsoleArgs), + /// A `console.log(args)` call to invoke, + /// resulting in a log message at runtime. Log(ConsoleArgs), } diff --git a/ast/src/statements/console/console_statement.rs b/ast/src/statements/console/console_statement.rs index 6ebd986cb9..7673ef3ca3 100644 --- a/ast/src/statements/console/console_statement.rs +++ b/ast/src/statements/console/console_statement.rs @@ -20,9 +20,12 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A console logging statement like `console.log(...);`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ConsoleStatement { + /// The logging function to run. pub function: ConsoleFunction, + /// The span excluding the semicolon. pub span: Span, } diff --git a/ast/src/statements/definition/declare.rs b/ast/src/statements/definition/declare.rs index 6748c255a3..9113221750 100644 --- a/ast/src/statements/definition/declare.rs +++ b/ast/src/statements/definition/declare.rs @@ -17,9 +17,12 @@ use serde::{Deserialize, Serialize}; use std::fmt; +/// The sort of bindings to introduce, either `let` or `const`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Declare { + /// This is a `const` binding. Const, + /// This is a `let` binding. Let, } diff --git a/ast/src/statements/definition/mod.rs b/ast/src/statements/definition/mod.rs index 6b52b5aa59..b73ae7b28b 100644 --- a/ast/src/statements/definition/mod.rs +++ b/ast/src/statements/definition/mod.rs @@ -26,12 +26,18 @@ pub use variable_name::*; mod declare; pub use declare::*; +/// A `let` or `const` declaration statement. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct DefinitionStatement { + /// What sort of declaration is this? `let` or `const`?. pub declaration_type: Declare, + /// The bindings / variable names to declare. pub variable_names: Vec, + /// The types of the bindings, if specified, or inferred otherwise. pub type_: Option, + /// An initializer value for the bindings. pub value: Expression, + /// The span excluding the semicolon. pub span: Span, } diff --git a/ast/src/statements/expression.rs b/ast/src/statements/expression.rs index 29f41eaad9..93ed15c3e5 100644 --- a/ast/src/statements/expression.rs +++ b/ast/src/statements/expression.rs @@ -20,9 +20,12 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// An expression statement `expr;`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct ExpressionStatement { + /// The expression to evaluate purely for its side-effects. pub expression: Expression, + /// The span excluding the semicolon. pub span: Span, } diff --git a/ast/src/statements/iteration.rs b/ast/src/statements/iteration.rs index 34e093b687..7e2a529565 100644 --- a/ast/src/statements/iteration.rs +++ b/ast/src/statements/iteration.rs @@ -20,13 +20,21 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A bounded `for` loop statement `for variable in start .. =? stop block`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct IterationStatement { + /// The binding / variable to introduce in the body `block`. pub variable: Identifier, + /// The start of the iteration. pub start: Expression, + /// The end of the iteration, possibly `inclusive`. pub stop: Expression, + /// Whether `stop` is inclusive or not. + /// Signified with `=` when parsing. pub inclusive: bool, + /// The block to run on each iteration. pub block: Block, + /// The span from `for` to `block`. pub span: Span, } diff --git a/ast/src/statements/return_statement.rs b/ast/src/statements/return_statement.rs index e0e90839fe..e1d25dc050 100644 --- a/ast/src/statements/return_statement.rs +++ b/ast/src/statements/return_statement.rs @@ -20,9 +20,12 @@ use leo_span::Span; use serde::{Deserialize, Serialize}; use std::fmt; +/// A return statement `return expression;`. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct ReturnStatement { + /// The expression to return to the function caller. pub expression: Expression, + /// The span of `return expression` excluding the semicolon. pub span: Span, } diff --git a/ast/src/statements/statement.rs b/ast/src/statements/statement.rs index 8db5410463..c6f97e8f45 100644 --- a/ast/src/statements/statement.rs +++ b/ast/src/statements/statement.rs @@ -24,13 +24,22 @@ use std::fmt; /// Program statement that defines some action (or expression) to be carried out. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum Statement { + /// A return statement `return expr;`. Return(ReturnStatement), + /// A binding or set of bindings / variables to declare. Definition(DefinitionStatement), + /// An assignment statement. Assign(Box), + /// An `if` statement. Conditional(ConditionalStatement), + /// A `for` statement. Iteration(Box), + /// A console logging statement. Console(ConsoleStatement), + /// An expression statement turning an expression into a statement, + /// using the expression only for its side-effects. Expression(ExpressionStatement), + /// A block statement. Block(Block), } diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index 9ac566b2d7..078d866305 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -40,11 +40,13 @@ pub enum IntegerType { } impl IntegerType { + /// Is the integer type a signed one? pub fn is_signed(&self) -> bool { use IntegerType::*; matches!(self, I8 | I16 | I32 | I64 | I128) } + /// Returns the symbol for the integer type. pub fn symbol(self) -> Symbol { match self { Self::I8 => sym::i8, diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index f02331fe1f..eb694ac39d 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -26,17 +26,30 @@ use std::fmt; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Type { // Data types + /// The `address` type. Address, + /// The boolean `bool` type. Boolean, + /// The `char` type. Char, + /// The `field` type. Field, + /// The `group` type for expressions like `(42, 24)group`. Group, + /// An integer type. IntegerType(IntegerType), // Data type wrappers + /// An array type `[element; dimensions]`. Array(Box, ArrayDimensions), + + /// A tuple type `(T_0, T_1, ...)` made up of a list of types. Tuple(Vec), - Identifier(Identifier), // ex Circuit or Alias + + /// A reference to either a nominal type (e.g., a `circuit`) or a type alias. + Identifier(Identifier), + + /// The `Self` type, allowed within `circuit` definitions. SelfType, /// Placeholder for a type that could not be resolved or was not well-formed. diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 4e740a3fba..52f8a4489c 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -148,14 +148,14 @@ impl ParserContext<'_> { /// Returns a vector of [`PackageAccess`] AST nodes if the next tokens represent package access /// expressions within an import statement. - pub fn parse_package_accesses(&mut self, span: &Span) -> Result> { - let (out, ..) = self.parse_paren_comma_list(|p| p.parse_package_access().map(Some))?; + pub fn parse_package_accesses(&mut self, start: &Span) -> Result<(Vec, Span)> { + let (out, _, end) = self.parse_paren_comma_list(|p| p.parse_package_access().map(Some))?; if out.is_empty() { - self.emit_err(ParserError::invalid_import_list(span)); + self.emit_err(ParserError::invalid_import_list(&end)); } - Ok(out) + Ok((out, start + &end)) } /// @@ -262,22 +262,15 @@ impl ParserContext<'_> { /// with accesses. /// pub fn parse_package_path(&mut self) -> Result { - let package_name = self.parse_package_name()?; + let name = self.parse_package_name()?; self.expect(Token::Dot)?; if self.peek_is_left_par() { - let accesses = self.parse_package_accesses(&package_name.span)?; - Ok(PackageOrPackages::Packages(Packages { - span: &package_name.span + accesses.last().map(|x| x.span()).unwrap_or(&package_name.span), - name: package_name, - accesses, - })) + let (accesses, span) = self.parse_package_accesses(&name.span)?; + Ok(PackageOrPackages::Packages(Packages { span, name, accesses })) } else { let access = self.parse_package_access()?; - Ok(PackageOrPackages::Package(Package { - span: &package_name.span + access.span(), - name: package_name, - access, - })) + let span = &name.span + access.span(); + Ok(PackageOrPackages::Package(Package { span, name, access })) } } diff --git a/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out b/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out index 0436fedf95..50ad5ede20 100644 --- a/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out +++ b/tests/expectations/parser/parser/import/import_empty_list_fail.leo.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370002]: Cannot import empty list\n --> test:3:8\n |\n 3 | import a.();\n | ^\nError [EPAR0370002]: Cannot import empty list\n --> test:5:8\n |\n 5 | import a.();\n | ^" + - "Error [EPAR0370002]: Cannot import empty list\n --> test:3:10\n |\n 3 | import a.();\n | ^^\nError [EPAR0370002]: Cannot import empty list\n --> test:5:10\n |\n 5 | import a.();\n | ^^" diff --git a/tests/expectations/parser/parser/import/many_import.leo.out b/tests/expectations/parser/parser/import/many_import.leo.out index ddc4e6ea24..503368ee35 100644 --- a/tests/expectations/parser/parser/import/many_import.leo.out +++ b/tests/expectations/parser/parser/import/many_import.leo.out @@ -31,18 +31,18 @@ outputs: content: " foo," span: line_start: 3 - line_stop: 5 + line_stop: 6 col_start: 8 - col_stop: 8 + col_stop: 2 path: "" - content: "import test-import.( // local import\n ...\n foo," + content: "import test-import.( // local import\n ...\n ...\n);" span: line_start: 3 - line_stop: 5 + line_stop: 6 col_start: 8 - col_stop: 8 + col_stop: 2 path: "" - content: "import test-import.( // local import\n ...\n foo," + content: "import test-import.( // local import\n ...\n ...\n);" - package_or_packages: Packages: name: "{\"name\":\"bar\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":8,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"import bar.( // imports directory import\\\"}\"}" @@ -84,7 +84,7 @@ outputs: line_start: 10 line_stop: 10 col_start: 5 - col_stop: 21 + col_stop: 22 path: "" content: " baz.(Baz, Bazzar)," - SubPackage: @@ -119,18 +119,18 @@ outputs: content: " bat.bat.Bat," span: line_start: 8 - line_stop: 11 + line_stop: 12 col_start: 8 - col_stop: 16 + col_stop: 2 path: "" - content: "import bar.( // imports directory import\n ...\n ...\n bat.bat.Bat," + content: "import bar.( // imports directory import\n ...\n ...\n ...\n);" span: line_start: 8 - line_stop: 11 + line_stop: 12 col_start: 8 - col_stop: 16 + col_stop: 2 path: "" - content: "import bar.( // imports directory import\n ...\n ...\n bat.bat.Bat," + content: "import bar.( // imports directory import\n ...\n ...\n ...\n);" imports: {} aliases: {} circuits: {} From 056905c5d0688a07af1a433468def71118a530fb Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 1 Feb 2022 11:23:36 -0800 Subject: [PATCH 14/14] apply suggestions from @acoglio --- ast/src/common/array_dimensions.rs | 2 +- ast/src/expression/array_init.rs | 2 +- ast/src/expression/binary.rs | 4 ++-- ast/src/expression/unary.rs | 8 ++++---- ast/src/expression/value.rs | 4 ++-- ast/src/functions/function.rs | 2 +- ast/src/groups/group_coordinate.rs | 2 +- ast/src/groups/group_value.rs | 6 +++--- ast/src/program.rs | 2 +- ast/src/statements/assign/mod.rs | 8 ++++---- ast/src/types/type_.rs | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ast/src/common/array_dimensions.rs b/ast/src/common/array_dimensions.rs index 811c862225..261b78df3a 100644 --- a/ast/src/common/array_dimensions.rs +++ b/ast/src/common/array_dimensions.rs @@ -67,7 +67,7 @@ impl Deref for ArrayDimensions { } impl ArrayDimensions { - /// Construct a single-dimensional array-dimension. + /// Returns a single-dimensional array dimension. pub fn single(dim: Dimension) -> Self { Self(smallvec![dim]) } diff --git a/ast/src/expression/array_init.rs b/ast/src/expression/array_init.rs index 5437757e51..357559ff8b 100644 --- a/ast/src/expression/array_init.rs +++ b/ast/src/expression/array_init.rs @@ -25,7 +25,7 @@ pub struct ArrayInitExpression { /// The dimensions of the array. /// /// This could be a multi-dimensional array, - /// e.g., `[42; (2, 2)]`, giving you a matrix `[[2, 2], [2, 2]]`. + /// e.g., `[42; (2, 2)]`, giving you a matrix `[[42, 42], [42, 42]]`. pub dimensions: ArrayDimensions, /// The span of the entire expression from `[` to `]`. pub span: Span, diff --git a/ast/src/expression/binary.rs b/ast/src/expression/binary.rs index 0a829fe193..5be8b12901 100644 --- a/ast/src/expression/binary.rs +++ b/ast/src/expression/binary.rs @@ -47,11 +47,11 @@ pub enum BinaryOperation { Le, /// Lesser-than relation, i.e. `<`. Lt, - /// Bitwise-or, i.e., `|`. + /// Bitwise-or inclusive, i.e., `|`. BitOr, /// Bitwise-and, i.e., `&`. BitAnd, - /// Bitwise-or, i.e., `^`. + /// Bitwise-or exclusive, i.e., `^`. BitXor, /// Shift-right, i.e `>>`. Shr, diff --git a/ast/src/expression/unary.rs b/ast/src/expression/unary.rs index 7b3193529b..4f52cc0d19 100644 --- a/ast/src/expression/unary.rs +++ b/ast/src/expression/unary.rs @@ -16,15 +16,15 @@ use super::*; -/// The unary operator for an unary expression. +/// A unary operator for a unary expression. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UnaryOperation { - /// The logical not operator, i.e., `!`. + /// The logical negation operator, i.e., `!`. /// For example, it transforms `true` to `false`. Not, - /// The negation operator, i.e., `-`. + /// The arithmetic negation operator, i.e., `-`. Negate, - /// The bitwise not operator, i.e., `~`. + /// The bitwise negation operator, i.e., `~`. /// For example, it transforms `1010` to `0101`. BitNot, } diff --git a/ast/src/expression/value.rs b/ast/src/expression/value.rs index 89c5960779..ccda457d4a 100644 --- a/ast/src/expression/value.rs +++ b/ast/src/expression/value.rs @@ -36,12 +36,12 @@ pub enum ValueExpression { /// A char literal, e.g., `'a'`, representing a single unicode code point. Char(CharValue), /// A field literal, e.g., `42field`. - /// That is, an unsigned number followed by the keyword `field`. + /// That is, a signed number followed by the keyword `field`. Field( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), - /// A group literal, either single or tuple. + /// A group literal, either product or affine. /// For example, `42group` or `(12, 52)group`. Group(Box), /// A negated non-integer literal, e.g., `-4.2`. diff --git a/ast/src/functions/function.rs b/ast/src/functions/function.rs index 3dac34440c..11b5686367 100644 --- a/ast/src/functions/function.rs +++ b/ast/src/functions/function.rs @@ -31,7 +31,7 @@ pub struct Function { pub identifier: Identifier, /// The function's parameters. pub input: Vec, - /// WHether the function is `const`. + /// The function returns a constant value. pub const_: bool, /// The function return type, if explicitly specified, or `()` if not. pub output: Option, diff --git a/ast/src/groups/group_coordinate.rs b/ast/src/groups/group_coordinate.rs index 4187daed19..a19c88c269 100644 --- a/ast/src/groups/group_coordinate.rs +++ b/ast/src/groups/group_coordinate.rs @@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; use tendril::StrTendril; -/// A coordinate in a tuple group literal. +/// A coordinate in a affine group literal. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GroupCoordinate { /// A number, e.g., `42`. diff --git a/ast/src/groups/group_value.rs b/ast/src/groups/group_value.rs index 22ec31757d..74e9a34779 100644 --- a/ast/src/groups/group_value.rs +++ b/ast/src/groups/group_value.rs @@ -27,12 +27,12 @@ use tendril::StrTendril; /// A group literal. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GroupValue { - /// Single group literal, e.g., `42group`. + /// Product group literal, e.g., `42group`. Single( #[serde(with = "leo_span::tendril_json")] StrTendril, #[serde(with = "leo_span::span_json")] Span, ), - /// A tuple group literal with (x, y) coordinates. + /// An affine group literal with (x, y) coordinates. Tuple(GroupTuple), } @@ -72,7 +72,7 @@ impl fmt::Display for GroupValue { } } -/// A group tuple literal, e.g., `(42, 24)group`. +/// An affine group literal, e.g., `(42, 24)group`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct GroupTuple { /// The left component of the type, e.g., `42` in the case above. diff --git a/ast/src/program.rs b/ast/src/program.rs index 0ea6c27179..40ef1e0d00 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -31,7 +31,7 @@ pub struct Program { /// The name of the program. /// Empty after parsing. pub name: String, - /// Expected function inputs. + /// Expected main function inputs. /// Empty after parsing. pub expected_input: Vec, /// The collected import statements. diff --git a/ast/src/statements/assign/mod.rs b/ast/src/statements/assign/mod.rs index 839b894116..fed8398c28 100644 --- a/ast/src/statements/assign/mod.rs +++ b/ast/src/statements/assign/mod.rs @@ -29,15 +29,15 @@ pub use assignee::*; pub enum AssignOperation { /// Plain assignment, `=`. Assign, - /// Add-assignment, `+=`. + /// Adding assignment, `+=`. Add, /// Subtracting assignment, `-=`. Sub, - /// Multiplicating assignment, `*=`. + /// Multiplying assignment, `*=`. Mul, - /// Divising-assignment, `/=`. + /// Dividing-assignment, `/=`. Div, - /// Exponentating assignment `**=`. + /// Exponentiating assignment `**=`. Pow, /// Logical or assignment. Or, diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index eb694ac39d..b1fcf01ba2 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -28,13 +28,13 @@ pub enum Type { // Data types /// The `address` type. Address, - /// The boolean `bool` type. + /// The `bool` type. Boolean, /// The `char` type. Char, /// The `field` type. Field, - /// The `group` type for expressions like `(42, 24)group`. + /// The `group` type. Group, /// An integer type. IntegerType(IntegerType),