rename struct alias Ast -> Grammar in ast module 1

This commit is contained in:
collin 2020-11-10 13:27:43 -08:00
parent 04f4e685ed
commit 9c9f29c496
10 changed files with 50 additions and 48 deletions

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_grammar::circuits::Circuit as AstCircuit;
use leo_grammar::circuits::Circuit as GrammarCircuit;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -26,8 +26,8 @@ pub struct Circuit {
pub members: Vec<CircuitMember>,
}
impl<'ast> From<AstCircuit<'ast>> for Circuit {
fn from(circuit: AstCircuit<'ast>) -> Self {
impl<'ast> From<GrammarCircuit<'ast>> for Circuit {
fn from(circuit: GrammarCircuit<'ast>) -> Self {
let circuit_name = Identifier::from(circuit.identifier);
let members = circuit.members.into_iter().map(CircuitMember::from).collect();

View File

@ -16,9 +16,9 @@
use crate::{Function, Identifier, Type};
use leo_grammar::circuits::{
CircuitFunction as AstCircuitFunction,
CircuitMember as AstCircuitMember,
CircuitVariableDefinition as AstCircuitVariableDefinition,
CircuitFunction as GrammarCircuitFunction,
CircuitMember as GrammarCircuitMember,
CircuitVariableDefinition as GrammarCircuitVariableDefinition,
};
use serde::{Deserialize, Serialize};
@ -32,8 +32,8 @@ pub enum CircuitMember {
CircuitFunction(bool, Function),
}
impl<'ast> From<AstCircuitVariableDefinition<'ast>> for CircuitMember {
fn from(circuit_value: AstCircuitVariableDefinition<'ast>) -> Self {
impl<'ast> From<GrammarCircuitVariableDefinition<'ast>> for CircuitMember {
fn from(circuit_value: GrammarCircuitVariableDefinition<'ast>) -> Self {
CircuitMember::CircuitVariable(
circuit_value.mutable.is_some(),
Identifier::from(circuit_value.identifier),
@ -42,8 +42,8 @@ impl<'ast> From<AstCircuitVariableDefinition<'ast>> for CircuitMember {
}
}
impl<'ast> From<AstCircuitFunction<'ast>> for CircuitMember {
fn from(circuit_function: AstCircuitFunction<'ast>) -> Self {
impl<'ast> From<GrammarCircuitFunction<'ast>> for CircuitMember {
fn from(circuit_function: GrammarCircuitFunction<'ast>) -> Self {
CircuitMember::CircuitFunction(
circuit_function._static.is_some(),
Function::from(circuit_function.function),
@ -51,11 +51,11 @@ impl<'ast> From<AstCircuitFunction<'ast>> for CircuitMember {
}
}
impl<'ast> From<AstCircuitMember<'ast>> for CircuitMember {
fn from(object: AstCircuitMember<'ast>) -> Self {
impl<'ast> From<GrammarCircuitMember<'ast>> for CircuitMember {
fn from(object: GrammarCircuitMember<'ast>) -> Self {
match object {
AstCircuitMember::CircuitVariableDefinition(circuit_value) => CircuitMember::from(circuit_value),
AstCircuitMember::CircuitFunction(circuit_function) => CircuitMember::from(circuit_function),
GrammarCircuitMember::CircuitVariableDefinition(circuit_value) => CircuitMember::from(circuit_value),
GrammarCircuitMember::CircuitFunction(circuit_function) => CircuitMember::from(circuit_function),
}
}
}

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_grammar::common::Declare as AstDeclare;
use leo_grammar::common::Declare as GrammarDeclare;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -25,11 +25,11 @@ pub enum Declare {
Let,
}
impl<'ast> From<AstDeclare> for Declare {
fn from(declare: AstDeclare) -> Self {
impl<'ast> From<GrammarDeclare> for Declare {
fn from(declare: GrammarDeclare) -> Self {
match declare {
AstDeclare::Const(_) => Declare::Const,
AstDeclare::Let(_) => Declare::Let,
GrammarDeclare::Const(_) => Declare::Const,
GrammarDeclare::Let(_) => Declare::Let,
}
}
}

View File

@ -17,13 +17,13 @@
use crate::Span;
use leo_grammar::{
annotations::AnnotationArgument,
common::{Identifier as AstIdentifier, KeywordOrIdentifier, SelfKeyword, SelfKeywordOrIdentifier},
common::{Identifier as GrammarIdentifier, KeywordOrIdentifier, SelfKeyword, SelfKeywordOrIdentifier},
expressions::CircuitName,
functions::InputKeyword,
imports::PackageName as AstPackageName,
imports::PackageName as GrammarPackageName,
types::SelfType,
};
use leo_input::common::Identifier as InputAstIdentifier;
use leo_input::common::Identifier as InputIdentifier;
use serde::{
de::{self, Visitor},
@ -73,8 +73,8 @@ impl Identifier {
}
}
impl<'ast> From<AstIdentifier<'ast>> for Identifier {
fn from(identifier: AstIdentifier<'ast>) -> Self {
impl<'ast> From<GrammarIdentifier<'ast>> for Identifier {
fn from(identifier: GrammarIdentifier<'ast>) -> Self {
Self {
name: identifier.value,
span: Span::from(identifier.span),
@ -82,8 +82,8 @@ impl<'ast> From<AstIdentifier<'ast>> for Identifier {
}
}
impl<'ast> From<AstPackageName<'ast>> for Identifier {
fn from(name: AstPackageName<'ast>) -> Self {
impl<'ast> From<GrammarPackageName<'ast>> for Identifier {
fn from(name: GrammarPackageName<'ast>) -> Self {
Self {
name: name.value,
span: Span::from(name.span),
@ -91,8 +91,8 @@ impl<'ast> From<AstPackageName<'ast>> for Identifier {
}
}
impl<'ast> From<InputAstIdentifier<'ast>> for Identifier {
fn from(identifier: InputAstIdentifier<'ast>) -> Self {
impl<'ast> From<InputIdentifier<'ast>> for Identifier {
fn from(identifier: InputIdentifier<'ast>) -> Self {
Self {
name: identifier.value,
span: Span::from(identifier.span),

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Expression;
use leo_grammar::common::RangeOrExpression as AstRangeOrExpression;
use leo_grammar::common::RangeOrExpression as GrammarRangeOrExpression;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -27,13 +27,15 @@ pub enum RangeOrExpression {
Expression(Expression),
}
impl<'ast> From<AstRangeOrExpression<'ast>> for RangeOrExpression {
fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self {
impl<'ast> From<GrammarRangeOrExpression<'ast>> for RangeOrExpression {
fn from(range_or_expression: GrammarRangeOrExpression<'ast>) -> Self {
match range_or_expression {
AstRangeOrExpression::Range(range) => {
GrammarRangeOrExpression::Range(range) => {
RangeOrExpression::Range(range.from.map(Expression::from), range.to.map(Expression::from))
}
AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)),
GrammarRangeOrExpression::Expression(expression) => {
RangeOrExpression::Expression(Expression::from(expression))
}
}
}
}

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 pest::Span as AstSpan;
use pest::Span as GrammarSpan;
use serde::{Deserialize, Serialize};
use std::hash::{Hash, Hasher};
@ -46,8 +46,8 @@ impl Hash for Span {
}
}
impl<'ast> From<AstSpan<'ast>> for Span {
fn from(span: AstSpan<'ast>) -> Self {
impl<'ast> From<GrammarSpan<'ast>> for Span {
fn from(span: GrammarSpan<'ast>) -> Self {
let mut text = " ".to_string();
let line_col = span.start_pos().line_col();
let end = span.end_pos().line_col().1;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Expression;
use leo_grammar::{common::SpreadOrExpression as AstSpreadOrExpression, expressions::Expression as AstExpression};
use leo_grammar::{common::SpreadOrExpression as AstSpreadOrExpression, expressions::Expression as GrammarExpression};
use serde::{Deserialize, Serialize};
use std::fmt;
@ -38,8 +38,8 @@ impl<'ast> From<AstSpreadOrExpression<'ast>> for SpreadOrExpression {
}
}
impl<'ast> From<AstExpression<'ast>> for SpreadOrExpression {
fn from(expression: AstExpression<'ast>) -> Self {
impl<'ast> From<GrammarExpression<'ast>> for SpreadOrExpression {
fn from(expression: GrammarExpression<'ast>) -> Self {
SpreadOrExpression::Expression(Expression::from(expression))
}
}

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_grammar::common::VariableName as AstVariableName;
use leo_grammar::common::VariableName as GrammarVariableName;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -27,8 +27,8 @@ pub struct VariableName {
pub span: Span,
}
impl<'ast> From<AstVariableName<'ast>> for VariableName {
fn from(name: AstVariableName<'ast>) -> Self {
impl<'ast> From<GrammarVariableName<'ast>> for VariableName {
fn from(name: GrammarVariableName<'ast>) -> Self {
Self {
mutable: name.mutable.is_some(),
identifier: Identifier::from(name.identifier),

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_grammar::common::Variables as AstVariables;
use leo_grammar::common::Variables as GrammarVariables;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -27,8 +27,8 @@ pub struct Variables {
pub type_: Option<Type>,
}
impl<'ast> From<AstVariables<'ast>> for Variables {
fn from(variables: AstVariables<'ast>) -> Self {
impl<'ast> From<GrammarVariables<'ast>> for Variables {
fn from(variables: GrammarVariables<'ast>) -> Self {
let names = variables.names.into_iter().map(VariableName::from).collect::<Vec<_>>();
let type_ = variables.type_.map(Type::from);

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_grammar::imports::ImportSymbol as AstImportSymbol;
use leo_grammar::imports::ImportSymbol as GrammarImportSymbol;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -27,8 +27,8 @@ pub struct ImportSymbol {
pub span: Span,
}
impl<'ast> From<AstImportSymbol<'ast>> for ImportSymbol {
fn from(symbol: AstImportSymbol<'ast>) -> Self {
impl<'ast> From<GrammarImportSymbol<'ast>> for ImportSymbol {
fn from(symbol: GrammarImportSymbol<'ast>) -> Self {
ImportSymbol {
symbol: Identifier::from(symbol.value),
alias: symbol.alias.map(Identifier::from),