add main, record, registers, state, state_leaf section headers to pest

This commit is contained in:
collin 2020-07-27 15:06:36 -07:00
parent 08f33eda01
commit 5ae8d550e5
8 changed files with 103 additions and 7 deletions

View File

@ -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

View File

@ -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>),
}

View File

@ -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>,
}

View File

@ -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::*;

View File

@ -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>,
}

View File

@ -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>,
}

View File

@ -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>,
}

View File

@ -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>,
}