Class: SyntaxTree::LBrace

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

Overview

LBrace represents the use of a left brace, i.e., {.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LBrace.



7871
7872
7873
7874
7875
# File 'lib/syntax_tree.rb', line 7871

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



7869
7870
7871
# File 'lib/syntax_tree.rb', line 7869

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7866
7867
7868
# File 'lib/syntax_tree.rb', line 7866

def location
  @location
end

#valueObject (readonly)

String

the left brace



7863
7864
7865
# File 'lib/syntax_tree.rb', line 7863

def value
  @value
end

Instance Method Details

#child_nodesObject



7877
7878
7879
# File 'lib/syntax_tree.rb', line 7877

def child_nodes
  []
end

#format(q) ⇒ Object



7881
7882
7883
# File 'lib/syntax_tree.rb', line 7881

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

#pretty_print(q) ⇒ Object



7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
# File 'lib/syntax_tree.rb', line 7885

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



7896
7897
7898
7899
7900
# File 'lib/syntax_tree.rb', line 7896

def to_json(*opts)
  { type: :lbrace, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end