Skip to content

Commit

Permalink
special syntax for Data and Struct subclasses
Browse files Browse the repository at this point in the history
allows declaring and typing variables, inject inherited methods OTTB
  • Loading branch information
HoneyryderChuck committed Nov 11, 2024
1 parent 36a3d5f commit f1425c8
Show file tree
Hide file tree
Showing 6 changed files with 1,372 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/process.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ end
# <!-- rdoc-file=process.c -->
# Placeholder for rusage
#
class Process::Tms < Struct[Float]
class Process::Tms < Struct(utime: Float, stime: Float, cutime: Float, cstime: Float)
end

class Process::Waiter < Thread
Expand Down
16 changes: 15 additions & 1 deletion ext/rbs_extension/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl

/**
* class_instance_name ::= {} <class_name>
* | {} Data `(` kwarg args `)`
* | {} Struct `(` kwarg args `)`
* | {} class_name `[` type args <`]`>
*
* @param kind
Expand All @@ -1756,7 +1758,19 @@ void class_instance_name(parserstate *state, TypeNameKind kind, VALUE *name, VAL

*name = parse_type_name(state, kind, name_range);

if (state->next_token.type == pLBRACKET) {
if (CLASS_OF(*name) == RBS_TypeName && rb_funcall(*name, rb_intern("data?"), 0) == Qtrue) {
parser_advance_assert(state, pLPAREN);
args_range->start = state->current_token.range.start;
*args = parse_record_attributes(state);
parser_advance_assert(state, pRPAREN);
args_range->end = state->current_token.range.end;
} else if (CLASS_OF(*name) == RBS_TypeName && rb_funcall(*name, rb_intern("struct?"), 0) == Qtrue) {
parser_advance_assert(state, pLPAREN);
args_range->start = state->current_token.range.start;
*args = parse_record_attributes(state);
parser_advance_assert(state, pRPAREN);
args_range->end = state->current_token.range.end;
} else if (state->next_token.type == pLBRACKET) {
parser_advance(state);
args_range->start = state->current_token.range.start;
parse_type_list(state, pRBRACKET, args);
Expand Down
Loading

0 comments on commit f1425c8

Please sign in to comment.