From f952da330c16ae5089eb97c65dba8c1acc930ea0 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 16 Feb 2021 15:33:31 -0500 Subject: [PATCH] re-add syntax in, then add deprecation warning for it --- asg/src/statement/definition.rs | 8 ++++++++ ast/src/errors/deprecated.rs | 7 +++++++ ast/src/statements/definition/declare.rs | 3 +++ grammar/src/common/declare.rs | 1 + grammar/src/leo.pest | 2 +- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index e49aae2cb6..fc1c7b20be 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -29,6 +29,8 @@ use crate::{ Variable, }; +use leo_ast::{AstError, DeprecatedError}; + use std::{ cell::RefCell, sync::{Arc, Weak}, @@ -92,6 +94,12 @@ impl FromAst for Arc { } for (variable, type_) in statement.variable_names.iter().zip(output_types.into_iter()) { + if statement.declaration_type == leo_ast::Declare::Const { + return Err(AsgConvertError::AstError(AstError::DeprecatedError( + DeprecatedError::const_statement(&statement.span), + ))); + } + variables.push(Arc::new(RefCell::new(InnerVariable { id: uuid::Uuid::new_v4(), name: variable.identifier.clone(), diff --git a/ast/src/errors/deprecated.rs b/ast/src/errors/deprecated.rs index a7ae558421..c22419d3ee 100644 --- a/ast/src/errors/deprecated.rs +++ b/ast/src/errors/deprecated.rs @@ -61,3 +61,10 @@ impl<'ast> TryFrom> for DeprecatedError { } } } + +impl DeprecatedError { + pub fn const_statement(span: &Span) -> Self { + let message = "const _ = ... is deprecated. Did you mean let?".to_string(); + Self::new_from_span(message, span.clone()) + } +} diff --git a/ast/src/statements/definition/declare.rs b/ast/src/statements/definition/declare.rs index 64ac86d269..de00d5f210 100644 --- a/ast/src/statements/definition/declare.rs +++ b/ast/src/statements/definition/declare.rs @@ -21,12 +21,14 @@ use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Declare { + Const, Let, } impl<'ast> From for Declare { fn from(declare: GrammarDeclare) -> Self { match declare { + GrammarDeclare::Const(_) => Declare::Const, GrammarDeclare::Let(_) => Declare::Let, } } @@ -35,6 +37,7 @@ impl<'ast> From for Declare { impl fmt::Display for Declare { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + Declare::Const => write!(f, "const"), Declare::Let => write!(f, "let"), } } diff --git a/grammar/src/common/declare.rs b/grammar/src/common/declare.rs index 5503fc6aef..c5a77ecacb 100644 --- a/grammar/src/common/declare.rs +++ b/grammar/src/common/declare.rs @@ -22,6 +22,7 @@ use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::declare))] pub enum Declare { + Const(Const), Let(Let), } diff --git a/grammar/src/leo.pest b/grammar/src/leo.pest index e59a404467..4a5fbdde2e 100644 --- a/grammar/src/leo.pest +++ b/grammar/src/leo.pest @@ -99,7 +99,7 @@ variable_name_tuple = _{"(" ~ variable_name ~ ("," ~ variable_name)+ ~ ")"} variables = { ( variable_name_tuple | variable_name ) ~ (":" ~ type_ )? } // Declared in common/declare.rs -declare = { let_ } +declare = { let_ | const_ } const_ = { "const " } let_ = { "let " }