merge master fix conflicts

This commit is contained in:
collin 2020-07-30 18:30:56 -07:00
commit a858b37fe0
102 changed files with 561 additions and 168 deletions

View File

@ -1,2 +1,5 @@
[build]
rustflags = ["-C", "target-cpu=native"]
[net]
git-fetch-with-cli = true

38
.github/ISSUE_TEMPLATE/01_bug_report.md vendored Normal file
View File

@ -0,0 +1,38 @@
---
name: "\U0001F41B Bug report"
about: Create a bug report if something isn't working 🔧
title: "[Bug]"
labels: bug
assignees: ''
---
## 🐛 Describe the Bug
<!-- A clear and concise description of what the bug is. -->
<!-- To report a security issue, please email security@aleo.org. -->
## Steps to Reproduce
#### Code snippet to reproduce
```rust
# Add code here
```
#### Stack trace & error message
```
// Paste the output here
```
## Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
## System information
- <!-- Leo Version -->
- <!-- Rust Version -->
- <!-- Computer OS -->

View File

@ -0,0 +1,34 @@
---
name: "\U0001F680 Feature request"
about: Submit a new feature request 💡
title: "[Feature]"
labels: feature
assignees: ''
---
## 🚀 Describe the Feature
<!-- A clear and concise description of the feature you are requesting -->
## Motivation
**Is the feature request related to a problem? If so, please describe.**
<!-- A clear and concise description of what the problem is.
Please link to any relevant issues or other PRs! -->
**Is this something that currently cannot be done?**
## Solution
<!-- A clear and concise description of what you want to happen. -->
**Are you willing to open a pull request?** (See [CONTRIBUTING](../../CONTRIBUTING.md))
## Alternative Solutions
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
## Relevant Context
<!-- Add any other context or screenshots about the feature request here. -->

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: ❓ Help and Support Discord Channel
url: https://discord.gg/dTw3wk9
about: Please ask and answer questions here. 🏥

2
Cargo.lock generated
View File

@ -570,6 +570,8 @@ dependencies = [
"pest",
"pest-ast",
"pest_derive",
"serde",
"serde_json",
"thiserror",
]

View File

@ -4,6 +4,10 @@ version = "0.1.0"
authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"
[[bin]]
name = "leo_ast"
path = "src/main.rs"
[dependencies]
from-pest = { version = "0.3.1" }
lazy_static = { version = "1.3.0" }
@ -11,4 +15,6 @@ log = { version = "0.4" }
pest = { version = "2.0" }
pest-ast = { version = "0.3.3" }
pest_derive = { version = "2.0" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
thiserror = { version = "1.0" }

View File

@ -1 +1,9 @@
# leo-ast
## Command-line instructions
To generate an AST of the Leo program and save it as a JSON file , run:
```
leo_ast {PATH/TO/INPUT_FILENAME}.leo {PATH/TO/OUTPUT_DIRECTORY (optional)}
```
If no output directory is provided, then the program will store the JSON file in the local working directory.

View File

@ -1,8 +1,9 @@
use crate::{access::*, ast::Rule};
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access))]
pub enum Access<'ast> {
Array(ArrayAccess<'ast>),

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, common::RangeOrExpression};
use crate::{ast::Rule, common::RangeOrExpression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access_array))]
pub struct ArrayAccess<'ast> {
pub expression: RangeOrExpression<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,9 +4,10 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access_assignee))]
pub enum AssigneeAccess<'ast> {
Array(ArrayAccess<'ast>),

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access_call))]
pub struct CallAccess<'ast> {
pub expressions: Vec<Expression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, common::Identifier};
use crate::{ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access_member))]
pub struct MemberAccess<'ast> {
pub identifier: Identifier<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, common::Identifier};
use crate::{ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::access_static_member))]
pub struct StaticMemberAccess<'ast> {
pub identifier: Identifier<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, circuits::CircuitMember, common::Identifier};
use crate::{ast::Rule, circuits::CircuitMember, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::circuit))]
pub struct Circuit<'ast> {
pub identifier: Identifier<'ast>,
pub members: Vec<CircuitMember<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::Identifier, expressions::Expression};
use crate::{ast::Rule, common::Identifier, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::circuit_field))]
pub struct CircuitField<'ast> {
pub identifier: Identifier<'ast>,
pub expression: Expression<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::Identifier, types::Type};
use crate::{ast::Rule, common::Identifier, types::Type, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::circuit_field_definition))]
pub struct CircuitFieldDefinition<'ast> {
pub identifier: Identifier<'ast>,
pub _type: Type<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::Static, functions::Function};
use crate::{ast::Rule, common::Static, functions::Function, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::circuit_function))]
pub struct CircuitFunction<'ast> {
pub _static: Option<Static>,
pub function: Function<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,8 +4,9 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::circuit_member))]
pub enum CircuitMember<'ast> {
CircuitFieldDefinition(CircuitFieldDefinition<'ast>),

View File

@ -1,15 +1,17 @@
use crate::{access::AssigneeAccess, ast::Rule, common::Identifier};
use crate::{access::AssigneeAccess, ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::assignee))]
pub struct Assignee<'ast> {
pub identifier: Identifier<'ast>,
pub accesses: Vec<AssigneeAccess<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,18 +1,19 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::declare))]
pub enum Declare {
Const(Const),
Let(Let),
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::const_))]
pub struct Const {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::let_))]
pub struct Let {}

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::EOI))]
pub struct EOI;

