diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs
index 9d37b4264d..b7dbeaee6c 100644
--- a/asg/src/program/mod.rs
+++ b/asg/src/program/mod.rs
@@ -270,7 +270,10 @@ impl<'a> Program<'a> {
}
for (name, global_const) in program.global_consts.iter() {
- assert_eq!(name.name, global_const.variable_name.identifier.name);
+ global_const
+ .variable_names
+ .iter()
+ .map(|variable_name| assert!(name.contains(&variable_name.identifier.name)));
// TODO re-enable
// let gc = GlobalConst::init(scope, global_const)?;
// scope.global_consts.borrow_mut().insert(name.name.clone(), gc);
diff --git a/ast/src/global_consts/all_global_consts.rs b/ast/src/global_consts/all_global_consts.rs
deleted file mode 100644
index 09f2ba14d7..0000000000
--- a/ast/src/global_consts/all_global_consts.rs
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright (C) 2019-2021 Aleo Systems Inc.
-// This file is part of the Leo library.
-
-// The Leo library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// The Leo library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with the Leo library. If not, see .
-
-use crate::{
- statements::{Declare, VariableName},
- Expression,
- GlobalConst,
- Node,
- Span,
- Type,
-};
-
-use serde::{Deserialize, Serialize};
-use std::fmt;
-
-#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
-pub struct GlobalConsts {
- pub declaration_type: Declare,
- pub variable_names: Vec,
- pub type_: Option,
- pub value: Expression,
- pub span: Span,
-}
-
-impl GlobalConsts {
- pub fn into_global_const(self) -> Vec {
- let mut global_consts = vec![];
- let mut types: Vec> = vec![];
-
- if self.type_.is_some() {
- match self.type_.clone().unwrap() {
- Type::Tuple(types_old) => {
- for type_ in &types_old {
- types.push(Some(type_.clone()));
- }
- }
- _ => types.push(self.type_.clone()),
- }
- }
-
- let values = match self.value.clone() {
- Expression::TupleInit(expr) => expr.elements,
- _ => vec![self.value.clone()],
- };
-
- for (i, variable_name) in self.variable_names.iter().enumerate() {
- global_consts.push(GlobalConst {
- declaration_type: self.declaration_type.clone(),
- variable_name: variable_name.clone(),
- type_: types.get(i).unwrap_or(&None).clone(),
- value: values.get(i).unwrap_or(&self.value.clone()).clone(),
- span: self.span.clone(),
- });
- }
-
- global_consts
- }
-}
-
-impl fmt::Display for GlobalConsts {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{} ", self.declaration_type)?;
- if self.variable_names.len() == 1 {
- // mut a
- write!(f, "{}", self.variable_names[0])?;
- } else {
- // (a, mut b)
- let names = self
- .variable_names
- .iter()
- .map(|x| x.to_string())
- .collect::>()
- .join(",");
-
- write!(f, "({})", names)?;
- }
-
- if self.type_.is_some() {
- write!(f, ": {}", self.type_.as_ref().unwrap())?;
- }
- write!(f, " = {};", self.value)
- }
-}
-
-// impl<'ast> From> for GlobalConsts {
-// fn from(global_const: GrammarGlobalConst<'ast>) -> Self {
-// let variable_names = global_const
-// .variables
-// .names
-// .into_iter()
-// .map(VariableName::from)
-// .collect::>();
-
-// let type_ = global_const.variables.type_.map(Type::from);
-
-// GlobalConsts {
-// declaration_type: Declare::Const,
-// variable_names,
-// type_,
-// value: Expression::from(global_const.expression),
-// span: Span::from(global_const.span),
-// }
-// }
-// }
-
-impl Node for GlobalConsts {
- fn span(&self) -> &Span {
- &self.span
- }
-
- fn set_span(&mut self, span: Span) {
- self.span = span;
- }
-}
diff --git a/ast/src/global_consts/global_const.rs b/ast/src/global_consts/global_const.rs
deleted file mode 100644
index 7941420e6e..0000000000
--- a/ast/src/global_consts/global_const.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2019-2021 Aleo Systems Inc.
-// This file is part of the Leo library.
-
-// The Leo library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// The Leo library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with the Leo library. If not, see .
-
-use crate::{
- statements::{Declare, VariableName},
- Expression,
- Node,
- Span,
- Type,
-};
-
-use serde::{Deserialize, Serialize};
-use std::fmt;
-
-#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
-pub struct GlobalConst {
- pub declaration_type: Declare,
- pub variable_name: VariableName,
- pub type_: Option,
- pub value: Expression,
- pub span: Span,
-}
-
-impl fmt::Display for GlobalConst {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{} {}", self.declaration_type, self.variable_name)?;
-
- if self.type_.is_some() {
- write!(f, ": {}", self.type_.as_ref().unwrap())?;
- }
- write!(f, " = {};", self.value)
- }
-}
-
-impl Node for GlobalConst {
- fn span(&self) -> &Span {
- &self.span
- }
-
- fn set_span(&mut self, span: Span) {
- self.span = span;
- }
-}
diff --git a/ast/src/global_consts/mod.rs b/ast/src/global_consts/mod.rs
deleted file mode 100644
index c83468f50a..0000000000
--- a/ast/src/global_consts/mod.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (C) 2019-2021 Aleo Systems Inc.
-// This file is part of the Leo library.
-
-// The Leo library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// The Leo library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with the Leo library. If not, see .
-
-pub mod all_global_consts;
-pub use all_global_consts::*;
-
-pub mod global_const;
-pub use global_const::*;
diff --git a/ast/src/lib.rs b/ast/src/lib.rs
index 3c88fa2a63..c50b3021bc 100644
--- a/ast/src/lib.rs
+++ b/ast/src/lib.rs
@@ -41,9 +41,6 @@ pub use self::expression::*;
pub mod functions;
pub use self::functions::*;
-pub mod global_consts;
-pub use self::global_consts::*;
-
pub mod groups;
pub use self::groups::*;
diff --git a/ast/src/program.rs b/ast/src/program.rs
index e8c07caa3f..23d2d1cbb4 100644
--- a/ast/src/program.rs
+++ b/ast/src/program.rs
@@ -17,7 +17,7 @@
//! A Leo program consists of import, circuit, and function definitions.
//! Each defined type consists of ast statements and expressions.
-use crate::{Circuit, Function, FunctionInput, GlobalConst, Identifier, ImportStatement};
+use crate::{Circuit, DefinitionStatement, Function, FunctionInput, Identifier, ImportStatement};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
@@ -30,7 +30,7 @@ pub struct Program {
pub expected_input: Vec,
pub imports: Vec,
pub circuits: IndexMap,
- pub global_consts: IndexMap,
+ pub global_consts: IndexMap,
pub functions: IndexMap,
}
diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs
index aca8ab9a25..a994eae080 100644
--- a/parser/src/parser/file.rs
+++ b/parser/src/parser/file.rs
@@ -55,7 +55,14 @@ impl ParserContext {
// });
}
Token::Const => {
- // TODO
+ let statement = self.parse_definition_statement()?;
+ let variable_names = statement
+ .variable_names
+ .iter()
+ .fold("".to_string(), |joined, variable_name| {
+ format!("{}, {}", joined, variable_name.identifier.name)
+ });
+ global_consts.insert(variable_names, statement);
}
_ => {
return Err(SyntaxError::unexpected(