mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-29 03:35:10 +03:00
re-add syntax in, then add deprecation warning for it
This commit is contained in:
parent
d549fda7b5
commit
f952da330c
@ -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<leo_ast::DefinitionStatement> for Arc<Statement> {
|
||||
}
|
||||
|
||||
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(),
|
||||
|
@ -61,3 +61,10 @@ impl<'ast> TryFrom<AnnotationName<'ast>> 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())
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Declare {
|
||||
Const,
|
||||
Let,
|
||||
}
|
||||
|
||||
impl<'ast> From<GrammarDeclare> for Declare {
|
||||
fn from(declare: GrammarDeclare) -> Self {
|
||||
match declare {
|
||||
GrammarDeclare::Const(_) => Declare::Const,
|
||||
GrammarDeclare::Let(_) => Declare::Let,
|
||||
}
|
||||
}
|
||||
@ -35,6 +37,7 @@ impl<'ast> From<GrammarDeclare> 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"),
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
|
||||
|
@ -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 " }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user