Class: RBS::Parser
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | lib/rbs/parser_aux.rb, ext/rbs_extension/main.c, lib/rbs/parser/lex_result.rb, lib/rbs/parser/token.rb |
Constant Summary
-
KEYWORDS =
# File 'lib/rbs/parser_aux.rb', line 85%w( bool bot class instance interface nil self singleton top void type unchecked in out end def include extend prepend alias module attr_reader attr_writer attr_accessor public private untyped true false ).each_with_object({}) do |keyword, hash| #$ Hash[String, bot] hash[keyword] = _ = nil end
Class Method Summary
- ._lex(buffer, end_pos)
- ._parse_method_type(buffer, start_pos, end_pos, variables, require_eof)
- ._parse_signature(buffer, start_pos, end_pos)
- ._parse_type(buffer, start_pos, end_pos, variables, require_eof)
- ._parse_type_params(buffer, start_pos, end_pos, module_type_params)
- .buffer(source)
- .lex(source)
- .magic_comment(buf)
- .parse_method_type(source, range: 0, variables: [], require_eof: false)
- .parse_signature(source)
- .parse_type(source, range: 0, variables: [], require_eof: false)
- .parse_type_params(source, module_type_params: true)
Class Method Details
._lex(buffer, end_pos)
[ GitHub ]# File 'ext/rbs_extension/main.c', line 311
static VALUE rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) {
VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
StringValue(string);
rb_encoding *encoding = rb_enc_get(string);
rbs_allocator_t *allocator = rbs_allocator_init();
rbs_lexer_t *lexer = alloc_lexer_from_buffer(allocator, string, encoding, 0, FIX2INT(end_pos));
VALUE results = rb_ary_new();
rbs_token_t token = NullToken;
while (token.type != pEOF) {
token = rbs_lexer_next_token(lexer);
VALUE type = ID2SYM(rb_intern(rbs_token_type_str(token.type)));
VALUE location = rbs_new_location(buffer, token.range);
VALUE pair = rb_ary_new3(2, type, location);
rb_ary_push(results, pair);
}
rbs_allocator_free(allocator);
RB_GC_GUARD(string);
return results;
}
._parse_method_type(buffer, start_pos, end_pos, variables, require_eof)
[ GitHub ]# File 'ext/rbs_extension/main.c', line 203
static VALUE rbsparser_parse_method_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE require_eof) {
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 = require_eof
};
VALUE result = rb_ensure(parse_method_type_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
RB_GC_GUARD(string);
return result;
}
._parse_signature(buffer, start_pos, end_pos)
[ GitHub ]# File 'ext/rbs_extension/main.c', line 242
static VALUE rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
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));
struct parse_type_arg arg = {
.buffer = buffer,
.encoding = encoding,
.parser = parser,
.require_eof = false
};
VALUE result = rb_ensure(parse_signature_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
RB_GC_GUARD(string);
return result;
}
._parse_type(buffer, start_pos, end_pos, variables, require_eof)
[ GitHub ]# File 'ext/rbs_extension/main.c', line 160
static VALUE rbsparser_parse_type(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables, VALUE require_eof) {
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 = require_eof
};
VALUE result = rb_ensure(parse_type_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
RB_GC_GUARD(string);
return result;
}
._parse_type_params(buffer, start_pos, end_pos, module_type_params)
[ GitHub ]# File 'ext/rbs_extension/main.c', line 291
static VALUE rbsparser_parse_type_params(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE module_type_params) {
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));
struct parse_type_params_arg arg = {
.buffer = buffer,
.encoding = encoding,
.parser = parser,
.module_type_params = module_type_params
};
VALUE result = rb_ensure(parse_type_params_try, (VALUE) &arg, ensure_free_parser, (VALUE) parser);
RB_GC_GUARD(string);
return result;
}
.buffer(source)
[ GitHub ].lex(source)
[ GitHub ].magic_comment(buf)
[ GitHub ]# File 'lib/rbs/parser_aux.rb', line 43
def self.magic_comment(buf) start_pos = 0 while true case when match = /\A#\s*(?<keyword>resolve-type-names)\s*(?<colon>:)\s+(?<value>true|false)$/.match(buf.content, start_pos) value = match[:value] or raise kw_offset = match.offset(:keyword) #: [Integer, Integer] colon_offset = match.offset(:colon) #: [Integer, Integer] value_offset = match.offset(:value) #: [Integer, Integer] location = Location.new(buf, kw_offset[0], value_offset[1]) location.add_required_child(:keyword, kw_offset[0]...kw_offset[1]) location.add_required_child(:colon, colon_offset[0]...colon_offset[1]) location.add_required_child(:value, value_offset[0]...value_offset[1]) return AST::Directives::ResolveTypeNames.new(value: value == "true", location: location) else return end end end
.parse_method_type(source, range: 0, variables: [], require_eof: false)
[ GitHub ]# File 'lib/rbs/parser_aux.rb', line 13
def self.parse_method_type(source, range: 0..., variables: [], require_eof: false) buf = buffer(source) _parse_method_type(buf, range.begin || 0, range.end || buf.last_position, variables, require_eof) end
.parse_signature(source)
[ GitHub ]# File 'lib/rbs/parser_aux.rb', line 18
def self.parse_signature(source) buf = buffer(source) resolved = magic_comment(buf) start_pos = if resolved (resolved.location || raise).end_pos else 0 end dirs, decls = _parse_signature(buf, start_pos, buf.last_position) if resolved dirs = dirs.dup if dirs.frozen? dirs.unshift(resolved) end [buf, dirs, decls] end
.parse_type(source, range: 0, variables: [], require_eof: false)
[ GitHub ]# File 'lib/rbs/parser_aux.rb', line 8
def self.parse_type(source, range: 0..., variables: [], require_eof: false) buf = buffer(source) _parse_type(buf, range.begin || 0, range.end || buf.last_position, variables, require_eof) end
.parse_type_params(source, module_type_params: true)
[ GitHub ]# File 'lib/rbs/parser_aux.rb', line 38
def self.parse_type_params(source, module_type_params: true) buf = buffer(source) _parse_type_params(buf, 0, buf.last_position, module_type_params) end