View File

@ -1,15 +1,20 @@
use crate::ast::{span_into_string, Rule};
use crate::{
ast::{span_into_string, Rule},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::identifier))]
pub struct Identifier<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::LINE_END))]
pub struct LineEnd;

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::mutable))]
pub struct Mutable {}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::range))]
pub struct Range<'ast> {
pub from: Option<Expression<'ast>>,
pub to: Option<Expression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, common::Range, expressions::Expression};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::range_or_expression))]
pub enum RangeOrExpression<'ast> {
Range(Range<'ast>),

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, common::ReturnTuple, expressions::Expression};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::return_))]
pub enum Return<'ast> {
Single(Expression<'ast>),

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::return_tuple))]
pub struct ReturnTuple<'ast> {
pub expressions: Vec<Expression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::spread))]
pub struct Spread<'ast> {
pub expression: Expression<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, common::Spread, expressions::Expression};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::spread_or_expression))]
pub enum SpreadOrExpression<'ast> {
Spread(Spread<'ast>),

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::static_))]
pub struct Static {}

View File

@ -2,19 +2,22 @@ use crate::{
ast::Rule,
common::{Identifier, Mutable},
types::Type,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::variable))]
pub struct Variable<'ast> {
pub mutable: Option<Mutable>,
pub identifier: Identifier<'ast>,
pub _type: Option<Type<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -5,9 +5,15 @@ use std::path::PathBuf;
#[derive(Debug, Error)]
pub enum ParserError {
#[error("{}: {}", _0, _1)]
Crate(&'static str, String),
#[error("Cannot read from the provided file path - {:?}", _0)]
FileReadError(PathBuf),
#[error("{}", _0)]
JsonError(#[from] serde_json::error::Error),
#[error("{}", _0)]
SyntaxError(#[from] SyntaxError),
@ -20,3 +26,9 @@ impl From<Error<Rule>> for ParserError {
ParserError::SyntaxError(SyntaxError::from(error))
}
}
impl From<std::io::Error> for ParserError {
fn from(error: std::io::Error) -> Self {
ParserError::Crate("std::io", format!("{}", error))
}
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::SpreadOrExpression, values::Value};
use crate::{ast::Rule, common::SpreadOrExpression, values::Value, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_array_initializer))]
pub struct ArrayInitializerExpression<'ast> {
pub expression: Box<SpreadOrExpression<'ast>>,
pub count: Value<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, common::SpreadOrExpression};
use crate::{ast::Rule, common::SpreadOrExpression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_array_inline))]
pub struct ArrayInlineExpression<'ast> {
pub expressions: Vec<SpreadOrExpression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,11 +1,13 @@
use crate::{expressions::Expression, operations::BinaryOperation};
use crate::{expressions::Expression, operations::BinaryOperation, SpanDef};
use pest::Span;
use serde::Serialize;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct BinaryExpression<'ast> {
pub operation: BinaryOperation,
pub left: Box<Expression<'ast>>,
pub right: Box<Expression<'ast>>,
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, circuits::CircuitField, common::Identifier};
use crate::{ast::Rule, circuits::CircuitField, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_circuit_inline))]
pub struct CircuitInlineExpression<'ast> {
pub identifier: Identifier<'ast>,
pub members: Vec<CircuitField<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::{common::Identifier, expressions::*, operations::BinaryOperation, values::Value};
use pest::Span;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum Expression<'ast> {
Value(Value<'ast>),
Identifier(Identifier<'ast>),

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, expressions::Expression, operations::NotOperation};
use crate::{ast::Rule, expressions::Expression, operations::NotOperation, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_not))]
pub struct NotExpression<'ast> {
pub operation: NotOperation<'ast>,
pub expression: Box<Expression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{access::Access, ast::Rule, common::Identifier};
use crate::{access::Access, ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_postfix))]
pub struct PostfixExpression<'ast> {
pub identifier: Identifier<'ast>,
pub accesses: Vec<Access<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::expression_conditional))]
pub struct TernaryExpression<'ast> {
pub first: Box<Expression<'ast>>,
pub second: Box<Expression<'ast>>,
pub third: Box<Expression<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,12 +4,14 @@ use crate::{
common::EOI,
functions::{Function, TestFunction},
imports::Import,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::file))]
pub struct File<'ast> {
pub imports: Vec<Import<'ast>>,
@ -18,5 +20,6 @@ pub struct File<'ast> {
pub tests: Vec<TestFunction<'ast>>,
pub eoi: EOI,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, common::Identifier, functions::inputs::Input, statements::Statement, types::Type};
use crate::{ast::Rule, common::Identifier, functions::input::Input, statements::Statement, types::Type, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::function_definition))]
pub struct Function<'ast> {
pub function_name: Identifier<'ast>,
@ -11,5 +12,6 @@ pub struct Function<'ast> {
pub returns: Vec<Type<'ast>>,
pub statements: Vec<Statement<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -2,17 +2,20 @@ use crate::{
ast::Rule,
common::{Identifier, Mutable},
types::Type,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::function_input))]
pub struct FunctionInput<'ast> {
pub mutable: Option<Mutable>,
pub identifier: Identifier<'ast>,
pub _type: Type<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,8 +4,9 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::input))]
pub enum Input<'ast> {
FunctionInput(FunctionInput<'ast>),

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::record))]
pub struct Record<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::registers))]
pub struct Registers<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::state))]
pub struct State<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::state_leaf))]
pub struct StateLeaf<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, functions::Function};
use crate::{ast::Rule, functions::Function, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::test_function))]
pub struct TestFunction<'ast> {
pub function: Function<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::LineEnd, imports::Package};
use crate::{ast::Rule, common::LineEnd, imports::Package, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::import))]
pub struct Import<'ast> {
pub package: Package<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::Identifier};
use crate::{ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::import_symbol))]
pub struct ImportSymbol<'ast> {
pub value: Identifier<'ast>,
pub alias: Option<Identifier<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::Identifier, imports::PackageAccess};
use crate::{ast::Rule, common::Identifier, imports::PackageAccess, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::package))]
pub struct Package<'ast> {
pub name: Identifier<'ast>,
pub access: PackageAccess<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,8 +4,9 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::package_access))]
pub enum PackageAccess<'ast> {
Star(Star<'ast>),

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::star))]
pub struct Star<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -5,11 +5,9 @@ extern crate pest_derive;
#[macro_use]
extern crate thiserror;
pub mod errors;
pub use errors::*;
mod ast;
pub mod access;
mod ast;
pub mod circuits;
pub mod common;
pub mod expressions;
@ -22,22 +20,28 @@ pub mod statements;
pub mod types;
pub mod values;
pub mod errors;
pub use errors::*;
pub(crate) mod span;
pub(crate) use span::*;
use from_pest::FromPest;
use std::{fs, path::PathBuf};
pub struct LeoParser;
impl LeoParser {
/// Reads in the given file path into a string.
/// Loads the Leo code as a string from the given file path.
pub fn load_file(file_path: &PathBuf) -> Result<String, ParserError> {
Ok(fs::read_to_string(file_path).map_err(|_| ParserError::FileReadError(file_path.clone()))?)
}
/// Parses the input file and constructs a syntax tree.
pub fn parse_file<'a>(file_path: &'a PathBuf, input_file: &'a str) -> Result<files::File<'a>, ParserError> {
/// Parses the Leo program string and constructs an abstract syntax tree.
pub fn parse_file<'a>(file_path: &'a PathBuf, program_string: &'a str) -> Result<files::File<'a>, ParserError> {
// Parse the file using leo.pest
let mut file =
ast::parse(input_file).map_err(|error| ParserError::from(error.with_path(file_path.to_str().unwrap())))?;
let mut file = ast::parse(program_string)
.map_err(|error| ParserError::from(error.with_path(file_path.to_str().unwrap())))?;
// Build the abstract syntax tree
let syntax_tree = files::File::from_pest(&mut file).map_err(|_| ParserError::SyntaxTreeError)?;
@ -45,4 +49,9 @@ impl LeoParser {
Ok(syntax_tree)
}
/// Serializes a given abstract syntax tree into a JSON string.
pub fn to_json_string(syntax_tree: &files::File) -> Result<String, ParserError> {
Ok(serde_json::to_string_pretty(syntax_tree)?)
}
}

View File

@ -1,16 +1,18 @@
use crate::{ast::Rule, common::LineEnd, expressions::Expression};
use crate::{ast::Rule, common::LineEnd, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::assert_eq))]
pub struct AssertEq<'ast> {
pub left: Expression<'ast>,
pub right: Expression<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::debug))]
pub struct Debug<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::error))]
pub struct Error<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::formatted_container))]
pub struct FormattedContainer<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -2,13 +2,15 @@ use crate::{
ast::Rule,
common::LineEnd,
macros::{FormattedString, MacroName, MacroSymbol},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::formatted_macro))]
pub struct FormattedMacro<'ast> {
pub name: MacroName<'ast>,
@ -16,6 +18,7 @@ pub struct FormattedMacro<'ast> {
pub string: Option<FormattedString<'ast>>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, expressions::Expression};
use crate::{ast::Rule, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::formatted_parameter))]
pub struct FormattedParameter<'ast> {
pub expression: Expression<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{
ast::{span_into_string, Rule},
macros::{FormattedContainer, FormattedParameter},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::formatted_string))]
pub struct FormattedString<'ast> {
#[pest_ast(outer(with(span_into_string)))]
@ -15,6 +17,7 @@ pub struct FormattedString<'ast> {
pub containers: Vec<FormattedContainer<'ast>>,
pub parameters: Vec<FormattedParameter<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,9 +4,10 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::macro_name))]
pub enum MacroName<'ast> {
Debug(Debug<'ast>),

View File

@ -1,9 +1,10 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::macro_symbol))]
pub struct MacroSymbol {}

