Skip to content

Inline #2377

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

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft

Inline #2377

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a5d2545
bundle prism
soutaro Jan 16, 2025
8bc685f
Update Steepfile
soutaro Jan 16, 2025
f24735d
Add syntax and parser
soutaro Jan 16, 2025
369a377
Add `Constant#type`
soutaro Jan 16, 2025
edce3a1
Update `Environment`
soutaro Jan 17, 2025
8dc1f67
DefinitionBuilder
soutaro Jan 18, 2025
b59256c
WIP
soutaro Jan 21, 2025
de7979e
Bump version to 4.0
soutaro Jan 21, 2025
fa21e59
Update `steep/Gemfile` for ruby-lsp environment
soutaro Jan 21, 2025
81585b8
:cat2:
soutaro Feb 5, 2025
84cde79
Add CommentBlock
soutaro Feb 12, 2025
f85fa0d
Add rbs-inline keywords, no changes on parser
soutaro Feb 12, 2025
7cb29b3
Working for parser
soutaro Feb 14, 2025
504f29f
WIP
soutaro Feb 19, 2025
c0154c2
Support generic module definition
soutaro Feb 19, 2025
598416a
Implement module-self annotation parsing
soutaro Feb 19, 2025
d009ef1
Fix module parsing
soutaro Feb 20, 2025
67a38fa
Parse module-self annotation
soutaro Feb 20, 2025
aa0565a
Implement `@rbs inherits` annotation parsing
soutaro Feb 20, 2025
f66233f
module self parsing
soutaro Feb 20, 2025
2b87b4f
Super annotation
soutaro Feb 20, 2025
4816d5a
Let `Buffer` can be nested
soutaro Feb 21, 2025
cb4d1a7
`module-self` annotation support
soutaro Feb 21, 2025
e1bd844
ivars: Implement annotation parser
soutaro Feb 21, 2025
1450863
Buffer/location fixup
soutaro Feb 21, 2025
39bc718
ivars: InlineParser
soutaro Feb 21, 2025
e626997
ivars: Fix DefinitionBuilder
soutaro Feb 21, 2025
e5ee033
@rbs!: annotation parsing
soutaro Feb 25, 2025
73636d7
@rbs!: implement inline parser
soutaro Feb 25, 2025
8777fee
Load declarations from embedded RBS
soutaro Feb 27, 2025
b39a58b
@rbs!: ancestor builder
soutaro Feb 27, 2025
f09c9f4
@rbs!: method builder
soutaro Feb 27, 2025
b9d0bc3
@rbs!: definition builder
soutaro Feb 27, 2025
0d14123
WIP
soutaro Mar 3, 2025
8b33b87
Limit singleton class members
soutaro Mar 19, 2025
bf124b5
WIP: singleton method definition ast
soutaro Mar 24, 2025
ad341f4
Fix type parameter handling
soutaro Mar 25, 2025
4b9f9fd
Method definition specific `private`/`public` visibility
soutaro Mar 27, 2025
5a39ba3
Add attribute members
soutaro Apr 1, 2025
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
Prev Previous commit
Next Next commit
@RBS!: annotation parsing
  • Loading branch information
