-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0698352
commit dab2851
Showing
69 changed files
with
2,616 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
[package] | ||
name = "leo-cst" | ||
version = "2.1.0" | ||
authors = [ "The Aleo Team <[email protected]>" ] | ||
description = "Concrete syntax tree (CST) for the Leo programming language" | ||
homepage = "https://aleo.org" | ||
repository = "https://github.com/AleoHQ/leo" | ||
keywords = [ | ||
"aleo", | ||
"cryptography", | ||
"leo", | ||
"programming-language", | ||
"zero-knowledge" | ||
] | ||
categories = [ "compilers", "cryptography", "web-programming" ] | ||
include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] | ||
license = "GPL-3.0" | ||
edition = "2021" | ||
rust-version = "1.69" | ||
|
||
[dependencies.snarkvm] | ||
workspace = true | ||
|
||
[dependencies.leo-errors] | ||
path = "../../errors" | ||
version = "2.1.0" | ||
|
||
[dependencies.leo-span] | ||
path = "../span" | ||
version = "2.1.0" | ||
|
||
[dependencies.indexmap] | ||
version = "1.9" | ||
features = [ "serde-1" ] | ||
|
||
[dependencies.itertools] | ||
version = "0.13.0" | ||
|
||
[dependencies.serde] | ||
version = "1.0" | ||
features = [ "derive", "rc" ] | ||
|
||
[dependencies.serde_json] | ||
version = "1.0" | ||
features = [ "preserve_order" ] | ||
|
||
[dependencies.smallvec] | ||
version = "1.13.1" | ||
features = [ "serde" ] | ||
|
||
[dev-dependencies.criterion] | ||
version = "0.5" | ||
|
||
[features] | ||
default = [ ] | ||
ci_skip = [ ] |
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 @@ | ||
# leo-cst | ||
|
||
[![Crates.io](https://img.shields.io/crates/v/leo-cst.svg?color=neon)](https://crates.io/crates/leo-cst) | ||
[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS) | ||
[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md) | ||
|
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,22 @@ | ||
|
||
|
||
use crate::{Expression, Node, NodeID}; | ||
use leo_span::Span; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An array access expression, e.g., `foo[index]`. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct ArrayAccess { | ||
/// An expression evaluating to some array type, e.g., `[false, true]`. | ||
pub array: Box<Expression>, | ||
/// The index to access in the array expression. E.g., `0` for `[false, true]` would yield `false`. | ||
pub index: Box<Expression>, | ||
/// The span for the entire expression `foo[index]`. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
|
||
crate::simple_node_impl!(ArrayAccess); |
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,21 @@ | ||
|
||
use crate::{Identifier, Node, NodeID, Type}; | ||
use leo_span::Span; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An access expression to an struct constant., e.g. `u8::MAX`. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct AssociatedConstant { | ||
/// The inner struct type. | ||
pub ty: Type, | ||
/// The struct constant that is being accessed. | ||
pub name: Identifier, | ||
/// The span for the entire expression `Foo::bar()`. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
|
||
crate::simple_node_impl!(AssociatedConstant); |
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,24 @@ | ||
|
||
|
||
use crate::{Expression, Identifier, Node, NodeID}; | ||
use leo_span::Span; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An access expression to an associated function in a struct, e.g.`Pedersen64::hash()`. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct AssociatedFunction { | ||
/// The inner struct variant. | ||
pub variant: Identifier, | ||
/// The static struct member function that is being accessed. | ||
pub name: Identifier, | ||
/// The arguments passed to the function `name`. | ||
pub arguments: Vec<Expression>, | ||
/// The span for the entire expression `Foo::bar()`. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
|
||
crate::simple_node_impl!(AssociatedFunction); |
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,22 @@ | ||
|
||
use crate::{Expression, Identifier, Node, NodeID}; | ||
use leo_span::Span; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
|
||
/// A struct member access expression `inner.name` to some structure with *named members*. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct MemberAccess { | ||
/// The inner struct that is being accessed. | ||
pub inner: Box<Expression>, | ||
/// The name of the struct member to access. | ||
pub name: Identifier, | ||
/// The span covering all of `inner.name`. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
|
||
crate::simple_node_impl!(MemberAccess); |
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,16 @@ | ||
|
||
|
||
mod array_access; | ||
pub use array_access::*; | ||
|
||
mod associated_constant_access; | ||
pub use associated_constant_access::*; | ||
|
||
mod associated_function_access; | ||
pub use associated_function_access::*; | ||
|
||
mod member_access; | ||
pub use member_access::*; | ||
|
||
mod tuple_access; | ||
pub use tuple_access::*; |
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,22 @@ | ||
|
||
|
||
use crate::{Expression, Node, NodeID, NonNegativeNumber}; | ||
use leo_span::Span; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A tuple access expression, e.g., `tuple.index`. | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct TupleAccess { | ||
/// An expression evaluating to some tuple type, e.g., `(5, 2)`. | ||
pub tuple: Box<Expression>, | ||
/// The index to access in the tuple expression. E.g., `0` for `(5, 2)` would yield `5`. | ||
pub index: NonNegativeNumber, | ||
/// The span for the entire expression `tuple.index`. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
|
||
crate::simple_node_impl!(TupleAccess); |
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,8 @@ | ||
|
||
use super::*; | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
|
||
pub enum Comment { | ||
Line(String, #[serde(with = "leo_span::span_json")] Span, NodeID), | ||
Block(String, #[serde(with = "leo_span::span_json")] Span, NodeID), | ||
} |
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,19 @@ | ||
use crate::{simple_node_impl, Node, NodeID}; | ||
use leo_span::{Span, Symbol}; | ||
|
||
use super::Space; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct Identifier { | ||
/// The symbol that the user wrote, e.g., `foo`. | ||
pub pl_name: Space, | ||
pub name: Symbol, | ||
pub pr_name: Space, | ||
|
||
/// A span locating where the identifier occurred in the source. | ||
pub span: Span, | ||
/// The ID of the node. | ||
pub id: NodeID, | ||
} | ||
|
||
simple_node_impl!(Identifier); |
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,8 @@ | ||
use super::Identifier; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ImportModule { | ||
pub module: Identifier, | ||
pub span: Span, | ||
pub id: NodeID, | ||
} |
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,5 @@ | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
pub struct Location { | ||
pub program: Option<Symbol>, | ||
pub name: Symbol, | ||
} |
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,22 @@ | ||
use leo_span::Span; | ||
|
||
pub mod comment; | ||
pub use comment::*; | ||
|
||
pub mod import_module; | ||
pub use import_module::*; | ||
|
||
pub mod node; | ||
pub use node::*; | ||
|
||
pub mod positive_number; | ||
pub use positive_number::*; | ||
|
||
pub mod location; | ||
pub use location::*; | ||
|
||
pub mod identifier; | ||
pub use identifier::*; | ||
|
||
pub mod space; | ||
pub use space::*; |
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,62 @@ | ||
// Copyright (C) 2019-2023 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 leo_span::Span; | ||
|
||
/// A node ID. | ||
// Development Note: | ||
// A `NodeID` must implement: `Copy`, `Default`, among others. | ||
pub type NodeID = usize; | ||
|
||
/// A node in the AST. | ||
pub trait Node: | ||
std::fmt::Debug + std::fmt::Display + Clone + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned | ||
{ | ||
/// Returns the span of the node. | ||
fn span(&self) -> Span; | ||
|
||
/// Sets the span of the node. | ||
fn set_span(&mut self, span: Span); | ||
|
||
/// Returns the ID of the node. | ||
fn id(&self) -> NodeID; | ||
|
||
/// Sets the ID of the node. | ||
fn set_id(&mut self, id: NodeID); | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! simple_node_impl { | ||
($ty:ty) => { | ||
impl Node for $ty { | ||
fn span(&self) -> Span { | ||
self.span | ||
} | ||
|
||
fn set_span(&mut self, span: Span) { | ||
self.span = span; | ||
} | ||
|
||
fn id(&self) -> NodeID { | ||
self.id | ||
} | ||
|
||
fn set_id(&mut self, id: NodeID) { | ||
self.id = id; | ||
} | ||
} | ||
}; | ||
} |
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,10 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A number string guaranteed to be non-negative. | ||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] | ||
pub struct NonNegativeNumber { | ||
/// The string representation of the non-negative number. | ||
string: String, | ||
/// The numeric value of the non-negative number. | ||
value: usize, | ||
} |
Oops, something went wrong.