View File

@ -1,13 +1,15 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::print))]
pub struct Print<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

52
ast/src/main.rs Normal file
View File

@ -0,0 +1,52 @@
use leo_ast::{LeoParser, ParserError};
use std::{env, fs, path::Path};
fn to_leo_ast(filepath: &Path) -> Result<String, ParserError> {
// Loads the Leo code as a string from the given file path.
let program_filepath = filepath.to_path_buf();
let program_string = LeoParser::load_file(&program_filepath)?;
// Parses the Leo program string and constructs an abstract syntax tree.
let abstract_syntax_tree = LeoParser::parse_file(&program_filepath, &program_string)?;
// Serializes the abstract syntax tree into JSON format.
let serialized_ast = LeoParser::to_json_string(&abstract_syntax_tree)?;
Ok(serialized_ast)
}
fn main() -> Result<(), ParserError> {
// Parse the command-line arguments as strings.
let cli_arguments = env::args().collect::<Vec<String>>();
// Check that the correct number of command-line arguments were passed in.
if cli_arguments.len() < 2 || cli_arguments.len() > 3 {
eprintln!("Warning - an invalid number of command-line arguments were provided.");
println!(
"\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n"
);
return Ok(()); // Exit innocently
}
// Construct the input filepath.
let input_filepath = Path::new(&cli_arguments[1]);
// Construct the serialized abstract syntax tree.
let serialized_ast = to_leo_ast(&input_filepath)?;
println!("{}", serialized_ast);
// Determine the output directory.
let output_directory = match cli_arguments.len() == 3 {
true => format!(
"{}/{}.json",
cli_arguments[2],
input_filepath.file_stem().unwrap().to_str().unwrap()
),
false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()),
};
// Write the serialized abstract syntax tree to the output directory.
fs::write(Path::new(&output_directory), serialized_ast)?;
Ok(())
}

