123456789_123456789_123456789_123456789_123456789_

Class: RBS::Parser

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/rbs/parser_aux.rb,
ext/rbs_extension/parser.c,
lib/rbs/parser/lex_result.rb,
lib/rbs/parser/token.rb

Constant Summary

  • KEYWORDS =
    # File 'lib/rbs/parser_aux.rb', line 43
    %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[keyword] = nil
    end

Class Method Summary

Class Method Details

._lex(buffer, end_pos)

[ GitHub ]

  
# File 'ext/rbs_extension/parser.c', line 2961

static VALUE
rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) {
  VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
  StringValue(string);
  lexstate *lexer = alloc_lexer(string, 0, FIX2INT(end_pos));
  VALUE results = rb_ary_new();

  token token = NullToken;
  while (token.type != pEOF) {
    token = rbsparser_next_token(lexer);
    VALUE type = ID2SYM(rb_intern(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);
  }

  free(lexer);

  return results;
}

._parse_method_type(buffer, start_pos, end_pos, variables, require_eof)

[ GitHub ]

  
# File 'ext/rbs_extension/parser.c', line 2931

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);
  lexstate *lexer = alloc_lexer(string, FIX2INT(start_pos), FIX2INT(end_pos));
  parserstate *parser = alloc_parser(buffer, lexer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
  struct parse_type_arg arg = {
    parser,
    require_eof
  };
  return rb_ensure(parse_method_type_try, (VALUE)&arg, ensure_free_parser, (VALUE)parser);
}

._parse_signature(buffer, end_pos)

[ GitHub ]

  
# File 'ext/rbs_extension/parser.c', line 2951

static VALUE
rbsparser_parse_signature(VALUE self, VALUE buffer, VALUE end_pos)
{
  VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
  StringValue(string);
  lexstate *lexer = alloc_lexer(string, 0, FIX2INT(end_pos));
  parserstate *parser = alloc_parser(buffer, lexer, 0, FIX2INT(end_pos), Qnil);
  return rb_ensure(parse_signature_try, (VALUE)parser, ensure_free_parser, (VALUE)parser);
}

._parse_type(buffer, start_pos, end_pos, variables, require_eof)

[ GitHub ]

  
# File 'ext/rbs_extension/parser.c', line 2900

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);
  lexstate *lexer = alloc_lexer(string, FIX2INT(start_pos), FIX2INT(end_pos));
  parserstate *parser = alloc_parser(buffer, lexer, FIX2INT(start_pos), FIX2INT(end_pos), variables);
  struct parse_type_arg arg = {
    parser,
    require_eof
  };
  return rb_ensure(parse_type_try, (VALUE)&arg, ensure_free_parser, (VALUE)parser);
}

.buffer(source)

[ GitHub ]

  
# File 'lib/rbs/parser_aux.rb', line 34

def self.buffer(source)
  case source
  when String
    Buffer.new(content: source, name: "a.rbs")
  when Buffer
    source
  end
end

.lex(source)

[ GitHub ]

  
# File 'lib/rbs/parser_aux.rb', line 25

def self.lex(source)
  buf = buffer(source)
  list = _lex(buf, buf.last_position)
  value = list.map do |type, location|
    Token.new(type: type, location: location)
  end
  LexResult.new(buffer: buf, value: value)
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)
  dirs, decls = _parse_signature(buf, buf.last_position)

  [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