Skip to content

Commit e1373f0

Browse files
authored
Merge pull request #2985 from ruby/rust-ast
2 parents d1bcab9 + a401d94 commit e1373f0

13 files changed

Lines changed: 2680 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::ast::location::LocationRange;
2+
use crate::ids::SymbolId;
3+
4+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5+
pub struct Annotation {
6+
pub string: SymbolId,
7+
pub location: Option<LocationRange>,
8+
}

rust/ruby-rbs/src/ast/comment.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::ast::location::LocationRange;
2+
use crate::ids::SymbolId;
3+
4+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5+
pub struct Comment {
6+
pub string: SymbolId,
7+
pub location: Option<LocationRange>,
8+
}

rust/ruby-rbs/src/ast/convert.rs

Lines changed: 1255 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
use crate::ast::annotation::Annotation;
2+
use crate::ast::comment::Comment;
3+
use crate::ast::location::{
4+
AliasDeclarationLocation, ClassDeclarationLocation, ClassSuperLocation,
5+
ConstantDeclarationLocation, GlobalDeclarationLocation, InterfaceDeclarationLocation,
6+
ModuleDeclarationLocation, ModuleSelfLocation, TypeAliasDeclarationLocation,
7+
};
8+
use crate::ast::members::Member;
9+
use crate::ast::type_param::TypeParam;
10+
use crate::ast::types::Type;
11+
use crate::ids::{SymbolId, TypeName};
12+
13+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
14+
pub enum Declaration {
15+
Class(ClassDeclaration),
16+
Module(ModuleDeclaration),
17+
Interface(InterfaceDeclaration),
18+
Constant(ConstantDeclaration),
19+
Global(GlobalDeclaration),
20+
TypeAlias(TypeAliasDeclaration),
21+
ClassAlias(ClassAliasDeclaration),
22+
ModuleAlias(ModuleAliasDeclaration),
23+
}
24+
25+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
26+
pub enum ClassMember {
27+
Member(Member),
28+
Declaration(Declaration),
29+
}
30+
31+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
32+
pub enum ModuleMember {
33+
Member(Member),
34+
Declaration(Declaration),
35+
}
36+
37+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
38+
pub struct ClassSuper {
39+
pub name: TypeName,
40+
pub args: Vec<Type>,
41+
pub location: Option<ClassSuperLocation>,
42+
}
43+
44+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
45+
pub struct ClassDeclaration {
46+
pub name: TypeName,
47+
pub type_params: Vec<TypeParam>,
48+
pub members: Vec<ClassMember>,
49+
pub super_class: Option<ClassSuper>,
50+
pub annotations: Vec<Annotation>,
51+
pub location: Option<ClassDeclarationLocation>,
52+
pub comment: Option<Comment>,
53+
}
54+
55+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
56+
pub struct ModuleSelf {
57+
pub name: TypeName,
58+
pub args: Vec<Type>,
59+
pub location: Option<ModuleSelfLocation>,
60+
}
61+
62+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
63+
pub struct ModuleDeclaration {
64+
pub name: TypeName,
65+
pub type_params: Vec<TypeParam>,
66+
pub members: Vec<ModuleMember>,
67+
pub location: Option<ModuleDeclarationLocation>,
68+
pub annotations: Vec<Annotation>,
69+
pub self_types: Vec<ModuleSelf>,
70+
pub comment: Option<Comment>,
71+
}
72+
73+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
74+
pub struct InterfaceDeclaration {
75+
pub name: TypeName,
76+
pub type_params: Vec<TypeParam>,
77+
pub members: Vec<Member>,
78+
pub annotations: Vec<Annotation>,
79+
pub location: Option<InterfaceDeclarationLocation>,
80+
pub comment: Option<Comment>,
81+
}
82+
83+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
84+
pub struct TypeAliasDeclaration {
85+
pub name: TypeName,
86+
pub type_params: Vec<TypeParam>,
87+
pub ty: Type,
88+
pub annotations: Vec<Annotation>,
89+
pub location: Option<TypeAliasDeclarationLocation>,
90+
pub comment: Option<Comment>,
91+
}
92+
93+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
94+
pub struct ConstantDeclaration {
95+
pub name: TypeName,
96+
pub ty: Type,
97+
pub location: Option<ConstantDeclarationLocation>,
98+
pub comment: Option<Comment>,
99+
pub annotations: Vec<Annotation>,
100+
}
101+
102+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
103+
pub struct GlobalDeclaration {
104+
pub name: SymbolId,
105+
pub ty: Type,
106+
pub location: Option<GlobalDeclarationLocation>,
107+
pub comment: Option<Comment>,
108+
pub annotations: Vec<Annotation>,
109+
}
110+
111+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
112+
pub struct ClassAliasDeclaration {
113+
pub new_name: TypeName,
114+
pub old_name: TypeName,
115+
pub location: Option<AliasDeclarationLocation>,
116+
pub comment: Option<Comment>,
117+
pub annotations: Vec<Annotation>,
118+
}
119+
120+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
121+
pub struct ModuleAliasDeclaration {
122+
pub new_name: TypeName,
123+
pub old_name: TypeName,
124+
pub location: Option<AliasDeclarationLocation>,
125+
pub comment: Option<Comment>,
126+
pub annotations: Vec<Annotation>,
127+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::ast::location::{
2+
ResolveTypeNamesDirectiveLocation, UseDirectiveLocation, UseSingleClauseLocation,
3+
UseWildcardClauseLocation,
4+
};
5+
use crate::ids::{SymbolId, TypeName};
6+
7+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
8+
pub enum Directive {
9+
Use(UseDirective),
10+
ResolveTypeNames(ResolveTypeNamesDirective),
11+
}
12+
13+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
14+
pub struct UseDirective {
15+
pub clauses: Vec<UseClause>,
16+
pub location: Option<UseDirectiveLocation>,
17+
}
18+
19+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
20+
pub enum UseClause {
21+
Single(UseSingleClause),
22+
Wildcard(UseWildcardClause),
23+
}
24+
25+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
26+
pub struct UseSingleClause {
27+
pub type_name: TypeName,
28+
pub new_name: Option<SymbolId>,
29+
pub location: Option<UseSingleClauseLocation>,
30+
}
31+
32+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
33+
pub struct UseWildcardClause {
34+
pub namespace: TypeName,
35+
pub location: Option<UseWildcardClauseLocation>,
36+
}
37+
38+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
39+
pub struct ResolveTypeNamesDirective {
40+
pub value: bool,
41+
pub location: Option<ResolveTypeNamesDirectiveLocation>,
42+
}

0 commit comments

Comments
 (0)