diff --git a/leo-inputs/src/leo-inputs.pest b/leo-inputs/src/leo-inputs.pest index 369451d779..520327f65f 100644 --- a/leo-inputs/src/leo-inputs.pest +++ b/leo-inputs/src/leo-inputs.pest @@ -14,10 +14,15 @@ protected_name = { | "import" | "in" | "let" + | "main" | "mut" | "private" | "public" + | "record" + | "registers" | "return" + | "state" + | "state_leaf" | "static" | "test" | "true" @@ -142,8 +147,23 @@ parameter = { identifier ~ ":" ~ type_ } // Declared in sections/section.rs section = { header ~ NEWLINE+ ~ (assignment ~ NEWLINE*)* } +// Declared in sections/main_.rs +main = { "main" } + +// Declared in sections/record.rs +record = { "record" } + +// Declared in sections/registers.rs +registers = { "registers" } + +// Declared in sections/state.rs +state = { "state" } + +// Declared in sections/state_leaf.rs +state_leaf = { "state_leaf" } + // Declared in sections/header.rs -header = { "[" ~ identifier ~ "]" } +header = { "[" ~ main | record | registers | state | state_leaf | identifier ~ "]" } /// Assignments diff --git a/leo-inputs/src/sections/header.rs b/leo-inputs/src/sections/header.rs index 5ecb08eb14..19ecd53d82 100644 --- a/leo-inputs/src/sections/header.rs +++ b/leo-inputs/src/sections/header.rs @@ -1,12 +1,18 @@ -use crate::{ast::Rule, common::Identifier}; +use crate::{ + ast::Rule, + common::Identifier, + sections::{Main, Record, Registers, State, StateLeaf}, +}; -use pest::Span; use pest_ast::FromPest; #[derive(Clone, Debug, FromPest, PartialEq)] #[pest_ast(rule(Rule::header))] -pub struct Header<'ast> { - pub name: Identifier<'ast>, - #[pest_ast(outer())] - pub span: Span<'ast>, +pub enum Header<'ast> { + Main(Main<'ast>), + Record(Record<'ast>), + Registers(Registers<'ast>), + State(State<'ast>), + StateLeaf(StateLeaf<'ast>), + Identifier(Identifier<'ast>), } diff --git a/leo-inputs/src/sections/main_.rs b/leo-inputs/src/sections/main_.rs new file mode 100644 index 0000000000..9f52418153 --- /dev/null +++ b/leo-inputs/src/sections/main_.rs @@ -0,0 +1,11 @@ +use crate::ast::Rule; + +use pest::Span; +use pest_ast::FromPest; + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::main))] +pub struct Main<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} diff --git a/leo-inputs/src/sections/mod.rs b/leo-inputs/src/sections/mod.rs index ad84b1fade..8fd04e6ba3 100644 --- a/leo-inputs/src/sections/mod.rs +++ b/leo-inputs/src/sections/mod.rs @@ -1,5 +1,20 @@ pub mod header; pub use header::*; +pub mod main_; +pub use main_::*; + +pub mod record; +pub use record::*; + +pub mod registers; +pub use registers::*; + +pub mod state; +pub use state::*; + +pub mod state_leaf; +pub use state_leaf::*; + pub mod section; pub use section::*; diff --git a/leo-inputs/src/sections/record.rs b/leo-inputs/src/sections/record.rs new file mode 100644 index 0000000000..2f67290130 --- /dev/null +++ b/leo-inputs/src/sections/record.rs @@ -0,0 +1,11 @@ +use crate::ast::Rule; + +use pest::Span; +use pest_ast::FromPest; + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::record))] +pub struct Record<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} diff --git a/leo-inputs/src/sections/registers.rs b/leo-inputs/src/sections/registers.rs new file mode 100644 index 0000000000..8e11fde122 --- /dev/null +++ b/leo-inputs/src/sections/registers.rs @@ -0,0 +1,11 @@ +use crate::ast::Rule; + +use pest::Span; +use pest_ast::FromPest; + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::registers))] +pub struct Registers<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} diff --git a/leo-inputs/src/sections/state.rs b/leo-inputs/src/sections/state.rs new file mode 100644 index 0000000000..8063e4f8a9 --- /dev/null +++ b/leo-inputs/src/sections/state.rs @@ -0,0 +1,11 @@ +use crate::ast::Rule; + +use pest::Span; +use pest_ast::FromPest; + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::state))] +pub struct State<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} diff --git a/leo-inputs/src/sections/state_leaf.rs b/leo-inputs/src/sections/state_leaf.rs new file mode 100644 index 0000000000..932203f24c --- /dev/null +++ b/leo-inputs/src/sections/state_leaf.rs @@ -0,0 +1,11 @@ +use crate::ast::Rule; + +use pest::Span; +use pest_ast::FromPest; + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::state_leaf))] +pub struct StateLeaf<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +}