Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial grammar for impl blocks and optimize grammar [3] #153

Merged
merged 11 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 75 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/ast/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@ pub struct DocString {
contents: String,
}

/// Identifiers, without a path or generics.
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct Ident {
pub name: String,
pub span: Span,
}

/// A type name, supporting fully qualified paths and generics:
/// ```
/// std::module::X<T>
/// ```
/// Used only when specifying types.
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct TypeName {
pub path: Vec<Ident>,
pub name: Ident,
pub generics: Vec<TypeName>,
pub span: Span,
}

/// Used as a generic param in function and struct declarations.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct GenericParam {
pub name: Ident,
Expand Down
7 changes: 7 additions & 0 deletions src/ast/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ pub struct Param {
pub name: Ident,
pub r#type: TypeDescriptor,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImplBlock {
pub target: Ident,
pub methods: Vec<FunctionDef>,
pub span: Span,
}
3 changes: 2 additions & 1 deletion src/ast/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{
common::{DocString, Ident, Span},
constants::ConstantDef,
enums::{EnumDecl, UnionDecl},
functions::{FunctionDecl, FunctionDef},
functions::{FunctionDecl, FunctionDef, ImplBlock},
imports::ImportStmt,
structs::StructDecl,
types::TypeDecl,
Expand All @@ -23,6 +23,7 @@ pub enum ModuleDefItem {
Constant(ConstantDef),
Function(FunctionDef),
FunctionDecl(FunctionDecl),
Impl(ImplBlock),
Struct(StructDecl),
Union(UnionDecl),
Enum(EnumDecl),
Expand Down
5 changes: 2 additions & 3 deletions src/ast/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::common::{DocString, Ident, Span};
use super::common::{DocString, Ident, Span, TypeName};

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum TypeDescriptor {
Type {
name: Ident,
generics: Vec<Self>,
name: TypeName,
span: Span,
},
Ref {
Expand Down
Loading
Loading