update leo-inputs ast

This commit is contained in:
collin 2020-06-08 12:00:27 -07:00
parent e10a1e1be0
commit 08e6eb145c
6 changed files with 209 additions and 340 deletions

View File

@ -1,4 +1,4 @@
[main] [main]
a: private u32 = 5 a: private u32 = 5;
b: public fe = 1fe b: public field = 1field;
c: private bool = true c: private bool = true;

View File

@ -34,39 +34,31 @@ pub enum Visibility {
// Types // Types
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u32))]
pub struct U32Type<'ast> {
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_field))] #[pest_ast(rule(Rule::type_field))]
pub struct FieldType<'ast> { pub struct FieldType {}
#[pest_ast(outer())]
pub span: Span<'ast>, #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_group))]
pub struct GroupType {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_boolean))]
pub struct BooleanType {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_data))]
pub enum DataType {
Integer(IntegerType),
Field(FieldType),
Group(GroupType),
Boolean(BooleanType),
} }
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_bool))] #[pest_ast(rule(Rule::type_circuit))]
pub struct BooleanType<'ast> { pub struct CircuitType<'ast> {
#[pest_ast(outer())] pub variable: Identifier<'ast>,
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_basic))]
pub enum BasicType<'ast> {
U32(U32Type<'ast>),
Field(FieldType<'ast>),
Boolean(BooleanType<'ast>),
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_struct))]
pub struct StructType<'ast> {
pub variable: Variable<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -74,8 +66,8 @@ pub struct StructType<'ast> {
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_array))] #[pest_ast(rule(Rule::type_array))]
pub struct ArrayType<'ast> { pub struct ArrayType<'ast> {
pub _type: BasicType<'ast>, pub _type: DataType,
pub count: Value<'ast>, pub dimensions: Vec<Value<'ast>>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -83,62 +75,125 @@ pub struct ArrayType<'ast> {
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::_type))] #[pest_ast(rule(Rule::_type))]
pub enum Type<'ast> { pub enum Type<'ast> {
Basic(BasicType<'ast>), Data(DataType),
Array(ArrayType<'ast>), Array(ArrayType<'ast>),
Struct(StructType<'ast>), Circuit(CircuitType<'ast>),
} }
// Values // Values
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_number))] #[pest_ast(rule(Rule::value_number))]
pub struct Number<'ast> { pub struct NumberValue<'ast> {
#[pest_ast(outer(with(span_into_string)))] #[pest_ast(outer(with(span_into_string)))]
pub value: String, pub value: String,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_u32))]
pub struct U32<'ast> {
pub number: Number<'ast>,
pub _type: Option<U32Type<'ast>>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_field))] #[pest_ast(rule(Rule::value_field))]
pub struct Field<'ast> { pub struct FieldValue<'ast> {
pub number: Number<'ast>, pub number: NumberValue<'ast>,
pub _type: FieldType<'ast>, pub _type: FieldType,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_group))]
pub struct GroupValue<'ast> {
pub value: GroupRepresentation<'ast>,
pub _type: GroupType,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::group_single_or_tuple))]
pub enum GroupRepresentation<'ast> {
Single(NumberValue<'ast>),
Tuple(GroupTuple<'ast>),
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::group_tuple))]
pub struct GroupTuple<'ast> {
pub x: NumberValue<'ast>,
pub y: NumberValue<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_boolean))] #[pest_ast(rule(Rule::value_boolean))]
pub struct Boolean<'ast> { pub struct BooleanValue<'ast> {
#[pest_ast(outer(with(span_into_string)))] #[pest_ast(outer(with(span_into_string)))]
pub value: String, pub value: String,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_integer))]
pub enum IntegerType {
U8Type(U8Type),
U16Type(U16Type),
U32Type(U32Type),
U64Type(U64Type),
U128Type(U128Type),
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u8))]
pub struct U8Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u16))]
pub struct U16Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u32))]
pub struct U32Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u64))]
pub struct U64Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::type_u128))]
pub struct U128Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_integer))]
pub struct IntegerValue<'ast> {
pub number: NumberValue<'ast>,
pub _type: IntegerType,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value_implicit))]
pub struct NumberImplicitValue<'ast> {
pub number: NumberValue<'ast>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::value))] #[pest_ast(rule(Rule::value))]
pub enum Value<'ast> { pub enum Value<'ast> {
Field(Field<'ast>), Integer(IntegerValue<'ast>),
Boolean(Boolean<'ast>), Field(FieldValue<'ast>),
U32(U32<'ast>), Group(GroupValue<'ast>),
Boolean(BooleanValue<'ast>),
Implicit(NumberImplicitValue<'ast>),
} }
// Identifier
// Variables
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::variable))] #[pest_ast(rule(Rule::identifier))]
pub struct Variable<'ast> { pub struct Identifier<'ast> {
#[pest_ast(outer(with(span_into_string)))] #[pest_ast(outer(with(span_into_string)))]
pub value: String, pub value: String,
#[pest_ast(outer())] #[pest_ast(outer())]
@ -164,22 +219,22 @@ pub struct ArrayInitializerExpression<'ast> {
pub span: Span<'ast>, pub span: Span<'ast>,
} }
// Structs // Circuits
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::inline_struct_member))] #[pest_ast(rule(Rule::circuit_field))]
pub struct InlineStructMember<'ast> { pub struct CircuitField<'ast> {
pub variable: Variable<'ast>, pub variable: Identifier<'ast>,
pub expression: Expression<'ast>, pub expression: Expression<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::expression_inline_struct))] #[pest_ast(rule(Rule::expression_circuit_inline))]
pub struct StructInlineExpression<'ast> { pub struct CircuitInlineExpression<'ast> {
pub variable: Variable<'ast>, pub variable: Identifier<'ast>,
pub members: Vec<InlineStructMember<'ast>>, pub members: Vec<CircuitField<'ast>>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -189,53 +244,27 @@ pub struct StructInlineExpression<'ast> {
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::expression))] #[pest_ast(rule(Rule::expression))]
pub enum Expression<'ast> { pub enum Expression<'ast> {
StructInline(StructInlineExpression<'ast>), CircuitInline(CircuitInlineExpression<'ast>),
ArrayInline(ArrayInlineExpression<'ast>), ArrayInline(ArrayInlineExpression<'ast>),
ArrayInitializer(ArrayInitializerExpression<'ast>), ArrayInitializer(ArrayInitializerExpression<'ast>),
Value(Value<'ast>), Value(Value<'ast>),
Variable(Variable<'ast>), Variable(Identifier<'ast>),
} }
// Functions // Parameters
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::parameter))] #[pest_ast(rule(Rule::parameter))]
pub struct Parameter<'ast> { pub struct Parameter<'ast> {
pub variable: Variable<'ast>, pub variable: Identifier<'ast>,
pub visibility: Option<Visibility>, pub visibility: Option<Visibility>,
pub _type: Type<'ast>, pub _type: Type<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::function_name))]
pub struct FunctionName<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
// Sections // Sections
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::header))]
pub struct Header<'ast> {
pub function_name: FunctionName<'ast>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::assignment))]
pub struct Assignment<'ast> {
pub parameter: Parameter<'ast>,
pub expression: Expression<'ast>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::section))] #[pest_ast(rule(Rule::section))]
pub struct Section<'ast> { pub struct Section<'ast> {
@ -245,12 +274,34 @@ pub struct Section<'ast> {
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[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>,
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::assignment))]
pub struct Assignment<'ast> {
pub parameter: Parameter<'ast>,
pub expression: Expression<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
// Utilities // Utilities
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::EOI))] #[pest_ast(rule(Rule::EOI))]
pub struct EOI; pub struct EOI;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::LINE_END))]
pub struct LineEnd;
// File // File
#[derive(Clone, Debug, FromPest, PartialEq)] #[derive(Clone, Debug, FromPest, PartialEq)]

