Class: Idl::IfSyntaxNode

Inherits:
Treetop::Runtime::SyntaxNode show all
Defined in:
lib/idl/ast.rb

Instance Method Summary collapse

Instance Method Details

#to_astObject



5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
# File 'lib/idl/ast.rb', line 5417

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