Class: TreeHaver::Backends::Tslp::Node
Constant Summary
collapse
- NODE_TYPE_ALIASES =
{
'json5' => {
'file' => 'document',
'member' => 'pair'
}
}.freeze
Instance Attribute Summary collapse
#inner_node, #lines, #source
Instance Method Summary
collapse
#<=>, #==, #child, #child_count, #each, #end_line, #first_child, #inspect, #last_child, #next_sibling, #prev_sibling, #source_position, #start_line, #text, #to_s
Constructor Details
#initialize(node, source: nil, lines: nil, language: nil) ⇒ Node
Returns a new instance of Node.
204
205
206
207
|
# File 'lib/tree_haver/backends/tslp.rb', line 204
def initialize(node, source: nil, lines: nil, language: nil)
super(node, source: source, lines: lines)
@language = language.to_s
end
|
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
202
203
204
|
# File 'lib/tree_haver/backends/tslp.rb', line 202
def language
@language
end
|
Instance Method Details
#child_by_field_name(name) ⇒ Object
242
243
244
245
|
# File 'lib/tree_haver/backends/tslp.rb', line 242
def child_by_field_name(name)
child = inner_node.child_by_field_name(name.to_s) if inner_node.respond_to?(:child_by_field_name)
child && self.class.new(child, source: source, lines: lines, language: language)
end
|
#children ⇒ Object
235
236
237
238
239
240
|
# File 'lib/tree_haver/backends/tslp.rb', line 235
def children
Array.new(inner_node.child_count) do |index|
child = inner_node.child(index)
child && self.class.new(child, source: source, lines: lines, language: language)
end.compact
end
|
#end_byte ⇒ Object
221
222
223
|
# File 'lib/tree_haver/backends/tslp.rb', line 221
def end_byte
inner_node.end_byte
end
|
#end_point ⇒ Object
230
231
232
233
|
# File 'lib/tree_haver/backends/tslp.rb', line 230
def end_point
point = inner_node.end_position
{ row: point.row, column: point.column }
end
|
#error? ⇒ Boolean
260
261
262
|
# File 'lib/tree_haver/backends/tslp.rb', line 260
def error?
inner_node.is_error
end
|
268
269
270
|
# File 'lib/tree_haver/backends/tslp.rb', line 268
def
inner_node.
end
|
#has_error? ⇒ Boolean
256
257
258
|
# File 'lib/tree_haver/backends/tslp.rb', line 256
def has_error?
inner_node.has_error
end
|
#missing? ⇒ Boolean
264
265
266
|
# File 'lib/tree_haver/backends/tslp.rb', line 264
def missing?
inner_node.is_missing
end
|
#named? ⇒ Boolean
252
253
254
|
# File 'lib/tree_haver/backends/tslp.rb', line 252
def named?
inner_node.is_named
end
|
#native_type ⇒ Object
213
214
215
|
# File 'lib/tree_haver/backends/tslp.rb', line 213
def native_type
inner_node.kind
end
|
#parent ⇒ Object
247
248
249
250
|
# File 'lib/tree_haver/backends/tslp.rb', line 247
def parent
parent = inner_node.parent if inner_node.respond_to?(:parent)
parent && self.class.new(parent, source: source, lines: lines, language: language)
end
|
#start_byte ⇒ Object
217
218
219
|
# File 'lib/tree_haver/backends/tslp.rb', line 217
def start_byte
inner_node.start_byte
end
|
#start_point ⇒ Object
225
226
227
228
|
# File 'lib/tree_haver/backends/tslp.rb', line 225
def start_point
point = inner_node.start_position
{ row: point.row, column: point.column }
end
|
#type ⇒ Object
209
210
211
|
# File 'lib/tree_haver/backends/tslp.rb', line 209
def type
NODE_TYPE_ALIASES.fetch(language, {}).fetch(native_type, native_type)
end
|