Class: Textlint::Nodes::TxtNode

Inherits:
Object
  • Object
show all
Defined in:
lib/textlint/nodes.rb

Overview

export interface TxtNode

type: TxtNodeType;
raw: string;
range: TextNodeRange;
loc: TxtNodeLineLocation;
// parent is runtime information
// Not need in AST
// For example, top Root Node like `Document` has not parent.
parent?: TxtNode;

[index: string]: any;

Direct Known Subclasses

TxtParentNode, TxtTextNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, raw:, range:, loc:) ⇒ TxtNode

Returns a new instance of TxtNode.

Parameters:



105
106
107
108
109
110
# File 'lib/textlint/nodes.rb', line 105

def initialize(type:, raw:, range:, loc:)
  @type = type
  @raw = raw
  @range = range
  @loc = loc
end

Instance Attribute Details

#locObject (readonly)

Returns the value of attribute loc.



99
100
101
# File 'lib/textlint/nodes.rb', line 99

def loc
  @loc
end

#rangeObject (readonly)

Returns the value of attribute range.



99
100
101
# File 'lib/textlint/nodes.rb', line 99

def range
  @range
end

#rawObject (readonly)

Returns the value of attribute raw.



99
100
101
# File 'lib/textlint/nodes.rb', line 99

def raw
  @raw
end

#typeObject (readonly)

Returns the value of attribute type.



99
100
101
# File 'lib/textlint/nodes.rb', line 99

def type
  @type
end

Instance Method Details

#as_textlint_jsonHash

Returns:

  • (Hash)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/textlint/nodes.rb', line 113

def as_textlint_json
  {
    type: type,
    raw: raw,
    range: [
      range.begin,
      (range.exclude_end? ? range.end : range.end - 1)
    ],
    loc: loc.as_textlint_json
  }
end