-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
620: Feature/254 strengthen import rules r=collinc97 a=gluax Grammar changes are a bit different than what was suggested in the original feature request #254. However, it should be logically equivalent and I think makes more sense on the rust side. Closes #254 Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com>
- Loading branch information
Showing
18 changed files
with
364 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
circuit Baz { | ||
z: u32 | ||
} | ||
|
||
circuit Bazzar { | ||
a: u32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
use crate::{Package, Packages}; | ||
use leo_grammar::imports::PackageOrPackages as GrammarPackageOrPackages; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
|
||
#[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] | ||
pub enum PackageOrPackages { | ||
Package(Package), | ||
Packages(Packages), | ||
} | ||
|
||
impl<'ast> From<GrammarPackageOrPackages<'ast>> for PackageOrPackages { | ||
fn from(package_or_packages: GrammarPackageOrPackages<'ast>) -> Self { | ||
match package_or_packages { | ||
GrammarPackageOrPackages::Package(package) => PackageOrPackages::Package(Package::from(package)), | ||
GrammarPackageOrPackages::Packages(packages) => PackageOrPackages::Packages(Packages::from(packages)), | ||
} | ||
} | ||
} | ||
|
||
impl PackageOrPackages { | ||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
PackageOrPackages::Package(ref package) => write!(f, "{}", package), | ||
PackageOrPackages::Packages(ref packages) => { | ||
write!(f, "(")?; | ||
for (i, access) in packages.accesses.iter().enumerate() { | ||
write!(f, "{}", access)?; | ||
if i < packages.accesses.len() - 1 { | ||
write!(f, ", ")?; | ||
} | ||
} | ||
write!(f, ")") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Debug for PackageOrPackages { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.format(f) | ||
} | ||
} | ||
|
||
impl fmt::Display for PackageOrPackages { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.format(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
use crate::{common::Identifier, PackageAccess, Span}; | ||
use leo_grammar::imports::Packages as GrammarPackages; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
|
||
#[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] | ||
pub struct Packages { | ||
pub name: Identifier, | ||
pub accesses: Vec<PackageAccess>, | ||
pub span: Span, | ||
} | ||
|
||
impl<'ast> From<GrammarPackages<'ast>> for Packages { | ||
fn from(packages: GrammarPackages<'ast>) -> Self { | ||
Packages { | ||
name: Identifier::from(packages.name), | ||
accesses: packages.accesses.into_iter().map(PackageAccess::from).collect(), | ||
span: Span::from(packages.span), | ||
} | ||
} | ||
} | ||
|
||
impl Packages { | ||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}.(", self.name)?; | ||
for (i, access) in self.accesses.iter().enumerate() { | ||
write!(f, "{}", access)?; | ||
if i < self.accesses.len() - 1 { | ||
write!(f, ", ")?; | ||
} | ||
} | ||
write!(f, ")") | ||
} | ||
} | ||
|
||
impl fmt::Display for Packages { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.format(f) | ||
} | ||
} | ||
|
||
impl fmt::Debug for Packages { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.format(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
circuit Baz { | ||
z: u32 | ||
} | ||
|
||
circuit Bazzar { | ||
a: u32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.