View File

@ -1,8 +1,9 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_assign))]
pub enum AssignOperation {
Assign(Assign),
@ -13,26 +14,26 @@ pub enum AssignOperation {
PowAssign(PowAssign),
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::assign))]
pub struct Assign {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_add_assign))]
pub struct AddAssign {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_sub_assign))]
pub struct SubAssign {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_mul_assign))]
pub struct MulAssign {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_div_assign))]
pub struct DivAssign {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_pow_assign))]
pub struct PowAssign {}

View File

@ -1,8 +1,9 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_binary))]
pub enum BinaryOperation {
Or,

View File

@ -1,11 +1,13 @@
use crate::ast::Rule;
use crate::{ast::Rule, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_not))]
pub struct NotOperation<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

53
ast/src/span.rs Normal file
View File

@ -0,0 +1,53 @@
use pest::Span;
use serde::Serialize;
// Provide getters for every private field of the remote struct. The getter must
// return either `T` or `&T` where `T` is the type of the field.
#[derive(Serialize)]
#[serde(remote = "Span")]
pub(crate) struct SpanDef<'i> {
/// # Attention
///
/// This getter only returns a subset of the input.
/// Namely, it returns `self.input[self.start..self.end]`.
/// This means you can only accurate serialize (and not deserialize).
#[serde(getter = "Span::as_str")]
input: &'i str,
/// # Safety
///
/// Must be a valid character boundary index into `input`.
#[serde(getter = "Span::start")]
start: usize,
/// # Safety
///
/// Must be a valid character boundary index into `input`.
#[serde(getter = "Span::end")]
end: usize,
}
// Provide a conversion to construct the remote type.
impl<'i> From<SpanDef<'i>> for Span<'i> {
fn from(def: SpanDef) -> Span {
Span::new(def.input, def.start, def.end).unwrap()
}
}
#[test]
fn test_span_def() {
// Wrapper serializable JSON struct
#[derive(Serialize)]
struct Element<'ast> {
#[serde(with = "SpanDef")]
span: Span<'ast>,
}
// Starting value
let span = Span::new("hello world", 1, 5).unwrap();
let element = Element { span };
// Attempt to serialize span to string.
let output = serde_json::to_string(&element).unwrap();
let expected_output = "{\"span\":{\"input\":\"ello\",\"start\":1,\"end\":5}}";
assert_eq!(expected_output, output);
}

