mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Rename function components
This commit is contained in:
parent
a380d83c75
commit
54b531c27f
@ -1,4 +1,4 @@
|
||||
use crate::{ast::Rule, common::EOI, functions::{Function, Test}, imports::Import, circuits::Circuit};
|
||||
use crate::{ast::Rule, common::EOI, functions::{Function, TestFunction}, imports::Import, circuits::Circuit};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -9,7 +9,7 @@ pub struct File<'ast> {
|
||||
pub imports: Vec<Import<'ast>>,
|
||||
pub circuits: Vec<Circuit<'ast>>,
|
||||
pub functions: Vec<Function<'ast>>,
|
||||
pub tests: Vec<Test<'ast>>,
|
||||
pub tests: Vec<TestFunction<'ast>>,
|
||||
pub eoi: EOI,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ast::Rule, common::Identifier, functions::InputModel, statements::Statement, types::Type};
|
||||
use crate::{ast::Rule, common::Identifier, functions::FunctionInput, statements::Statement, types::Type};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -7,7 +7,7 @@ use pest_ast::FromPest;
|
||||
#[pest_ast(rule(Rule::function_definition))]
|
||||
pub struct Function<'ast> {
|
||||
pub function_name: Identifier<'ast>,
|
||||
pub parameters: Vec<InputModel<'ast>>,
|
||||
pub parameters: Vec<FunctionInput<'ast>>,
|
||||
pub returns: Vec<Type<'ast>>,
|
||||
pub statements: Vec<Statement<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
|
@ -4,8 +4,8 @@ use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::input_model))]
|
||||
pub struct InputModel<'ast> {
|
||||
#[pest_ast(rule(Rule::function_input))]
|
||||
pub struct FunctionInput<'ast> {
|
||||
pub mutable: Option<Mutable>,
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub visibility: Option<Visibility>,
|
||||
|
@ -4,8 +4,8 @@ use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::test))]
|
||||
pub struct Test<'ast> {
|
||||
#[pest_ast(rule(Rule::test_function))]
|
||||
pub struct TestFunction<'ast> {
|
||||
pub function: Function<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -4,12 +4,15 @@
|
||||
assignee = { identifier ~ access_assignee* }
|
||||
|
||||
// Declared in common/file.rs
|
||||
file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ circuit_definition* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ test* ~ NEWLINE* ~ EOI }
|
||||
file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ circuit_definition* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ test_function* ~ NEWLINE* ~ EOI }
|
||||
|
||||
// Declared in common/identifier.rs
|
||||
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
protected_name = { visibility | "let" | "for"| "if" | "else" | "as" | "return" }
|
||||
|
||||
// Declared in common/line_end.rs
|
||||
LINE_END = { ";" ~ NEWLINE* }
|
||||
|
||||
// Declared in common/mutable.rs
|
||||
mutable = { "mut" }
|
||||
|
||||
@ -268,10 +271,15 @@ statement_return = { "return" ~ expression_tuple }
|
||||
|
||||
/// Functions
|
||||
|
||||
function_definition = {"function" ~ identifier ~ "(" ~ input_model_list ~ ")" ~ ("->" ~ (type_ | "(" ~ type_list ~ ")"))? ~ "{" ~ NEWLINE* ~ statement* ~ NEWLINE* ~ "}" ~ NEWLINE* }
|
||||
// Declared in functions/function.rs
|
||||
function_definition = { "function" ~ identifier ~ "(" ~ input_model_list ~ ")" ~ ("->" ~ (type_ | "(" ~ type_list ~ ")"))? ~ "{" ~ NEWLINE* ~ statement* ~ NEWLINE* ~ "}" ~ NEWLINE* }
|
||||
|
||||
input_model = {mutable? ~ identifier ~ ":" ~ visibility? ~ type_}
|
||||
input_model_list = _{(input_model ~ ("," ~ input_model)*)?}
|
||||
// Declared in functions/function_input.rs
|
||||
function_input = { mutable? ~ identifier ~ ":" ~ visibility? ~ type_ }
|
||||
input_model_list = _{ (function_input ~ ("," ~ function_input)*)? }
|
||||
|
||||
// Declared in functions/test_function.rs
|
||||
test_function = { "test" ~ function_definition }
|
||||
|
||||
/// Imports
|
||||
|
||||
@ -279,7 +287,7 @@ input_model_list = _{(input_model ~ ("," ~ input_model)*)?}
|
||||
import = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ ("*" | ("{" ~ NEWLINE* ~ import_symbol_tuple ~ NEWLINE* ~ "}") | import_symbol) ~ LINE_END}
|
||||
|
||||
// Declared in imports/import_source.rs
|
||||
import_source = @{(!"\"" ~ ANY)*}
|
||||
import_source = @{ (!"\"" ~ ANY)* }
|
||||
|
||||
// Declared in imports/import_symbol.rs
|
||||
import_symbol = { identifier ~ ("as" ~ identifier)? }
|
||||
@ -289,8 +297,3 @@ import_symbol_tuple = _{ import_symbol ~ ("," ~ NEWLINE* ~ import_symbol)* }
|
||||
|
||||
COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) }
|
||||
WHITESPACE = _{ " " | "\t" ~ (NEWLINE)* }
|
||||
LINE_END = {";" ~ NEWLINE*}
|
||||
|
||||
/// Tests
|
||||
|
||||
test = { "test" ~ function_definition }
|
||||
|
@ -35,8 +35,8 @@ use leo_ast::{
|
||||
},
|
||||
functions::{
|
||||
Function,
|
||||
InputModel,
|
||||
Test
|
||||
FunctionInput,
|
||||
TestFunction
|
||||
},
|
||||
imports::{
|
||||
Import as AstImport,
|
||||
@ -794,8 +794,8 @@ impl<'ast> From<Circuit<'ast>> for types::Circuit {
|
||||
|
||||
/// pest ast -> function types::Parameters
|
||||
|
||||
impl<'ast> From<InputModel<'ast>> for types::InputModel {
|
||||
fn from(parameter: InputModel<'ast>) -> Self {
|
||||
impl<'ast> From<FunctionInput<'ast>> for types::InputModel {
|
||||
fn from(parameter: FunctionInput<'ast>) -> Self {
|
||||
types::InputModel {
|
||||
identifier: types::Identifier::from(parameter.identifier),
|
||||
mutable: parameter.mutable.is_some(),
|
||||
@ -863,8 +863,8 @@ impl<'ast> From<AstImport<'ast>> for Import {
|
||||
}
|
||||
|
||||
/// pest ast -> Test
|
||||
impl<'ast> From<Test<'ast>> for types::Test {
|
||||
fn from(test: Test) -> Self {
|
||||
impl<'ast> From<TestFunction<'ast>> for types::Test {
|
||||
fn from(test: TestFunction) -> Self {
|
||||
types::Test(types::Function::from(test.function))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user