File: nary.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 (97 lines) | stat: -rw-r--r-- 1,984 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module Morpher
  class Evaluator

    # Mixin for nary evaluators
    module Nary
      CONCORD = Concord::Public.new(:body)

      PRINTER = lambda do |_|
        name
        indent do
          visit_many(:body)
        end
      end

      # Return AST
      #
      # @return [AST::Node]
      #
      # @api private
      #
      def node
        s(type, *body.map(&:node))
      end

    private

      # Return positive evaluation
      #
      # @param [Object] input
      # @param [Array<Evaluation>] evaluations
      #
      # @return [Evaluation]
      #
      # @api private
      #
      def evaluation_positive(input, evaluations)
        Evaluation::Nary.success(
          evaluator:   self,
          input:       input,
          output:      true,
          evaluations: evaluations
        )
      end

      # Return negative evaluation
      #
      # @param [Object] input
      # @param [Array<Evaluation>] evaluations
      #
      # @return [Evaluation]
      #
      # @api private
      #
      def evaluation_negative(input, evaluations)
        Evaluation::Nary.success(
          evaluator:   self,
          input:       input,
          output:      false,
          evaluations: evaluations
        )
      end

      # Return evaluation error
      #
      # @param [Object] input
      # @param [Array<Evaluation>] evaluations
      #
      # @return [Evaluation]
      #
      # @api private
      #
      def evaluation_error(input, evaluations)
        Evaluation::Nary.error(
          evaluator:   self,
          input:       input,
          evaluations: evaluations
        )
      end

      # Hook called when module gets included
      #
      # @return [undefined]
      #
      # @api private
      #
      def self.included(descendant)
        descendant.class_eval do
          include CONCORD
          printer(&PRINTER)
        end
      end
      private_class_method :included

    end # Nary

  end # Evaluator
end # Morpher