View File

@ -3,13 +3,15 @@ use crate::{
common::{Assignee, LineEnd},
expressions::Expression,
operations::AssignOperation,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_assign))]
pub struct AssignStatement<'ast> {
pub assignee: Assignee<'ast>,
@ -17,6 +19,7 @@ pub struct AssignStatement<'ast> {
pub expression: Expression<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,9 +4,10 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::conditional_nested_or_end_statement))]
pub enum ConditionalNestedOrEndStatement<'ast> {
Nested(Box<ConditionalStatement<'ast>>),

View File

@ -2,19 +2,22 @@ use crate::{
ast::Rule,
expressions::Expression,
statements::{ConditionalNestedOrEndStatement, Statement},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_conditional))]
pub struct ConditionalStatement<'ast> {
pub condition: Expression<'ast>,
pub statements: Vec<Statement<'ast>>,
pub next: Option<ConditionalNestedOrEndStatement<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -2,13 +2,15 @@ use crate::{
ast::Rule,
common::{Declare, LineEnd, Variable},
expressions::Expression,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_definition))]
pub struct DefinitionStatement<'ast> {
pub declare: Declare,
@ -16,6 +18,7 @@ pub struct DefinitionStatement<'ast> {
pub expression: Expression<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, common::LineEnd, expressions::Expression};
use crate::{ast::Rule, common::LineEnd, expressions::Expression, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_expression))]
pub struct ExpressionStatement<'ast> {
pub expression: Expression<'ast>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,10 +1,11 @@
use crate::{ast::Rule, common::Identifier, expressions::Expression, statements::Statement};
use crate::{ast::Rule, common::Identifier, expressions::Expression, statements::Statement, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_for))]
pub struct ForStatement<'ast> {
pub index: Identifier<'ast>,
@ -12,6 +13,7 @@ pub struct ForStatement<'ast> {
pub stop: Expression<'ast>,
pub statements: Vec<Statement<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,9 +4,10 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_macro))]
pub enum MacroStatement<'ast> {
AssertEq(AssertEq<'ast>),

View File

@ -2,13 +2,15 @@ use crate::{
ast::Rule,
common::{Declare, Identifier, LineEnd, Variable},
expressions::Expression,
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_multiple_assignment))]
pub struct MultipleAssignmentStatement<'ast> {
pub declare: Declare,
@ -17,6 +19,7 @@ pub struct MultipleAssignmentStatement<'ast> {
pub arguments: Vec<Expression<'ast>>,
pub line_end: LineEnd,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, common::Return};
use crate::{ast::Rule, common::Return, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement_return))]
pub struct ReturnStatement<'ast> {
pub return_: Return<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, statements::*};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::statement))]
pub enum Statement<'ast> {
Return(ReturnStatement<'ast>),

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_address))]
pub struct AddressType {}

