Class: SyntaxTree::TStringContent

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

Overview

TStringContent represents plain characters inside of an entity that accepts string content like a string, heredoc, command string, or regular expression.

"string"

In the example above, TStringContent represents the string token contained within the string.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ TStringContent

Returns a new instance of TStringContent.



11409
11410
11411
11412
11413
# File 'lib/syntax_tree.rb', line 11409

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11407
11408
11409
# File 'lib/syntax_tree.rb', line 11407

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11404
11405
11406
# File 'lib/syntax_tree.rb', line 11404

def location
  @location
end

#valueObject (readonly)

String

the content of the string



11401
11402
11403
# File 'lib/syntax_tree.rb', line 11401

def value
  @value
end

Instance Method Details

#child_nodesObject



11415
11416
11417
# File 'lib/syntax_tree.rb', line 11415

def child_nodes
  []
end

#format(q) ⇒ Object



11419
11420
11421
# File 'lib/syntax_tree.rb', line 11419

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
# File 'lib/syntax_tree.rb', line 11423

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("tstring_content")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



11434
11435
11436
11437
11438
11439
11440
11441
# File 'lib/syntax_tree.rb', line 11434

def to_json(*opts)
  {
    type: :tstring_content,
    value: value.force_encoding("UTF-8"),
    loc: location,
    cmts: comments
  }.to_json(*opts)
end