Class: Idl::IfSyntaxNode

Inherits:
SyntaxNode show all
Defined in:
lib/idlc/ast.rb

Instance Method Summary collapse

Methods inherited from Treetop::Runtime::SyntaxNode

#set_input_file, #set_input_file_unless_already_set, #space?

Instance Method Details

#to_astObject



9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
# File 'lib/idlc/ast.rb', line 9030

def to_ast
  if_body_stmts = T.let([], T::Array[StatementAst])
  send(:if_body).elements.each do |e|
    if_body_stmts << e.e.to_ast
  end
  eifs = T.let([], T::Array[ElseIfAst])
  unless send(:elseifs).empty?
    send(:elseifs).elements.each do |eif|
      stmts = []
      eif.body.elements.each do |e|
        stmts << e.e.to_ast
      end
      elseif_body = IfBodyAst.new(input, eif.body.interval, stmts)
      eifs << ElseIfAst.new(input, eif.interval, elseif_body.interval, eif.expression.to_ast, elseif_body.stmts)
    end
  end
  final_else_stmts = T.let([], T::Array[StatementAst])
  unless send(:final_else).empty?
    send(:final_else).body.elements.each do |e|
      final_else_stmts << e.e.to_ast
    end
  end
  if_body_ast = IfBodyAst.new(input, send(:if_body).interval, if_body_stmts)
  final_else_ast =
    if send(:final_else).empty?
      IfBodyAst.new(input, 0..0, final_else_stmts)
    else
      IfBodyAst.new(input, send(:final_else).body.interval, final_else_stmts)
    end
  ast = IfAst.new(input, interval, send(:if_cond).to_ast, if_body_ast, eifs, final_else_ast)
  ast
end