diff --git a/Gemfile.lock b/Gemfile.lock index 0dd2f94e5..cf1190bbe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,13 +34,13 @@ GEM benchmark-ips (2.14.0) bigdecimal (3.1.9) concurrent-ruby (1.3.5) - connection_pool (2.5.0) - csv (3.3.3) + connection_pool (2.5.1) + csv (3.3.4) dbm (1.1.0) diff-lcs (1.6.1) digest (3.2.0) drb (2.2.1) - ffi (1.17.1) + ffi (1.17.2) fileutils (1.7.3) goodcheck (3.1.0) marcel (>= 1.0, < 2.0) @@ -69,12 +69,12 @@ GEM net-smtp (0.5.1) net-protocol nkf (0.2.0) - nokogiri (1.18.7) + nokogiri (1.18.8) mini_portile2 (~> 2.8.2) racc (~> 1.4) ostruct (0.6.1) - parallel (1.26.3) - parser (3.3.7.4) + parallel (1.27.0) + parser (3.3.8.0) ast (~> 2.4.1) racc pathname (0.4.0) @@ -90,7 +90,7 @@ GEM racc (1.8.1) rainbow (3.1.1) rake (13.2.1) - rake-compiler (1.2.9) + rake-compiler (1.3.0) rake rb-fsevent (0.11.2) rb-inotify (0.11.1) @@ -111,7 +111,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.2) - rubocop (1.75.2) + rubocop (1.75.3) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -122,7 +122,7 @@ GEM rubocop-ast (>= 1.44.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.44.0) + rubocop-ast (1.44.1) parser (>= 3.3.7.2) prism (~> 1.4) rubocop-on-rbs (1.5.0) @@ -155,9 +155,9 @@ GEM strscan (>= 1.0.0) terminal-table (>= 2, < 5) uri (>= 0.12.0) - stringio (3.1.6) + stringio (3.1.7) strong_json (2.1.2) - strscan (3.1.2) + strscan (3.1.3) tempfile (0.3.1) terminal-table (4.0.0) unicode-display_width (>= 1.1.1, < 4) diff --git a/config.yml b/config.yml index 682ae299e..389f2033e 100644 --- a/config.yml +++ b/config.yml @@ -443,3 +443,45 @@ nodes: fields: - name: name c_type: rbs_ast_symbol + - name: RBS::AST::Ruby::Annotations::NodeTypeAssertion + fields: + - name: prefix_location + c_type: rbs_location + - name: type + c_type: rbs_node + - name: RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation + fields: + - name: prefix_location + c_type: rbs_location + - name: annotations + c_type: rbs_node_list + - name: method_type + c_type: rbs_node + - name: RBS::AST::Ruby::Annotations::MethodTypesAnnotation + fields: + - name: prefix_location + c_type: rbs_location + - name: overloads + c_type: rbs_node_list + - name: vertical_bar_locations + c_type: rbs_location_list + - name: RBS::AST::Ruby::Annotations::SkipAnnotation + fields: + - name: prefix_location + c_type: rbs_location + - name: skip_location + c_type: rbs_location + - name: comment_location + c_type: rbs_location + - name: RBS::AST::Ruby::Annotations::ReturnTypeAnnotation + fields: + - name: prefix_location + c_type: rbs_location + - name: return_location + c_type: rbs_location + - name: colon_location + c_type: rbs_location + - name: return_type + c_type: rbs_node + - name: comment_location + c_type: rbs_location diff --git a/ext/rbs_extension/ast_translation.c b/ext/rbs_extension/ast_translation.c index 1cd1e68e2..3a3d0c83e 100644 --- a/ext/rbs_extension/ast_translation.c +++ b/ext/rbs_extension/ast_translation.c @@ -44,6 +44,10 @@ VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash) } VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *source_loc) { + if (source_loc == NULL) { + return Qnil; + } + VALUE new_loc = rbs_new_location(ctx.buffer, source_loc->rg); rbs_loc *new_loc_struct = rbs_check_location(new_loc); @@ -55,6 +59,20 @@ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *so return new_loc; } +VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_location_list_t *list) { + VALUE ruby_array = rb_ary_new(); + + if (list == NULL) { + return ruby_array; + } + + for (rbs_location_list_node_t *n = list->head; n != NULL; n = n->next) { + rb_ary_push(ruby_array, rbs_loc_to_ruby_location(ctx, n->loc)); + } + + return ruby_array; +} + #ifdef RB_PASS_KEYWORDS // Ruby 2.7 or later #define CLASS_NEW_INSTANCE(klass, argc, argv)\ @@ -586,6 +604,87 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan &h ); } + case RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION: { + rbs_ast_ruby_annotations_colon_method_type_annotation_t *node = (rbs_ast_ruby_annotations_colon_method_type_annotation_t *)instance; + + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations)); + rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node + + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, + 1, + &h + ); + } + case RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION: { + rbs_ast_ruby_annotations_method_types_annotation_t *node = (rbs_ast_ruby_annotations_method_types_annotation_t *)instance; + + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads)); + rb_hash_aset(h, ID2SYM(rb_intern("vertical_bar_locations")), rbs_location_list_to_ruby_array(ctx, node->vertical_bar_locations)); + + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_MethodTypesAnnotation, + 1, + &h + ); + } + case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION: { + rbs_ast_ruby_annotations_node_type_assertion_t *node = (rbs_ast_ruby_annotations_node_type_assertion_t *)instance; + + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node + + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_NodeTypeAssertion, + 1, + &h + ); + } + case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: { + rbs_ast_ruby_annotations_return_type_annotation_t *node = (rbs_ast_ruby_annotations_return_type_annotation_t *)instance; + + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("return_location")), rbs_loc_to_ruby_location(ctx, node->return_location)); + rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location)); + rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node + rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); + + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, + 1, + &h + ); + } + case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION: { + rbs_ast_ruby_annotations_skip_annotation_t *node = (rbs_ast_ruby_annotations_skip_annotation_t *)instance; + + VALUE h = rb_hash_new(); + rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location)); + rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location)); + rb_hash_aset(h, ID2SYM(rb_intern("skip_location")), rbs_loc_to_ruby_location(ctx, node->skip_location)); + rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location)); + + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_SkipAnnotation, + 1, + &h + ); + } case RBS_AST_STRING: { rbs_ast_string_t *string_node = (rbs_ast_string_t *) instance; rbs_string_t s = string_node->string; diff --git a/ext/rbs_extension/class_constants.c b/ext/rbs_extension/class_constants.c index 1ff669da2..b406aa832 100644 --- a/ext/rbs_extension/class_constants.c +++ b/ext/rbs_extension/class_constants.c @@ -14,6 +14,8 @@ VALUE RBS_AST; VALUE RBS_AST_Declarations; VALUE RBS_AST_Directives; VALUE RBS_AST_Members; +VALUE RBS_AST_Ruby; +VALUE RBS_AST_Ruby_Annotations; VALUE RBS_Parser; VALUE RBS_Types; VALUE RBS_Types_Bases; @@ -47,6 +49,11 @@ VALUE RBS_AST_Members_MethodDefinition_Overload; VALUE RBS_AST_Members_Prepend; VALUE RBS_AST_Members_Private; VALUE RBS_AST_Members_Public; +VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation; +VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation; +VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion; +VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation; +VALUE RBS_AST_Ruby_Annotations_SkipAnnotation; VALUE RBS_AST_TypeParam; VALUE RBS_MethodType; VALUE RBS_Namespace; @@ -89,6 +96,8 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Declarations, RBS_AST, "Declarations"); IMPORT_CONSTANT(RBS_AST_Directives, RBS_AST, "Directives"); IMPORT_CONSTANT(RBS_AST_Members, RBS_AST, "Members"); + IMPORT_CONSTANT(RBS_AST_Ruby, RBS_AST, "Ruby"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations, RBS_AST_Ruby, "Annotations"); IMPORT_CONSTANT(RBS_Types, RBS, "Types"); IMPORT_CONSTANT(RBS_Types_Bases, RBS_Types, "Bases"); @@ -121,6 +130,11 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Members_Prepend, RBS_AST_Members, "Prepend"); IMPORT_CONSTANT(RBS_AST_Members_Private, RBS_AST_Members, "Private"); IMPORT_CONSTANT(RBS_AST_Members_Public, RBS_AST_Members, "Public"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, RBS_AST_Ruby_Annotations, "ColonMethodTypeAnnotation"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_MethodTypesAnnotation, RBS_AST_Ruby_Annotations, "MethodTypesAnnotation"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_NodeTypeAssertion, RBS_AST_Ruby_Annotations, "NodeTypeAssertion"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, RBS_AST_Ruby_Annotations, "ReturnTypeAnnotation"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_SkipAnnotation, RBS_AST_Ruby_Annotations, "SkipAnnotation"); IMPORT_CONSTANT(RBS_AST_TypeParam, RBS_AST, "TypeParam"); IMPORT_CONSTANT(RBS_MethodType, RBS, "MethodType"); IMPORT_CONSTANT(RBS_Namespace, RBS, "Namespace"); diff --git a/ext/rbs_extension/class_constants.h b/ext/rbs_extension/class_constants.h index de571b4ca..b59e4f706 100644 --- a/ext/rbs_extension/class_constants.h +++ b/ext/rbs_extension/class_constants.h @@ -16,6 +16,8 @@ extern VALUE RBS_AST; extern VALUE RBS_AST_Declarations; extern VALUE RBS_AST_Directives; extern VALUE RBS_AST_Members; +extern VALUE RBS_AST_Ruby; +extern VALUE RBS_AST_Ruby_Annotations; extern VALUE RBS_Types; extern VALUE RBS_Types_Bases; extern VALUE RBS_ParsingError; @@ -49,6 +51,11 @@ extern VALUE RBS_AST_Members_MethodDefinition_Overload; extern VALUE RBS_AST_Members_Prepend; extern VALUE RBS_AST_Members_Private; extern VALUE RBS_AST_Members_Public; +extern VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation; +extern VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation; +extern VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion; +extern VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation; +extern VALUE RBS_AST_Ruby_Annotations_SkipAnnotation; extern VALUE RBS_AST_TypeParam; extern VALUE RBS_MethodType; extern VALUE RBS_Namespace; diff --git a/ext/rbs_extension/legacy_location.c b/ext/rbs_extension/legacy_location.c index 187c4fca5..ecfd5d6d8 100644 --- a/ext/rbs_extension/legacy_location.c +++ b/ext/rbs_extension/legacy_location.c @@ -305,8 +305,8 @@ void rbs__init_location(void) { rb_define_private_method(RBS_Location, "initialize", location_initialize, 3); rb_define_private_method(RBS_Location, "initialize_copy", location_initialize_copy, 1); rb_define_method(RBS_Location, "buffer", location_buffer, 0); - rb_define_method(RBS_Location, "start_pos", location_start_pos, 0); - rb_define_method(RBS_Location, "end_pos", location_end_pos, 0); + rb_define_method(RBS_Location, "_start_pos", location_start_pos, 0); + rb_define_method(RBS_Location, "_end_pos", location_end_pos, 0); rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3); rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3); rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1); diff --git a/ext/rbs_extension/main.c b/ext/rbs_extension/main.c index 5360e69f2..8ab04615d 100644 --- a/ext/rbs_extension/main.c +++ b/ext/rbs_extension/main.c @@ -272,6 +272,92 @@ static VALUE rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE start_pos return result; } +static VALUE parse_inline_leading_annotation_try(VALUE a) { + struct parse_type_arg *arg = (struct parse_type_arg *) a; + rbs_parser_t *parser = arg->parser; + + rbs_ast_ruby_annotations_t *annotation = NULL; + bool success = rbs_parse_inline_leading_annotation(parser, &annotation); + + raise_error_if_any(parser, arg->buffer); + + if (!success || annotation == NULL) { + return Qnil; + } + + rbs_translation_context_t ctx = rbs_translation_context_create( + &parser->constant_pool, + arg->buffer, + arg->encoding + ); + + return rbs_struct_to_ruby_value(ctx, (rbs_node_t *) annotation); +} + +static VALUE rbsparser_parse_inline_leading_annotation(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables) { + VALUE string = rb_funcall(buffer, rb_intern("content"), 0); + StringValue(string); + rb_encoding *encoding = rb_enc_get(string); + + rbs_parser_t *parser = alloc_parser_from_buffer(buffer, FIX2INT(start_pos), FIX2INT(end_pos)); + declare_type_variables(parser, variables, buffer); + struct parse_type_arg arg = { + .buffer = buffer, + .encoding = encoding, + .parser = parser, + .require_eof = Qfalse + }; + + VALUE result = rb_ensure(parse_inline_leading_annotation_try, (VALUE)&arg, ensure_free_parser, (VALUE)parser); + + RB_GC_GUARD(string); + + return result; +} + +static VALUE parse_inline_trailing_annotation_try(VALUE a) { + struct parse_type_arg *arg = (struct parse_type_arg *) a; + rbs_parser_t *parser = arg->parser; + + rbs_ast_ruby_annotations_t *annotation = NULL; + bool success = rbs_parse_inline_trailing_annotation(parser, &annotation); + + raise_error_if_any(parser, arg->buffer); + + if (!success || annotation == NULL) { + return Qnil; + } + + rbs_translation_context_t ctx = rbs_translation_context_create( + &parser->constant_pool, + arg->buffer, + arg->encoding + ); + + return rbs_struct_to_ruby_value(ctx, (rbs_node_t *) annotation); +} + +static VALUE rbsparser_parse_inline_trailing_annotation(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables) { + VALUE string = rb_funcall(buffer, rb_intern("content"), 0); + StringValue(string); + rb_encoding *encoding = rb_enc_get(string); + + rbs_parser_t *parser = alloc_parser_from_buffer(buffer, FIX2INT(start_pos), FIX2INT(end_pos)); + declare_type_variables(parser, variables, buffer); + struct parse_type_arg arg = { + .buffer = buffer, + .encoding = encoding, + .parser = parser, + .require_eof = Qfalse + }; + + VALUE result = rb_ensure(parse_inline_trailing_annotation_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser); + + RB_GC_GUARD(string); + + return result; +} + static VALUE rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) { VALUE string = rb_funcall(buffer, rb_intern("content"), 0); StringValue(string); @@ -305,6 +391,8 @@ void rbs__init_parser(void) { rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 5); rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5); rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3); + rb_define_singleton_method(RBS_Parser, "_parse_inline_leading_annotation", rbsparser_parse_inline_leading_annotation, 4); + rb_define_singleton_method(RBS_Parser, "_parse_inline_trailing_annotation", rbsparser_parse_inline_trailing_annotation, 4); rb_define_singleton_method(RBS_Parser, "_lex", rbsparser_lex, 2); } diff --git a/include/rbs/ast.h b/include/rbs/ast.h index 4f337c7ba..a5c0fdbee 100644 --- a/include/rbs/ast.h +++ b/include/rbs/ast.h @@ -45,38 +45,43 @@ enum rbs_node_type { RBS_AST_MEMBERS_PREPEND = 29, RBS_AST_MEMBERS_PRIVATE = 30, RBS_AST_MEMBERS_PUBLIC = 31, - RBS_AST_STRING = 32, - RBS_AST_TYPE_PARAM = 33, - RBS_METHOD_TYPE = 34, - RBS_NAMESPACE = 35, - RBS_SIGNATURE = 36, - RBS_TYPE_NAME = 37, - RBS_TYPES_ALIAS = 38, - RBS_TYPES_BASES_ANY = 39, - RBS_TYPES_BASES_BOOL = 40, - RBS_TYPES_BASES_BOTTOM = 41, - RBS_TYPES_BASES_CLASS = 42, - RBS_TYPES_BASES_INSTANCE = 43, - RBS_TYPES_BASES_NIL = 44, - RBS_TYPES_BASES_SELF = 45, - RBS_TYPES_BASES_TOP = 46, - RBS_TYPES_BASES_VOID = 47, - RBS_TYPES_BLOCK = 48, - RBS_TYPES_CLASS_INSTANCE = 49, - RBS_TYPES_CLASS_SINGLETON = 50, - RBS_TYPES_FUNCTION = 51, - RBS_TYPES_FUNCTION_PARAM = 52, - RBS_TYPES_INTERFACE = 53, - RBS_TYPES_INTERSECTION = 54, - RBS_TYPES_LITERAL = 55, - RBS_TYPES_OPTIONAL = 56, - RBS_TYPES_PROC = 57, - RBS_TYPES_RECORD = 58, - RBS_TYPES_RECORD_FIELD_TYPE = 59, - RBS_TYPES_TUPLE = 60, - RBS_TYPES_UNION = 61, - RBS_TYPES_UNTYPED_FUNCTION = 62, - RBS_TYPES_VARIABLE = 63, + RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION = 32, + RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION = 33, + RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION = 34, + RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 35, + RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 36, + RBS_AST_STRING = 37, + RBS_AST_TYPE_PARAM = 38, + RBS_METHOD_TYPE = 39, + RBS_NAMESPACE = 40, + RBS_SIGNATURE = 41, + RBS_TYPE_NAME = 42, + RBS_TYPES_ALIAS = 43, + RBS_TYPES_BASES_ANY = 44, + RBS_TYPES_BASES_BOOL = 45, + RBS_TYPES_BASES_BOTTOM = 46, + RBS_TYPES_BASES_CLASS = 47, + RBS_TYPES_BASES_INSTANCE = 48, + RBS_TYPES_BASES_NIL = 49, + RBS_TYPES_BASES_SELF = 50, + RBS_TYPES_BASES_TOP = 51, + RBS_TYPES_BASES_VOID = 52, + RBS_TYPES_BLOCK = 53, + RBS_TYPES_CLASS_INSTANCE = 54, + RBS_TYPES_CLASS_SINGLETON = 55, + RBS_TYPES_FUNCTION = 56, + RBS_TYPES_FUNCTION_PARAM = 57, + RBS_TYPES_INTERFACE = 58, + RBS_TYPES_INTERSECTION = 59, + RBS_TYPES_LITERAL = 60, + RBS_TYPES_OPTIONAL = 61, + RBS_TYPES_PROC = 62, + RBS_TYPES_RECORD = 63, + RBS_TYPES_RECORD_FIELD_TYPE = 64, + RBS_TYPES_TUPLE = 65, + RBS_TYPES_UNION = 66, + RBS_TYPES_UNTYPED_FUNCTION = 67, + RBS_TYPES_VARIABLE = 68, RBS_KEYWORD, RBS_AST_SYMBOL, }; @@ -392,6 +397,47 @@ typedef struct rbs_ast_members_public { } rbs_ast_members_public_t; +typedef struct rbs_ast_ruby_annotations_colon_method_type_annotation { + rbs_node_t base; + + struct rbs_location *prefix_location; + struct rbs_node_list *annotations; + struct rbs_node *method_type; +} rbs_ast_ruby_annotations_colon_method_type_annotation_t; + +typedef struct rbs_ast_ruby_annotations_method_types_annotation { + rbs_node_t base; + + struct rbs_location *prefix_location; + struct rbs_node_list *overloads; + struct rbs_location_list *vertical_bar_locations; +} rbs_ast_ruby_annotations_method_types_annotation_t; + +typedef struct rbs_ast_ruby_annotations_node_type_assertion { + rbs_node_t base; + + struct rbs_location *prefix_location; + struct rbs_node *type; +} rbs_ast_ruby_annotations_node_type_assertion_t; + +typedef struct rbs_ast_ruby_annotations_return_type_annotation { + rbs_node_t base; + + struct rbs_location *prefix_location; + struct rbs_location *return_location; + struct rbs_location *colon_location; + struct rbs_node *return_type; + struct rbs_location *comment_location; +} rbs_ast_ruby_annotations_return_type_annotation_t; + +typedef struct rbs_ast_ruby_annotations_skip_annotation { + rbs_node_t base; + + struct rbs_location *prefix_location; + struct rbs_location *skip_location; + struct rbs_location *comment_location; +} rbs_ast_ruby_annotations_skip_annotation_t; + typedef struct rbs_ast_string { rbs_node_t base; @@ -602,6 +648,15 @@ typedef struct rbs_types_variable { } rbs_types_variable_t; +typedef union rbs_ast_ruby_annotations { + rbs_node_t base; + rbs_ast_ruby_annotations_colon_method_type_annotation_t colon_method_type_annotation; + rbs_ast_ruby_annotations_method_types_annotation_t method_types_annotation; + rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion; + rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation; + rbs_ast_ruby_annotations_skip_annotation_t skip_annotation; +} rbs_ast_ruby_annotations_t; + /// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc. /// These are stored in the global constant pool, and get surfaced to Ruby as `Symbol`s, /// just like `rbs_ast_symbol_t`s. @@ -652,6 +707,11 @@ rbs_ast_members_method_definition_overload_t *rbs_ast_members_method_definition_ rbs_ast_members_prepend_t *rbs_ast_members_prepend_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_type_name_t *name, rbs_node_list_t *args, rbs_node_list_t *annotations, rbs_ast_comment_t *comment); rbs_ast_members_private_t *rbs_ast_members_private_new(rbs_allocator_t *allocator, rbs_location_t *location); rbs_ast_members_public_t *rbs_ast_members_public_new(rbs_allocator_t *allocator, rbs_location_t *location); +rbs_ast_ruby_annotations_colon_method_type_annotation_t *rbs_ast_ruby_annotations_colon_method_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *annotations, rbs_node_t *method_type); +rbs_ast_ruby_annotations_method_types_annotation_t *rbs_ast_ruby_annotations_method_types_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *overloads, rbs_location_list_t *vertical_bar_locations); +rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_type_assertion_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_t *type); +rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *return_location, rbs_location_t *colon_location, rbs_node_t *return_type, rbs_location_t *comment_location); +rbs_ast_ruby_annotations_skip_annotation_t *rbs_ast_ruby_annotations_skip_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *skip_location, rbs_location_t *comment_location); rbs_ast_string_t *rbs_ast_string_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_string_t string); rbs_ast_type_param_t *rbs_ast_type_param_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_ast_symbol_t *name, rbs_keyword_t *variance, rbs_node_t *upper_bound, rbs_node_t *default_type, bool unchecked); rbs_method_type_t *rbs_method_type_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_node_list_t *type_params, rbs_node_t *type, rbs_types_block_t *block); diff --git a/include/rbs/lexer.h b/include/rbs/lexer.h index 8c6b92c27..ea0bc11f7 100644 --- a/include/rbs/lexer.h +++ b/include/rbs/lexer.h @@ -64,6 +64,9 @@ enum RBSTokenType { kUSE, /* use */ kAS, /* as */ k__TODO__, /* __todo__ */ + kATRBS, /* @rbs */ + kSKIP, /* skip */ + kRETURN, /* return */ tLIDENT, /* Identifiers starting with lower case */ tUIDENT, /* Identifiers starting with upper case */ @@ -80,6 +83,7 @@ enum RBSTokenType { tCOMMENT, /* Comment */ tLINECOMMENT, /* Comment of all line */ + tINLINECOMMENT, /* Comment in inline decl starting with -- */ tTRIVIA, /* Trivia tokens -- space and new line */ diff --git a/include/rbs/location.h b/include/rbs/location.h index c2d825e8a..fef3443df 100644 --- a/include/rbs/location.h +++ b/include/rbs/location.h @@ -32,6 +32,18 @@ typedef struct rbs_location { rbs_loc_children *children; } rbs_location_t; +typedef struct rbs_location_list_node { + rbs_location_t *loc; + struct rbs_location_list_node *next; +} rbs_location_list_node_t; + +typedef struct rbs_location_list { + rbs_allocator_t *allocator; + rbs_location_list_node_t *head; + rbs_location_list_node_t *tail; + size_t length; +} rbs_location_list_t; + void rbs_loc_alloc_children(rbs_allocator_t *, rbs_location_t *loc, size_t capacity); void rbs_loc_add_required_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r); void rbs_loc_add_optional_child(rbs_location_t *loc, rbs_constant_id_t name, rbs_range_t r); @@ -41,4 +53,7 @@ void rbs_loc_add_optional_child(rbs_location_t *loc, rbs_constant_id_t name, rbs * */ rbs_location_t *rbs_location_new(rbs_allocator_t *, rbs_range_t rg); +rbs_location_list_t *rbs_location_list_new(rbs_allocator_t *allocator); +void rbs_location_list_append(rbs_location_list_t *list, rbs_location_t *loc); + #endif diff --git a/include/rbs/parser.h b/include/rbs/parser.h index 38326cf93..0b974e94c 100644 --- a/include/rbs/parser.h +++ b/include/rbs/parser.h @@ -130,4 +130,22 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type); bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type); bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature); +/** + * Parse an inline leading annotation from a string. + * + * @param parser The parser to use + * @param annotation Pointer to store the resulting annotation + * @return true if parsing succeeded, false otherwise + */ +bool rbs_parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation); + +/** + * Parse an inline trailing annotation from a string. + * + * @param parser The parser to use + * @param annotation Pointer to store the resulting annotation + * @return true if parsing succeeded, false otherwise + */ +bool rbs_parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation); + #endif diff --git a/lib/rbs.rb b/lib/rbs.rb index 2a98abc6d..b4a8b6aa5 100644 --- a/lib/rbs.rb +++ b/lib/rbs.rb @@ -25,12 +25,15 @@ require "rbs/ast/members" require "rbs/ast/annotation" require "rbs/ast/visitor" +require "rbs/ast/ruby/comment_block" require "rbs/ast/ruby/helpers/constant_helper" require "rbs/ast/ruby/helpers/location_helper" +require "rbs/ast/ruby/annotations" require "rbs/ast/ruby/declarations" require "rbs/ast/ruby/members" require "rbs/source" require "rbs/inline_parser" +require "rbs/inline_parser/comment_association" require "rbs/environment" require "rbs/environment/use_map" require "rbs/environment/class_entry" diff --git a/lib/rbs/ast/ruby/annotations.rb b/lib/rbs/ast/ruby/annotations.rb new file mode 100644 index 000000000..4de877a25 --- /dev/null +++ b/lib/rbs/ast/ruby/annotations.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +module RBS + module AST + module Ruby + module Annotations + class Base + attr_reader :location, :prefix_location + + def initialize(location, prefix_location) + @location = location + @prefix_location = prefix_location + end + + def buffer + location.buffer + end + end + + class NodeTypeAssertion < Base + attr_reader :type + + def initialize(location:, prefix_location:, type:) + super(location, prefix_location) + @type = type + end + + def map_type_name + self.class.new( + location:, prefix_location:, + type: type.map_type_name { yield _1 } + ) #: self + end + end + + class ColonMethodTypeAnnotation < Base + attr_reader :annotations, :method_type + + def initialize(location:, prefix_location:, annotations:, method_type:) + super(location, prefix_location) + @annotations = annotations + @method_type = method_type + end + + def map_type_name + self.class.new( + location:, + prefix_location:, + annotations: annotations, + method_type: method_type.map_type {|type| type.map_type_name { yield _1 }} + ) #: self + end + end + + class MethodTypesAnnotation < Base + Overload = AST::Members::MethodDefinition::Overload + + attr_reader :overloads, :vertical_bar_locations + + def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:) + super(location, prefix_location) + @overloads = overloads + @vertical_bar_locations = vertical_bar_locations + end + + def map_type_name(&block) + ovs = overloads.map do |overload| + Overload.new( + method_type: overload.method_type.map_type {|type| type.map_type_name { yield _1 } }, + annotations: overload.annotations + ) + end + + self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:) #: self + end + end + + class SkipAnnotation < Base + attr_reader :skip_location, :comment_location + + def initialize(location:, prefix_location:, skip_location:, comment_location:) + super(location, prefix_location) + @skip_location = skip_location + @comment_location = comment_location + end + end + + class ReturnTypeAnnotation < Base + attr_reader :return_location + + attr_reader :colon_location + + attr_reader :return_type + + attr_reader :comment_location + + def initialize(location:, prefix_location:, return_location:, colon_location:, return_type:, comment_location:) + super(location, prefix_location) + @return_location = return_location + @colon_location = colon_location + @return_type = return_type + @comment_location = comment_location + end + + def map_type_name(&block) + self.class.new( + location:, + prefix_location:, + return_location: return_location, + colon_location: colon_location, + return_type: return_type.map_type_name { yield _1 }, + comment_location: comment_location + ) #: self + end + end + end + end + end +end diff --git a/lib/rbs/ast/ruby/comment_block.rb b/lib/rbs/ast/ruby/comment_block.rb new file mode 100644 index 000000000..72a07ea5d --- /dev/null +++ b/lib/rbs/ast/ruby/comment_block.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +module RBS + module AST + module Ruby + class CommentBlock + attr_reader :name, :offsets, :comment_buffer + + def initialize(source_buffer, comments) + @name = source_buffer.name + + @offsets = [] + + # Assume the comment starts with a prefix whitespace + prefix_str = "# " + + ranges = [] #: Array[Range[Integer]] + + comments.each do |comment| + tuple = [comment, 2] #: [Prism::Comment, Integer] + + unless comment.location.slice.start_with?(prefix_str) + tuple[1] = 1 + end + + offsets << tuple + + start_char = comment.location.start_character_offset + tuple[1] + end_char = comment.location.end_character_offset + ranges << (start_char ... end_char) + end + + @comment_buffer = source_buffer.sub_buffer(lines: ranges) + end + + def leading? + comment = offsets[0][0] or raise + comment.location.start_line_slice.index(/\S/) ? false : true + end + + def trailing? + comment = offsets[0][0] or raise + comment.location.start_line_slice.index(/\S/) ? true : false + end + + def start_line + comments[0].location.start_line + end + + def end_line + comments[-1].location.end_line + end + + def line_starts + offsets.map do |comment, prefix_size| + comment.location.start_character_offset + prefix_size + end + end + + def self.build(buffer, comments) + blocks = [] #: Array[CommentBlock] + + comments = comments.filter {|comment| comment.is_a?(Prism::InlineComment) } + + until comments.empty? + block_comments = [] #: Array[Prism::Comment] + + until comments.empty? + comment = comments.first or raise + last_comment = block_comments.last + + if last_comment + if last_comment.location.end_line + 1 == comment.location.start_line + if last_comment.location.start_column == comment.location.start_column + unless comment.location.start_line_slice.index(/\S/) + block_comments << comments.shift + next + end + end + end + + break + else + block_comments << comments.shift + end + end + + unless block_comments.empty? + blocks << CommentBlock.new(buffer, block_comments.dup) + end + end + + blocks + end + + AnnotationSyntaxError = _ = Struct.new(:location, :error) + + def each_paragraph(variables, &block) + if block + if leading_annotation?(0) + yield_annotation(0, 0, 0, variables, &block) + else + yield_paragraph(0, 0, variables, &block) + end + else + enum_for :each_paragraph, variables + end + end + + def yield_paragraph(start_line, current_line, variables, &block) + # We already know at start_line..current_line are paragraph. + + while true + next_line = current_line + 1 + + if next_line >= comment_buffer.line_count + yield line_location(start_line, current_line) + return + end + + if leading_annotation?(next_line) + yield line_location(start_line, current_line) + return yield_annotation(next_line, next_line, next_line, variables, &block) + else + current_line = next_line + end + end + end + + def yield_annotation(start_line, end_line, current_line, variables, &block) + # We already know at start_line..end_line are annotation. + while true + next_line = current_line + 1 + + if next_line >= comment_buffer.line_count + annotation = parse_annotation_lines(start_line, end_line, variables) + yield annotation + + if end_line > current_line + yield_paragraph(end_line + 1, end_line + 1, variables, &block) + end + + return + end + + line_text = text(next_line) + if leading_spaces = line_text.index(/\S/) + if leading_spaces == 0 + # End of annotation + yield parse_annotation_lines(start_line, end_line, variables) + + if leading_annotation?(end_line + 1) + yield_annotation(end_line + 1, end_line + 1, end_line + 1, variables, &block) + else + yield_paragraph(end_line + 1, end_line + 1, variables, &block) + end + + return + else + current_line = next_line + end_line = next_line + end + else + current_line = next_line + end + end + end + + def text(comment_index) + range = comment_buffer.ranges[comment_index] + comment_buffer.content[range] or raise + end + + def line_location(start_line, end_line) + start_offset = comment_buffer.ranges[start_line].begin + end_offset = comment_buffer.ranges[end_line].end + Location.new(comment_buffer, start_offset, end_offset) + end + + def parse_annotation_lines(start_line, end_line, variables) + start_pos = comment_buffer.ranges[start_line].begin + end_pos = comment_buffer.ranges[end_line].end + begin + Parser.parse_inline_leading_annotation(comment_buffer, start_pos...end_pos, variables: variables) + rescue ParsingError => error + AnnotationSyntaxError.new(line_location(start_line, end_line), error) + end + end + + def trailing_annotation(variables) + if trailing? + comment = comments[0] or raise + if comment.location.slice.start_with?(/#[:\[]/) + begin + Parser.parse_inline_trailing_annotation(comment_buffer, 0...comment_buffer.last_position, variables: variables) + rescue ParsingError => error + location = line_location(0, offsets.size - 1) + AnnotationSyntaxError.new(location, error) + end + end + end + end + + def comments + offsets.map { _1[0]} + end + + def leading_annotation?(index) + if index < comment_buffer.line_count + text(index).start_with?(/@rbs\b/) and return true + + comment = offsets[index][0] + comment.location.slice.start_with?(/\#:/) and return true + end + + false + end + end + end + end +end diff --git a/lib/rbs/ast/ruby/members.rb b/lib/rbs/ast/ruby/members.rb index 03903b342..e4cf7d00b 100644 --- a/lib/rbs/ast/ruby/members.rb +++ b/lib/rbs/ast/ruby/members.rb @@ -14,16 +14,181 @@ def initialize(buffer) include Helpers::LocationHelper end + class MethodTypeAnnotation + class DocStyle + attr_accessor :return_type_annotation + + def initialize + @return_type_annotation = nil + end + + def map_type_name(&block) + DocStyle.new.tap do |new| + new.return_type_annotation = return_type_annotation&.map_type_name(&block) + end #: self + end + + def method_type + return_type = + case return_type_annotation + when Annotations::NodeTypeAssertion + return_type_annotation.type + when Annotations::ReturnTypeAnnotation + return_type_annotation.return_type + else + Types::Bases::Any.new(location: nil) + end + + type = Types::Function.new( + required_positionals: [], + optional_positionals: [], + rest_positionals: nil, + trailing_positionals: [], + required_keywords: {}, + optional_keywords: {}, + rest_keywords: nil, + return_type: return_type + ) + + MethodType.new( + type_params: [], + type: type, + block: nil, + location: nil + ) + end + end + + attr_reader :type_annotations + + def initialize(type_annotations:) + @type_annotations = type_annotations + end + + def map_type_name(&block) + case type_annotations + when Array + updated_annots = type_annotations.map do |annotation| + annotation.map_type_name(&block) + end + when DocStyle + updated_annots = type_annotations.map_type_name(&block) + end + + MethodTypeAnnotation.new(type_annotations: updated_annots) #: self + end + + def self.build(leading_block, trailing_block, variables) + unused_annotations = [] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError] + unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil + + type_annotations = nil #: type_annotations + + if trailing_block + case annotation = trailing_block.trailing_annotation(variables) + when Annotations::NodeTypeAssertion + type_annotations = DocStyle.new() + type_annotations.return_type_annotation = annotation + else + unused_trailing_annotation = annotation + end + end + + if leading_block + leading_block.each_paragraph(variables) do |paragraph| + next if paragraph.is_a?(Location) + + if paragraph.is_a?(CommentBlock::AnnotationSyntaxError) + unused_annotations << paragraph + next + end + + case paragraph + when Annotations::MethodTypesAnnotation, Annotations::ColonMethodTypeAnnotation + type_annotations = [] unless type_annotations + if type_annotations.is_a?(Array) + type_annotations << paragraph + next + end + when Annotations::ReturnTypeAnnotation + unless type_annotations + type_annotations = DocStyle.new() + end + + if type_annotations.is_a?(DocStyle) + unless type_annotations.return_type_annotation + type_annotations.return_type_annotation = paragraph + next + end + end + end + + unused_annotations << paragraph + end + end + + [ + MethodTypeAnnotation.new( + type_annotations: type_annotations + ), + unused_annotations, + unused_trailing_annotation + ] + end + + def empty? + type_annotations.nil? + end + + def overloads + case type_annotations + when DocStyle + method_type = type_annotations.method_type + + [ + AST::Members::MethodDefinition::Overload.new(annotations: [], method_type: method_type) + ] + when Array + type_annotations.flat_map do |annotation| + case annotation + when Annotations::ColonMethodTypeAnnotation + [ + AST::Members::MethodDefinition::Overload.new( + annotations: annotation.annotations, + method_type: annotation.method_type + ) + ] + when Annotations::MethodTypesAnnotation + annotation.overloads + end + end + when nil + method_type = MethodType.new( + type_params: [], + type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)), + block: nil, + location: nil + ) + + [ + AST::Members::MethodDefinition::Overload.new(method_type: method_type, annotations: []) + ] + end + end + end + class DefMember < Base Overload = AST::Members::MethodDefinition::Overload attr_reader :name attr_reader :node + attr_reader :method_type - def initialize(buffer, name, node) + def initialize(buffer, name, node, method_type) super(buffer) @name = name @node = node + @method_type = method_type end def location @@ -31,16 +196,7 @@ def location end def overloads - method_type = MethodType.new( - type_params: [], - type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)), - block: nil, - location: nil - ) - - [ - Overload.new(method_type: method_type, annotations: []) - ] + method_type.overloads end def overloading? diff --git a/lib/rbs/buffer.rb b/lib/rbs/buffer.rb index c5f48dcfe..7990a07d2 100644 --- a/lib/rbs/buffer.rb +++ b/lib/rbs/buffer.rb @@ -4,39 +4,53 @@ module RBS class Buffer attr_reader :name attr_reader :content + attr_reader :parent - def initialize(name:, content:) - @name = name - @content = content + def initialize(name: nil, content:, parent: nil) + case + when name && content + @name = name + @content = content + @parent = nil + when parent && content + @name = parent[0].name + @content = content + @parent = parent + end end def lines - @lines ||= content.lines + ranges.map { self.content[_1] || raise } #$ String + end + + def line_count + ranges.size end def ranges - @ranges ||= - begin - @ranges = [] - offset = 0 - lines.each do |line| - size = line.size - range = offset...(offset+size) - @ranges << range - offset += size - end - - if !content.end_with?("\n") && content.size > 0 - @ranges[-1] = @ranges[-1].begin...(@ranges[-1].end+1) - end - - @ranges + @ranges ||= begin + lines = content.lines + lines << "" if content.end_with?("\n") + + ranges = [] #: Array[Range[Integer]] + offset = 0 + + lines.each do |line| + size0 = line.size + line = line.chomp + range = offset...(offset+line.size) + ranges << range + + offset += size0 end + + ranges + end end def pos_to_loc(pos) index = ranges.bsearch_index do |range| - pos < range.end ? true : false + pos <= range.end ? true : false end if index @@ -49,7 +63,7 @@ def pos_to_loc(pos) def loc_to_pos(loc) line, column = loc - if range = ranges[line - 1] + if range = ranges.fetch(line - 1, nil) range.begin + column else last_position @@ -57,11 +71,77 @@ def loc_to_pos(loc) end def last_position - content.size + if ranges.empty? + 0 + else + ranges[-1].end + end end def inspect - "#" + "#" + end + + def rbs_location(location, loc2=nil) + if loc2 + Location.new(self, location.start_character_offset, loc2.end_character_offset) + else + Location.new(self, location.start_character_offset, location.end_character_offset) + end + end + + def sub_buffer(lines:) + buf = +"" + lines.each_with_index do |range, index| + start_pos = range.begin + end_pos = range.end + slice = content[start_pos...end_pos] or raise + if slice.include?("\n") + raise "Line #{index + 1} cannot contain newline character." + end + buf << slice + buf << "\n" + end + + buf.chomp! + + Buffer.new(content: buf, parent: [self, lines]) + end + + def parent_buffer + if parent + parent[0] + end + end + + def parent_position(position) + parent or raise "#parent_position is unavailable with buffer without parent" + return nil unless position <= last_position + + line, column = pos_to_loc(position) + parent_range = parent[1][line - 1] + parent_range.begin + column + end + + def absolute_position(position) + if parent_buffer + pos = parent_position(position) or return + parent_buffer.absolute_position(pos) + else + position + end + end + + def top_buffer + if parent_buffer + parent_buffer.top_buffer + else + self + end + end + + def detach + Buffer.new(name: name, content: content) end end end diff --git a/lib/rbs/environment.rb b/lib/rbs/environment.rb index e013c3529..a6475fa1e 100644 --- a/lib/rbs/environment.rb +++ b/lib/rbs/environment.rb @@ -673,7 +673,7 @@ def resolve_ruby_decl(resolver, decl, context:, prefix:) when AST::Ruby::Declarations::Base resolved.members << resolve_ruby_decl(resolver, member, context: inner_context, prefix: inner_prefix) when AST::Ruby::Members::Base - resolved.members << member + resolved.members << resolve_ruby_member(resolver, member, context: inner_context) else raise "Unknown member type: #{member.class}" end @@ -701,6 +701,20 @@ def resolve_ruby_decl(resolver, decl, context:, prefix:) end end + def resolve_ruby_member(resolver, member, context:) + case member + when AST::Ruby::Members::DefMember + AST::Ruby::Members::DefMember.new( + member.buffer, + member.name, + member.node, + member.method_type.map_type_name {|name, _, _| absolute_type_name(resolver, nil, name, context: context) } + ) + else + raise "Unknown member type: #{member.class}" + end + end + def resolve_member(resolver, map, member, context:) case member when AST::Members::MethodDefinition @@ -816,7 +830,7 @@ def resolve_type_params(resolver, map, params, context:) end def absolute_type_name(resolver, map, type_name, context:) - type_name = map.resolve(type_name) + type_name = map.resolve(type_name) if map resolver.resolve(type_name, context: context) || type_name end diff --git a/lib/rbs/inline_parser.rb b/lib/rbs/inline_parser.rb index 26348a8f3..2e9863012 100644 --- a/lib/rbs/inline_parser.rb +++ b/lib/rbs/inline_parser.rb @@ -27,6 +27,8 @@ def initialize(location, message) NonConstantClassName = _ = Class.new(Base) NonConstantModuleName = _ = Class.new(Base) TopLevelMethodDefinition = _ = Class.new(Base) + UnusedInlineAnnotation = _ = Class.new(Base) + AnnotationSyntaxError = _ = Class.new(Base) end def self.parse(buffer, prism) @@ -38,7 +40,7 @@ def self.parse(buffer, prism) end class Parser < Prism::Visitor - attr_reader :module_nesting, :result + attr_reader :module_nesting, :result, :comments include AST::Ruby::Helpers::ConstantHelper include AST::Ruby::Helpers::LocationHelper @@ -46,6 +48,7 @@ class Parser < Prism::Visitor def initialize(result) @result = result @module_nesting = [] + @comments = CommentAssociation.build(result.buffer, result.prism_result) end def buffer @@ -71,7 +74,20 @@ def push_module_nesting(mod) module_nesting.pop() end + def skip_node?(node) + if ref = comments.leading_block(node) + if ref.block.each_paragraph([]).any? { _1.is_a?(AST::Ruby::Annotations::SkipAnnotation) } + ref.associate! + return true + end + end + + false + end + def visit_class_node(node) + return if skip_node?(node) + unless class_name = constant_as_type_name(node.constant_path) diagnostics << Diagnostic::NonConstantClassName.new( rbs_location(node.constant_path.location), @@ -85,9 +101,15 @@ def visit_class_node(node) push_module_nesting(class_decl) do visit_child_nodes(node) end + + comments.each_enclosed_block(node) do |block| + report_unused_block(block) + end end def visit_module_node(node) + return if skip_node?(node) + unless module_name = constant_as_type_name(node.constant_path) diagnostics << Diagnostic::NonConstantModuleName.new( rbs_location(node.constant_path.location), @@ -101,9 +123,15 @@ def visit_module_node(node) push_module_nesting(module_decl) do visit_child_nodes(node) end + + comments.each_enclosed_block(node) do |block| + report_unused_block(block) + end end def visit_def_node(node) + return if skip_node?(node) + if node.receiver diagnostics << Diagnostic::NotImplementedYet.new( rbs_location(node.receiver.location), @@ -114,8 +142,24 @@ def visit_def_node(node) case current = current_module when AST::Ruby::Declarations::ClassDecl, AST::Ruby::Declarations::ModuleDecl - defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node) + leading_block = comments.leading_block!(node) + + if node.end_keyword_loc + # Not an end-less def + end_loc = node.rparen_loc || node.parameters&.location || node.name_loc + trailing_block = comments.trailing_block!(end_loc) + end + + method_type, leading_unuseds, trailing_unused = AST::Ruby::Members::MethodTypeAnnotation.build(leading_block, trailing_block, []) + report_unused_annotation(trailing_unused, *leading_unuseds) + + defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node, method_type) current.members << defn + + # Skip other comments in `def` node + comments.each_enclosed_block(node) do |block| + comments.associated_blocks << block + end else diagnostics << Diagnostic::TopLevelMethodDefinition.new( rbs_location(node.name_loc), @@ -131,6 +175,32 @@ def insert_declaration(decl) result.declarations << decl end end + + def report_unused_annotation(*annotations) + annotations.each do |annotation| + case annotation + when AST::Ruby::CommentBlock::AnnotationSyntaxError + diagnostics << Diagnostic::AnnotationSyntaxError.new( + annotation.location, "Syntax error: " + annotation.error.error_message + ) + when AST::Ruby::Annotations::Base + diagnostics << Diagnostic::UnusedInlineAnnotation.new( + annotation.location, "Unused inline rbs annotation" + ) + end + end + end + + def report_unused_block(block) + block.each_paragraph([]) do |paragraph| + case paragraph + when Location + # noop + else + report_unused_annotation(paragraph) + end + end + end end end end diff --git a/lib/rbs/inline_parser/comment_association.rb b/lib/rbs/inline_parser/comment_association.rb new file mode 100644 index 000000000..91db2cd5a --- /dev/null +++ b/lib/rbs/inline_parser/comment_association.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +module RBS + class InlineParser + class CommentAssociation + attr_reader :blocks, :associated_blocks, :start_line_map, :end_line_map + + def initialize(blocks) + @blocks = blocks.sort_by {|block| block.start_line } + @associated_blocks = Set[].compare_by_identity + + @start_line_map = {} + @end_line_map = {} + + blocks.each do |block| + if block.leading? + end_line_map[block.end_line] = block + else + start_line_map[block.start_line] = block + end + end + end + + def self.build(buffer, result) + blocks = AST::Ruby::CommentBlock.build(buffer, result.comments) + new(blocks) + end + + class Reference + attr_reader :block + + def initialize(block, association) + @block = block + @associated_blocks = association + end + + def associate! + @associated_blocks << block + self + end + + def associated? + @associated_blocks.include?(block) + end + end + + def leading_block(node) + start_line = node.location.start_line + + if block = end_line_map.fetch(start_line - 1, nil) + Reference.new(block, associated_blocks) + end + end + + def leading_block!(node) + if ref = leading_block(node) + unless ref.associated? + ref.associate!.block + end + end + end + + def trailing_block(node) + location = + if node.is_a?(Prism::Node) + node.location + else + node + end #: Prism::Location + end_line = location.end_line + if block = start_line_map.fetch(end_line, nil) + Reference.new(block, associated_blocks) + end + end + + def trailing_block!(node) + if ref = trailing_block(node) + unless ref.associated? + ref.associate!.block + end + end + end + + def each_enclosed_block(node) + if block_given? + start_line = node.location.start_line + end_line = node.location.end_line + + if start_line+1 < end_line + ((start_line + 1)...end_line).each do |line| + if block = end_line_map.fetch(line, nil) + unless associated_blocks.include?(block) + associated_blocks << block + yield block + end + end + end + end + else + enum_for :each_enclosed_block, node + end + end + + def each_unassociated_block + if block_given? + blocks.each do |block| + unless associated_blocks.include?(block) + yield block + end + end + else + enum_for :each_unassociated_block + end + end + end + end +end diff --git a/lib/rbs/location_aux.rb b/lib/rbs/location_aux.rb index de0413686..7a5cf7988 100644 --- a/lib/rbs/location_aux.rb +++ b/lib/rbs/location_aux.rb @@ -28,6 +28,14 @@ def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start WithChildren = self + def start_pos + buffer.absolute_position(_start_pos) || raise + end + + def end_pos + buffer.absolute_position(_end_pos) || raise + end + def name buffer.name end @@ -49,11 +57,11 @@ def end_column end def start_loc - @start_loc ||= buffer.pos_to_loc(start_pos) + @start_loc ||= buffer.top_buffer.pos_to_loc(start_pos) end def end_loc - @end_loc ||= buffer.pos_to_loc(end_pos) + @end_loc ||= buffer.top_buffer.pos_to_loc(end_pos) end def range @@ -61,7 +69,7 @@ def range end def source - @source ||= (buffer.content[range] || raise) + @source ||= (buffer.top_buffer.content[range] || raise) end def to_s @@ -134,5 +142,29 @@ def optional_key?(name) def required_key?(name) _required_keys.include?(name) end + + def local_location + loc = Location.new(buffer.detach, _start_pos, _end_pos) + + each_optional_key do |key| + value = self[key] + if value + loc.add_optional_child(key, value._start_pos...value._end_pos) + else + loc.add_optional_child(key, nil) + end + end + + each_required_key do |key| + value = self[key] or raise + loc.add_required_child(key, value._start_pos...value._end_pos) + end + + loc #: self + end + + def local_source + local_location.source + end end end diff --git a/lib/rbs/parser_aux.rb b/lib/rbs/parser_aux.rb index 8b746d39b..cb81cd204 100644 --- a/lib/rbs/parser_aux.rb +++ b/lib/rbs/parser_aux.rb @@ -110,5 +110,15 @@ def self.buffer(source) ).each_with_object({}) do |keyword, hash| #$ Hash[String, bot] hash[keyword] = _ = nil end + + def self.parse_inline_leading_annotation(source, range, variables: []) + buf = buffer(source) + _parse_inline_leading_annotation(buf, range.begin || 0, range.end || buf.last_position, variables) + end + + def self.parse_inline_trailing_annotation(source, range, variables: []) + buf = buffer(source) + _parse_inline_trailing_annotation(buf, range.begin || 0, range.end || buf.last_position, variables) + end end end diff --git a/sig/ast/ruby/annotations.rbs b/sig/ast/ruby/annotations.rbs new file mode 100644 index 000000000..18a8cbb9c --- /dev/null +++ b/sig/ast/ruby/annotations.rbs @@ -0,0 +1,110 @@ +module RBS + module AST + module Ruby + module Annotations + type leading_annotation = ColonMethodTypeAnnotation + | MethodTypesAnnotation + | SkipAnnotation + | ReturnTypeAnnotation + + type trailing_annotation = NodeTypeAssertion + + type t = leading_annotation | trailing_annotation + + class Base + # Location that covers all of the annotation + # + attr_reader location: Location + + # Location of `@rbs`, `@rbs!`, or `:` prefix + # + attr_reader prefix_location: Location + + def initialize: (Location location, Location prefix_location) -> void + + def buffer: () -> Buffer + end + + # `: TYPE` annotation attached to nodes + # + class NodeTypeAssertion < Base + attr_reader type: Types::t + + def initialize: (location: Location, prefix_location: Location, type: Types::t) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + + # `: METHOD-TYPE` annotation in leading comments + # + class ColonMethodTypeAnnotation < Base + attr_reader annotations: Array[AST::Annotation] + + attr_reader method_type: MethodType + + def initialize: (location: Location, prefix_location: Location, annotations: Array[AST::Annotation], method_type: MethodType) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + + # `@rbs METHOD-TYPEs` annotation in leading comments + # + # ``` + # @rbs () -> void | %a{foo} () -> String + # ^^^^ -- prefix_location + # ^ -- vertical_bar_locations[0] + # ``` + class MethodTypesAnnotation < Base + class Overload = AST::Members::MethodDefinition::Overload + + attr_reader overloads: Array[Overload] + + attr_reader vertical_bar_locations: Array[Location] + + def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location]) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + + # `@rbs skip -- comment` annotation in leading comments + # + class SkipAnnotation < Base + attr_reader skip_location: Location + attr_reader comment_location: Location? + + def initialize: (location: Location, prefix_location: Location, skip_location: Location, comment_location: Location?) -> void + end + + # `@rbs return: T -- comment` annotation in leading comments + # + # ``` + # @rbs return: String -- Returns a string + # ^^^ -- prefix_location + # ^^^^^^ -- return_location + # ^ -- colon_location + # ^^^^^^^^^^^^^^^^^^^ -- comment + # ``` + class ReturnTypeAnnotation < Base + attr_reader return_location: Location + + attr_reader colon_location: Location + + attr_reader return_type: Types::t + + attr_reader comment_location: Location? + + def initialize: ( + location: Location, + prefix_location: Location, + return_location: Location, + colon_location: Location, + return_type: Types::t, + comment_location: Location?, + ) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + end + end + end +end diff --git a/sig/ast/ruby/comment_block.rbs b/sig/ast/ruby/comment_block.rbs new file mode 100644 index 000000000..7dd7bde03 --- /dev/null +++ b/sig/ast/ruby/comment_block.rbs @@ -0,0 +1,119 @@ +use Prism::Comment + +module RBS + module AST + module Ruby + # CommentBlock is a collection of comments + # + # ```ruby + # # Comment1 < block1 + # # Comment2 < + # + # # Comment3 < block2 + # ``` + # + # A comment block is a *leading* block or *trailing* block. + # + # ```ruby + # # This is leading block. + # # This is the second line of the leading block. + # + # foo # This is trailing block. + # # This is second line of the trailing block. + # ``` + # + # A leading block is a comment block where all of the comments are at the start of the line content. + # A trailing block is a comment block where the first comment of the block has something at the line before the comment. + # + class CommentBlock + attr_reader name: Pathname + + # Sub buffer of the contents of the comments + # + attr_reader comment_buffer: Buffer + + attr_reader offsets: Array[ + [ + Comment, + Integer, # -- prefix size + ] + ] + + def initialize: (Buffer source_buffer, Array[Comment]) -> void + + # Build comment block instances + def self.build: (Buffer, Array[Comment]) -> Array[instance] + + # Returns true if the comment block is a *leading* comment, which is attached to the successor node + def leading?: () -> bool + + # Returns true if the comment block is a *trailing* comment, which is attached to the predecessor node + def trailing?: () -> bool + + # The line number of the first comment in the block + def start_line: () -> Integer + + # The line number of the last comment in the block + def end_line: () -> Integer + + # The character index of `#comment_buffer` at the start of the lines + # + def line_starts: () -> Array[Integer] + + # Returns the text content of the comment + def text: (Integer index) -> String + + # Yields paragraph and annotation + # + # A paragraph is a sequence of lines that are separated by annotations. + # An annotation starts with a line starting with `@rbs` or `:`, and may continue with lines that has more leading spaces. + # + # ``` + # # Line 1 ^ Paragraph 1 + # # Line 2 | + # # | + # # Line 3 v + # # @rbs ... < Annotation 1 + # # @rbs ... ^ Annotation 2 + # # ... | + # # | + # # ... v + # # ^ Paragraph 2 + # # Line 4 | + # # Line 5 v + # ``` + # + def each_paragraph: (Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + | (Array[Symbol] variables) -> Enumerator[Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError] + + # Returns a trailing annotation if it exists + # + # * Returns `nil` if the block is not a type annotation + # * Returns an annotation if the block has a type annotation + # * Returns AnnotationSyntaxError if the annotation has a syntax error + # + def trailing_annotation: (Array[Symbol] variables) -> (AST::Ruby::Annotations::trailing_annotation | AnnotationSyntaxError | nil) + + class AnnotationSyntaxError + attr_reader location: Location + + attr_reader error: ParsingError + + def initialize: (Location, ParsingError) -> void + end + + private def yield_paragraph: (Integer start_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + + private def yield_annotation: (Integer start_line, Integer end_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + + private def parse_annotation_lines: (Integer start_line, Integer end_line, Array[Symbol] variables) -> (AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) + + def comments: () -> Array[Comment] + + def line_location: (Integer start_line, Integer end_line) -> Location + + private def leading_annotation?: (Integer index) -> bool + end + end + end +end diff --git a/sig/ast/ruby/members.rbs b/sig/ast/ruby/members.rbs index d737d25f7..82452460f 100644 --- a/sig/ast/ruby/members.rbs +++ b/sig/ast/ruby/members.rbs @@ -12,13 +12,51 @@ module RBS type t = DefMember + class MethodTypeAnnotation + class DocStyle + attr_accessor return_type_annotation: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil + + def initialize: () -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + + def method_type: () -> MethodType + end + + type type_annotations = DocStyle | Array[Annotations::ColonMethodTypeAnnotation | Annotations::MethodTypesAnnotation] | nil + + attr_reader type_annotations: type_annotations + + def initialize: (type_annotations: type_annotations) -> void + + def map_type_name: { (TypeName) -> TypeName } -> self + + # Returns the method type annotations from the comment block + # + # Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation. + # + def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [ + MethodTypeAnnotation, + Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError], + Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil + ] + + # Returns `true` if it doesn't have any annotation + def empty?: () -> bool + + # Returns the method type overloads + # + def overloads: () -> Array[AST::Members::MethodDefinition::Overload] + end + class DefMember < Base class Overload = AST::Members::MethodDefinition::Overload attr_reader name: Symbol attr_reader node: Prism::DefNode + attr_reader method_type: MethodTypeAnnotation - def initialize: (Buffer, Symbol name, Prism::DefNode node) -> void + def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation) -> void def location: () -> Location diff --git a/sig/buffer.rbs b/sig/buffer.rbs index 9d23ad6aa..31230c39a 100644 --- a/sig/buffer.rbs +++ b/sig/buffer.rbs @@ -11,16 +11,40 @@ module RBS # The content of the buffer. attr_reader content: String - @lines: Array[String] - - @ranges: Array[Range[Integer]] + attr_reader parent: [Buffer, Array[Range[Integer]]]? def initialize: (name: Pathname name, content: String content) -> void + | (content: String content, parent: [Buffer, Array[Range[Integer]]] parent) -> void + # Array of lines of the content, without the EOL + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc") + # buffer.lines # => ["123", "abc"] + # ``` + # + # If the input has EOL at the end of the file, the `lines` has an empty string at the end. + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc\n") + # buffer.lines # => ["123", "abc", ""] + # ``` + # def lines: () -> Array[String] + @ranges: Array[Range[Integer]]? + # Array of ranges that stores the ranges of the each line, without the EOL + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc\n") + # buffer.ranges # => [0...3, 4...7, 8...8] + # ``` + # def ranges: () -> Array[Range[Integer]] + # Returns the number of the lines + def line_count: () -> Integer + # Translate position to location. def pos_to_loc: (Integer pos) -> loc @@ -28,5 +52,39 @@ module RBS def loc_to_pos: (loc loc) -> Integer def last_position: () -> Integer + + # Translate `Prism::Location` to `RBS::Location` attached to this buffer + # + # It assumes the `Prism::Location` has a source which is equivalent to `self`. + # + def rbs_location: (Prism::Location) -> Location + | (Prism::Location, Prism::Location) -> Location + + # Construct a buffer from substrings of this buffer. + # + # The returned buffer contains lines from given ranges. + # + # ```rb + # buffer = Buffer.new(name: name, content: < Buffer with content = 1\n34 + # buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline + # ``` + # + %a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer + + %a{pure} def parent_buffer: () -> Buffer? + + %a{pure} def parent_position: (Integer) -> Integer? + + %a{pure} def absolute_position: (Integer) -> Integer? + + %a{pure} def top_buffer: () -> Buffer + + %a{pure} def detach: () -> Buffer end end diff --git a/sig/environment.rbs b/sig/environment.rbs index 0d7e783aa..ec6f90fac 100644 --- a/sig/environment.rbs +++ b/sig/environment.rbs @@ -216,8 +216,10 @@ module RBS def resolve_ruby_decl: (Resolver::TypeNameResolver, AST::Ruby::Declarations::t, context: Resolver::context, prefix: Namespace) -> AST::Ruby::Declarations::t - def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t + def resolve_ruby_member: (Resolver::TypeNameResolver, AST::Ruby::Members::t, context: Resolver::context) -> AST::Ruby::Members::t - def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName + def absolute_type: (Resolver::TypeNameResolver, UseMap? map, Types::t, context: Resolver::context) -> Types::t + + def absolute_type_name: (Resolver::TypeNameResolver, UseMap? map, TypeName, context: Resolver::context) -> TypeName end end diff --git a/sig/inline_parser.rbs b/sig/inline_parser.rbs index a7d05a14f..bf2861434 100644 --- a/sig/inline_parser.rbs +++ b/sig/inline_parser.rbs @@ -32,9 +32,16 @@ module RBS class TopLevelMethodDefinition < Base end + class UnusedInlineAnnotation < Base + end + + class AnnotationSyntaxError < Base + end + type t = NotImplementedYet | NonConstantClassName | NonConstantModuleName | TopLevelMethodDefinition + | UnusedInlineAnnotation | AnnotationSyntaxError end def self.parse: (Buffer, Prism::ParseResult) -> Result @@ -46,6 +53,8 @@ module RBS include AST::Ruby::Helpers::LocationHelper + attr_reader comments: CommentAssociation + attr_reader result: Result attr_reader module_nesting: Array[module_context] @@ -62,7 +71,17 @@ module RBS def push_module_nesting: [T] (module_context) { () -> T } -> T + # Returns `true` if the node is a comment block including `@rbs skip` annotation + # + # Doesn't update the `association` flag if returning `false`. + # + def skip_node?: (Prism::Node) -> bool + def insert_declaration: (module_context) -> void + + def report_unused_annotation: (*AST::Ruby::Annotations::t | nil | AST::Ruby::CommentBlock::AnnotationSyntaxError) -> void + + def report_unused_block: (AST::Ruby::CommentBlock) -> void end end end diff --git a/sig/inline_parser/comment_association.rbs b/sig/inline_parser/comment_association.rbs new file mode 100644 index 000000000..00826469e --- /dev/null +++ b/sig/inline_parser/comment_association.rbs @@ -0,0 +1,71 @@ +use RBS::AST::Ruby::CommentBlock + +module RBS + class InlineParser + # CommentAssociation manages the association between `Prism::Node` and `CommentBlock` + # + class CommentAssociation + attr_reader blocks: Array[CommentBlock] + + attr_reader start_line_map: Hash[Integer, CommentBlock] + + attr_reader end_line_map: Hash[Integer, CommentBlock] + + # CommentBlocks that are already associated to a node, which cannot be associated to another node again + # + attr_reader associated_blocks: Set[CommentBlock] + + def self.build: (Buffer, Prism::Result) -> instance + + def initialize: (Array[CommentBlock]) -> void + + class Reference + attr_reader block: CommentBlock + + @associated_blocks: Set[CommentBlock] + + def initialize: (CommentBlock, Set[CommentBlock]) -> void + + def associate!: () -> self + + def associated?: () -> bool + end + + # Returns an unassociated CommentBlock that can be associated to given node + # + # Automatically updates association status. + # + def leading_block!: (Prism::Node) -> CommentBlock? + + # Returns a Reference that is associated to given node + # + # Updates association explicitly through the reference. + # + def leading_block: (Prism::Node) -> Reference? + + # Returns a CommentBlock that is associated to given node, or by its location + # + # Update association status. + # + def trailing_block!: (Prism::Node | Prism::Location) -> CommentBlock? + + # Returns a Reference that is associated to given node, or by its location + # + # Updates association explicitly through the reference. + # + def trailing_block: (Prism::Node | Prism::Location) -> Reference? + + # Yields leading CommentBlocks that is enclosed in the given node + # + # Note that `enclosed_blocks` works only after all of the *leading* blocks inside the node is associated. + # + # Update association status. + # + def each_enclosed_block: (Prism::Node) { (CommentBlock) -> void } -> void + | (Prism::Node) -> Enumerator[CommentBlock] + + def each_unassociated_block: () { (CommentBlock) -> void } -> void + | () -> Enumerator[CommentBlock] + end + end +end diff --git a/sig/location.rbs b/sig/location.rbs index e6d7fac45..d27bb616b 100644 --- a/sig/location.rbs +++ b/sig/location.rbs @@ -8,10 +8,16 @@ module RBS # The buffer this location points on. attr_reader buffer (): Buffer - # The index of character the range starts from. + # The absolute start index of character the range starts from + # + # It returns the index in the `buffer.top_buffer`. + # attr_reader start_pos (): Integer - # The index of character the range ends at. + # The absolute end index of character the range ends at + # + # It returns the index in the `buffer.top_buffer`. + # attr_reader end_pos (): Integer def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void @@ -24,26 +30,37 @@ module RBS # Returns the name of the buffer. def name: () -> untyped - # Line of the `start_pos` (1 origin) + # The *raw* index of character the range starts from. + attr_reader _start_pos (): Integer + + # The *raw* index of character the range ends at. + attr_reader _end_pos (): Integer + + # Line of the `start_pos` (1 origin, absolute) attr_reader start_line (): Integer - # Column of the `start_pos` (0 origin) + # Column of the `start_pos` (0 origin, absolute) attr_reader start_column (): Integer - # Line of the `end_pos` (1 origin) + # Line of the `end_pos` (1 origin, absolute) attr_reader end_line (): Integer - # Column of the `end_pos` (0 origin) + # Column of the `end_pos` (0 origin, absolute) attr_reader end_column (): Integer + # The absolute line-column pair of the start position + # attr_reader start_loc (): Buffer::loc @start_loc: Buffer::loc? + # The absolute line-column pair of the end position + # attr_reader end_loc (): Buffer::loc @end_loc: Buffer::loc? + # The absolute range of the start and end position attr_reader range (): Range[Integer] @range: Range[Integer]? @@ -97,6 +114,14 @@ module RBS def key?: (Symbol) -> bool + # Returns the location of the buffer, but the buffer is detached from the parent buffer + # + def local_location: () -> self + + # Returns the source of `#local_location` + # + def local_source: () -> String + private def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void diff --git a/sig/parser.rbs b/sig/parser.rbs index da9e94692..c19c09de3 100644 --- a/sig/parser.rbs +++ b/sig/parser.rbs @@ -82,6 +82,18 @@ module RBS KEYWORDS: Hash[String, bot] + # Parse a leading annotation and return it + # + # Raises an exception if the source text contains a syntax error. + # + def self.parse_inline_leading_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::leading_annotation + + # Parse a leading annotation and return it + # + # Raises an exception if the source text contains a syntax error. + # + def self.parse_inline_trailing_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::trailing_annotation + private def self.buffer: (String | Buffer source) -> Buffer @@ -94,6 +106,10 @@ module RBS def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]] + def self._parse_inline_leading_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::leading_annotation + + def self._parse_inline_trailing_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::trailing_annotation + class LocatedValue end end diff --git a/src/ast.c b/src/ast.c index 738e06b08..1e4a89151 100644 --- a/src/ast.c +++ b/src/ast.c @@ -44,6 +44,11 @@ const char* rbs_node_type_name(rbs_node_t *node) { case RBS_AST_MEMBERS_PREPEND: return "RBS::AST::Members::Prepend"; case RBS_AST_MEMBERS_PRIVATE: return "RBS::AST::Members::Private"; case RBS_AST_MEMBERS_PUBLIC: return "RBS::AST::Members::Public"; + case RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION: return "RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation"; + case RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION: return "RBS::AST::Ruby::Annotations::MethodTypesAnnotation"; + case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION: return "RBS::AST::Ruby::Annotations::NodeTypeAssertion"; + case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: return "RBS::AST::Ruby::Annotations::ReturnTypeAnnotation"; + case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION: return "RBS::AST::Ruby::Annotations::SkipAnnotation"; case RBS_AST_STRING: return "RBS::AST::String"; case RBS_AST_TYPE_PARAM: return "RBS::AST::TypeParam"; case RBS_METHOD_TYPE: return "RBS::MethodType"; @@ -756,6 +761,92 @@ rbs_ast_members_public_t *rbs_ast_members_public_new(rbs_allocator_t *allocator, return instance; } #line 153 "prism/templates/src/ast.c.erb" +rbs_ast_ruby_annotations_colon_method_type_annotation_t *rbs_ast_ruby_annotations_colon_method_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *annotations, rbs_node_t *method_type) { + rbs_ast_ruby_annotations_colon_method_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_colon_method_type_annotation_t); + + + *instance = (rbs_ast_ruby_annotations_colon_method_type_annotation_t) { + .base = (rbs_node_t) { + .type = RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION, + .location = location, + }, + .prefix_location = prefix_location, + .annotations = annotations, + .method_type = method_type, + }; + + return instance; +} +#line 153 "prism/templates/src/ast.c.erb" +rbs_ast_ruby_annotations_method_types_annotation_t *rbs_ast_ruby_annotations_method_types_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *overloads, rbs_location_list_t *vertical_bar_locations) { + rbs_ast_ruby_annotations_method_types_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_method_types_annotation_t); + + + *instance = (rbs_ast_ruby_annotations_method_types_annotation_t) { + .base = (rbs_node_t) { + .type = RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION, + .location = location, + }, + .prefix_location = prefix_location, + .overloads = overloads, + .vertical_bar_locations = vertical_bar_locations, + }; + + return instance; +} +#line 153 "prism/templates/src/ast.c.erb" +rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_type_assertion_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_t *type) { + rbs_ast_ruby_annotations_node_type_assertion_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_node_type_assertion_t); + + + *instance = (rbs_ast_ruby_annotations_node_type_assertion_t) { + .base = (rbs_node_t) { + .type = RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION, + .location = location, + }, + .prefix_location = prefix_location, + .type = type, + }; + + return instance; +} +#line 153 "prism/templates/src/ast.c.erb" +rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *return_location, rbs_location_t *colon_location, rbs_node_t *return_type, rbs_location_t *comment_location) { + rbs_ast_ruby_annotations_return_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_return_type_annotation_t); + + + *instance = (rbs_ast_ruby_annotations_return_type_annotation_t) { + .base = (rbs_node_t) { + .type = RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION, + .location = location, + }, + .prefix_location = prefix_location, + .return_location = return_location, + .colon_location = colon_location, + .return_type = return_type, + .comment_location = comment_location, + }; + + return instance; +} +#line 153 "prism/templates/src/ast.c.erb" +rbs_ast_ruby_annotations_skip_annotation_t *rbs_ast_ruby_annotations_skip_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *skip_location, rbs_location_t *comment_location) { + rbs_ast_ruby_annotations_skip_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_skip_annotation_t); + + + *instance = (rbs_ast_ruby_annotations_skip_annotation_t) { + .base = (rbs_node_t) { + .type = RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION, + .location = location, + }, + .prefix_location = prefix_location, + .skip_location = skip_location, + .comment_location = comment_location, + }; + + return instance; +} +#line 153 "prism/templates/src/ast.c.erb" rbs_ast_string_t *rbs_ast_string_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_string_t string) { rbs_ast_string_t *instance = rbs_allocator_alloc(allocator, rbs_ast_string_t); diff --git a/src/lexer.c b/src/lexer.c index 432966fdf..685d1dcef 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -94,7 +94,6 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { case 'k': case 'l': case 'q': - case 'r': case 'w': case 'x': case 'y': @@ -104,24 +103,25 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { case 'n': goto yy56; case 'o': goto yy57; case 'p': goto yy58; - case 's': goto yy59; - case 't': goto yy60; - case 'u': goto yy61; - case 'v': goto yy62; - case '{': goto yy63; - case '|': goto yy64; - case '}': goto yy65; + case 'r': goto yy59; + case 's': goto yy60; + case 't': goto yy61; + case 'u': goto yy62; + case 'v': goto yy63; + case '{': goto yy64; + case '|': goto yy65; + case '}': goto yy66; default: goto yy2; } yy1: rbs_skip(lexer); -#line 144 "src/lexer.re" +#line 148 "src/lexer.re" { return rbs_next_eof_token(lexer); } #line 121 "src/lexer.c" yy2: rbs_skip(lexer); yy3: -#line 145 "src/lexer.re" +#line 149 "src/lexer.re" { return rbs_next_token(lexer, ErrorToken); } #line 127 "src/lexer.c" yy4: @@ -130,7 +130,7 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { if (yych == '\t') goto yy4; if (yych == ' ') goto yy4; yy5: -#line 143 "src/lexer.re" +#line 147 "src/lexer.re" { return rbs_next_token(lexer, tTRIVIA); } #line 136 "src/lexer.c" yy6: @@ -151,14 +151,14 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { backup = *lexer; yych = rbs_peek(lexer); if (yych <= 0x00000000) goto yy3; - goto yy67; + goto yy68; yy10: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= 0x00000000) goto yy11; if (yych != '\n') goto yy10; yy11: -#line 59 "src/lexer.re" +#line 60 "src/lexer.re" { return rbs_next_token( lexer, @@ -173,42 +173,42 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { if (yych <= 0x0000001F) { if (yych <= '\n') { if (yych <= 0x00000000) goto yy3; - if (yych <= 0x00000008) goto yy71; + if (yych <= 0x00000008) goto yy72; goto yy3; } else { if (yych == '\r') goto yy3; - goto yy71; + goto yy72; } } else { if (yych <= '#') { if (yych <= ' ') goto yy3; - if (yych <= '"') goto yy73; - goto yy71; + if (yych <= '"') goto yy74; + goto yy72; } else { if (yych == '%') goto yy3; - if (yych <= '\'') goto yy73; + if (yych <= '\'') goto yy74; goto yy3; } } } else { if (yych <= 'Z') { if (yych <= '/') { - if (yych == '-') goto yy71; - goto yy73; + if (yych == '-') goto yy72; + goto yy74; } else { - if (yych <= '9') goto yy71; - if (yych <= '>') goto yy73; - goto yy71; + if (yych <= '9') goto yy72; + if (yych <= '>') goto yy74; + goto yy72; } } else { if (yych <= '^') { - if (yych == '\\') goto yy73; + if (yych == '\\') goto yy74; goto yy3; } else { - if (yych <= 'z') goto yy71; + if (yych <= 'z') goto yy72; if (yych <= '}') goto yy3; - if (yych <= '~') goto yy73; - goto yy71; + if (yych <= '~') goto yy74; + goto yy72; } } } @@ -217,7 +217,7 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { rbs_skip(lexer); backup = *lexer; yych = rbs_peek(lexer); - if (yych == 'a') goto yy74; + if (yych == 'a') goto yy75; goto yy8; yy14: rbs_skip(lexer); @@ -230,7 +230,7 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { backup = *lexer; yych = rbs_peek(lexer); if (yych <= 0x00000000) goto yy3; - goto yy76; + goto yy77; yy16: rbs_skip(lexer); #line 24 "src/lexer.re" @@ -244,7 +244,7 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy18: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '*') goto yy80; + if (yych == '*') goto yy81; #line 35 "src/lexer.re" { return rbs_next_token(lexer, pSTAR); } #line 251 "src/lexer.c" @@ -263,25 +263,32 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy21: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= '=') { - if (yych <= '/') goto yy8; - if (yych <= '9') goto yy25; - goto yy8; - } else { - if (yych <= '>') goto yy81; - if (yych == '@') goto yy24; - goto yy8; + switch (yych) { + case '-': goto yy82; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy25; + case '>': goto yy83; + case '@': goto yy24; + default: goto yy8; } yy22: yyaccept = 2; rbs_skip(lexer); backup = *lexer; yych = rbs_peek(lexer); - if (yych == '.') goto yy82; + if (yych == '.') goto yy84; yy23: #line 37 "src/lexer.re" { return rbs_next_token(lexer, pDOT); } -#line 285 "src/lexer.c" +#line 292 "src/lexer.c" yy24: rbs_skip(lexer); goto yy8; @@ -292,34 +299,34 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { if (yych <= '9') goto yy25; if (yych == '_') goto yy25; yy26: -#line 51 "src/lexer.re" +#line 52 "src/lexer.re" { return rbs_next_token(lexer, tINTEGER); } -#line 298 "src/lexer.c" +#line 305 "src/lexer.c" yy27: yyaccept = 3; rbs_skip(lexer); backup = *lexer; yych = rbs_peek(lexer); switch (yych) { - case '!': goto yy83; - case '"': goto yy85; - case '$': goto yy86; + case '!': goto yy85; + case '"': goto yy87; + case '$': goto yy88; case '%': case '&': case '/': case '^': case '`': case '|': - case '~': goto yy87; - case '\'': goto yy88; - case '*': goto yy89; + case '~': goto yy89; + case '\'': goto yy90; + case '*': goto yy91; case '+': - case '-': goto yy90; - case ':': goto yy91; - case '<': goto yy92; - case '=': goto yy93; - case '>': goto yy94; - case '@': goto yy95; + case '-': goto yy92; + case ':': goto yy93; + case '<': goto yy94; + case '=': goto yy95; + case '>': goto yy96; + case '@': goto yy97; case 'A': case 'B': case 'C': @@ -372,38 +379,38 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { case 'w': case 'x': case 'y': - case 'z': goto yy96; - case '[': goto yy98; + case 'z': goto yy98; + case '[': goto yy100; default: goto yy28; } yy28: #line 44 "src/lexer.re" { return rbs_next_token(lexer, pCOLON); } -#line 383 "src/lexer.c" +#line 390 "src/lexer.c" yy29: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= ';') goto yy30; if (yych <= '<') goto yy24; - if (yych <= '=') goto yy99; + if (yych <= '=') goto yy101; yy30: #line 46 "src/lexer.re" { return rbs_next_token(lexer, pLT); } -#line 393 "src/lexer.c" +#line 400 "src/lexer.c" yy31: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '>') { if (yych <= '<') goto yy32; - if (yych <= '=') goto yy100; - goto yy101; + if (yych <= '=') goto yy102; + goto yy103; } else { if (yych == '~') goto yy24; } yy32: #line 43 "src/lexer.re" { return rbs_next_token(lexer, pEQ); } -#line 407 "src/lexer.c" +#line 414 "src/lexer.c" yy33: rbs_skip(lexer); yych = rbs_peek(lexer); @@ -414,31 +421,40 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { rbs_skip(lexer); #line 34 "src/lexer.re" { return rbs_next_token(lexer, pQUESTION); } -#line 418 "src/lexer.c" +#line 425 "src/lexer.c" yy35: yyaccept = 0; rbs_skip(lexer); backup = *lexer; yych = rbs_peek(lexer); - if (yych <= '^') { - if (yych <= '?') goto yy3; - if (yych <= '@') goto yy102; - if (yych <= 'Z') goto yy103; - goto yy3; + if (yych <= '_') { + if (yych <= '@') { + if (yych <= '?') goto yy3; + goto yy104; + } else { + if (yych <= 'Z') goto yy105; + if (yych <= '^') goto yy3; + goto yy105; + } } else { - if (yych == '`') goto yy3; - if (yych <= 'z') goto yy103; - goto yy3; + if (yych <= 'q') { + if (yych <= '`') goto yy3; + goto yy105; + } else { + if (yych <= 'r') goto yy108; + if (yych <= 'z') goto yy105; + goto yy3; + } } yy36: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy36; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { @@ -450,50 +466,50 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { } } yy37: -#line 129 "src/lexer.re" +#line 133 "src/lexer.re" { return rbs_next_token(lexer, tUIDENT); } -#line 456 "src/lexer.c" +#line 472 "src/lexer.c" yy38: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == ']') goto yy107; + if (yych == ']') goto yy111; #line 26 "src/lexer.re" { return rbs_next_token(lexer, pLBRACKET); } -#line 463 "src/lexer.c" +#line 479 "src/lexer.c" yy39: rbs_skip(lexer); #line 27 "src/lexer.re" { return rbs_next_token(lexer, pRBRACKET); } -#line 468 "src/lexer.c" +#line 484 "src/lexer.c" yy40: rbs_skip(lexer); #line 32 "src/lexer.re" { return rbs_next_token(lexer, pHAT); } -#line 473 "src/lexer.c" +#line 489 "src/lexer.c" yy41: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy112; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { if (yych <= '@') goto yy42; - if (yych <= 'Z') goto yy111; + if (yych <= 'Z') goto yy115; } else { - if (yych <= '_') goto yy113; + if (yych <= '_') goto yy117; if (yych <= '`') goto yy42; - if (yych <= 'z') goto yy108; + if (yych <= 'z') goto yy112; } } yy42: -#line 132 "src/lexer.re" +#line 136 "src/lexer.re" { return rbs_next_token(lexer, tULLIDENT); } -#line 497 "src/lexer.c" +#line 513 "src/lexer.c" yy43: yyaccept = 4; rbs_skip(lexer); @@ -501,54 +517,54 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yych = rbs_peek(lexer); if (yych <= ' ') { if (yych <= 0x00000000) goto yy44; - if (yych <= 0x0000001F) goto yy114; + if (yych <= 0x0000001F) goto yy118; } else { - if (yych != ':') goto yy114; + if (yych != ':') goto yy118; } yy44: #line 39 "src/lexer.re" { return rbs_next_token(lexer, tOPERATOR); } -#line 512 "src/lexer.c" +#line 528 "src/lexer.c" yy45: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= 'r') { - if (yych == 'l') goto yy115; + if (yych == 'l') goto yy119; goto yy53; } else { - if (yych <= 's') goto yy116; - if (yych <= 't') goto yy118; + if (yych <= 's') goto yy120; + if (yych <= 't') goto yy122; goto yy53; } yy46: -#line 128 "src/lexer.re" +#line 132 "src/lexer.re" { return rbs_next_token(lexer, tLIDENT); } -#line 527 "src/lexer.c" +#line 543 "src/lexer.c" yy47: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy119; + if (yych == 'o') goto yy123; goto yy53; yy48: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy120; + if (yych == 'l') goto yy124; goto yy53; yy49: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy121; + if (yych == 'e') goto yy125; goto yy53; yy50: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy122; - if (yych == 'x') goto yy123; + if (yych == 'n') goto yy126; + if (yych == 'x') goto yy127; goto yy53; yy51: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy124; + if (yych == 'a') goto yy128; goto yy53; yy52: rbs_skip(lexer); @@ -556,12 +572,12 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy53: if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; goto yy46; } else { if (yych <= '9') goto yy52; if (yych <= '<') goto yy46; - goto yy106; + goto yy110; } } else { if (yych <= '^') { @@ -577,85 +593,95 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy54: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy125; + if (yych == 'n') goto yy129; goto yy53; yy55: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy127; + if (yych == 'o') goto yy131; goto yy53; yy56: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'i') goto yy128; + if (yych == 'i') goto yy132; goto yy53; yy57: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy129; + if (yych == 'u') goto yy133; goto yy53; yy58: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy130; - if (yych == 'u') goto yy131; + if (yych == 'r') goto yy134; + if (yych == 'u') goto yy135; goto yy53; yy59: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy132; - if (yych == 'i') goto yy133; + if (yych == 'e') goto yy136; goto yy53; yy60: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 'q') { - if (yych == 'o') goto yy134; + if (yych <= 'h') { + if (yych == 'e') goto yy137; goto yy53; } else { - if (yych <= 'r') goto yy135; - if (yych == 'y') goto yy136; + if (yych <= 'i') goto yy138; + if (yych == 'k') goto yy139; goto yy53; } yy61: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy137; - if (yych == 's') goto yy138; - goto yy53; + if (yych <= 'q') { + if (yych == 'o') goto yy140; + goto yy53; + } else { + if (yych <= 'r') goto yy141; + if (yych == 'y') goto yy142; + goto yy53; + } yy62: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy139; + if (yych == 'n') goto yy143; + if (yych == 's') goto yy144; goto yy53; yy63: rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'o') goto yy145; + goto yy53; +yy64: + rbs_skip(lexer); #line 28 "src/lexer.re" { return rbs_next_token(lexer, pLBRACE); } -#line 636 "src/lexer.c" -yy64: +#line 662 "src/lexer.c" +yy65: rbs_skip(lexer); #line 31 "src/lexer.re" { return rbs_next_token(lexer, pBAR); } -#line 641 "src/lexer.c" -yy65: +#line 667 "src/lexer.c" +yy66: rbs_skip(lexer); #line 29 "src/lexer.re" { return rbs_next_token(lexer, pRBRACE); } -#line 646 "src/lexer.c" -yy66: +#line 672 "src/lexer.c" +yy67: rbs_skip(lexer); yych = rbs_peek(lexer); -yy67: +yy68: if (yych <= '"') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '!') goto yy66; - goto yy69; + if (yych <= 0x00000000) goto yy69; + if (yych <= '!') goto yy67; + goto yy70; } else { - if (yych == '\\') goto yy70; - goto yy66; + if (yych == '\\') goto yy71; + goto yy67; } -yy68: +yy69: *lexer = backup; if (yyaccept <= 3) { if (yyaccept <= 1) { @@ -676,523 +702,515 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { if (yyaccept == 4) { goto yy44; } else { - goto yy78; + goto yy79; } } else { - goto yy155; + goto yy161; } } -yy69: +yy70: rbs_skip(lexer); -#line 106 "src/lexer.re" +#line 110 "src/lexer.re" { return rbs_next_token(lexer, tDQSTRING); } -#line 690 "src/lexer.c" -yy70: +#line 716 "src/lexer.c" +yy71: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy140; - if (yych == 'x') goto yy141; - goto yy66; -yy71: + if (yych == 'u') goto yy146; + if (yych == 'x') goto yy147; + goto yy67; +yy72: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= ',') { if (yych <= '\f') { - if (yych <= 0x00000000) goto yy72; - if (yych <= 0x00000008) goto yy71; - if (yych >= '\v') goto yy71; + if (yych <= 0x00000000) goto yy73; + if (yych <= 0x00000008) goto yy72; + if (yych >= '\v') goto yy72; } else { if (yych <= 0x0000001F) { - if (yych >= 0x0000000E) goto yy71; + if (yych >= 0x0000000E) goto yy72; } else { - if (yych == '#') goto yy71; + if (yych == '#') goto yy72; } } } else { if (yych <= '>') { - if (yych <= '-') goto yy71; - if (yych <= '/') goto yy72; - if (yych <= '9') goto yy71; + if (yych <= '-') goto yy72; + if (yych <= '/') goto yy73; + if (yych <= '9') goto yy72; } else { if (yych <= '^') { - if (yych <= 'Z') goto yy71; + if (yych <= 'Z') goto yy72; } else { - if (yych <= 'z') goto yy71; - if (yych >= 0x0000007F) goto yy71; + if (yych <= 'z') goto yy72; + if (yych >= 0x0000007F) goto yy72; } } } -yy72: -#line 139 "src/lexer.re" - { return rbs_next_token(lexer, tGIDENT); } -#line 729 "src/lexer.c" yy73: - rbs_skip(lexer); - goto yy72; +#line 143 "src/lexer.re" + { return rbs_next_token(lexer, tGIDENT); } +#line 755 "src/lexer.c" yy74: + rbs_skip(lexer); + goto yy73; +yy75: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= 'Z') { if (yych <= '(') { - if (yych <= '\'') goto yy68; - goto yy142; + if (yych <= '\'') goto yy69; + goto yy148; } else { - if (yych == '<') goto yy143; - goto yy68; + if (yych == '<') goto yy149; + goto yy69; } } else { if (yych <= 'z') { - if (yych <= '[') goto yy144; - goto yy68; + if (yych <= '[') goto yy150; + goto yy69; } else { - if (yych <= '{') goto yy145; - if (yych <= '|') goto yy146; - goto yy68; + if (yych <= '{') goto yy151; + if (yych <= '|') goto yy152; + goto yy69; } } -yy75: +yy76: rbs_skip(lexer); yych = rbs_peek(lexer); -yy76: +yy77: if (yych <= '\'') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '&') goto yy75; + if (yych <= 0x00000000) goto yy69; + if (yych <= '&') goto yy76; } else { - if (yych == '\\') goto yy79; - goto yy75; + if (yych == '\\') goto yy80; + goto yy76; } -yy77: - rbs_skip(lexer); yy78: -#line 107 "src/lexer.re" - { return rbs_next_token(lexer, tSQSTRING); } -#line 770 "src/lexer.c" + rbs_skip(lexer); yy79: +#line 111 "src/lexer.re" + { return rbs_next_token(lexer, tSQSTRING); } +#line 796 "src/lexer.c" +yy80: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '\'') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '&') goto yy75; - goto yy147; + if (yych <= 0x00000000) goto yy69; + if (yych <= '&') goto yy76; + goto yy153; } else { - if (yych == '\\') goto yy79; - goto yy75; + if (yych == '\\') goto yy80; + goto yy76; } -yy80: +yy81: rbs_skip(lexer); #line 36 "src/lexer.re" { return rbs_next_token(lexer, pSTAR2); } -#line 786 "src/lexer.c" -yy81: +#line 812 "src/lexer.c" +yy82: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych >= 0x00000001) goto yy82; +#line 49 "src/lexer.re" + { return rbs_next_token(lexer, tINLINECOMMENT); } +#line 819 "src/lexer.c" +yy83: rbs_skip(lexer); #line 41 "src/lexer.re" { return rbs_next_token(lexer, pARROW); } -#line 791 "src/lexer.c" -yy82: +#line 824 "src/lexer.c" +yy84: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '.') goto yy148; - goto yy68; -yy83: + if (yych == '.') goto yy154; + goto yy69; +yy85: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '=') goto yy87; - if (yych == '~') goto yy87; -yy84: -#line 126 "src/lexer.re" + if (yych == '=') goto yy89; + if (yych == '~') goto yy89; +yy86: +#line 130 "src/lexer.re" { return rbs_next_token(lexer, tSYMBOL); } -#line 805 "src/lexer.c" -yy85: +#line 838 "src/lexer.c" +yy87: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '"') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '!') goto yy85; - goto yy149; + if (yych <= 0x00000000) goto yy69; + if (yych <= '!') goto yy87; + goto yy155; } else { - if (yych == '\\') goto yy150; - goto yy85; + if (yych == '\\') goto yy156; + goto yy87; } -yy86: +yy88: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= ')') { if (yych <= 0x0000001F) { if (yych <= '\n') { - if (yych <= 0x00000000) goto yy68; - if (yych <= 0x00000008) goto yy151; - goto yy68; + if (yych <= 0x00000000) goto yy69; + if (yych <= 0x00000008) goto yy157; + goto yy69; } else { - if (yych == '\r') goto yy68; - goto yy151; + if (yych == '\r') goto yy69; + goto yy157; } } else { if (yych <= '#') { - if (yych <= ' ') goto yy68; - if (yych <= '"') goto yy153; - goto yy151; + if (yych <= ' ') goto yy69; + if (yych <= '"') goto yy159; + goto yy157; } else { - if (yych == '%') goto yy68; - if (yych <= '\'') goto yy153; - goto yy68; + if (yych == '%') goto yy69; + if (yych <= '\'') goto yy159; + goto yy69; } } } else { if (yych <= 'Z') { if (yych <= '/') { - if (yych == '-') goto yy151; - goto yy153; + if (yych == '-') goto yy157; + goto yy159; } else { - if (yych <= '9') goto yy151; - if (yych <= '>') goto yy153; - goto yy151; + if (yych <= '9') goto yy157; + if (yych <= '>') goto yy159; + goto yy157; } } else { if (yych <= '^') { - if (yych == '\\') goto yy153; - goto yy68; + if (yych == '\\') goto yy159; + goto yy69; } else { - if (yych <= 'z') goto yy151; - if (yych <= '}') goto yy68; - if (yych <= '~') goto yy153; - goto yy151; + if (yych <= 'z') goto yy157; + if (yych <= '}') goto yy69; + if (yych <= '~') goto yy159; + goto yy157; } } } -yy87: +yy89: rbs_skip(lexer); - goto yy84; -yy88: + goto yy86; +yy90: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '\'') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '&') goto yy88; - goto yy154; + if (yych <= 0x00000000) goto yy69; + if (yych <= '&') goto yy90; + goto yy160; } else { - if (yych == '\\') goto yy156; - goto yy88; + if (yych == '\\') goto yy162; + goto yy90; } -yy89: +yy91: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '*') goto yy87; - goto yy84; -yy90: + if (yych == '*') goto yy89; + goto yy86; +yy92: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '@') goto yy87; - goto yy84; -yy91: + if (yych == '@') goto yy89; + goto yy86; +yy93: rbs_skip(lexer); #line 45 "src/lexer.re" { return rbs_next_token(lexer, pCOLON2); } -#line 891 "src/lexer.c" -yy92: +#line 924 "src/lexer.c" +yy94: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= ';') goto yy84; - if (yych <= '<') goto yy87; - if (yych <= '=') goto yy157; - goto yy84; -yy93: + if (yych <= ';') goto yy86; + if (yych <= '<') goto yy89; + if (yych <= '=') goto yy163; + goto yy86; +yy95: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '=') goto yy158; - if (yych == '~') goto yy87; - goto yy68; -yy94: + if (yych == '=') goto yy164; + if (yych == '~') goto yy89; + goto yy69; +yy96: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= '<') goto yy84; - if (yych <= '>') goto yy87; - goto yy84; -yy95: + if (yych <= '<') goto yy86; + if (yych <= '>') goto yy89; + goto yy86; +yy97: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '^') { - if (yych <= '?') goto yy68; - if (yych <= '@') goto yy159; - if (yych <= 'Z') goto yy160; - goto yy68; + if (yych <= '?') goto yy69; + if (yych <= '@') goto yy165; + if (yych <= 'Z') goto yy166; + goto yy69; } else { - if (yych == '`') goto yy68; - if (yych <= 'z') goto yy160; - goto yy68; + if (yych == '`') goto yy69; + if (yych <= 'z') goto yy166; + goto yy69; } -yy96: +yy98: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy162; + if (yych == '!') goto yy168; } else { - if (yych <= '9') goto yy96; - if (yych == '=') goto yy162; + if (yych <= '9') goto yy98; + if (yych == '=') goto yy168; } } else { if (yych <= '^') { - if (yych <= '?') goto yy162; - if (yych <= '@') goto yy97; - if (yych <= 'Z') goto yy96; + if (yych <= '?') goto yy168; + if (yych <= '@') goto yy99; + if (yych <= 'Z') goto yy98; } else { - if (yych == '`') goto yy97; - if (yych <= 'z') goto yy96; + if (yych == '`') goto yy99; + if (yych <= 'z') goto yy98; } } -yy97: -#line 122 "src/lexer.re" +yy99: +#line 126 "src/lexer.re" { return rbs_next_token(lexer, tSYMBOL); } -#line 947 "src/lexer.c" -yy98: +#line 980 "src/lexer.c" +yy100: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == ']') goto yy158; - goto yy68; -yy99: + if (yych == ']') goto yy164; + goto yy69; +yy101: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych == '>') goto yy24; goto yy8; -yy100: +yy102: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych == '=') goto yy24; goto yy8; -yy101: +yy103: rbs_skip(lexer); #line 42 "src/lexer.re" { return rbs_next_token(lexer, pFATARROW); } -#line 967 "src/lexer.c" -yy102: +#line 1000 "src/lexer.c" +yy104: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '^') { - if (yych <= '@') goto yy68; - if (yych <= 'Z') goto yy163; - goto yy68; + if (yych <= '@') goto yy69; + if (yych <= 'Z') goto yy169; + goto yy69; } else { - if (yych == '`') goto yy68; - if (yych <= 'z') goto yy163; - goto yy68; + if (yych == '`') goto yy69; + if (yych <= 'z') goto yy169; + goto yy69; } -yy103: +yy105: rbs_skip(lexer); yych = rbs_peek(lexer); +yy106: if (yych <= 'Z') { - if (yych <= '/') goto yy104; - if (yych <= '9') goto yy103; - if (yych >= 'A') goto yy103; + if (yych <= '/') goto yy107; + if (yych <= '9') goto yy105; + if (yych >= 'A') goto yy105; } else { if (yych <= '_') { - if (yych >= '_') goto yy103; + if (yych >= '_') goto yy105; } else { - if (yych <= '`') goto yy104; - if (yych <= 'z') goto yy103; + if (yych <= '`') goto yy107; + if (yych <= 'z') goto yy105; } } -yy104: -#line 136 "src/lexer.re" +yy107: +#line 140 "src/lexer.re" { return rbs_next_token(lexer, tAIDENT); } -#line 998 "src/lexer.c" -yy105: +#line 1032 "src/lexer.c" +yy108: rbs_skip(lexer); -#line 133 "src/lexer.re" + yych = rbs_peek(lexer); + if (yych == 'b') goto yy171; + goto yy106; +yy109: + rbs_skip(lexer); +#line 137 "src/lexer.re" { return rbs_next_token(lexer, tBANGIDENT); } -#line 1003 "src/lexer.c" -yy106: +#line 1042 "src/lexer.c" +yy110: rbs_skip(lexer); -#line 134 "src/lexer.re" +#line 138 "src/lexer.re" { return rbs_next_token(lexer, tEQIDENT); } -#line 1008 "src/lexer.c" -yy107: +#line 1047 "src/lexer.c" +yy111: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych == '=') goto yy24; #line 47 "src/lexer.re" { return rbs_next_token(lexer, pAREF_OPR); } -#line 1015 "src/lexer.c" -yy108: +#line 1054 "src/lexer.c" +yy112: rbs_skip(lexer); yych = rbs_peek(lexer); -yy109: +yy113: if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy112; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy110; - if (yych <= 'Z') goto yy108; + if (yych <= '@') goto yy114; + if (yych <= 'Z') goto yy112; } else { - if (yych == '`') goto yy110; - if (yych <= 'z') goto yy108; + if (yych == '`') goto yy114; + if (yych <= 'z') goto yy112; } } -yy110: -#line 130 "src/lexer.re" +yy114: +#line 134 "src/lexer.re" { return rbs_next_token(lexer, tULLIDENT); } -#line 1039 "src/lexer.c" -yy111: +#line 1078 "src/lexer.c" +yy115: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { - if (yych <= '9') goto yy111; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy115; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy112; - if (yych <= 'Z') goto yy111; + if (yych <= '@') goto yy116; + if (yych <= 'Z') goto yy115; } else { - if (yych == '`') goto yy112; - if (yych <= 'z') goto yy111; + if (yych == '`') goto yy116; + if (yych <= 'z') goto yy115; } } -yy112: -#line 131 "src/lexer.re" +yy116: +#line 135 "src/lexer.re" { return rbs_next_token(lexer, tULIDENT); } -#line 1062 "src/lexer.c" -yy113: +#line 1101 "src/lexer.c" +yy117: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy165; - goto yy109; -yy114: + if (yych == 't') goto yy172; + goto yy113; +yy118: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == '`') goto yy166; - goto yy114; -yy115: + if (yych <= 0x00000000) goto yy69; + if (yych == '`') goto yy173; + goto yy118; +yy119: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'i') goto yy167; + if (yych == 'i') goto yy174; goto yy53; -yy116: +yy120: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy117; + if (yych <= '@') goto yy121; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy117; + if (yych == '`') goto yy121; if (yych <= 'z') goto yy52; } } -yy117: -#line 96 "src/lexer.re" +yy121: +#line 97 "src/lexer.re" { return rbs_next_token(lexer, kAS); } -#line 1101 "src/lexer.c" -yy118: +#line 1140 "src/lexer.c" +yy122: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy168; + if (yych == 't') goto yy175; goto yy53; -yy119: +yy123: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy169; - if (yych == 't') goto yy170; + if (yych == 'o') goto yy176; + if (yych == 't') goto yy177; goto yy53; -yy120: +yy124: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy172; + if (yych == 'a') goto yy179; goto yy53; -yy121: +yy125: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'f') goto yy173; + if (yych == 'f') goto yy180; goto yy53; -yy122: +yy126: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy175; + if (yych == 'd') goto yy182; goto yy53; -yy123: +yy127: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy177; + if (yych == 't') goto yy184; goto yy53; -yy124: +yy128: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy178; + if (yych == 'l') goto yy185; goto yy53; -yy125: +yy129: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '^') { if (yych <= '9') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; if (yych >= '0') goto yy52; } else { if (yych <= '=') { - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } else { - if (yych <= '@') goto yy126; + if (yych <= '@') goto yy130; if (yych <= 'Z') goto yy52; } } } else { if (yych <= 'c') { - if (yych == '`') goto yy126; + if (yych == '`') goto yy130; if (yych <= 'b') goto yy52; - goto yy179; + goto yy186; } else { if (yych <= 's') { if (yych <= 'r') goto yy52; - goto yy180; + goto yy187; } else { - if (yych <= 't') goto yy181; + if (yych <= 't') goto yy188; if (yych <= 'z') goto yy52; } } } -yy126: -#line 77 "src/lexer.re" - { return rbs_next_token(lexer, kIN); } -#line 1171 "src/lexer.c" -yy127: - rbs_skip(lexer); - yych = rbs_peek(lexer); - if (yych == 'd') goto yy182; - goto yy53; -yy128: - rbs_skip(lexer); - yych = rbs_peek(lexer); - if (yych == 'l') goto yy183; - goto yy53; -yy129: - rbs_skip(lexer); - yych = rbs_peek(lexer); - if (yych == 't') goto yy185; - goto yy53; yy130: - rbs_skip(lexer); - yych = rbs_peek(lexer); - if (yych == 'e') goto yy187; - if (yych == 'i') goto yy188; - goto yy53; +#line 78 "src/lexer.re" + { return rbs_next_token(lexer, kIN); } +#line 1210 "src/lexer.c" yy131: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'b') goto yy189; + if (yych == 'd') goto yy189; goto yy53; yy132: rbs_skip(lexer); @@ -1202,33 +1220,33 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy133: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy191; + if (yych == 't') goto yy192; goto yy53; yy134: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'p') goto yy192; + if (yych == 'e') goto yy194; + if (yych == 'i') goto yy195; goto yy53; yy135: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy194; + if (yych == 'b') goto yy196; goto yy53; yy136: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'p') goto yy195; + if (yych == 't') goto yy197; goto yy53; yy137: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy196; - if (yych == 't') goto yy197; + if (yych == 'l') goto yy198; goto yy53; yy138: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy198; + if (yych == 'n') goto yy199; goto yy53; yy139: rbs_skip(lexer); @@ -1238,1465 +1256,1586 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yy140: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy201; - goto yy68; - } else { - if (yych <= 'F') goto yy201; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy201; - goto yy68; - } + if (yych == 'p') goto yy201; + goto yy53; yy141: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy66; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy66; - goto yy68; + if (yych == 'u') goto yy203; + goto yy53; yy142: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == ')') goto yy202; - goto yy142; + if (yych == 'p') goto yy204; + goto yy53; yy143: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == '>') goto yy203; - goto yy143; + if (yych == 'c') goto yy205; + if (yych == 't') goto yy206; + goto yy53; yy144: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == ']') goto yy204; - goto yy144; + if (yych == 'e') goto yy207; + goto yy53; yy145: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == '}') goto yy205; - goto yy145; + if (yych == 'i') goto yy209; + goto yy53; yy146: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= 0x00000000) goto yy68; - if (yych == '|') goto yy206; - goto yy146; + if (yych <= '@') { + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy210; + goto yy69; + } else { + if (yych <= 'F') goto yy210; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy210; + goto yy69; + } yy147: - yyaccept = 5; rbs_skip(lexer); - backup = *lexer; yych = rbs_peek(lexer); - if (yych <= '\'') { - if (yych <= 0x00000000) goto yy78; - if (yych <= '&') goto yy75; - goto yy77; - } else { - if (yych == '\\') goto yy79; - goto yy75; - } + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy67; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy67; + goto yy69; yy148: rbs_skip(lexer); -#line 38 "src/lexer.re" - { return rbs_next_token(lexer, pDOT3); } -#line 1307 "src/lexer.c" + yych = rbs_peek(lexer); + if (yych <= 0x00000000) goto yy69; + if (yych == ')') goto yy211; + goto yy148; yy149: rbs_skip(lexer); -#line 108 "src/lexer.re" - { return rbs_next_token(lexer, tDQSYMBOL); } -#line 1312 "src/lexer.c" + yych = rbs_peek(lexer); + if (yych <= 0x00000000) goto yy69; + if (yych == '>') goto yy212; + goto yy149; yy150: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy207; - if (yych == 'x') goto yy208; - goto yy85; + if (yych <= 0x00000000) goto yy69; + if (yych == ']') goto yy213; + goto yy150; yy151: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= ',') { - if (yych <= '\f') { - if (yych <= 0x00000000) goto yy152; - if (yych <= 0x00000008) goto yy151; - if (yych >= '\v') goto yy151; - } else { - if (yych <= 0x0000001F) { - if (yych >= 0x0000000E) goto yy151; - } else { - if (yych == '#') goto yy151; - } - } - } else { - if (yych <= '>') { - if (yych <= '-') goto yy151; - if (yych <= '/') goto yy152; - if (yych <= '9') goto yy151; - } else { + if (yych <= 0x00000000) goto yy69; + if (yych == '}') goto yy214; + goto yy151; +yy152: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych <= 0x00000000) goto yy69; + if (yych == '|') goto yy215; + goto yy152; +yy153: + yyaccept = 5; + rbs_skip(lexer); + backup = *lexer; + yych = rbs_peek(lexer); + if (yych <= '\'') { + if (yych <= 0x00000000) goto yy79; + if (yych <= '&') goto yy76; + goto yy78; + } else { + if (yych == '\\') goto yy80; + goto yy76; + } +yy154: + rbs_skip(lexer); +#line 38 "src/lexer.re" + { return rbs_next_token(lexer, pDOT3); } +#line 1356 "src/lexer.c" +yy155: + rbs_skip(lexer); +#line 112 "src/lexer.re" + { return rbs_next_token(lexer, tDQSYMBOL); } +#line 1361 "src/lexer.c" +yy156: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'u') goto yy216; + if (yych == 'x') goto yy217; + goto yy87; +yy157: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych <= ',') { + if (yych <= '\f') { + if (yych <= 0x00000000) goto yy158; + if (yych <= 0x00000008) goto yy157; + if (yych >= '\v') goto yy157; + } else { + if (yych <= 0x0000001F) { + if (yych >= 0x0000000E) goto yy157; + } else { + if (yych == '#') goto yy157; + } + } + } else { + if (yych <= '>') { + if (yych <= '-') goto yy157; + if (yych <= '/') goto yy158; + if (yych <= '9') goto yy157; + } else { if (yych <= '^') { - if (yych <= 'Z') goto yy151; + if (yych <= 'Z') goto yy157; } else { - if (yych <= 'z') goto yy151; - if (yych >= 0x0000007F) goto yy151; + if (yych <= 'z') goto yy157; + if (yych >= 0x0000007F) goto yy157; } } } -yy152: -#line 125 "src/lexer.re" +yy158: +#line 129 "src/lexer.re" { return rbs_next_token(lexer, tSYMBOL); } -#line 1351 "src/lexer.c" -yy153: +#line 1400 "src/lexer.c" +yy159: rbs_skip(lexer); - goto yy152; -yy154: + goto yy158; +yy160: rbs_skip(lexer); -yy155: -#line 109 "src/lexer.re" +yy161: +#line 113 "src/lexer.re" { return rbs_next_token(lexer, tSQSYMBOL); } -#line 1360 "src/lexer.c" -yy156: +#line 1409 "src/lexer.c" +yy162: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '\'') { - if (yych <= 0x00000000) goto yy68; - if (yych <= '&') goto yy88; - goto yy209; + if (yych <= 0x00000000) goto yy69; + if (yych <= '&') goto yy90; + goto yy218; } else { - if (yych == '\\') goto yy156; - goto yy88; + if (yych == '\\') goto yy162; + goto yy90; } -yy157: +yy163: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '>') goto yy87; - goto yy84; -yy158: + if (yych == '>') goto yy89; + goto yy86; +yy164: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '=') goto yy87; - goto yy84; -yy159: + if (yych == '=') goto yy89; + goto yy86; +yy165: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '^') { - if (yych <= '@') goto yy68; - if (yych <= 'Z') goto yy210; - goto yy68; + if (yych <= '@') goto yy69; + if (yych <= 'Z') goto yy219; + goto yy69; } else { - if (yych == '`') goto yy68; - if (yych <= 'z') goto yy210; - goto yy68; + if (yych == '`') goto yy69; + if (yych <= 'z') goto yy219; + goto yy69; } -yy160: +yy166: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy212; + if (yych == '!') goto yy221; } else { - if (yych <= '9') goto yy160; - if (yych == '=') goto yy212; + if (yych <= '9') goto yy166; + if (yych == '=') goto yy221; } } else { if (yych <= '^') { - if (yych <= '?') goto yy212; - if (yych <= '@') goto yy161; - if (yych <= 'Z') goto yy160; + if (yych <= '?') goto yy221; + if (yych <= '@') goto yy167; + if (yych <= 'Z') goto yy166; } else { - if (yych == '`') goto yy161; - if (yych <= 'z') goto yy160; + if (yych == '`') goto yy167; + if (yych <= 'z') goto yy166; } } -yy161: -#line 123 "src/lexer.re" +yy167: +#line 127 "src/lexer.re" { return rbs_next_token(lexer, tSYMBOL); } -#line 1417 "src/lexer.c" -yy162: +#line 1466 "src/lexer.c" +yy168: rbs_skip(lexer); - goto yy97; -yy163: + goto yy99; +yy169: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= 'Z') { - if (yych <= '/') goto yy164; - if (yych <= '9') goto yy163; - if (yych >= 'A') goto yy163; + if (yych <= '/') goto yy170; + if (yych <= '9') goto yy169; + if (yych >= 'A') goto yy169; } else { if (yych <= '_') { - if (yych >= '_') goto yy163; + if (yych >= '_') goto yy169; } else { - if (yych <= '`') goto yy164; - if (yych <= 'z') goto yy163; + if (yych <= '`') goto yy170; + if (yych <= 'z') goto yy169; } } -yy164: -#line 137 "src/lexer.re" +yy170: +#line 141 "src/lexer.re" { return rbs_next_token(lexer, tA2IDENT); } -#line 1439 "src/lexer.c" -yy165: +#line 1488 "src/lexer.c" +yy171: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy213; - goto yy109; -yy166: + if (yych == 's') goto yy222; + goto yy106; +yy172: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'o') goto yy224; + goto yy113; +yy173: rbs_skip(lexer); #line 40 "src/lexer.re" { return rbs_next_token(lexer, tQIDENT); } -#line 1449 "src/lexer.c" -yy167: +#line 1503 "src/lexer.c" +yy174: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy214; + if (yych == 'a') goto yy225; goto yy53; -yy168: +yy175: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy215; + if (yych == 'r') goto yy226; goto yy53; -yy169: +yy176: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy216; + if (yych == 'l') goto yy227; goto yy53; -yy170: +yy177: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy171; + if (yych <= '@') goto yy178; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy171; + if (yych == '`') goto yy178; if (yych <= 'z') goto yy52; } } -yy171: -#line 71 "src/lexer.re" +yy178: +#line 72 "src/lexer.re" { return rbs_next_token(lexer, kBOT); } -#line 1487 "src/lexer.c" -yy172: +#line 1541 "src/lexer.c" +yy179: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy218; + if (yych == 's') goto yy229; goto yy53; -yy173: +yy180: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy174; + if (yych <= '@') goto yy181; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy174; + if (yych == '`') goto yy181; if (yych <= 'z') goto yy52; } } -yy174: -#line 73 "src/lexer.re" +yy181: +#line 74 "src/lexer.re" { return rbs_next_token(lexer, kDEF); } -#line 1515 "src/lexer.c" -yy175: +#line 1569 "src/lexer.c" +yy182: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy176; + if (yych <= '@') goto yy183; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy176; + if (yych == '`') goto yy183; if (yych <= 'z') goto yy52; } } -yy176: -#line 74 "src/lexer.re" +yy183: +#line 75 "src/lexer.re" { return rbs_next_token(lexer, kEND); } -#line 1538 "src/lexer.c" -yy177: +#line 1592 "src/lexer.c" +yy184: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy219; + if (yych == 'e') goto yy230; goto yy53; -yy178: +yy185: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy220; + if (yych == 's') goto yy231; goto yy53; -yy179: +yy186: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy221; + if (yych == 'l') goto yy232; goto yy53; -yy180: +yy187: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy222; + if (yych == 't') goto yy233; goto yy53; -yy181: +yy188: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy223; + if (yych == 'e') goto yy234; goto yy53; -yy182: +yy189: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy224; + if (yych == 'u') goto yy235; goto yy53; -yy183: +yy190: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy184; + if (yych <= '@') goto yy191; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy184; + if (yych == '`') goto yy191; if (yych <= 'z') goto yy52; } } -yy184: -#line 82 "src/lexer.re" +yy191: +#line 83 "src/lexer.re" { return rbs_next_token(lexer, kNIL); } -#line 1591 "src/lexer.c" -yy185: +#line 1645 "src/lexer.c" +yy192: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy186; + if (yych <= '@') goto yy193; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy186; + if (yych == '`') goto yy193; if (yych <= 'z') goto yy52; } } -yy186: -#line 83 "src/lexer.re" +yy193: +#line 84 "src/lexer.re" { return rbs_next_token(lexer, kOUT); } -#line 1614 "src/lexer.c" -yy187: +#line 1668 "src/lexer.c" +yy194: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'p') goto yy225; + if (yych == 'p') goto yy236; goto yy53; -yy188: +yy195: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'v') goto yy226; + if (yych == 'v') goto yy237; goto yy53; -yy189: +yy196: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy227; + if (yych == 'l') goto yy238; goto yy53; -yy190: +yy197: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'f') goto yy228; + if (yych == 'u') goto yy239; goto yy53; -yy191: +yy198: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'g') goto yy230; + if (yych == 'f') goto yy240; goto yy53; -yy192: +yy199: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'g') goto yy242; + goto yy53; +yy200: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'p') goto yy243; + goto yy53; +yy201: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy193; + if (yych <= '@') goto yy202; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy193; + if (yych == '`') goto yy202; if (yych <= 'z') goto yy52; } } -yy193: -#line 89 "src/lexer.re" +yy202: +#line 90 "src/lexer.re" { return rbs_next_token(lexer, kTOP); } -#line 1662 "src/lexer.c" -yy194: +#line 1726 "src/lexer.c" +yy203: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy231; + if (yych == 'e') goto yy245; goto yy53; -yy195: +yy204: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy233; + if (yych == 'e') goto yy247; goto yy53; -yy196: +yy205: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'h') goto yy235; + if (yych == 'h') goto yy249; goto yy53; -yy197: +yy206: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'y') goto yy236; + if (yych == 'y') goto yy250; goto yy53; -yy198: +yy207: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy199; + if (yych <= '@') goto yy208; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy199; + if (yych == '`') goto yy208; if (yych <= 'z') goto yy52; } } -yy199: -#line 95 "src/lexer.re" +yy208: +#line 96 "src/lexer.re" { return rbs_next_token(lexer, kUSE); } -#line 1705 "src/lexer.c" -yy200: +#line 1769 "src/lexer.c" +yy209: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy237; + if (yych == 'd') goto yy251; goto yy53; -yy201: +yy210: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy239; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy253; + goto yy69; } else { - if (yych <= 'F') goto yy239; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy239; - goto yy68; + if (yych <= 'F') goto yy253; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy253; + goto yy69; } -yy202: +yy211: rbs_skip(lexer); -#line 54 "src/lexer.re" +#line 55 "src/lexer.re" { return rbs_next_token(lexer, tANNOTATION); } -#line 1728 "src/lexer.c" -yy203: +#line 1792 "src/lexer.c" +yy212: rbs_skip(lexer); -#line 57 "src/lexer.re" +#line 58 "src/lexer.re" { return rbs_next_token(lexer, tANNOTATION); } -#line 1733 "src/lexer.c" -yy204: +#line 1797 "src/lexer.c" +yy213: rbs_skip(lexer); -#line 55 "src/lexer.re" +#line 56 "src/lexer.re" { return rbs_next_token(lexer, tANNOTATION); } -#line 1738 "src/lexer.c" -yy205: +#line 1802 "src/lexer.c" +yy214: rbs_skip(lexer); -#line 53 "src/lexer.re" +#line 54 "src/lexer.re" { return rbs_next_token(lexer, tANNOTATION); } -#line 1743 "src/lexer.c" -yy206: +#line 1807 "src/lexer.c" +yy215: rbs_skip(lexer); -#line 56 "src/lexer.re" +#line 57 "src/lexer.re" { return rbs_next_token(lexer, tANNOTATION); } -#line 1748 "src/lexer.c" -yy207: +#line 1812 "src/lexer.c" +yy216: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy240; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy254; + goto yy69; } else { - if (yych <= 'F') goto yy240; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy240; - goto yy68; + if (yych <= 'F') goto yy254; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy254; + goto yy69; } -yy208: +yy217: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy85; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy85; - goto yy68; -yy209: + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy87; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy87; + goto yy69; +yy218: yyaccept = 6; rbs_skip(lexer); backup = *lexer; yych = rbs_peek(lexer); if (yych <= '\'') { - if (yych <= 0x00000000) goto yy155; - if (yych <= '&') goto yy88; - goto yy154; + if (yych <= 0x00000000) goto yy161; + if (yych <= '&') goto yy90; + goto yy160; } else { - if (yych == '\\') goto yy156; - goto yy88; + if (yych == '\\') goto yy162; + goto yy90; } -yy210: +yy219: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy241; + if (yych == '!') goto yy255; } else { - if (yych <= '9') goto yy210; - if (yych == '=') goto yy241; + if (yych <= '9') goto yy219; + if (yych == '=') goto yy255; } } else { if (yych <= '^') { - if (yych <= '?') goto yy241; - if (yych <= '@') goto yy211; - if (yych <= 'Z') goto yy210; + if (yych <= '?') goto yy255; + if (yych <= '@') goto yy220; + if (yych <= 'Z') goto yy219; } else { - if (yych == '`') goto yy211; - if (yych <= 'z') goto yy210; + if (yych == '`') goto yy220; + if (yych <= 'z') goto yy219; } } -yy211: -#line 124 "src/lexer.re" +yy220: +#line 128 "src/lexer.re" { return rbs_next_token(lexer, tSYMBOL); } -#line 1806 "src/lexer.c" -yy212: +#line 1870 "src/lexer.c" +yy221: rbs_skip(lexer); - goto yy161; -yy213: + goto yy167; +yy222: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy242; - goto yy109; -yy214: + if (yych <= 'Z') { + if (yych <= '/') goto yy223; + if (yych <= '9') goto yy105; + if (yych >= 'A') goto yy105; + } else { + if (yych <= '_') { + if (yych >= '_') goto yy105; + } else { + if (yych <= '`') goto yy223; + if (yych <= 'z') goto yy105; + } + } +yy223: +#line 99 "src/lexer.re" + { return rbs_next_token(lexer, kATRBS); } +#line 1892 "src/lexer.c" +yy224: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'd') goto yy256; + goto yy113; +yy225: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy243; + if (yych == 's') goto yy257; goto yy53; -yy215: +yy226: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '_') goto yy245; + if (yych == '_') goto yy259; goto yy53; -yy216: +yy227: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy217; + if (yych <= '@') goto yy228; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy217; + if (yych == '`') goto yy228; if (yych <= 'z') goto yy52; } } -yy217: -#line 70 "src/lexer.re" +yy228: +#line 71 "src/lexer.re" { return rbs_next_token(lexer, kBOOL); } -#line 1847 "src/lexer.c" -yy218: +#line 1930 "src/lexer.c" +yy229: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy246; + if (yych == 's') goto yy260; goto yy53; -yy219: +yy230: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy248; + if (yych == 'n') goto yy262; goto yy53; -yy220: +yy231: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy249; + if (yych == 'e') goto yy263; goto yy53; -yy221: +yy232: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'u') goto yy251; + if (yych == 'u') goto yy265; goto yy53; -yy222: +yy233: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy252; + if (yych == 'a') goto yy266; goto yy53; -yy223: +yy234: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy253; + if (yych == 'r') goto yy267; goto yy53; -yy224: +yy235: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy254; + if (yych == 'l') goto yy268; goto yy53; -yy225: +yy236: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy255; + if (yych == 'e') goto yy269; goto yy53; -yy226: +yy237: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy256; + if (yych == 'a') goto yy270; goto yy53; -yy227: +yy238: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'i') goto yy257; + if (yych == 'i') goto yy271; goto yy53; -yy228: +yy239: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'r') goto yy272; + goto yy53; +yy240: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy229; + if (yych <= '@') goto yy241; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy229; + if (yych == '`') goto yy241; if (yych <= 'z') goto yy52; } } -yy229: -#line 87 "src/lexer.re" +yy241: +#line 88 "src/lexer.re" { return rbs_next_token(lexer, kSELF); } -#line 1920 "src/lexer.c" -yy230: +#line 2008 "src/lexer.c" +yy242: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'l') goto yy258; + if (yych == 'l') goto yy273; goto yy53; -yy231: +yy243: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy232; + if (yych <= '@') goto yy244; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy232; + if (yych == '`') goto yy244; if (yych <= 'z') goto yy52; } } -yy232: -#line 90 "src/lexer.re" - { return rbs_next_token(lexer, kTRUE); } -#line 1948 "src/lexer.c" -yy233: +yy244: +#line 100 "src/lexer.re" + { return rbs_next_token(lexer, kSKIP); } +#line 2036 "src/lexer.c" +yy245: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy234; + if (yych <= '@') goto yy246; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy234; + if (yych == '`') goto yy246; if (yych <= 'z') goto yy52; } } -yy234: +yy246: #line 91 "src/lexer.re" + { return rbs_next_token(lexer, kTRUE); } +#line 2059 "src/lexer.c" +yy247: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych <= '=') { + if (yych <= '/') { + if (yych == '!') goto yy109; + } else { + if (yych <= '9') goto yy52; + if (yych >= '=') goto yy110; + } + } else { + if (yych <= '^') { + if (yych <= '@') goto yy248; + if (yych <= 'Z') goto yy52; + } else { + if (yych == '`') goto yy248; + if (yych <= 'z') goto yy52; + } + } +yy248: +#line 92 "src/lexer.re" { return rbs_next_token(lexer, kTYPE); } -#line 1971 "src/lexer.c" -yy235: +#line 2082 "src/lexer.c" +yy249: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy259; + if (yych == 'e') goto yy274; goto yy53; -yy236: +yy250: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'p') goto yy260; + if (yych == 'p') goto yy275; goto yy53; -yy237: +yy251: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy238; + if (yych <= '@') goto yy252; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy238; + if (yych == '`') goto yy252; if (yych <= 'z') goto yy52; } } -yy238: -#line 94 "src/lexer.re" +yy252: +#line 95 "src/lexer.re" { return rbs_next_token(lexer, kVOID); } -#line 2004 "src/lexer.c" -yy239: +#line 2115 "src/lexer.c" +yy253: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy261; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy276; + goto yy69; } else { - if (yych <= 'F') goto yy261; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy261; - goto yy68; + if (yych <= 'F') goto yy276; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy276; + goto yy69; } -yy240: +yy254: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy262; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy277; + goto yy69; } else { - if (yych <= 'F') goto yy262; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy262; - goto yy68; + if (yych <= 'F') goto yy277; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy277; + goto yy69; } -yy241: +yy255: rbs_skip(lexer); - goto yy211; -yy242: + goto yy220; +yy256: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy263; - goto yy109; -yy243: + if (yych == 'o') goto yy278; + goto yy113; +yy257: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy244; + if (yych <= '@') goto yy258; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy244; + if (yych == '`') goto yy258; if (yych <= 'z') goto yy52; } } -yy244: -#line 66 "src/lexer.re" +yy258: +#line 67 "src/lexer.re" { return rbs_next_token(lexer, kALIAS); } -#line 2061 "src/lexer.c" -yy245: +#line 2172 "src/lexer.c" +yy259: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= 'q') { - if (yych == 'a') goto yy264; + if (yych == 'a') goto yy279; goto yy53; } else { - if (yych <= 'r') goto yy265; - if (yych == 'w') goto yy266; + if (yych <= 'r') goto yy280; + if (yych == 'w') goto yy281; goto yy53; } -yy246: +yy260: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy247; + if (yych <= '@') goto yy261; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy247; + if (yych == '`') goto yy261; if (yych <= 'z') goto yy52; } } -yy247: -#line 72 "src/lexer.re" +yy261: +#line 73 "src/lexer.re" { return rbs_next_token(lexer, kCLASS); } -#line 2095 "src/lexer.c" -yy248: +#line 2206 "src/lexer.c" +yy262: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy267; + if (yych == 'd') goto yy282; goto yy53; -yy249: +yy263: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy250; + if (yych <= '@') goto yy264; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy250; + if (yych == '`') goto yy264; if (yych <= 'z') goto yy52; } } -yy250: -#line 76 "src/lexer.re" +yy264: +#line 77 "src/lexer.re" { return rbs_next_token(lexer, kFALSE); } -#line 2123 "src/lexer.c" -yy251: +#line 2234 "src/lexer.c" +yy265: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy269; + if (yych == 'd') goto yy284; goto yy53; -yy252: +yy266: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy270; + if (yych == 'n') goto yy285; goto yy53; -yy253: +yy267: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'f') goto yy271; + if (yych == 'f') goto yy286; goto yy53; -yy254: +yy268: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy272; + if (yych == 'e') goto yy287; goto yy53; -yy255: +yy269: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy274; + if (yych == 'n') goto yy289; goto yy53; -yy256: +yy270: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy275; + if (yych == 't') goto yy290; goto yy53; -yy257: +yy271: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy276; + if (yych == 'c') goto yy291; goto yy53; -yy258: +yy272: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy278; + if (yych == 'n') goto yy293; goto yy53; -yy259: +yy273: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy279; + if (yych == 'e') goto yy295; goto yy53; -yy260: +yy274: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy280; + if (yych == 'c') goto yy296; goto yy53; -yy261: +yy275: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych == 'e') goto yy297; + goto yy53; +yy276: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy66; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy67; + goto yy69; } else { - if (yych <= 'F') goto yy66; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy66; - goto yy68; + if (yych <= 'F') goto yy67; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy67; + goto yy69; } -yy262: +yy277: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy281; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy298; + goto yy69; } else { - if (yych <= 'F') goto yy281; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy281; - goto yy68; + if (yych <= 'F') goto yy298; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy298; + goto yy69; } -yy263: +yy278: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '_') goto yy282; - goto yy109; -yy264: + if (yych == '_') goto yy299; + goto yy113; +yy279: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy283; + if (yych == 'c') goto yy300; goto yy53; -yy265: +yy280: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy284; + if (yych == 'e') goto yy301; goto yy53; -yy266: +yy281: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy285; + if (yych == 'r') goto yy302; goto yy53; -yy267: +yy282: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy268; + if (yych <= '@') goto yy283; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy268; + if (yych == '`') goto yy283; if (yych <= 'z') goto yy52; } } -yy268: -#line 75 "src/lexer.re" +yy283: +#line 76 "src/lexer.re" { return rbs_next_token(lexer, kEXTEND); } -#line 2242 "src/lexer.c" -yy269: +#line 2358 "src/lexer.c" +yy284: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy286; + if (yych == 'e') goto yy303; goto yy53; -yy270: +yy285: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy288; + if (yych == 'c') goto yy305; goto yy53; -yy271: +yy286: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy289; + if (yych == 'a') goto yy306; goto yy53; -yy272: +yy287: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy273; + if (yych <= '@') goto yy288; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy273; + if (yych == '`') goto yy288; if (yych <= 'z') goto yy52; } } -yy273: -#line 81 "src/lexer.re" +yy288: +#line 82 "src/lexer.re" { return rbs_next_token(lexer, kMODULE); } -#line 2280 "src/lexer.c" -yy274: +#line 2396 "src/lexer.c" +yy289: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy290; + if (yych == 'd') goto yy307; goto yy53; -yy275: +yy290: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy292; + if (yych == 'e') goto yy309; goto yy53; -yy276: +yy291: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy277; + if (yych <= '@') goto yy292; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy277; + if (yych == '`') goto yy292; if (yych <= 'z') goto yy52; } } -yy277: -#line 86 "src/lexer.re" +yy292: +#line 87 "src/lexer.re" { return rbs_next_token(lexer, kPUBLIC); } -#line 2313 "src/lexer.c" -yy278: +#line 2429 "src/lexer.c" +yy293: + rbs_skip(lexer); + yych = rbs_peek(lexer); + if (yych <= '=') { + if (yych <= '/') { + if (yych == '!') goto yy109; + } else { + if (yych <= '9') goto yy52; + if (yych >= '=') goto yy110; + } + } else { + if (yych <= '^') { + if (yych <= '@') goto yy294; + if (yych <= 'Z') goto yy52; + } else { + if (yych == '`') goto yy294; + if (yych <= 'z') goto yy52; + } + } +yy294: +#line 101 "src/lexer.re" + { return rbs_next_token(lexer, kRETURN); } +#line 2452 "src/lexer.c" +yy295: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy294; + if (yych == 't') goto yy311; goto yy53; -yy279: +yy296: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'k') goto yy295; + if (yych == 'k') goto yy312; goto yy53; -yy280: +yy297: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy296; + if (yych == 'd') goto yy313; goto yy53; -yy281: +yy298: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '@') { - if (yych <= '/') goto yy68; - if (yych <= '9') goto yy85; - goto yy68; + if (yych <= '/') goto yy69; + if (yych <= '9') goto yy87; + goto yy69; } else { - if (yych <= 'F') goto yy85; - if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy85; - goto yy68; + if (yych <= 'F') goto yy87; + if (yych <= '`') goto yy69; + if (yych <= 'f') goto yy87; + goto yy69; } -yy282: +yy299: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == '_') goto yy298; - goto yy109; -yy283: + if (yych == '_') goto yy315; + goto yy113; +yy300: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy300; + if (yych == 'c') goto yy317; goto yy53; -yy284: +yy301: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'a') goto yy301; + if (yych == 'a') goto yy318; goto yy53; -yy285: +yy302: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'i') goto yy302; + if (yych == 'i') goto yy319; goto yy53; -yy286: +yy303: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy287; + if (yych <= '@') goto yy304; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy287; + if (yych == '`') goto yy304; if (yych <= 'z') goto yy52; } } -yy287: -#line 78 "src/lexer.re" +yy304: +#line 79 "src/lexer.re" { return rbs_next_token(lexer, kINCLUDE); } -#line 2384 "src/lexer.c" -yy288: +#line 2523 "src/lexer.c" +yy305: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy303; + if (yych == 'e') goto yy320; goto yy53; -yy289: +yy306: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'c') goto yy305; + if (yych == 'c') goto yy322; goto yy53; -yy290: +yy307: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy291; + if (yych <= '@') goto yy308; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy291; + if (yych == '`') goto yy308; if (yych <= 'z') goto yy52; } } -yy291: -#line 84 "src/lexer.re" +yy308: +#line 85 "src/lexer.re" { return rbs_next_token(lexer, kPREPEND); } -#line 2417 "src/lexer.c" -yy292: +#line 2556 "src/lexer.c" +yy309: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy293; + if (yych <= '@') goto yy310; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy293; + if (yych == '`') goto yy310; if (yych <= 'z') goto yy52; } } -yy293: -#line 85 "src/lexer.re" +yy310: +#line 86 "src/lexer.re" { return rbs_next_token(lexer, kPRIVATE); } -#line 2440 "src/lexer.c" -yy294: +#line 2579 "src/lexer.c" +yy311: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy306; + if (yych == 'o') goto yy323; goto yy53; -yy295: +yy312: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy307; + if (yych == 'e') goto yy324; goto yy53; -yy296: +yy313: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy297; + if (yych <= '@') goto yy314; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy297; + if (yych == '`') goto yy314; if (yych <= 'z') goto yy52; } } -yy297: -#line 93 "src/lexer.re" +yy314: +#line 94 "src/lexer.re" { return rbs_next_token(lexer, kUNTYPED); } -#line 2473 "src/lexer.c" -yy298: +#line 2612 "src/lexer.c" +yy315: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy112; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy299; - if (yych <= 'Z') goto yy108; + if (yych <= '@') goto yy316; + if (yych <= 'Z') goto yy112; } else { - if (yych == '`') goto yy299; - if (yych <= 'z') goto yy108; + if (yych == '`') goto yy316; + if (yych <= 'z') goto yy112; } } -yy299: -#line 97 "src/lexer.re" +yy316: +#line 98 "src/lexer.re" { return rbs_next_token(lexer, k__TODO__); } -#line 2496 "src/lexer.c" -yy300: +#line 2635 "src/lexer.c" +yy317: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy308; + if (yych == 'e') goto yy325; goto yy53; -yy301: +yy318: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy309; + if (yych == 'd') goto yy326; goto yy53; -yy302: +yy319: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 't') goto yy310; + if (yych == 't') goto yy327; goto yy53; -yy303: +yy320: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy304; + if (yych <= '@') goto yy321; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy304; + if (yych == '`') goto yy321; if (yych <= 'z') goto yy52; } } -yy304: -#line 79 "src/lexer.re" +yy321: +#line 80 "src/lexer.re" { return rbs_next_token(lexer, kINSTANCE); } -#line 2534 "src/lexer.c" -yy305: +#line 2673 "src/lexer.c" +yy322: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy311; + if (yych == 'e') goto yy328; goto yy53; -yy306: +yy323: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'n') goto yy313; + if (yych == 'n') goto yy330; goto yy53; -yy307: +yy324: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'd') goto yy315; + if (yych == 'd') goto yy332; goto yy53; -yy308: +yy325: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy317; + if (yych == 's') goto yy334; goto yy53; -yy309: +yy326: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy318; + if (yych == 'e') goto yy335; goto yy53; -yy310: +yy327: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'e') goto yy319; + if (yych == 'e') goto yy336; goto yy53; -yy311: +yy328: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy312; + if (yych <= '@') goto yy329; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy312; + if (yych == '`') goto yy329; if (yych <= 'z') goto yy52; } } -yy312: -#line 80 "src/lexer.re" +yy329: +#line 81 "src/lexer.re" { return rbs_next_token(lexer, kINTERFACE); } -#line 2587 "src/lexer.c" -yy313: +#line 2726 "src/lexer.c" +yy330: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy314; + if (yych <= '@') goto yy331; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy314; + if (yych == '`') goto yy331; if (yych <= 'z') goto yy52; } } -yy314: -#line 88 "src/lexer.re" +yy331: +#line 89 "src/lexer.re" { return rbs_next_token(lexer, kSINGLETON); } -#line 2610 "src/lexer.c" -yy315: +#line 2749 "src/lexer.c" +yy332: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy316; + if (yych <= '@') goto yy333; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy316; + if (yych == '`') goto yy333; if (yych <= 'z') goto yy52; } } -yy316: -#line 92 "src/lexer.re" +yy333: +#line 93 "src/lexer.re" { return rbs_next_token(lexer, kUNCHECKED); } -#line 2633 "src/lexer.c" -yy317: +#line 2772 "src/lexer.c" +yy334: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 's') goto yy320; + if (yych == 's') goto yy337; goto yy53; -yy318: +yy335: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy321; + if (yych == 'r') goto yy338; goto yy53; -yy319: +yy336: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'r') goto yy323; + if (yych == 'r') goto yy340; goto yy53; -yy320: +yy337: rbs_skip(lexer); yych = rbs_peek(lexer); - if (yych == 'o') goto yy325; + if (yych == 'o') goto yy342; goto yy53; -yy321: +yy338: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy322; + if (yych <= '@') goto yy339; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy322; + if (yych == '`') goto yy339; if (yych <= 'z') goto yy52; } } -yy322: -#line 68 "src/lexer.re" +yy339: +#line 69 "src/lexer.re" { return rbs_next_token(lexer, kATTRREADER); } -#line 2676 "src/lexer.c" -yy323: +#line 2815 "src/lexer.c" +yy340: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy324; + if (yych <= '@') goto yy341; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy324; + if (yych == '`') goto yy341; if (yych <= 'z') goto yy52; } } -yy324: -#line 69 "src/lexer.re" +yy341: +#line 70 "src/lexer.re" { return rbs_next_token(lexer, kATTRWRITER); } -#line 2699 "src/lexer.c" -yy325: +#line 2838 "src/lexer.c" +yy342: rbs_skip(lexer); yych = rbs_peek(lexer); if (yych != 'r') goto yy53; @@ -2704,25 +2843,25 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { yych = rbs_peek(lexer); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy109; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy110; } } else { if (yych <= '^') { - if (yych <= '@') goto yy326; + if (yych <= '@') goto yy343; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy326; + if (yych == '`') goto yy343; if (yych <= 'z') goto yy52; } } -yy326: -#line 67 "src/lexer.re" +yy343: +#line 68 "src/lexer.re" { return rbs_next_token(lexer, kATTRACCESSOR); } -#line 2725 "src/lexer.c" +#line 2864 "src/lexer.c" } -#line 146 "src/lexer.re" +#line 150 "src/lexer.re" } diff --git a/src/lexer.re b/src/lexer.re index 575a0c301..28b41a5cc 100644 --- a/src/lexer.re +++ b/src/lexer.re @@ -46,6 +46,7 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { "<" { return rbs_next_token(lexer, pLT); } "[]" { return rbs_next_token(lexer, pAREF_OPR); } operator { return rbs_next_token(lexer, tOPERATOR); } + "--" [^\x00]* { return rbs_next_token(lexer, tINLINECOMMENT); } number = [0-9] [0-9_]*; ("-"|"+")? number { return rbs_next_token(lexer, tINTEGER); } @@ -95,6 +96,9 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer) { "use" { return rbs_next_token(lexer, kUSE); } "as" { return rbs_next_token(lexer, kAS); } "__todo__" { return rbs_next_token(lexer, k__TODO__); } + "@rbs" { return rbs_next_token(lexer, kATRBS); } + "skip" { return rbs_next_token(lexer, kSKIP); } + "return" { return rbs_next_token(lexer, kRETURN); } unicode_char = "\\u" [0-9a-fA-F]{4}; oct_char = "\\x" [0-9a-f]{1,2}; diff --git a/src/lexstate.c b/src/lexstate.c index 02f654d5f..701711a7a 100644 --- a/src/lexstate.c +++ b/src/lexstate.c @@ -60,6 +60,9 @@ static const char *RBS_TOKENTYPE_NAMES[] = { "kUSE", /* use */ "kAS", /* as */ "k__TODO__", /* __todo__ */ + "kATRBS", /* @rbs */ + "kSKIP", /* skip */ + "kRETURN", /* return */ "tLIDENT", /* Identifiers starting with lower case */ "tUIDENT", /* Identifiers starting with upper case */ @@ -76,6 +79,7 @@ static const char *RBS_TOKENTYPE_NAMES[] = { "tCOMMENT", "tLINECOMMENT", + "tINLINECOMMENT", "tTRIVIA", diff --git a/src/location.c b/src/location.c index 45c80b4fb..5a90be180 100644 --- a/src/location.c +++ b/src/location.c @@ -40,3 +40,32 @@ rbs_location_t *rbs_location_new(rbs_allocator_t *allocator, rbs_range_t rg) { return location; } +rbs_location_list_t *rbs_location_list_new(rbs_allocator_t *allocator) { + rbs_location_list_t *list = rbs_allocator_alloc(allocator, rbs_location_list_t); + *list = (rbs_location_list_t) { + .allocator = allocator, + .head = NULL, + .tail = NULL, + .length = 0, + }; + + return list; +} + +void rbs_location_list_append(rbs_location_list_t *list, rbs_location_t *loc) { + rbs_location_list_node_t *node = rbs_allocator_alloc(list->allocator, rbs_location_list_node_t); + *node = (rbs_location_list_node_t) { + .loc = loc, + .next = NULL, + }; + + if (list->head == NULL) { + list->head = node; + list->tail = node; + } else { + list->tail->next = node; + list->tail = node; + } + + list->length++; +} diff --git a/src/parser.c b/src/parser.c index dce12189c..5b559e40a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -60,6 +60,8 @@ case kUSE: \ case kAS: \ case k__TODO__: \ + case kSKIP: \ + case kRETURN: \ /* nop */ #define CHECK_PARSE(call) \ @@ -194,6 +196,8 @@ static bool parse_type_name(rbs_parser_t *parser, TypeNameKind kind, rbs_range_t switch (parser->current_token.type) { case tLIDENT: + case kSKIP: + case kRETURN: if (kind & ALIAS_NAME) goto success; goto error_handling; case tULIDENT: @@ -962,16 +966,25 @@ static bool parse_instance_type(rbs_parser_t *parser, bool parse_alias, rbs_node rbs_node_list_t *types = rbs_node_list_new(ALLOCATOR()); TypeNameKind kind; - if (parser->current_token.type == tUIDENT) { - kind = CLASS_NAME; - } else if (parser->current_token.type == tULIDENT) { - kind = INTERFACE_NAME; - } else if (parser->current_token.type == tLIDENT) { - kind = ALIAS_NAME; - } else { - rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error"); - return false; - } + switch (parser->current_token.type) { + case tUIDENT: { + kind = CLASS_NAME; + break; + } + case tULIDENT: { + kind = INTERFACE_NAME; + break; + } + case kSKIP: + case kRETURN: + case tLIDENT: { + kind = ALIAS_NAME; + break; + } + default: + rbs_parser_set_error(parser, parser->current_token, false, "unexpected token for type name"); + return false; + } rbs_range_t args_range; if (parser->next_token.type == pLBRACKET) { @@ -1180,6 +1193,8 @@ static bool parse_simple(rbs_parser_t *parser, rbs_node_t **type) { } case tULIDENT: case tLIDENT: + case kSKIP: + case kRETURN: case pCOLON2: { rbs_node_t *instance_type = NULL; CHECK_PARSE(parse_instance_type(parser, true, &instance_type)); @@ -2126,7 +2141,8 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p switch (parser->current_token.type) { - case tAIDENT: { + case tAIDENT: + case kATRBS: { rbs_range_t name_range = parser->current_token.range; rbs_location_t *symbolLoc = rbs_location_new(ALLOCATOR(), name_range); rbs_ast_symbol_t *name = rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token)); @@ -2180,7 +2196,12 @@ static bool parse_variable_member(rbs_parser_t *parser, rbs_position_t comment_p }; ADVANCE_ASSERT(parser, pDOT); - ADVANCE_ASSERT(parser, tAIDENT); + if (parser->next_token.type == tAIDENT || parser->next_token.type == kATRBS) { + rbs_parser_advance(parser); + } else { + rbs_parser_set_error(parser, parser->current_token, false, "Unexpected error"); + return false; + } rbs_range_t name_range = parser->current_token.range; rbs_location_t *symbolLoc = rbs_location_new(ALLOCATOR(), name_range); @@ -2308,7 +2329,7 @@ static bool parse_attribute_member(rbs_parser_t *parser, rbs_position_t comment_ ADVANCE_ASSERT(parser, pLPAREN); ivar_range.start = parser->current_token.range.start; - if (parser_advance_if(parser, tAIDENT)) { + if (parser_advance_if(parser, tAIDENT) || parser_advance_if(parser, kATRBS)) { rbs_location_t *symbolLoc = rbs_location_current_token(parser); ivar_name = (rbs_node_t *) rbs_ast_symbol_new(ALLOCATOR(), symbolLoc, &parser->constant_pool, INTERN_TOKEN(parser, parser->current_token)); ivar_name_range = parser->current_token.range; @@ -2561,6 +2582,7 @@ static bool parse_module_members(rbs_parser_t *parser, rbs_node_list_t **members } case tAIDENT: case tA2IDENT: + case kATRBS: case kSELF: { CHECK_PARSE(parse_variable_member(parser, annot_pos, annotations, &member)); break; @@ -3452,3 +3474,266 @@ void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_err parser->error->message = message; parser->error->syntax_error = syntax_error; } + +/* + parse_method_overload ::= {} annotations + */ +NODISCARD +static bool parse_method_overload(rbs_parser_t *parser, rbs_node_list_t *annotations, rbs_method_type_t **method_type) { + rbs_position_t pos = NullPosition; + + if (!parse_annotations(parser, annotations, &pos)) { + return false; + } + + return rbs_parse_method_type(parser, method_type); +} + +/* + inline_method_overloads ::= {} -- returns true + | {} overload `|` ... `|` overload -- returns true + | {<>} -- returns false +*/ +NODISCARD +static bool parse_inline_method_overloads(rbs_parser_t *parser, rbs_node_list_t *overloads, rbs_location_list_t *bar_locations) { + while (true) { + rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR()); + rbs_method_type_t *method_type = NULL; + + if (!parse_method_overload(parser, annotations, &method_type)) { + return false; + } + + rbs_location_t *location = rbs_location_new(ALLOCATOR(), parser->current_token.range); + rbs_ast_members_method_definition_overload_t *overload = rbs_ast_members_method_definition_overload_new( + ALLOCATOR(), + location, + annotations, + (rbs_node_t *) method_type + ); + rbs_node_list_append(overloads, (rbs_node_t *) overload); + + if (parser->next_token.type == pBAR) { + rbs_location_t *bar_location = rbs_location_new(ALLOCATOR(), parser->next_token.range); + + rbs_parser_advance(parser); + + rbs_location_list_append(bar_locations, bar_location); + + continue; + } + + return true; + } +} + +NODISCARD +static bool parse_inline_comment(rbs_parser_t *parser, rbs_location_t **comment) { + if (parser->next_token.type != tINLINECOMMENT) { + *comment = NULL; + return true; + } + + rbs_range_t comment_range = parser->next_token.range; + rbs_parser_advance(parser); + + *comment = rbs_location_new(ALLOCATOR(), comment_range); + return true; +} + +NODISCARD +static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) { + switch (parser->next_token.type) { + case pCOLON: { + rbs_range_t colon_range = parser->next_token.range; + rbs_parser_advance(parser); + + rbs_node_list_t *annotations = rbs_node_list_new(ALLOCATOR()); + rbs_method_type_t *method_type = NULL; + + if (!parse_method_overload(parser, annotations, &method_type)) { + return false; + } + + rbs_range_t full_range = { + .start = colon_range.start, + .end = parser->current_token.range.end + }; + + rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range); + rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range); + + *annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_colon_method_type_annotation_new( + ALLOCATOR(), + full_loc, + colon_loc, + annotations, + (rbs_node_t *) method_type + ); + return true; + } + case kATRBS: { + rbs_range_t rbs_range = parser->next_token.range; + rbs_parser_advance(parser); + + switch (parser->next_token.type) { + case pLPAREN: + case pLBRACKET: + case pLBRACE: + case tANNOTATION: { + rbs_node_list_t *overloads = rbs_node_list_new(ALLOCATOR()); + rbs_location_list_t *bar_locations = rbs_location_list_new(ALLOCATOR()); + + if (!parse_inline_method_overloads(parser, overloads, bar_locations)) { + return false; + } + + rbs_range_t full_range = { + .start = rbs_range.start, + .end = parser->current_token.range.end + }; + + rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range); + rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range); + + *annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_method_types_annotation_new( + ALLOCATOR(), + full_loc, + rbs_loc, + overloads, + bar_locations + ); + return true; + } + case kSKIP: { + rbs_parser_advance(parser); + + rbs_range_t skip_range = parser->current_token.range; + rbs_location_t *skip_loc = rbs_location_new(ALLOCATOR(), skip_range); + + rbs_location_t *comment_loc = NULL; + if (!parse_inline_comment(parser, &comment_loc)) { + return false; + } + + rbs_range_t full_range = { + .start = rbs_range.start, + .end = parser->current_token.range.end + }; + + rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range); + rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range); + + *annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_skip_annotation_new( + ALLOCATOR(), + full_loc, + rbs_loc, + skip_loc, + comment_loc + ); + return true; + } + case kRETURN: { + rbs_parser_advance(parser); + + rbs_range_t return_range = parser->current_token.range; + rbs_location_t *return_loc = rbs_location_new(ALLOCATOR(), return_range); + + ADVANCE_ASSERT(parser, pCOLON); + + rbs_range_t colon_range = parser->current_token.range; + rbs_location_t *colon_loc = rbs_location_new(ALLOCATOR(), colon_range); + + rbs_node_t *return_type = NULL; + if (!rbs_parse_type(parser, &return_type)) { + return false; + } + + rbs_location_t *comment_loc = NULL; + if (!parse_inline_comment(parser, &comment_loc)) { + return false; + } + + rbs_range_t full_range = { + .start = rbs_range.start, + .end = parser->current_token.range.end + }; + + rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range); + rbs_location_t *rbs_loc = rbs_location_new(ALLOCATOR(), rbs_range); + + *annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_return_type_annotation_new( + ALLOCATOR(), + full_loc, + rbs_loc, + return_loc, + colon_loc, + return_type, + comment_loc + ); + return true; + } + default: { + rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for @rbs annotation"); + return false; + } + } + } + default: { + rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for inline leading annotation"); + return false; + } + } +} + +NODISCARD +static bool parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) { + rbs_range_t prefix_range = parser->next_token.range; + + switch (parser->next_token.type) { + case pCOLON: { + rbs_parser_advance(parser); + + rbs_node_t *type = NULL; + if (!rbs_parse_type(parser, &type)) { + return false; + } + + rbs_range_t full_range = { + .start = prefix_range.start, + .end = parser->current_token.range.end + }; + + rbs_location_t *full_loc = rbs_location_new(ALLOCATOR(), full_range); + rbs_location_t *prefix_loc = rbs_location_new(ALLOCATOR(), prefix_range); + + *annotation = (rbs_ast_ruby_annotations_t *) rbs_ast_ruby_annotations_node_type_assertion_new( + ALLOCATOR(), + full_loc, + prefix_loc, + type + ); + return true; + } + default: { + rbs_parser_set_error(parser, parser->next_token, true, "unexpected token for inline trailing annotation"); + return false; + } + } +} + +bool rbs_parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) { + bool success = parse_inline_leading_annotation(parser, annotation); + + ADVANCE_ASSERT(parser, pEOF); + + return success; +} + +bool rbs_parse_inline_trailing_annotation(rbs_parser_t *parser, rbs_ast_ruby_annotations_t **annotation) { + bool success = parse_inline_trailing_annotation(parser, annotation); + + ADVANCE_ASSERT(parser, pEOF); + + return success; +} diff --git a/steep/Gemfile.lock b/steep/Gemfile.lock index db306ab6e..2ea4724aa 100644 --- a/steep/Gemfile.lock +++ b/steep/Gemfile.lock @@ -19,10 +19,10 @@ GEM benchmark (0.4.0) bigdecimal (3.1.9) concurrent-ruby (1.3.5) - connection_pool (2.5.0) - csv (3.3.3) + connection_pool (2.5.1) + csv (3.3.4) drb (2.2.1) - ffi (1.17.1) + ffi (1.17.2) fileutils (1.7.3) i18n (1.14.7) concurrent-ruby (~> 1.0) @@ -34,7 +34,7 @@ GEM logger (1.7.0) minitest (5.25.5) mutex_m (0.3.0) - parser (3.3.7.4) + parser (3.3.8.0) ast (~> 2.4.1) racc power_assert (2.0.5) @@ -52,7 +52,7 @@ GEM rbs (>= 3, < 4) sorbet-runtime (>= 0.5.10782) securerandom (0.4.1) - sorbet-runtime (0.5.12003) + sorbet-runtime (0.5.12032) steep (1.10.0) activesupport (>= 5.1) concurrent-ruby (>= 1.1.10) @@ -70,7 +70,7 @@ GEM strscan (>= 1.0.0) terminal-table (>= 2, < 5) uri (>= 0.12.0) - strscan (3.1.2) + strscan (3.1.3) terminal-table (4.0.0) unicode-display_width (>= 1.1.1, < 4) test-unit (3.6.8) diff --git a/templates/ext/rbs_extension/ast_translation.c.erb b/templates/ext/rbs_extension/ast_translation.c.erb index 49ff27b4a..a248a9be7 100644 --- a/templates/ext/rbs_extension/ast_translation.c.erb +++ b/templates/ext/rbs_extension/ast_translation.c.erb @@ -37,6 +37,10 @@ VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash) } VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *source_loc) { + if (source_loc == NULL) { + return Qnil; + } + VALUE new_loc = rbs_new_location(ctx.buffer, source_loc->rg); rbs_loc *new_loc_struct = rbs_check_location(new_loc); @@ -48,6 +52,20 @@ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *so return new_loc; } +VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_location_list_t *list) { + VALUE ruby_array = rb_ary_new(); + + if (list == NULL) { + return ruby_array; + } + + for (rbs_location_list_node_t *n = list->head; n != NULL; n = n->next) { + rb_ary_push(ruby_array, rbs_loc_to_ruby_location(ctx, n->loc)); + } + + return ruby_array; +} + #ifdef RB_PASS_KEYWORDS // Ruby 2.7 or later #define CLASS_NEW_INSTANCE(klass, argc, argv)\ @@ -120,6 +138,10 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_string_to_ruby_string(&node-><%= field.c_name %>, ctx.encoding)); <%- when "bool" -%> rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), node-><%= field.c_name %> ? Qtrue : Qfalse); + <%- when "rbs_location" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_loc_to_ruby_location(ctx, node-><%= field.name %>)); + <%- when "rbs_location_list" -%> + rb_hash_aset(h, ID2SYM(rb_intern("<%= field.name %>")), rbs_location_list_to_ruby_array(ctx, node-><%= field.name %>)); <%- else -%> <%- unless field.ast_node? -%> #warning unexpected type <%= field.c_type -%> diff --git a/templates/ext/rbs_extension/class_constants.c.erb b/templates/ext/rbs_extension/class_constants.c.erb index e4f9e9b1c..209f8ceaa 100644 --- a/templates/ext/rbs_extension/class_constants.c.erb +++ b/templates/ext/rbs_extension/class_constants.c.erb @@ -7,6 +7,8 @@ VALUE RBS_AST; VALUE RBS_AST_Declarations; VALUE RBS_AST_Directives; VALUE RBS_AST_Members; +VALUE RBS_AST_Ruby; +VALUE RBS_AST_Ruby_Annotations; VALUE RBS_Parser; VALUE RBS_Types; VALUE RBS_Types_Bases; @@ -27,6 +29,8 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Declarations, RBS_AST, "Declarations"); IMPORT_CONSTANT(RBS_AST_Directives, RBS_AST, "Directives"); IMPORT_CONSTANT(RBS_AST_Members, RBS_AST, "Members"); + IMPORT_CONSTANT(RBS_AST_Ruby, RBS_AST, "Ruby"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations, RBS_AST_Ruby, "Annotations"); IMPORT_CONSTANT(RBS_Types, RBS, "Types"); IMPORT_CONSTANT(RBS_Types_Bases, RBS_Types, "Bases"); diff --git a/templates/ext/rbs_extension/class_constants.h.erb b/templates/ext/rbs_extension/class_constants.h.erb index fadb2ed9a..9c1e858e4 100644 --- a/templates/ext/rbs_extension/class_constants.h.erb +++ b/templates/ext/rbs_extension/class_constants.h.erb @@ -9,6 +9,8 @@ extern VALUE RBS_AST; extern VALUE RBS_AST_Declarations; extern VALUE RBS_AST_Directives; extern VALUE RBS_AST_Members; +extern VALUE RBS_AST_Ruby; +extern VALUE RBS_AST_Ruby_Annotations; extern VALUE RBS_Types; extern VALUE RBS_Types_Bases; extern VALUE RBS_ParsingError; diff --git a/templates/include/rbs/ast.h.erb b/templates/include/rbs/ast.h.erb index c45df362c..7bf4c0a87 100644 --- a/templates/include/rbs/ast.h.erb +++ b/templates/include/rbs/ast.h.erb @@ -75,6 +75,15 @@ typedef struct <%= node.c_base_name %> { <%- end -%> +typedef union rbs_ast_ruby_annotations { + rbs_node_t base; + rbs_ast_ruby_annotations_colon_method_type_annotation_t colon_method_type_annotation; + rbs_ast_ruby_annotations_method_types_annotation_t method_types_annotation; + rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion; + rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation; + rbs_ast_ruby_annotations_skip_annotation_t skip_annotation; +} rbs_ast_ruby_annotations_t; + /// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc. /// These are stored in the global constant pool, and get surfaced to Ruby as `Symbol`s, /// just like `rbs_ast_symbol_t`s. diff --git a/test/rbs/ast/ruby/comment_block_test.rb b/test/rbs/ast/ruby/comment_block_test.rb new file mode 100644 index 000000000..2072de1b0 --- /dev/null +++ b/test/rbs/ast/ruby/comment_block_test.rb @@ -0,0 +1,204 @@ +require "test_helper" + +class RBS::AST::Ruby::CommentBlockTest < Test::Unit::TestCase + include TestHelper + + include RBS::AST::Ruby + + def parse_comments(source) + buffer = RBS::Buffer.new(name: Pathname("a.rb"), content: source) + [buffer, Prism.parse_comments(source)] + end + + def test__buffer__single_line + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!", block.comment_buffer.content + assert_equal [[comments[0], 2]], block.offsets + end + + def test__buffer__multi_line_prefix + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + # This is the second line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!\nThis is the second line.", block.comment_buffer.content + assert_equal [[comments[0], 2], [comments[1], 2]], block.offsets + end + + def test__buffer__multi_line_prefix_inconsistent + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + # This is the second line. + #This is the third line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!\n This is the second line.\nThis is the third line.", block.comment_buffer.content + assert_equal [[comments[0], 2], [comments[1], 2], [comments[2], 1]], block.offsets + end + + def test__buffer__multi_line_prefix_header_line + buffer, comments = parse_comments(<<~RUBY) + #### + # Hello, world! + # This is the second line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "###\nHello, world!\nThis is the second line.", block.comment_buffer.content + assert_equal [[comments[0], 1], [comments[1], 2], [comments[2], 2]], block.offsets + end + + def test_build + buffer, comments = parse_comments(<<~RUBY) + # Comment1 + # Comment2 + + # Comment3 + foo() # Comment4 + # Comment5 + + bar() # Comment6 + baz() # Comment7 + RUBY + + blocks = CommentBlock.build(buffer, comments) + + assert_equal 5, blocks.size + + assert_equal <<~COMMENT.chomp, blocks[0].comment_buffer.content + Comment1 + Comment2 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[1].comment_buffer.content + Comment3 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[2].comment_buffer.content + Comment4 + Comment5 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[3].comment_buffer.content + Comment6 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[4].comment_buffer.content + Comment7 + COMMENT + end + + def test_each_paragraph + buffer, comments = parse_comments(<<~RUBY) + # Line 1 + # + # @rbs () -> void + # @rbs () + # -> Array[ + # String + # + # ] + # + # Line 2 + # Line 3 + # + # @rbs () + # + # Line 4 + RUBY + + block = CommentBlock.new(buffer, comments) + + paragraphs = block.each_paragraph([]).to_a + + paragraphs[0].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "Line 1\n", paragraph.local_source + end + paragraphs[1].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::MethodTypesAnnotation, paragraph + assert_equal "@rbs () -> void", paragraph.location.local_source + end + paragraphs[2].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::MethodTypesAnnotation, paragraph + assert_equal "@rbs ()\n -> Array[\n String\n\n ]", paragraph.location.local_source + end + paragraphs[3].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nLine 2\nLine 3\n", paragraph.local_source + end + paragraphs[4].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::CommentBlock::AnnotationSyntaxError, paragraph + assert_equal "@rbs ()", paragraph.location.local_source + end + paragraphs[5].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nLine 4", paragraph.local_source + end + end + + def test_each_paragraph_colon + buffer, comments = parse_comments(<<~RUBY) + # : Foo + # + #: %a{foo} + # () -> Bar + # + # Bar + RUBY + + block = CommentBlock.new(buffer, comments) + + paragraphs = block.each_paragraph([]).to_a + + paragraphs[0].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal ": Foo\n", paragraph.local_source + end + paragraphs[1].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation, paragraph + assert_equal ": %a{foo}\n () -> Bar", paragraph.location.local_source + end + paragraphs[2].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nBar", paragraph.local_source + end + end + + def test_trailing_annotation + buffer, comments = parse_comments(<<~RUBY) + foo #: String + + foo #: String[ + + foo # This is some comment + + #: String + RUBY + + blocks = CommentBlock.build(buffer, comments) + + blocks[0].trailing_annotation([]).tap do |annotation| + assert_instance_of RBS::AST::Ruby::Annotations::NodeTypeAssertion, annotation + end + + blocks[1].trailing_annotation([]).tap do |annotation| + assert_instance_of CommentBlock::AnnotationSyntaxError, annotation + end + + blocks[2].trailing_annotation([]).tap do |annotation| + assert_nil annotation + end + + blocks[3].trailing_annotation([]).tap do |annotation| + assert_nil annotation + end + end +end diff --git a/test/rbs/buffer_test.rb b/test/rbs/buffer_test.rb index a3fbc01c6..03bb1baad 100644 --- a/test/rbs/buffer_test.rb +++ b/test/rbs/buffer_test.rb @@ -9,8 +9,8 @@ def test_buffer abc CONTENT - assert_equal ["123\n", "abc\n"], buffer.lines - assert_equal [0...4, 4...8], buffer.ranges + assert_equal ["123", "abc", ""], buffer.lines + assert_equal [0...3, 4...7, 8...8], buffer.ranges assert_equal [1, 0], buffer.pos_to_loc(0) assert_equal [1, 1], buffer.pos_to_loc(1) @@ -41,8 +41,8 @@ def test_buffer def test_buffer_with_no_eol buffer = Buffer.new(name: Pathname("foo.rbs"), content: "123\nabc") - assert_equal ["123\n", "abc"], buffer.lines - assert_equal [0...4, 4...8], buffer.ranges + assert_equal ["123", "abc"], buffer.lines + assert_equal [0...3, 4...7], buffer.ranges assert_equal [1, 0], buffer.pos_to_loc(0) assert_equal [1, 1], buffer.pos_to_loc(1) @@ -67,4 +67,33 @@ def test_buffer_with_no_eol assert_equal 7, buffer.last_position end + + def test_sub_buffer + buffer = Buffer.new(name: Pathname("foo.rbs"), content: <<~CONTENT) + 123 + abc + CONTENT + + buffer.sub_buffer(lines: [1...3, 5...7]).tap do |sub_buffer| + assert_equal <<~CONTENT.chomp, sub_buffer.content + 23 + bc + CONTENT + + assert_equal 1, sub_buffer.parent_position(0) + assert_equal 2, sub_buffer.parent_position(1) + assert_equal 3, sub_buffer.parent_position(2) + assert_equal 5, sub_buffer.parent_position(3) + assert_equal 6, sub_buffer.parent_position(4) + assert_equal 7, sub_buffer.parent_position(5) + + assert_equal [1, 0], sub_buffer.pos_to_loc(0) + assert_equal [1, 1], sub_buffer.pos_to_loc(1) + assert_equal [1, 2], sub_buffer.pos_to_loc(2) + assert_equal [2, 0], sub_buffer.pos_to_loc(3) + assert_equal [2, 1], sub_buffer.pos_to_loc(4) + assert_equal [2, 2], sub_buffer.pos_to_loc(5) + assert_equal [3, 0], sub_buffer.pos_to_loc(6) + end + end end diff --git a/test/rbs/definition_builder_test.rb b/test/rbs/definition_builder_test.rb index 62509636b..9aa9ac20b 100644 --- a/test/rbs/definition_builder_test.rb +++ b/test/rbs/definition_builder_test.rb @@ -3201,7 +3201,7 @@ module A end end - def test_inline_decl__class_def + def test_inline_decl__class_def__untyped SignatureManager.new do |manager| manager.add_ruby_file("inherited.rbs", <<~RUBY) class A @@ -3226,4 +3226,31 @@ def hello(x) = 123 end end end + + def test_inline_decl__class_def__typed + SignatureManager.new do |manager| + manager.add_ruby_file("inherited.rbs", <<~RUBY) + class A + # @rbs (String) -> Integer + def hello(x) = 123 + end + RUBY + + manager.build do |env| + builder = DefinitionBuilder.new(env: env) + + builder.build_instance(type_name("::A")).tap do |definition| + definition.methods[:hello].tap do |method| + assert_equal type_name("::A"), method.defined_in + assert_equal type_name("::A"), method.implemented_in + + assert_equal [parse_method_type("(::String) -> ::Integer")], method.method_types + assert_equal [parse_method_type("(::String) -> ::Integer")], method.defs.map(&:type) + + assert_equal [], method.annotations + end + end + end + end + end end diff --git a/test/rbs/inline_annotation_parsing_test.rb b/test/rbs/inline_annotation_parsing_test.rb new file mode 100644 index 000000000..1fef5ff51 --- /dev/null +++ b/test/rbs/inline_annotation_parsing_test.rb @@ -0,0 +1,118 @@ +require "test_helper" + +class RBS::InlineAnnotationParsingTest < Test::Unit::TestCase + include RBS + + include TestHelper + + def test_parse__trailing_assertion + Parser.parse_inline_trailing_annotation(": String", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::NodeTypeAssertion, annot + assert_equal ": String", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "String", annot.type.location.source + end + end + + def test_error__trailing_assertion + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(": String[", 0...) + end + + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(":", 0...) + end + + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(": String is a ", 0...) + end + end + + def test_parse__colon_method_type_annotation + Parser.parse_inline_leading_annotation(": (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ColonMethodTypeAnnotation, annot + assert_equal ": (String) -> void", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "(String) -> void", annot.method_type.location.source + assert_empty annot.annotations + end + + Parser.parse_inline_leading_annotation(": %a{a} %a{b} (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ColonMethodTypeAnnotation, annot + assert_equal ": %a{a} %a{b} (String) -> void", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "(String) -> void", annot.method_type.location.source + assert_equal ["a", "b"], annot.annotations.map(&:string) + end + end + + def test_parse__rbs_method_types_annotation + Parser.parse_inline_leading_annotation("@rbs %a{a} (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::MethodTypesAnnotation, annot + assert_equal "@rbs %a{a} (String) -> void", annot.location.source + assert_equal "@rbs", annot.prefix_location.source + annot.overloads[0].tap do |overload| + assert_equal "(String) -> void", overload.method_type.location.source + assert_equal ["a"], overload.annotations.map(&:string) + end + assert_empty annot.vertical_bar_locations + end + + Parser.parse_inline_leading_annotation("@rbs %a{a} (String) -> void | [T] (T) -> T", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::MethodTypesAnnotation, annot + assert_equal "@rbs %a{a} (String) -> void | [T] (T) -> T", annot.location.source + assert_equal "@rbs", annot.prefix_location.source + annot.overloads[0].tap do |overload| + assert_equal "(String) -> void", overload.method_type.location.source + assert_equal ["a"], overload.annotations.map(&:string) + end + annot.overloads[1].tap do |overload| + assert_equal "[T] (T) -> T", overload.method_type.location.source + assert_equal [], overload.annotations.map(&:string) + end + assert_equal ["|"], annot.vertical_bar_locations.map(&:source) + end + end + + def test_error__unknown_annotation + assert_raises RBS::ParsingError do + Parser.parse_inline_leading_annotation("@rbs super String", 0...) + end + end + + def test_parse__skip + Parser.parse_inline_leading_annotation("@rbs skip", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::SkipAnnotation, annot + assert_equal "@rbs skip", annot.location.source + assert_equal "skip", annot.skip_location.source + assert_nil annot.comment_location + end + + Parser.parse_inline_leading_annotation("@rbs skip -- some comment here", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::SkipAnnotation, annot + assert_equal "@rbs skip -- some comment here", annot.location.source + assert_equal "skip", annot.skip_location.source + assert_equal "-- some comment here", annot.comment_location.source + end + end + + def test_parse__return + Parser.parse_inline_leading_annotation("@rbs return: untyped", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ReturnTypeAnnotation, annot + assert_equal "@rbs return: untyped", annot.location.source + assert_equal "return", annot.return_location.source + assert_equal ":", annot.colon_location.source + assert_equal "untyped", annot.return_type.location.source + assert_nil annot.comment_location + end + + Parser.parse_inline_leading_annotation("@rbs return: untyped -- some comment here", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ReturnTypeAnnotation, annot + assert_equal "@rbs return: untyped -- some comment here", annot.location.source + assert_equal "return", annot.return_location.source + assert_equal ":", annot.colon_location.source + assert_equal "untyped", annot.return_type.location.source + assert_equal "-- some comment here", annot.comment_location.source + end + end +end diff --git a/test/rbs/inline_parser_test.rb b/test/rbs/inline_parser_test.rb index 0386f4f7b..2090b42a1 100644 --- a/test/rbs/inline_parser_test.rb +++ b/test/rbs/inline_parser_test.rb @@ -139,4 +139,152 @@ def self.foo; end assert_equal "Singleton method definition is not supported yet", diagnostic.message end end + + def test_parse__def_return_type_assertion + result = parse(<<~RUBY) + class Foo + def foo #: void + "" + end + + def bar = "" #: void + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void"], member.overloads.map { _1.method_type.to_s } + end + + decl.members[1].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["(?) -> untyped"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_error__def_return_type_assertion + result = parse(<<~RUBY) + class Foo + def foo #: void[ + "" + end + end + RUBY + + assert_any!(result.diagnostics) do |diagnostic| + assert_instance_of RBS::InlineParser::Diagnostic::AnnotationSyntaxError, diagnostic + assert_equal ": void[", diagnostic.location.source + assert_equal "Syntax error: expected a token `pEOF`", diagnostic.message + end + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["(?) -> untyped"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_parse__def_colon_method_type + result = parse(<<~RUBY) + class Foo + #: () -> void + # + def foo + "" + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_parse__def_method_types + result = parse(<<~RUBY) + class Foo + # @rbs () -> void + # | (String) -> bot + def foo(x = nil) + "" + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void", "(String) -> bot"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_parse__skip_class_module + result = parse(<<~RUBY) + # @rbs skip -- not a constant + class (c::)Foo + end + + # @rbs skip + module Bar + end + RUBY + + assert_empty result.diagnostics + + assert_empty result.declarations + end + + def test_parse__skip_def + result = parse(<<~RUBY) + class Foo + # @rbs skip + def foo + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + assert_empty decl.members + end + end + + def test_parse__return_type + result = parse(<<~RUBY) + class Foo + # @rbs return: void + def foo + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void"], member.overloads.map { _1.method_type.to_s } + end + end + end end diff --git a/test/rbs/location_test.rb b/test/rbs/location_test.rb index ffcbe2b44..5d8e8e4d2 100644 --- a/test/rbs/location_test.rb +++ b/test/rbs/location_test.rb @@ -89,6 +89,78 @@ def test_location_inspect assert_include loc.inspect, "source=\"class Foo\"" end + def test_sub_buffer_location + buffer = buffer() + # 01 + # bc + buffer = buffer.sub_buffer(lines: [0...2, 5...7]) + + loc = Location.new(buffer, 0, 5) + + # Raw positions + assert_equal 0, loc._start_pos + assert_equal 5, loc._end_pos + + # Absolute positions + assert_equal 0, loc.start_pos + assert_equal 7, loc.end_pos + assert_equal [1, 0], loc.start_loc + assert_equal [2, 3], loc.end_loc + + assert_equal "123\nabc", loc.source + + loc.add_optional_child(:opt, 0...2) + loc[:opt].tap do |loc| + assert_equal 0, loc.start_pos + assert_equal 2, loc.end_pos + assert_equal "12", loc.source + end + + loc.add_required_child(:req, 1...4) + loc[:req].tap do |loc| + assert_equal 1, loc.start_pos + assert_equal 6, loc.end_pos + assert_equal "23\nab", loc.source + end + end + + def test_sub_buffer_local_location + buffer = buffer() + # 01 + # bc + buffer = buffer.sub_buffer(lines: [0...2, 5...7]) + + loc = Location.new(buffer, 0, 5) + loc.add_optional_child(:opt, 0...2) + loc.add_required_child(:req, 1...4) + + loc = loc.local_location + + # Raw positions + assert_equal 0, loc._start_pos + assert_equal 5, loc._end_pos + + # Absolute positions in sub buffer + assert_equal 0, loc.start_pos + assert_equal 5, loc.end_pos + assert_equal [1, 0], loc.start_loc + assert_equal [2, 2], loc.end_loc + + assert_equal "12\nbc", loc.source + + loc[:opt].tap do |loc| + assert_equal 0, loc.start_pos + assert_equal 2, loc.end_pos + assert_equal "12", loc.source + end + + loc[:req].tap do |loc| + assert_equal 1, loc.start_pos + assert_equal 4, loc.end_pos + assert_equal "2\nb", loc.source + end + end + private def buffer(content: nil) diff --git a/test/rbs/parser_test.rb b/test/rbs/parser_test.rb index 5de729450..dd5bc1848 100644 --- a/test/rbs/parser_test.rb +++ b/test/rbs/parser_test.rb @@ -62,7 +62,7 @@ def test_interface_mixin end def test_type_error_for_content - buffer = RBS::Buffer.new(content: 1, name: nil) + buffer = RBS::Buffer.new(content: 1, name: Pathname("a.rbs")) assert_raises TypeError do RBS::Parser.parse_signature(buffer) end diff --git a/test/rbs/signature_parsing_test.rb b/test/rbs/signature_parsing_test.rb index 96e082ca8..de7ac56ea 100644 --- a/test/rbs/signature_parsing_test.rb +++ b/test/rbs/signature_parsing_test.rb @@ -2279,4 +2279,42 @@ def foo: (?) { () -> void } -> void end end end + + def test_inline_keyword__rbs + Parser.parse_signature(<<~RBS) + class Foo + @rbs: untyped + self.@rbs: untyped + + attr_reader rbs (@rbs): untyped + attr_reader self.rbs (@rbs): untyped + end + RBS + end + + def test_inline_keyword__skip + Parser.parse_signature(<<~RBS) + class Foo + def skip: (untyped skip) -> void + attr_reader skip: untyped + + type skip = untyped + + @foo: Array[skip] + end + RBS + end + + def test_inline_keyword__return + Parser.parse_signature(<<~RBS) + class Foo + def return: (untyped return) -> void + attr_reader return: untyped + + type return = untyped + + @foo: Array[return] + end + RBS + end end