Class: Ibex::Runtime::CST::GreenToken
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::GreenToken
- Defined in:
- lib/json5/generated_parser.rb
Overview
Immutable position-independent terminal occurrence.
Constant Summary collapse
- EMPTY_TRIVIA =
empty_trivia.freeze
Instance Attribute Summary collapse
- #expected_kind ⇒ Object readonly
- #flags ⇒ Object readonly
- #full_width ⇒ Object readonly
- #hash ⇒ Object readonly
- #kind ⇒ Object readonly
- #leading ⇒ Object readonly
- #leading_width ⇒ Object readonly
- #text ⇒ Object readonly
- #trailing ⇒ Object readonly
- #trailing_width ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #descendant_count ⇒ Object
-
#initialize(kind:, text:, leading: EMPTY_TRIVIA, trailing: EMPTY_TRIVIA, flags: 0, expected_kind: nil) ⇒ GreenToken
constructor
A new instance of GreenToken.
- #to_source ⇒ Object
Constructor Details
#initialize(kind:, text:, leading: EMPTY_TRIVIA, trailing: EMPTY_TRIVIA, flags: 0, expected_kind: nil) ⇒ GreenToken
Returns a new instance of GreenToken.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/json5/generated_parser.rb', line 341 def initialize( kind:, text:, leading: EMPTY_TRIVIA, trailing: EMPTY_TRIVIA, flags: 0, expected_kind: nil ) @kind = kind @text = text.encoding == Encoding::BINARY && text.frozen? ? text : text.b.freeze @leading = leading.frozen? ? leading : leading.dup.freeze @trailing = trailing.frozen? ? trailing : trailing.dup.freeze @flags = flags @expected_kind = expected_kind @leading_width = trivia_width(@leading) @trailing_width = trivia_width(@trailing) @full_width = @leading_width + @text.bytesize + @trailing_width @hash = @kind.hash ^ @text.hash ^ @leading.hash ^ @trailing.hash ^ @flags.hash ^ @expected_kind.hash freeze end |
Instance Attribute Details
#expected_kind ⇒ Object (readonly)
336 337 338 |
# File 'lib/json5/generated_parser.rb', line 336 def expected_kind @expected_kind end |
#flags ⇒ Object (readonly)
332 333 334 |
# File 'lib/json5/generated_parser.rb', line 332 def flags @flags end |
#full_width ⇒ Object (readonly)
333 334 335 |
# File 'lib/json5/generated_parser.rb', line 333 def full_width @full_width end |
#hash ⇒ Object (readonly)
337 338 339 |
# File 'lib/json5/generated_parser.rb', line 337 def hash @hash end |
#kind ⇒ Object (readonly)
328 329 330 |
# File 'lib/json5/generated_parser.rb', line 328 def kind @kind end |
#leading ⇒ Object (readonly)
330 331 332 |
# File 'lib/json5/generated_parser.rb', line 330 def leading @leading end |
#leading_width ⇒ Object (readonly)
334 335 336 |
# File 'lib/json5/generated_parser.rb', line 334 def leading_width @leading_width end |
#text ⇒ Object (readonly)
329 330 331 |
# File 'lib/json5/generated_parser.rb', line 329 def text @text end |
#trailing ⇒ Object (readonly)
331 332 333 |
# File 'lib/json5/generated_parser.rb', line 331 def trailing @trailing end |
#trailing_width ⇒ Object (readonly)
335 336 337 |
# File 'lib/json5/generated_parser.rb', line 335 def trailing_width @trailing_width end |
Class Method Details
.lexical_error(kind:, text:, leading: []) ⇒ Object
366 367 368 |
# File 'lib/json5/generated_parser.rb', line 366 def self.lexical_error(kind:, text:, leading: []) new(kind: kind, text: text, leading: leading, flags: Flags::CONTAINS_ERROR) end |
.missing(kind:, expected_kind:) ⇒ Object
358 359 360 361 362 363 |
# File 'lib/json5/generated_parser.rb', line 358 def self.missing(kind:, expected_kind:) new( kind: kind, text: "", expected_kind: expected_kind, flags: Flags::CONTAINS_MISSING | Flags::SYNTHETIC ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
383 384 385 386 387 388 389 390 391 |
# File 'lib/json5/generated_parser.rb', line 383 def ==(other) other.is_a?(GreenToken) && @kind == other.kind && @text == other.text && @leading == other.leading && @trailing == other.trailing && @flags == other.flags && @expected_kind == other.expected_kind end |
#descendant_count ⇒ Object
371 |
# File 'lib/json5/generated_parser.rb', line 371 def descendant_count = 1 |
#to_source ⇒ Object
374 375 376 377 378 379 380 |
# File 'lib/json5/generated_parser.rb', line 374 def to_source source = String.new(encoding: Encoding::BINARY) @leading.each { |trivia| source << trivia.text } source << @text @trailing.each { |trivia| source << trivia.text } source end |