View File

@ -1,13 +1,15 @@
use crate::{ast::Rule, types::DataType, values::Value};
use crate::{ast::Rule, types::DataType, values::Value, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_array))]
pub struct ArrayType<'ast> {
pub _type: DataType,
pub dimensions: Vec<Value<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_boolean))]
pub struct BooleanType {}

View File

@ -1,12 +1,14 @@
use crate::{ast::Rule, common::Identifier};
use crate::{ast::Rule, common::Identifier, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_circuit))]
pub struct CircuitType<'ast> {
pub identifier: Identifier<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -4,8 +4,9 @@ use crate::{
};
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_data))]
pub enum DataType {
Address(AddressType),

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_field))]
pub struct FieldType {}

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_group))]
pub struct GroupType {}

View File

@ -1,8 +1,9 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_integer))]
pub enum IntegerType {
U8Type(U8Type),
@ -20,44 +21,44 @@ pub enum IntegerType {
// Unsigned
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_u8))]
pub struct U8Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_u16))]
pub struct U16Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_u32))]
pub struct U32Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_u64))]
pub struct U64Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_u128))]
pub struct U128Type {}
// Signed
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_i8))]
pub struct I8Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_i16))]
pub struct I16Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_i32))]
pub struct I32Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_i64))]
pub struct I64Type {}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_i128))]
pub struct I128Type {}

View File

@ -1,7 +1,8 @@
use crate::ast::Rule;
use pest_ast::FromPest;
use serde::Serialize;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_self))]
pub struct SelfType {}

View File

@ -1,9 +1,10 @@
use crate::{ast::Rule, types::*};
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::type_))]
pub enum Type<'ast> {
Basic(DataType),

View File

@ -1,15 +1,20 @@
use crate::ast::{span_into_string, Rule};
use crate::{
ast::{span_into_string, Rule},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::address))]
pub struct Address<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,17 @@
use crate::{ast::Rule, types::AddressType, values::address::Address};
use crate::{ast::Rule, types::AddressType, values::address::Address, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_address))]
pub struct AddressValue<'ast> {
pub _type: AddressType,
pub address: Address<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,20 @@
use crate::ast::{span_into_string, Rule};
use crate::{
ast::{span_into_string, Rule},
SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_boolean))]
pub struct BooleanValue<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,17 @@
use crate::{ast::Rule, types::FieldType, values::NumberValue};
use crate::{ast::Rule, types::FieldType, values::NumberValue, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_field))]
pub struct FieldValue<'ast> {
pub number: NumberValue<'ast>,
pub _type: FieldType,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,17 @@
use crate::{ast::Rule, types::GroupType, values::NumberValue};
use crate::{ast::Rule, types::GroupType, values::NumberValue, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_group))]
pub struct GroupValue<'ast> {
pub value: GroupRepresentation<'ast>,
pub _type: GroupType,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}
@ -19,7 +21,7 @@ impl<'ast> fmt::Display for GroupValue<'ast> {
}
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::group_single_or_tuple))]
pub enum GroupRepresentation<'ast> {
Single(NumberValue<'ast>),
@ -35,12 +37,13 @@ impl<'ast> fmt::Display for GroupRepresentation<'ast> {
}
}
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::group_tuple))]
pub struct GroupTuple<'ast> {
pub x: NumberValue<'ast>,
pub y: NumberValue<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,17 @@
use crate::{ast::Rule, types::IntegerType, values::NumberValue};
use crate::{ast::Rule, types::IntegerType, values::NumberValue, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_integer))]
pub struct IntegerValue<'ast> {
pub number: NumberValue<'ast>,
pub _type: IntegerType,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,14 +1,16 @@
use crate::{ast::Rule, values::NumberValue};
use crate::{ast::Rule, values::NumberValue, SpanDef};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_implicit))]
pub struct NumberImplicitValue<'ast> {
pub number: NumberValue<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

View File

@ -1,15 +1,20 @@
use crate::ast::{span_into_string, Rule};
use crate::{
ast::{span_into_string, Rule},
span::SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq)]
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::value_number))]
pub struct NumberValue<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}

Some files were not shown because too many files have changed in this diff Show More