soutaro committed Mar 19, 2025
commit e5ee033207d04713dac4edcc233aa8a8d2999bf8
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,8 @@ nodes:
- name: colon_location
- name: type
- name: comment
- name: RBS::AST::Ruby::Annotation::EmbeddedRBSAnnotation
fields:
- name: location
- name: prefix_location
- name: members
18 changes: 14 additions & 4 deletions ext/rbs_extension/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2456,10 +2456,10 @@ static VALUE parse_nested_decl(parserstate *state, const char *nested_in, positi
| `public`
| `private`
*/
static VALUE parse_module_members(parserstate *state) {
static VALUE parse_module_members(parserstate *state, enum TokenType end_token) {
VALUE members = EMPTY_ARRAY;

while (state->next_token.type != kEND) {
while (state->next_token.type != end_token) {
VALUE annotations = EMPTY_ARRAY;
position annot_pos = NullPosition;
parse_annotations(state, &annotations, &annot_pos);
Expand Down Expand Up @@ -2562,7 +2562,7 @@ static VALUE parse_module_decl0(parserstate *state, range keyword_range, VALUE m
self_types_range = NULL_RANGE;
}

VALUE members = parse_module_members(state);
VALUE members = parse_module_members(state, kEND);

parser_advance_assert(state, kEND);
range end_range = state->current_token.range;
Expand Down Expand Up @@ -2682,7 +2682,7 @@ static VALUE parse_class_decl0(parserstate *state, range keyword_range, VALUE na
range lt_range;
VALUE super = parse_class_decl_super(state, &lt_range);

VALUE members = parse_module_members(state);
VALUE members = parse_module_members(state, kEND);

parser_advance_assert(state, kEND);

Expand Down Expand Up @@ -3519,6 +3519,16 @@ VALUE parse_inline_annotation(parserstate *state) {
}
case kATRBSB: {
// @rbs!
range prefix_range = state->next_token.range;
parser_advance_assert(state, kATRBSB);

VALUE members = parse_module_members(state, pEOF);

return rbs_ast_ruby_annotation_embedded_rbs_annotation(
rbs_new_location(state->buffer, (range) { .start = prefix_range.start, .end = state->current_token.range.end }),
rbs_new_location(state->buffer, prefix_range),
members
);
}
case pCOLON: {
// :
Expand Down
1 change: 1 addition & 0 deletions include/rbs/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern VALUE RBS_AST_Ruby_Annotation_ClassIvarTypeAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_ClassVarTypeAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_ColonMethodTypeAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_DoubleSplatParamTypeAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_EmbeddedRBSAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_GenericAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_InheritsAnnotation;
extern VALUE RBS_AST_Ruby_Annotation_IvarTypeAnnotation;
Expand Down
1 change: 1 addition & 0 deletions include/rbs/ruby_objs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ VALUE rbs_ast_ruby_annotation_class_ivar_type_annotation(VALUE location, VALUE p
VALUE rbs_ast_ruby_annotation_class_var_type_annotation(VALUE location, VALUE prefix_location, VALUE var_name_location, VALUE colon_location, VALUE type, VALUE comment);
VALUE rbs_ast_ruby_annotation_colon_method_type_annotation(VALUE location, VALUE prefix_location, VALUE annotations, VALUE method_type);
VALUE rbs_ast_ruby_annotation_double_splat_param_type_annotation(VALUE location, VALUE prefix_location, VALUE operator_location, VALUE param_name_location, VALUE colon_location, VALUE type, VALUE comment);
VALUE rbs_ast_ruby_annotation_embedded_rbs_annotation(VALUE location, VALUE prefix_location, VALUE members);
VALUE rbs_ast_ruby_annotation_generic_annotation(VALUE location, VALUE prefix_location, VALUE generic_location, VALUE unchecked_location, VALUE variance_location, VALUE name_location, VALUE upper_bound_operator_location, VALUE upper_bound, VALUE default_type_operator_location, VALUE default_type, VALUE comment);
VALUE rbs_ast_ruby_annotation_inherits_annotation(VALUE location, VALUE prefix_location, VALUE inherits_location, VALUE type_name, VALUE type_name_location, VALUE open_paren_location, VALUE type_args, VALUE close_paren_location, VALUE comment);
VALUE rbs_ast_ruby_annotation_ivar_type_annotation(VALUE location, VALUE prefix_location, VALUE var_name_location, VALUE colon_location, VALUE type, VALUE comment);
Expand Down
9 changes: 9 additions & 0 deletions lib/rbs/ast/ruby/annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ def initialize(location:, prefix_location:, self_location:, dot_location:, var_n
@comment = comment
end
end

class EmbeddedRBSAnnotation < Base
attr_reader :members

def initialize(location:, prefix_location:, members:)
super(location, prefix_location)
@members = members
end
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions sig/ast/ruby/annotation.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@ module RBS
comment: Location?
) -> void
end

class EmbeddedRBSAnnotation < Base
type member = AST::Declarations::t | AST::Members::t

attr_reader members: Array[member]

def initialize: (location: Location, prefix_location: Location, members: Array[member]) -> void
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ VALUE RBS_AST_Ruby_Annotation_ClassIvarTypeAnnotation;
VALUE RBS_AST_Ruby_Annotation_ClassVarTypeAnnotation;
VALUE RBS_AST_Ruby_Annotation_ColonMethodTypeAnnotation;
VALUE RBS_AST_Ruby_Annotation_DoubleSplatParamTypeAnnotation;
VALUE RBS_AST_Ruby_Annotation_EmbeddedRBSAnnotation;
VALUE RBS_AST_Ruby_Annotation_GenericAnnotation;
VALUE RBS_AST_Ruby_Annotation_InheritsAnnotation;
VALUE RBS_AST_Ruby_Annotation_IvarTypeAnnotation;
Expand Down Expand Up @@ -151,6 +152,7 @@ void rbs__init_constants(void) {
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_ClassVarTypeAnnotation, RBS_AST_Ruby_Annotation, "ClassVarTypeAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_ColonMethodTypeAnnotation, RBS_AST_Ruby_Annotation, "ColonMethodTypeAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_DoubleSplatParamTypeAnnotation, RBS_AST_Ruby_Annotation, "DoubleSplatParamTypeAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_EmbeddedRBSAnnotation, RBS_AST_Ruby_Annotation, "EmbeddedRBSAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_GenericAnnotation, RBS_AST_Ruby_Annotation, "GenericAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_InheritsAnnotation, RBS_AST_Ruby_Annotation, "InheritsAnnotation");
IMPORT_CONSTANT(RBS_AST_Ruby_Annotation_IvarTypeAnnotation, RBS_AST_Ruby_Annotation, "IvarTypeAnnotation");
Expand Down
13 changes: 13 additions & 0 deletions src/ruby_objs.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,19 @@ VALUE rbs_ast_ruby_annotation_double_splat_param_type_annotation(VALUE location,
);
}

VALUE rbs_ast_ruby_annotation_embedded_rbs_annotation(VALUE location, VALUE prefix_location, VALUE members) {
VALUE _init_kwargs = rb_hash_new();
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("prefix_location")), prefix_location);
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("members")), members);

return CLASS_NEW_INSTANCE(
RBS_AST_Ruby_Annotation_EmbeddedRBSAnnotation,
1,
&_init_kwargs
);
}

VALUE rbs_ast_ruby_annotation_generic_annotation(VALUE location, VALUE prefix_location, VALUE generic_location, VALUE unchecked_location, VALUE variance_location, VALUE name_location, VALUE upper_bound_operator_location, VALUE upper_bound, VALUE default_type_operator_location, VALUE default_type, VALUE comment) {
VALUE _init_kwargs = rb_hash_new();
rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location);
Expand Down
15 changes: 14 additions & 1 deletion test/rbs/inline_annotation_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ def test_instance_variable_annotation
end

def test_embbed_syntax
omit("Implement `@rbs!` annotation")
Parser.parse_inline(<<~RBS, 0...).tap do |annot|
@rbs!
interface _Hello
Expand All @@ -395,6 +394,20 @@ def foo: () -> void

type world = top
RBS

assert_instance_of AST::Ruby::Annotation::EmbeddedRBSAnnotation, annot

assert_equal <<~RBS.chomp, annot.location.source
@rbs!
interface _Hello
def foo: () -> void
end

type world = top
RBS

assert_equal "@rbs!", annot.prefix_location.source
assert_equal [AST::Declarations::Interface, AST::Declarations::TypeAlias], annot.members.map(&:class)
end
end

Expand Down