rename ast -> grammar 1

This commit is contained in:
collin 2020-10-30 17:17:17 -07:00
parent 61f4189483
commit ffcd93f781
189 changed files with 134 additions and 134 deletions

42
Cargo.lock generated
View File

@ -1229,32 +1229,16 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "leo-ast"
version = "1.0.3"
dependencies = [
"criterion",
"from-pest",
"lazy_static",
"pest",
"pest-ast",
"pest_derive",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "leo-compiler"
version = "1.0.3"
dependencies = [
"bincode",
"hex",
"leo-ast",
"leo-core-ast",
"leo-core-packages",
"leo-gadgets",
"leo-grammar",
"leo-imports",
"leo-input",
"leo-package",
@ -1285,7 +1269,7 @@ name = "leo-core-ast"
version = "1.0.3"
dependencies = [
"criterion",
"leo-ast",
"leo-grammar",
"leo-input",
"pest",
"serde",
@ -1323,12 +1307,28 @@ dependencies = [
"thiserror",
]
[[package]]
name = "leo-grammar"
version = "1.0.3"
dependencies = [
"criterion",
"from-pest",
"lazy_static",
"pest",
"pest-ast",
"pest_derive",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "leo-imports"
version = "1.0.3"
dependencies = [
"leo-ast",
"leo-core-ast",
"leo-grammar",
"thiserror",
"tracing",
]
@ -1433,9 +1433,9 @@ dependencies = [
name = "leo-symbol-table"
version = "1.0.3"
dependencies = [
"leo-ast",
"leo-core-ast",
"leo-core-packages",
"leo-grammar",
"leo-imports",
"serde",
"thiserror",
@ -1445,8 +1445,8 @@ dependencies = [
name = "leo-type-inference"
version = "1.0.3"
dependencies = [
"leo-ast",
"leo-core-ast",
"leo-grammar",
"leo-imports",
"leo-symbol-table",
"serde",

View File

@ -26,11 +26,11 @@ path = "leo/main.rs"
[workspace]
members = [
"ast",
"compiler",
"core-ast",
"core-packages",
"gadgets",
"grammar",
"imports",
"input",
"linter",

View File

@ -17,10 +17,6 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2018"
[dependencies.leo-ast]
path = "../ast"
version = "1.0.3"
[dependencies.leo-core-ast]
path = "../core-ast"
version = "1.0.3"
@ -33,6 +29,10 @@ version = "1.0.3"
path = "../gadgets"
version = "1.0.3"
[dependencies.leo-grammar]
path = "../grammar"
version = "1.0.3"
[dependencies.leo-imports]
path = "../imports"
version = "1.0.3"
@ -124,4 +124,4 @@ default-features = false
[features]
default = [ ]
ci_skip = [ "leo-ast/ci_skip", "leo-core-ast/ci_skip" ]
ci_skip = [ "leo-grammar/ci_skip", "leo-core-ast/ci_skip" ]

View File

@ -23,8 +23,8 @@ use crate::{
OutputBytes,
OutputFile,
};
use leo_ast::LeoAst;
use leo_core_ast::{Input, LeoCoreAst, MainInput, Program};
use leo_grammar::Grammar;
use leo_imports::ImportParser;
use leo_input::LeoInputParser;
use leo_package::inputs::InputPairs;
@ -174,10 +174,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
///
pub(crate) fn parse_program(&mut self) -> Result<(), CompilerError> {
// Load the program file.
let program_string = LeoAst::load_file(&self.main_file_path)?;
let program_string = Grammar::load_file(&self.main_file_path)?;
// Use the parser to construct the pest abstract syntax tree (ast).
let pest_ast = LeoAst::new(&self.main_file_path, &program_string).map_err(|mut e| {
let pest_ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| {
e.set_path(&self.main_file_path);
e
@ -234,7 +234,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
#[deprecated(note = "Please use the 'parse_program' method instead.")]
pub fn parse_program_from_string(&mut self, program_string: &str) -> Result<(), CompilerError> {
// Use the given bytes to construct the abstract syntax tree.
let ast = LeoAst::new(&self.main_file_path, &program_string).map_err(|mut e| {
let ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| {
e.set_path(&self.main_file_path);
e

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError};
use leo_ast::ParserError;
use leo_grammar::ParserError;
use leo_imports::ImportParserError;
use leo_input::InputParserError;
use leo_state::LocalDataVerificationError;

View File

@ -15,8 +15,8 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{expect_compiler_error, parse_input, parse_program};
use leo_ast::ParserError;
use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, StatementError};
use leo_grammar::ParserError;
use leo_input::InputParserError;
use leo_type_inference::errors::{FrameError, TypeAssertionError, TypeInferenceError};

View File

@ -26,8 +26,8 @@ name = "core_ast"
path = "benches/core_ast.rs"
harness = false
[dependencies.leo-ast]
path = "../ast"
[dependencies.leo-grammar]
path = "../grammar"
version = "1.0.3"
[dependencies.leo-input]
@ -56,4 +56,4 @@ version = "0.3"
[features]
default = [ ]
ci_skip = [ "leo-ast/ci_skip" ]
ci_skip = [ "leo-grammar/ci_skip" ]

View File

@ -14,20 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::LeoAst;
use leo_core_ast::LeoCoreAst;
use leo_grammar::Grammar;
use criterion::{criterion_group, criterion_main, Criterion};
use std::{path::Path, time::Duration};
fn leo_core_ast<'ast>(ast: &LeoAst<'ast>) -> LeoCoreAst {
fn leo_core_ast<'ast>(ast: &Grammar<'ast>) -> LeoCoreAst {
LeoCoreAst::new("leo_core_tree", &ast)
}
fn bench_big_if_else(c: &mut Criterion) {
let filepath = Path::new("./big_if_else.leo").to_path_buf();
let program_string = include_str!("./big_if_else.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_if_else", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -35,7 +35,7 @@ fn bench_big_if_else(c: &mut Criterion) {
fn bench_big_ternary(c: &mut Criterion) {
let filepath = Path::new("./big_ternary.leo").to_path_buf();
let program_string = include_str!("./big_ternary.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_ternary", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -43,7 +43,7 @@ fn bench_big_ternary(c: &mut Criterion) {
fn bench_big_circuit(c: &mut Criterion) {
let filepath = Path::new("./big_circuit.leo").to_path_buf();
let program_string = include_str!("./big_circuit.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_circuit", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -51,7 +51,7 @@ fn bench_big_circuit(c: &mut Criterion) {
fn bench_long_expr(c: &mut Criterion) {
let filepath = Path::new("./long_expr.leo").to_path_buf();
let program_string = include_str!("./long_expr.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::long_expr", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -59,7 +59,7 @@ fn bench_long_expr(c: &mut Criterion) {
fn bench_long_array(c: &mut Criterion) {
let filepath = Path::new("./long_array.leo").to_path_buf();
let program_string = include_str!("./long_array.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::long_array", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -67,7 +67,7 @@ fn bench_long_array(c: &mut Criterion) {
fn bench_many_foos(c: &mut Criterion) {
let filepath = Path::new("./many_foos.leo").to_path_buf();
let program_string = include_str!("./many_foos.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::many_foos", |b| b.iter(|| leo_core_ast(&ast)));
}
@ -75,7 +75,7 @@ fn bench_many_foos(c: &mut Criterion) {
fn bench_many_assigns(c: &mut Criterion) {
let filepath = Path::new("./many_assigns.leo").to_path_buf();
let program_string = include_str!("./many_assigns.leo");
let ast = LeoAst::new(&filepath, program_string).unwrap();
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::many_assigns", |b| b.iter(|| leo_core_ast(&ast)));
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Circuit, Function, FunctionInput, Identifier, ImportStatement, TestFunction};
use leo_ast::{
use leo_grammar::{
annotations::{Annotation, AnnotationArguments, AnnotationName},
definitions::{AnnotatedDefinition, Definition},
};

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{CircuitMember, Identifier};
use leo_ast::circuits::Circuit as AstCircuit;
use leo_grammar::circuits::Circuit as AstCircuit;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Function, Identifier, Type};
use leo_ast::circuits::{
use leo_grammar::circuits::{
CircuitFunction as AstCircuitFunction,
CircuitMember as AstCircuitMember,
CircuitVariableDefinition as AstCircuitVariableDefinition,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, Identifier};
use leo_ast::circuits::CircuitVariable;
use leo_grammar::circuits::CircuitVariable;
use serde::{Deserialize, Serialize};

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, Identifier, RangeOrExpression, Span};
use leo_ast::{access::AssigneeAccess as AstAssigneeAccess, common::Assignee as AstAssignee};
use leo_grammar::{access::AssigneeAccess as AstAssigneeAccess, common::Assignee as AstAssignee};
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::common::Declare as AstDeclare;
use leo_grammar::common::Declare as AstDeclare;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Span;
use leo_ast::{
use leo_grammar::{
annotations::AnnotationArgument,
common::{Identifier as AstIdentifier, KeywordOrIdentifier, SelfKeyword, SelfKeywordOrIdentifier},
expressions::CircuitName,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Expression;
use leo_ast::common::RangeOrExpression as AstRangeOrExpression;
use leo_grammar::common::RangeOrExpression as AstRangeOrExpression;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Expression;
use leo_ast::{common::SpreadOrExpression as AstSpreadOrExpression, expressions::Expression as AstExpression};
use leo_grammar::{common::SpreadOrExpression as AstSpreadOrExpression, expressions::Expression as AstExpression};
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::common::{Identifier, Span};
use leo_ast::common::VariableName as AstVariableName;
use leo_grammar::common::VariableName as AstVariableName;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Type, VariableName};
use leo_ast::common::Variables as AstVariables;
use leo_grammar::common::Variables as AstVariables;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, FormattedString};
use leo_ast::console::{
use leo_grammar::console::{
ConsoleAssert as AstConsoleAssert,
ConsoleDebug as AstConsoleDebug,
ConsoleError as AstConsoleError,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConsoleFunction, Span};
use leo_ast::console::ConsoleFunctionCall as AstConsoleFunctionCall;
use leo_grammar::console::ConsoleFunctionCall as AstConsoleFunctionCall;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Span;
use leo_ast::console::FormattedContainer as AstFormattedContainer;
use leo_grammar::console::FormattedContainer as AstFormattedContainer;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, Span};
use leo_ast::console::FormattedParameter as AstFormattedParameter;
use leo_grammar::console::FormattedParameter as AstFormattedParameter;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{FormattedContainer, FormattedParameter, Span};
use leo_ast::console::FormattedString as AstFormattedString;
use leo_grammar::console::FormattedString as AstFormattedString;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -23,7 +23,7 @@ use crate::{
Span,
SpreadOrExpression,
};
use leo_ast::{
use leo_grammar::{
access::{Access, AssigneeAccess},
common::{Assignee, Identifier as AstIdentifier},
expressions::{
@ -50,7 +50,7 @@ use leo_ast::{
};
use leo_input::{types::ArrayDimensions as InputArrayDimensions, values::PositiveNumber as InputAstPositiveNumber};
use leo_ast::{expressions::TupleExpression, types::ArrayDimensions};
use leo_grammar::{expressions::TupleExpression, types::ArrayDimensions};
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{FunctionInput, Identifier, Span, Statement, Type};
use leo_ast::functions::Function as AstFunction;
use leo_grammar::functions::Function as AstFunction;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Identifier, Span, Type};
use leo_ast::functions::FunctionInput as AstFunctionInput;
use leo_grammar::functions::FunctionInput as AstFunctionInput;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{FunctionInputVariable, Identifier, Span};
use leo_ast::functions::input::Input as AstInput;
use leo_grammar::functions::input::Input as AstInput;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Function, Identifier};
use leo_ast::functions::TestFunction as AstTestFunction;
use leo_grammar::functions::TestFunction as AstTestFunction;
use serde::{Deserialize, Serialize};

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::common::span::Span;
use leo_ast::values::{
use leo_grammar::values::{
GroupCoordinate as AstGroupCoordinate,
Inferred as AstInferred,
NumberValue as AstNumberValue,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{common::span::Span, groups::GroupCoordinate};
use leo_ast::values::{
use leo_grammar::values::{
GroupRepresentation as AstGroupRepresentation,
GroupTuple as AstGroupTuple,
GroupValue as AstGroupValue,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Package, Span};
use leo_ast::imports::Import as AstImport;
use leo_grammar::imports::Import as AstImport;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Identifier, Span};
use leo_ast::imports::ImportSymbol as AstImportSymbol;
use leo_grammar::imports::ImportSymbol as AstImportSymbol;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{common::Identifier, PackageAccess, Span};
use leo_ast::imports::Package as AstPackage;
use leo_grammar::imports::Package as AstPackage;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ImportSymbol, Package, Span};
use leo_ast::imports::PackageAccess as AstPackageAccess;
use leo_grammar::imports::PackageAccess as AstPackageAccess;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -59,7 +59,7 @@ pub use self::statements::*;
pub mod types;
pub use self::types::*;
use leo_ast::LeoAst;
use leo_grammar::Grammar;
/// The core abstract syntax tree (ast) for a Leo program.
///
@ -74,7 +74,7 @@ pub struct LeoCoreAst {
impl LeoCoreAst {
/// Creates a new core syntax tree from a given program name and abstract syntax tree.
pub fn new<'ast>(program_name: &str, ast: &LeoAst<'ast>) -> Self {
pub fn new<'ast>(program_name: &str, ast: &Grammar<'ast>) -> Self {
Self {
core_ast: Program::from(program_name, ast.as_repr()),
}

View File

@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::{LeoAst, ParserError};
use leo_core_ast::LeoCoreAst;
use leo_grammar::{Grammar, ParserError};
use std::{env, fs, path::Path};
fn to_leo_core_tree(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 = LeoAst::load_file(&program_filepath)?;
let program_string = Grammar::load_file(&program_filepath)?;
// Parses the Leo file and constructs a pest ast.
let ast = LeoAst::new(&program_filepath, &program_string)?;
let ast = Grammar::new(&program_filepath, &program_string)?;
// Parse the pest ast and constructs a core ast.
let core_ast = LeoCoreAst::new("leo_core_tree", &ast);

View File

@ -18,7 +18,7 @@
//! Each defined type consists of typed statements and expressions.
use crate::{load_annotation, Circuit, Function, FunctionInput, Identifier, ImportStatement, TestFunction};
use leo_ast::{definitions::Definition, files::File};
use leo_grammar::{definitions::Definition, files::File};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConditionalStatement, Statement};
use leo_ast::statements::ConditionalNestedOrEndStatement as AstConditionalNestedOrEndStatement;
use leo_grammar::statements::ConditionalNestedOrEndStatement as AstConditionalNestedOrEndStatement;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConditionalNestedOrEndStatement, Expression, Statement};
use leo_ast::statements::ConditionalStatement as AstConditionalStatement;
use leo_grammar::statements::ConditionalStatement as AstConditionalStatement;
use serde::{Deserialize, Serialize};
use std::fmt;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Assignee, ConditionalStatement, ConsoleFunctionCall, Declare, Expression, Identifier, Span, Variables};
use leo_ast::{
use leo_grammar::{
console::ConsoleFunctionCall as AstConsoleFunctionCall,
operations::AssignOperation,
statements::{

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::types::{
use leo_grammar::types::{
IntegerType as AstIntegerType,
SignedIntegerType as AstSignedIntegerType,
UnsignedIntegerType as AstUnsignedIntegerType,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, Identifier, IntegerType};
use leo_ast::types::{ArrayType, CircuitType, DataType, TupleType, Type as AstType};
use leo_grammar::types::{ArrayType, CircuitType, DataType, TupleType, Type as AstType};
use leo_input::types::{
ArrayType as InputArrayType,
DataType as InputDataType,

View File

@ -14,19 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::LeoAst;
use leo_core_ast::LeoCoreAst;
#[cfg(not(feature = "ci_skip"))]
use leo_core_ast::Program;
use leo_grammar::Grammar;
use std::path::{Path, PathBuf};
fn to_core_ast(program_filepath: &Path) -> LeoCoreAst {
// Loads the Leo code as a string from the given file path.
let program_string = LeoAst::load_file(program_filepath).unwrap();
let program_string = Grammar::load_file(program_filepath).unwrap();
// Parses the Leo file and constructs a pest ast.
let ast = LeoAst::new(&program_filepath, &program_string).unwrap();
let ast = Grammar::new(&program_filepath, &program_string).unwrap();
// Parses the pest ast and constructs a core ast.
LeoCoreAst::new("leo_core_tree", &ast)

View File

@ -1,5 +1,5 @@
[package]
name = "leo-ast"
name = "leo-grammar"
version = "1.0.3"
authors = [ "The Aleo Team <hello@aleo.org>" ]
description = "AST of the Leo programming language"
@ -18,7 +18,7 @@ license = "GPL-3.0"
edition = "2018"
[[bin]]
name = "leo_ast"
name = "leo_grammar"
path = "src/main.rs"
[[bench]]

View File

@ -1,9 +1,9 @@
# leo-ast
# leo-grammar
## 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)}
leo_grammar {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

@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::LeoAst;
use leo_grammar::Grammar;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::path::Path;
fn leo_ast<'ast>(filepath: &'ast Path, program_string: &'ast str) {
let result = LeoAst::<'ast>::new(filepath, program_string).unwrap();
fn leo_grammar<'ast>(filepath: &'ast Path, program_string: &'ast str) {
let result = Grammar::<'ast>::new(filepath, program_string).unwrap();
black_box(result);
}
@ -28,7 +28,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let filepath = Path::new("./main.leo").to_path_buf();
let program_string = include_str!("./main.leo");
c.bench_function("LeoAst::new", |b| b.iter(|| leo_ast(&filepath, program_string)));
c.bench_function("Grammar::new", |b| b.iter(|| leo_grammar(&filepath, program_string)));
}
criterion_group!(benches, criterion_benchmark);

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