Skip to content
Open
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
8 changes: 8 additions & 0 deletions rust/ruby-rbs/src/ast/annotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::ast::location::LocationRange;
use crate::ids::SymbolId;

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Annotation {
pub string: SymbolId,
pub location: Option<LocationRange>,
}
8 changes: 8 additions & 0 deletions rust/ruby-rbs/src/ast/comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::ast::location::LocationRange;
use crate::ids::SymbolId;

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Comment {
pub string: SymbolId,
pub location: Option<LocationRange>,
}
1,255 changes: 1,255 additions & 0 deletions rust/ruby-rbs/src/ast/convert.rs

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions rust/ruby-rbs/src/ast/declarations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use crate::ast::annotation::Annotation;
use crate::ast::comment::Comment;
use crate::ast::location::{
AliasDeclarationLocation, ClassDeclarationLocation, ClassSuperLocation,
ConstantDeclarationLocation, GlobalDeclarationLocation, InterfaceDeclarationLocation,
ModuleDeclarationLocation, ModuleSelfLocation, TypeAliasDeclarationLocation,
};
use crate::ast::members::Member;
use crate::ast::type_param::TypeParam;
use crate::ast::types::Type;
use crate::ids::{SymbolId, TypeName};

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum Declaration {
Class(ClassDeclaration),
Module(ModuleDeclaration),
Interface(InterfaceDeclaration),
Constant(ConstantDeclaration),
Global(GlobalDeclaration),
TypeAlias(TypeAliasDeclaration),
ClassAlias(ClassAliasDeclaration),
ModuleAlias(ModuleAliasDeclaration),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum ClassMember {
Member(Member),
Declaration(Declaration),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum ModuleMember {
Member(Member),
Declaration(Declaration),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ClassSuper {
pub name: TypeName,
pub args: Vec<Type>,
pub location: Option<ClassSuperLocation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ClassDeclaration {
pub name: TypeName,
pub type_params: Vec<TypeParam>,
pub members: Vec<ClassMember>,
pub super_class: Option<ClassSuper>,
pub annotations: Vec<Annotation>,
pub location: Option<ClassDeclarationLocation>,
pub comment: Option<Comment>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ModuleSelf {
pub name: TypeName,
pub args: Vec<Type>,
pub location: Option<ModuleSelfLocation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ModuleDeclaration {
pub name: TypeName,
pub type_params: Vec<TypeParam>,
pub members: Vec<ModuleMember>,
pub location: Option<ModuleDeclarationLocation>,
pub annotations: Vec<Annotation>,
pub self_types: Vec<ModuleSelf>,
pub comment: Option<Comment>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct InterfaceDeclaration {
pub name: TypeName,
pub type_params: Vec<TypeParam>,
pub members: Vec<Member>,
pub annotations: Vec<Annotation>,
pub location: Option<InterfaceDeclarationLocation>,
pub comment: Option<Comment>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct TypeAliasDeclaration {
pub name: TypeName,
pub type_params: Vec<TypeParam>,
pub ty: Type,
pub annotations: Vec<Annotation>,
pub location: Option<TypeAliasDeclarationLocation>,
pub comment: Option<Comment>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ConstantDeclaration {
pub name: TypeName,
pub ty: Type,
pub location: Option<ConstantDeclarationLocation>,
pub comment: Option<Comment>,
pub annotations: Vec<Annotation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct GlobalDeclaration {
pub name: SymbolId,
pub ty: Type,
pub location: Option<GlobalDeclarationLocation>,
pub comment: Option<Comment>,
pub annotations: Vec<Annotation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ClassAliasDeclaration {
pub new_name: TypeName,
pub old_name: TypeName,
pub location: Option<AliasDeclarationLocation>,
pub comment: Option<Comment>,
pub annotations: Vec<Annotation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ModuleAliasDeclaration {
pub new_name: TypeName,
pub old_name: TypeName,
pub location: Option<AliasDeclarationLocation>,
pub comment: Option<Comment>,
pub annotations: Vec<Annotation>,
}
42 changes: 42 additions & 0 deletions rust/ruby-rbs/src/ast/directives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::ast::location::{
ResolveTypeNamesDirectiveLocation, UseDirectiveLocation, UseSingleClauseLocation,
UseWildcardClauseLocation,
};
use crate::ids::{SymbolId, TypeName};

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum Directive {
Use(UseDirective),
ResolveTypeNames(ResolveTypeNamesDirective),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct UseDirective {
pub clauses: Vec<UseClause>,
pub location: Option<UseDirectiveLocation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum UseClause {
Single(UseSingleClause),
Wildcard(UseWildcardClause),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct UseSingleClause {
pub type_name: TypeName,
pub new_name: Option<SymbolId>,
pub location: Option<UseSingleClauseLocation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct UseWildcardClause {
pub namespace: TypeName,
pub location: Option<UseWildcardClauseLocation>,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ResolveTypeNamesDirective {
pub value: bool,
pub location: Option<ResolveTypeNamesDirectiveLocation>,
}
Loading
Loading