Class: SyntaxTree::Until

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

Overview

Until represents an until loop.

until predicate
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate:, statements:, location:, comments: []) ⇒ Until

Returns a new instance of Until.



11954
11955
11956
11957
11958
11959
# File 'lib/syntax_tree.rb', line 11954

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11952
11953
11954
# File 'lib/syntax_tree.rb', line 11952

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11949
11950
11951
# File 'lib/syntax_tree.rb', line 11949

def location
  @location
end

#predicateObject (readonly)

untyped

the expression to be checked



11943
11944
11945
# File 'lib/syntax_tree.rb', line 11943

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



11946
11947
11948
# File 'lib/syntax_tree.rb', line 11946

def statements
  @statements
end

Instance Method Details

#child_nodesObject



11961
11962
11963
# File 'lib/syntax_tree.rb', line 11961

def child_nodes
  [predicate, statements]
end

#format(q) ⇒ Object



11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
# File 'lib/syntax_tree.rb', line 11965

def format(q)
  if statements.empty?
    keyword = "until "

    q.group do
      q.text(keyword)
      q.nest(keyword.length) { q.format(predicate) }
      q.breakable(force: true)
      q.text("end")
    end
  else
    LoopFormatter.new("until", self, statements).format(q)
  end
end

#pretty_print(q) ⇒ Object



11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
# File 'lib/syntax_tree.rb', line 11980

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

    q.breakable
    q.pp(predicate)

    q.breakable
    q.pp(statements)

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

#to_json(*opts) ⇒ Object



11994
11995
11996
11997
11998
11999
12000
12001
12002
# File 'lib/syntax_tree.rb', line 11994

def to_json(*opts)
  {
    type: :until,
    pred: predicate,
    stmts: statements,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end