View File

@ -1,204 +0,0 @@
//! Display implementations for a Leo inputs file
use crate::inputs_ast::{
ArrayInitializerExpression, ArrayInlineExpression, ArrayType, Assignment, BasicType, Boolean,
BooleanType, Expression, Field, FieldType, File, Number, Parameter, Private, Section,
StructInlineExpression, StructType, Type, U32Type, Value, Variable, Visibility, U32,
};
use std::fmt;
// Visibility
impl fmt::Display for Visibility {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Visibility::Private(_private) => write!(f, "private"),
Visibility::Public(_public) => write!(f, "public"),
}
}
}
// Types
impl<'ast> fmt::Display for BooleanType<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "bool")
}
}
impl<'ast> fmt::Display for FieldType<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "fe")
}
}
impl<'ast> fmt::Display for U32Type<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "u32")
}
}
impl<'ast> fmt::Display for BasicType<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
BasicType::Boolean(bool) => write!(f, "{}", bool),
BasicType::Field(field) => write!(f, "{}", field),
BasicType::U32(u32) => write!(f, "{}", u32),
}
}
}
impl<'ast> fmt::Display for ArrayType<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}; {}]", self._type, self.count)
}
}
impl<'ast> fmt::Display for StructType<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.variable)
}
}
impl<'ast> fmt::Display for Type<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Type::Basic(ref _type) => write!(f, "{}", _type),
Type::Array(ref _type) => write!(f, "{}", _type),
Type::Struct(ref _type) => write!(f, "{}", _type),
}
}
}
// Values
impl<'ast> fmt::Display for Number<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value)
}
}
impl<'ast> fmt::Display for U32<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.number)
}
}
impl<'ast> fmt::Display for Field<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.number)
}
}
impl<'ast> fmt::Display for Boolean<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value)
}
}
impl<'ast> fmt::Display for Value<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Value::U32(ref value) => write!(f, "{}", value),
Value::Field(ref value) => write!(f, "{}", value),
Value::Boolean(ref value) => write!(f, "{}", value),
}
}
}
// Variables
impl<'ast> fmt::Display for Variable<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value)
}
}
// Expressions
impl<'ast> fmt::Display for StructInlineExpression<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {{", self.variable)?;
for (i, member) in self.members.iter().enumerate() {
write!(f, "{}: {}", member.variable, member.expression)?;
if i < self.members.len() - 1 {
write!(f, ", ")?;
}
}
write!(f, "}}")
}
}
impl<'ast> fmt::Display for ArrayInlineExpression<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[")?;
for (i, expression) in self.expressions.iter().enumerate() {
write!(f, "{}", expression)?;
if i < self.expressions.len() - 1 {
write!(f, ", ")?;
}
}
write!(f, "]")
}
}
impl<'ast> fmt::Display for ArrayInitializerExpression<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{} ; {}]", self.expression, self.count)
}
}
impl<'ast> fmt::Display for Expression<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::StructInline(_struct) => write!(f, "{}", _struct),
Expression::ArrayInline(array) => write!(f, "{}", array),
Expression::ArrayInitializer(array) => write!(f, "{}", array),
Expression::Value(value) => write!(f, "{}", value),
Expression::Variable(variable) => write!(f, "{}", variable),
}
}
}
// Sections
impl<'ast> fmt::Display for Parameter<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}: {} {}",
self.variable,
self.visibility
.as_ref()
.unwrap_or(&Visibility::Private(Private {})), // private by default
self._type
)
}
}
impl<'ast> fmt::Display for Assignment<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} = {}", self.parameter, self.expression)
}
}
impl<'ast> fmt::Display for Section<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{}]\n", self.header.function_name.value)?;
for assignment in self.assignments.iter() {
write!(f, "\t{}\n", assignment)?;
}
write!(f, "")
}
}
// File
impl<'ast> fmt::Display for File<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for value in self.sections.iter() {
write!(f, "{}", value)?;
}
write!(f, "")
}
}

