class SyntaxSuggest::Token - Documentation for Ruby 4.1
Description: class SyntaxSuggest::Token: lex. location # => (1,0)-(1,8) lex.
Keywords: ruby,class,SyntaxSuggest::Token

🔍

No recent searches

# class SyntaxSuggest::Token

Value object for accessing lex values

This lex:

    [IDENTIFIER(1,0)-(1,8)("describe"), 32]

Would translate into:

    lex.location # => (1,0)-(1,8)
    lex.type # => :IDENTIFIER
    lex.token # => "describe"

### Constants

KW_TYPES

### Attributes

location [R]
type [R]
value [R]

### Public Class Methods

new (prism_token, previous_prism_token, visitor)
Source

    # File lib/syntax_suggest/token.rb, line 24
    def initialize(prism_token, previous_prism_token, visitor)
      @location = prism_token.location
      @type = prism_token.type
      @value = prism_token.value

      # Prism lexes `:module` as SYMBOL_BEGIN, KEYWORD_MODULE
      # https://github.com/ruby/prism/issues/3940
      symbol_content = previous_prism_token&.type == :SYMBOL_BEGIN
      @is_kw = KW_TYPES.include?(@type)
      @is_kw = false if symbol_content || visitor.endless_def_keyword_offsets.include?(@location.start_offset)
      @is_end = @type == :KEYWORD_END
    end

### Public Instance Methods

is_end? ()
Source

    # File lib/syntax_suggest/token.rb, line 41
    def is_end?
      @is_end
    end

is_kw? ()
Source

    # File lib/syntax_suggest/token.rb, line 45
    def is_kw?
      @is_kw
    end

line ()
Source

    # File lib/syntax_suggest/token.rb, line 37
    def line
      @location.start_line
    end