Class: Yoda::AST::CommentBlock::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/ast/comment_block/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, range:) ⇒ Token

Returns a new instance of Token.

Parameters:



31
32
33
34
# File 'lib/yoda/ast/comment_block/token.rb', line 31

def initialize(content, range:)
  @content = content
  @range = range
end

Instance Attribute Details

#contentString (readonly)

Returns:

  • (String)


24
25
26
# File 'lib/yoda/ast/comment_block/token.rb', line 24

def content
  @content
end

#rangeParsing::Range? (readonly)

Returns:



27
28
29
# File 'lib/yoda/ast/comment_block/token.rb', line 27

def range
  @range
end

Class Method Details

.from_parslet(slice, comment_block:) ⇒ CommentBlock::Slice

Parameters:

Returns:

  • (CommentBlock::Slice)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yoda/ast/comment_block/token.rb', line 10

def self.from_parslet(slice, comment_block:)
  begin_location = comment_block.location_from_index(slice.offset)
  end_location = comment_block.location_from_index(slice.offset + slice.length)

  range = if begin_location && end_location
    Parsing::Range.new(begin_location, end_location)
  else
    nil
  end

  new(slice.to_s, range: range)
end

Instance Method Details

#include?(location) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


38
39
40
# File 'lib/yoda/ast/comment_block/token.rb', line 38

def include?(location)
  range&.include?(location)
end