Class: Y2R::AST::YCP::ModuleBlock
- Defined in:
- lib/y2r/ast/ycp.rb
Instance Method Summary collapse
Methods inherited from Node
#always_returns?, #compile_as_copy_if_needed, #compile_statements, #compile_statements_inside_block, #compile_statements_with_whitespace, #creates_local_scope?, #needs_copy?, #never_nil?, #optimize_last_statement, #optimize_next, #optimize_return, #remove_duplicate_imports, transfers_comments
Instance Method Details
#compile(context) ⇒ Object
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 |
# File 'lib/y2r/ast/ycp.rb', line 1613 def compile(context) if name !~ /^[A-Z][a-zA-Z0-9_]*$/ raise NotImplementedError, "Invalid module name: #{name.inspect}. Module names that are not Ruby class names are not supported." end class_statements = [] context.inside self do |inner_context| class_statements += build_main_def(inner_context) class_statements += build_other_defs(inner_context) class_statements += build_publish_calls(inner_context) end module_statements = [ Ruby::Class.new( :name => "#{name}Class", :superclass => Ruby::Variable.new(:name => "Module"), :statements => Ruby::Statements.new( :statements => class_statements ) ), Ruby::Assignment.new( :lhs => Ruby::Variable.new(:name => name), :rhs => Ruby::MethodCall.new( :receiver => Ruby::Variable.new(:name => "#{name}Class"), :name => "new", :args => [], :block => nil, :parens => true ), :comment_before => "" ) ] if has_main_def? module_statements << Ruby::MethodCall.new( :receiver => Ruby::Variable.new(:name => name), :name => "main", :args => [], :block => nil, :parens => true ) end Ruby::Program.new( :statements => Ruby::Statements.new( :statements => [ Ruby::MethodCall.new( :receiver => nil, :name => "require", :args => [Ruby::Literal.new(:value => "yast")], :block => nil, :parens => false ), Ruby::Module.new( :name => "Yast", :statements => Ruby::Statements.new( :statements => module_statements ), :comment_before => "" ) ] ) ) end |