Class: Sith::MacroExpander
- Inherits:
-
Object
- Object
- Sith::MacroExpander
- Defined in:
- lib/sith/macro_expander.rb
Instance Method Summary collapse
- #expand(source) ⇒ Object
- #expand_node(node) ⇒ Object
- #expand_to_source(source) ⇒ Object
-
#initialize(macros) ⇒ MacroExpander
constructor
A new instance of MacroExpander.
Constructor Details
#initialize(macros) ⇒ MacroExpander
Returns a new instance of MacroExpander.
6 7 8 |
# File 'lib/sith/macro_expander.rb', line 6 def initialize(macros) @macros = macros end |
Instance Method Details
#expand(source) ⇒ Object
10 11 12 13 |
# File 'lib/sith/macro_expander.rb', line 10 def (source) ast = Parser::CurrentRuby.parse(source) ast end |
#expand_node(node) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/sith/macro_expander.rb', line 19 def (node) return node unless node.is_a?(Parser::AST::Node) if node.type == :send && @macros.key?(node.children[1]) node = @macros[node.children[1]].(node.children[2..-1]) end children = node.children.map(&method(:expand_node)) Parser::AST::Node.new node.type, children end |
#expand_to_source(source) ⇒ Object
15 16 17 |
# File 'lib/sith/macro_expander.rb', line 15 def (source) Unparser.unparse((source)) end |