Class: Oxc::Comment

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

Constant Summary collapse

LINE =

Signature:

  • String

Returns:

  • (String)
"Line"
BLOCK =

Signature:

  • String

Returns:

  • (String)
"Block"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, value:, start:, finish:) ⇒ Comment

: (type: String, value: String, start: Integer, finish: Integer) -> void

Parameters:

  • type: (String)
  • value: (String)
  • start: (Integer)
  • finish: (Integer)


87
88
89
90
91
92
93
94
# File 'lib/oxc/parse_result.rb', line 87

def initialize(type:, value:, start:, finish:)
  @type = type
  @value = value
  @start = start
  @finish = finish

  freeze
end

Instance Attribute Details

#finishInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


74
75
76
# File 'lib/oxc/parse_result.rb', line 74

def finish
  @finish
end

#startInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


73
74
75
# File 'lib/oxc/parse_result.rb', line 73

def start
  @start
end

#typeString (readonly)

Signature:

  • String

Returns:

  • (String)


71
72
73
# File 'lib/oxc/parse_result.rb', line 71

def type
  @type
end

#valueString (readonly)

Signature:

  • String

Returns:

  • (String)


72
73
74
# File 'lib/oxc/parse_result.rb', line 72

def value
  @value
end

Class Method Details

.from_hash(parsed) ⇒ Oxc::Comment

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

Parameters:

  • (Hash[String, untyped])

Returns:



77
78
79
80
81
82
83
84
# File 'lib/oxc/parse_result.rb', line 77

def self.from_hash(parsed)
  new(
    type: parsed.fetch("type"),
    value: parsed.fetch("value"),
    start: parsed.fetch("start"),
    finish: parsed.fetch("end")
  )
end

Instance Method Details

#block?Boolean

: () -> bool

Returns:

  • (Boolean)


102
103
104
# File 'lib/oxc/parse_result.rb', line 102

def block?
  type == BLOCK
end

#inspectString

: () -> String

Returns:

  • (String)


112
113
114
# File 'lib/oxc/parse_result.rb', line 112

def inspect
  "#<#{self.class.name} #{type} #{value.inspect}>"
end

#line?Boolean

: () -> bool

Returns:

  • (Boolean)


97
98
99
# File 'lib/oxc/parse_result.rb', line 97

def line?
  type == LINE
end

#slice(source) ⇒ String?

: (String) -> String?

Parameters:

  • (String)

Returns:

  • (String, nil)


107
108
109
# File 'lib/oxc/parse_result.rb', line 107

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