Skip to content

Commit

Permalink
Add __todo__ type
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Sep 15, 2023
1 parent 1c9b959 commit d777416
Show file tree
Hide file tree
Showing 9 changed files with 662 additions and 571 deletions.
1,193 changes: 624 additions & 569 deletions ext/rbs_extension/lexer.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ext/rbs_extension/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum TokenType {
kVOID, /* void */
kUSE, /* use */
kAS, /* as */
k__TODO__, /* __todo__ */

tLIDENT, /* Identifiers starting with lower case */
tUIDENT, /* Identifiers starting with upper case */
Expand Down
1 change: 1 addition & 0 deletions ext/rbs_extension/lexer.re
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ start:
"void" { return next_token(state, kVOID); }
"use" { return next_token(state, kUSE); }
"as" { return next_token(state, kAS); }
"__todo__" { return next_token(state, k__TODO__); }
dqstring = ["] ("\\"[abefnrstv"\\] | [^"\\\x00])* ["];
sqstring = ['] ("\\"['\\] | [^'\x00])* ['];
Expand Down
1 change: 1 addition & 0 deletions ext/rbs_extension/lexstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static const char *RBS_TOKENTYPE_NAMES[] = {
"kVOID", /* void */
"kUSE", /* use */
"kAS", /* as */
"k__TODO__", /* __todo__ */

"tLIDENT", /* Identifiers starting with lower case */
"tUIDENT", /* Identifiers starting with upper case */
Expand Down
6 changes: 6 additions & 0 deletions ext/rbs_extension/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
case kUNTYPED: \
case kUSE: \
case kAS: \
case k__TODO__: \
/* nop */

typedef struct {
Expand Down Expand Up @@ -898,6 +899,11 @@ static VALUE parse_simple(parserstate *state) {
return rbs_base_type(RBS_Types_Bases_Void, rbs_location_current_token(state));
case kUNTYPED:
return rbs_base_type(RBS_Types_Bases_Any, rbs_location_current_token(state));
case k__TODO__: {
VALUE type = rbs_base_type(RBS_Types_Bases_Any, rbs_location_current_token(state));
rb_funcall(type, rb_intern("todo!"), 0);
return type;
}
case tINTEGER: {
VALUE literal = rb_funcall(
string_of_loc(state, state->current_token.range.start, state->current_token.range.end),
Expand Down
13 changes: 11 additions & 2 deletions lib/rbs/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def to_s(level = 0)
when Types::Bases::Void
'void'
when Types::Bases::Any
'untyped'
raise
when Types::Bases::Nil
'nil'
when Types::Bases::Top
Expand All @@ -94,7 +94,16 @@ def to_s(level = 0)

class Bool < Base; end
class Void < Base; end
class Any < Base; end
class Any < Base
def to_s(level=0)
@string || "untyped"
end

def todo!
@string = '__todo__'
self
end
end
class Nil < Base; end
class Top < Base; end
class Bottom < Base; end
Expand Down
3 changes: 3 additions & 0 deletions sig/types.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ module RBS
end

class Any < Base
@string: String?

def todo!: () -> self
end

class Nil < Base
Expand Down
7 changes: 7 additions & 0 deletions test/rbs/type_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,11 @@ def test_location_children
assert_equal "::Foo", type.location[:name].source
end
end

def test_untyped__todo
Parser.parse_type("__todo__").yield_self do |type|
assert_instance_of Types::Bases::Any, type
assert_equal "__todo__", type.location.source
end
end
end
8 changes: 8 additions & 0 deletions test/rbs/writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,12 @@ def test_use
$hoge: Foo
SIG
end

def test___todo__
assert_writer <<-SIG
class Foo
attr_reader name: __todo__
end
SIG
end
end

0 comments on commit d777416

Please sign in to comment.