Class: Ibex::Runtime::CST::GreenTrivia

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/cst/green/trivia.rb

Overview

Immutable source text ignored by the grammar but owned by a token.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, text:) ⇒ GreenTrivia

Returns a new instance of GreenTrivia.



15
16
17
18
19
20
21
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 15

def initialize(kind:, text:)
  @kind = kind
  @text = text.b.freeze
  @full_width = @text.bytesize
  @hash = [@kind, @text].hash
  freeze
end

Instance Attribute Details

#full_widthObject (readonly)

: Integer



11
12
13
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 11

def full_width
  @full_width
end

#hashObject (readonly)

: Integer



12
13
14
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 12

def hash
  @hash
end

#kindObject (readonly)

: Integer



9
10
11
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 9

def kind
  @kind
end

#textObject (readonly)

: String



10
11
12
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 10

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



27
28
29
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 27

def ==(other)
  other.is_a?(GreenTrivia) && @kind == other.kind && @text == other.text
end

#to_sourceObject



24
# File 'lib/ibex/runtime/cst/green/trivia.rb', line 24

def to_source = @text