File: emitter.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 (54 lines) | stat: -rw-r--r-- 1,059 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Morpher
  class Compiler
    class Preprocessor
      # Abstract preprocessor emitter
      class Emitter < Compiler::Emitter
        include Registry, Concord.new(:preprocessor, :node)

        # Return output
        #
        # @return [AST::Node]
        #
        # @api private
        #
        def output
          validate_node
          processed_node
        end
        memoize :output

      private

        # Visit node
        #
        # @param [Node] node
        #   original untransformed node
        #
        # @return [Node]
        #   transformed node
        #
        # @api private
        #
        def visit(node)
          preprocessor.call(node)
        end

        # Validate node
        #
        # @return [undefined]
        #   if successful
        #
        # @raise [Error]
        #   otherwise
        #
        # @api private
        #
        def validate_node
          assert_children_amount(named_children.length)
        end

      end # Emitter

    end # Preprocessor
  end # Compiler
end # Morpher