Class: Oxc::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/oxc/diagnostic.rb,
sig/oxc/diagnostic.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start:, finish:, message: nil) ⇒ Label

: (start: Integer, finish: Integer, ?message: String?) -> void

Parameters:

  • start: (Integer)
  • finish: (Integer)
  • message: (String, nil) (defaults to: nil)


68
69
70
71
72
73
74
# File 'lib/oxc/diagnostic.rb', line 68

def initialize(start:, finish:, message: nil)
  @start = start
  @finish = finish
  @message = message

  freeze
end

Instance Attribute Details

#finishInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


60
61
62
# File 'lib/oxc/diagnostic.rb', line 60

def finish
  @finish
end

#messageString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


58
59
60
# File 'lib/oxc/diagnostic.rb', line 58

def message
  @message
end

#startInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


59
60
61
# File 'lib/oxc/diagnostic.rb', line 59

def start
  @start
end

Class Method Details

.from_hash(parsed) ⇒ Oxc::Label

: (Hash[String, untyped]) -> Oxc::Label

Parameters:

  • (Hash[String, untyped])

Returns:



63
64
65
# File 'lib/oxc/diagnostic.rb', line 63

def self.from_hash(parsed)
  new(message: parsed["message"], start: parsed.fetch("start"), finish: parsed.fetch("end"))
end

Instance Method Details

#inspectString

: () -> String

Returns:

  • (String)


82
83
84
# File 'lib/oxc/diagnostic.rb', line 82

def inspect
  "#<#{self.class.name} range=[#{start}, #{finish}]#{" #{message.inspect}" if message}>"
end

#slice(source) ⇒ String?

: (String) -> String?

Parameters:

  • (String)

Returns:

  • (String, nil)


77
78
79
# File 'lib/oxc/diagnostic.rb', line 77

def slice(source)
  source.byteslice(start, finish - start)
end