View File

@ -1,73 +1,97 @@
/// Visibility /// Common
file = { SOI ~ NEWLINE* ~ section* ~ NEWLINE* ~ EOI }
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
protected_name = { visibility | "let" | "for"| "if" | "else" | "as" | "return" }
LINE_END = { ";" ~ NEWLINE* }
visibility = { visibility_public | visibility_private }
visibility_public = { "public" } visibility_public = { "public" }
visibility_private = { "private" } visibility_private = { "private" }
visibility = { visibility_public | visibility_private }
/// Types /// Types
type_u32 = {"u32"} _type = { type_array | type_data | type_circuit }
type_field = {"fe"} type_integer = {
type_bool = {"bool"} type_u8
type_basic = { type_u32 | type_field | type_bool } | type_u16
type_struct = { variable } | type_u32
type_array = {type_basic ~ ("[" ~ value ~ "]")+ } | type_u64
_type = { type_array | type_basic | type_struct } | type_u128
}
type_u8 = { "u8" }
type_u16 = { "u16" }
type_u32 = { "u32" }
type_u64 = { "u64" }
type_u128 = { "u128" }
type_field = { "field" }
type_group = { "group" }
type_boolean = { "bool" }
type_data = { type_field | type_group | type_boolean | type_integer }
type_circuit = { identifier }
type_array = { type_data ~ ("[" ~ value ~ "]")+ }
/// Values /// Values
value = { value_field | value_group | value_boolean | value_integer | value_implicit }
value_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } value_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* }
value_u32 = { value_number ~ type_u32? }
value_field = { value_number ~ type_field } value_implicit = { value_number }
value_integer = { value_number ~ type_integer }
value_boolean = { "true" | "false" } value_boolean = { "true" | "false" }
value = { value_field | value_boolean | value_u32 }
/// Variables value_field = { value_number ~ type_field }
protected_name = { visibility | "return" } value_group = { group_single_or_tuple ~ type_group }
variable = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* } group_tuple = { "(" ~ NEWLINE* ~ value_number ~ "," ~ NEWLINE* ~ value_number ~ NEWLINE* ~")" }
group_single_or_tuple = { value_number | group_tuple }
/// Arrays
inline_array_inner = _{(expression ~ ("," ~ NEWLINE* ~ expression)*)?}
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
expression_array_initializer = { "[" ~ expression ~ ";" ~ value ~ "]" }
/// Structs
inline_struct_member = { variable ~ ":" ~ expression }
inline_struct_member_list = _{(inline_struct_member ~ ("," ~ NEWLINE* ~ inline_struct_member)*)? ~ ","? }
expression_inline_struct = { variable ~ "{" ~ NEWLINE* ~ inline_struct_member_list ~ NEWLINE* ~ "}" }
/// Expressions /// Expressions
expression_array_initializer = { "[" ~ expression ~ ";" ~ value ~ "]" }
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
inline_array_inner = _{ (expression ~ ("," ~ NEWLINE* ~ expression)*)? }
expression_circuit_inline = { identifier ~ "{" ~ NEWLINE* ~ circuit_field_list ~ NEWLINE* ~ "}" }
circuit_field = { identifier ~ ":" ~ expression }
circuit_field_list = _{ (circuit_field ~ ("," ~ NEWLINE* ~ circuit_field)*)? ~ ","? }
expression = { expression = {
expression_inline_struct expression_circuit_inline
| expression_array_inline | expression_array_inline
| expression_array_initializer | expression_array_initializer
| value | value
| variable | identifier
} }
/// Functions /// Parameters
parameter = { variable ~ ":" ~ visibility? ~ _type } parameter = { identifier ~ ":" ~ visibility? ~ _type }
function_name = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
/// Section /// Section
header = { "[" ~ function_name ~ "]" }
assignment = { parameter ~ "=" ~ expression }
// assignment = { parameter ~ "=" }
section = { header ~ NEWLINE+ ~ (assignment ~ NEWLINE*)* } section = { header ~ NEWLINE+ ~ (assignment ~ NEWLINE*)* }
header = { "[" ~ identifier ~ "]" }
assignment = { parameter ~ "=" ~ NEWLINE* ~ expression ~ LINE_END }
/// Utilities /// Utilities
COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) } COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) }
WHITESPACE = _{ " " | "\t" ~ (NEWLINE)* } WHITESPACE = _{ " " | "\t" ~ (NEWLINE)* }
/// Program File
file = { SOI ~ NEWLINE* ~ section* ~ NEWLINE* ~ EOI }

View File

@ -6,5 +6,3 @@ extern crate pest_ast;
extern crate pest_derive; extern crate pest_derive;
pub mod inputs_ast; pub mod inputs_ast;
pub(crate) mod inputs_display;

View File

@ -13,5 +13,5 @@ fn main() {
// Build the abstract syntax tree // Build the abstract syntax tree
let syntax_tree = inputs_ast::File::from_pest(&mut file).expect("infallible"); let syntax_tree = inputs_ast::File::from_pest(&mut file).expect("infallible");
println!("tree: {}", syntax_tree); println!("tree: {:?}", syntax_tree);
} }