File: preprocessor.rb

package info (click to toggle)
ruby-morpher 0.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 2,366; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Morpher
  class Compiler
    # AST preprocessor
    class Preprocessor < self
      include Concord.new(:emitters)

      # Call preprocessor
      #
      # @param [Node] node
      #   the raw AST node after DSL
      #
      # @return [Node]
      #   the transformed ast node
      #
      # @api private
      #
      def call(node)
        loop do
          emitter = emitters.fetch(node.type, Emitter::Noop)
          node = emitter.call(self, node)
          break if emitter.equal?(Emitter::Noop)
        end

        node
      end

    end # Preprocessor
  end # Compiler
end # Morpher