Class: Idl::IfSyntaxNode

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

Instance Method Summary collapse

Instance Method Details

#to_astObject



5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
# File 'lib/idl/ast.rb', line 5452

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