mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-29 03:35:10 +03:00
circuit grammar tests
This commit is contained in:
parent
c59ff6d107
commit
6082fc9bf3
41
ast/src/circuits/circuit_implied_variable_definition.rs
Normal file
41
ast/src/circuits/circuit_implied_variable_definition.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2019-2020 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Expression, Identifier};
|
||||
use leo_grammar::circuits::CircuitImpliedVariable;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CircuitImpliedVariableDefinition {
|
||||
pub identifier: Identifier,
|
||||
pub expression: Option<Expression>,
|
||||
}
|
||||
|
||||
impl<'ast> From<CircuitImpliedVariable<'ast>> for CircuitImpliedVariableDefinition {
|
||||
fn from(member: CircuitImpliedVariable<'ast>) -> Self {
|
||||
match member {
|
||||
CircuitImpliedVariable::CircuitVariable(circuit_variable) => Self {
|
||||
identifier: Identifier::from(circuit_variable.identifier),
|
||||
expression: Some(Expression::from(circuit_variable.expression)),
|
||||
},
|
||||
CircuitImpliedVariable::Identifier(identifier) => Self {
|
||||
identifier: Identifier::from(identifier),
|
||||
expression: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Expression, Identifier};
|
||||
use leo_grammar::circuits::{CircuitImpliedVariable, CircuitVariable};
|
||||
use leo_grammar::circuits::CircuitVariable;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -33,24 +33,3 @@ impl<'ast> From<CircuitVariable<'ast>> for CircuitVariableDefinition {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CircuitImpliedVariableDefinition {
|
||||
pub identifier: Identifier,
|
||||
pub expression: Option<Expression>,
|
||||
}
|
||||
|
||||
impl<'ast> From<CircuitImpliedVariable<'ast>> for CircuitImpliedVariableDefinition {
|
||||
fn from(member: CircuitImpliedVariable<'ast>) -> Self {
|
||||
match member {
|
||||
CircuitImpliedVariable::CircuitVariable(circuit_variable) => Self {
|
||||
identifier: Identifier::from(circuit_variable.identifier),
|
||||
expression: Some(Expression::from(circuit_variable.expression)),
|
||||
},
|
||||
CircuitImpliedVariable::Identifier(identifier) => Self {
|
||||
identifier: Identifier::from(identifier),
|
||||
expression: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,8 @@ pub use circuit::*;
|
||||
pub mod circuit_variable_definition;
|
||||
pub use circuit_variable_definition::*;
|
||||
|
||||
pub mod circuit_implied_variable_definition;
|
||||
pub use circuit_implied_variable_definition::*;
|
||||
|
||||
pub mod circuit_member;
|
||||
pub use circuit_member::*;
|
||||
|
@ -177,7 +177,6 @@ impl<'ast> fmt::Display for Expression {
|
||||
|
||||
impl<'ast> From<CircuitInlineExpression<'ast>> for Expression {
|
||||
fn from(expression: CircuitInlineExpression<'ast>) -> Self {
|
||||
// println!("from CircuitInlineExpression");
|
||||
let circuit_name = Identifier::from(expression.name);
|
||||
let members = expression
|
||||
.members
|
||||
|
116
grammar/tests/circuits.rs
Normal file
116
grammar/tests/circuits.rs
Normal file
@ -0,0 +1,116 @@
|
||||
// Copyright (C) 2019-2020 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_grammar::ast::{LanguageParser, Rule};
|
||||
|
||||
use pest::*;
|
||||
|
||||
#[test]
|
||||
fn circuit_definition() {
|
||||
parses_to! {
|
||||
parser: LanguageParser,
|
||||
input: "circuit Foo { a: u32, }",
|
||||
rule: Rule::circuit,
|
||||
tokens: [
|
||||
circuit(0, 23, [
|
||||
identifier(8, 11, []),
|
||||
circuit_member(14, 21,
|
||||
[circuit_variable_definition(14, 21, [
|
||||
identifier(14, 15, []),
|
||||
type_(17, 20, [type_data(17, 20, [type_integer(17, 20, [type_integer_unsigned(17, 20, [type_u32(17, 20, [])])])])])
|
||||
])
|
||||
])
|
||||
])
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn circuit_instantiation() {
|
||||
parses_to! {
|
||||
parser: LanguageParser,
|
||||
input: r#"circuit Foo { a: u32, }
|
||||
function main() { let foo = Foo { a, b: 1u32 }; }"#,
|
||||
rule: Rule::file,
|
||||
tokens: [
|
||||
file(0, 77, [
|
||||
definition(0, 23, [
|
||||
circuit(0, 23, [
|
||||
identifier(8, 11, []),
|
||||
circuit_member(14, 21,
|
||||
[circuit_variable_definition(14, 21, [
|
||||
identifier(14, 15, []),
|
||||
type_(17, 20, [type_data(17, 20, [type_integer(17, 20, [type_integer_unsigned(17, 20, [type_u32(17, 20, [])])])])])
|
||||
])
|
||||
])
|
||||
]),
|
||||
]),
|
||||
definition(28, 77, [
|
||||
function(28, 77, [
|
||||
identifier(37, 41, []),
|
||||
block(44, 77, [
|
||||
statement(46, 75, [
|
||||
statement_definition(46, 75, [
|
||||
declare(46, 50, [
|
||||
let_(46, 50, []),
|
||||
]),
|
||||
variables(50, 54, [
|
||||
variable_name(50, 53, [
|
||||
identifier(50, 53, [])
|
||||
])
|
||||
]),
|
||||
expression(56, 74, [
|
||||
expression_term(56, 74, [
|
||||
expression_circuit_inline(56, 74, [
|
||||
circuit_name(56, 59, [
|
||||
identifier(56, 59, [])
|
||||
]),
|
||||
circuit_implied_variable(62, 63, [
|
||||
identifier(62, 63, [])
|
||||
]),
|
||||
circuit_implied_variable(65, 73, [
|
||||
circuit_variable(65, 73, [
|
||||
identifier(65, 66, []),
|
||||
expression(68, 73, [
|
||||
expression_term(68, 72, [
|
||||
value(68, 72, [
|
||||
value_integer(68, 72, [
|
||||
value_integer_unsigned(68, 72, [
|
||||
number_positive(68, 69, []),
|
||||
type_integer_unsigned(69, 72, [
|
||||
type_u32(69, 72, [])
|
||||
])
|
||||
]),
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
LINE_END(74, 75, [])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
EOI(77, 77, [])
|
||||
])
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user