File: error.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 (84 lines) | stat: -rw-r--r-- 1,712 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
module Morpher
  class Compiler

    # Abstract error class for compiler errors
    class Error < RuntimeError
      include AbstractType

      # Error raised when node children have incorrect amount
      class NodeChildren < self
        include Concord.new(:node, :expected_amount)

        # Return exception message
        #
        # @return [String]
        #
        # @api private
        #
        def message
          "Expected #{expected_amount} #{_children} for #{type}, got #{actual_amount}: #{children}"
        end

        private

        # Return inspected type
        #
        # @return [String]
        #
        # @api private
        #
        def type
          node.type.inspect
        end

        # Return actual amount of children
        #
        # @return [String]
        #
        # @api private
        #
        def actual_amount
          children.length
        end

        # Return children
        #
        # @return [Array]
        #
        # @api private
        #
        def children
          node.children
        end

        # Return user firendly children message
        #
        # @return [String]
        #
        # @api private
        #
        def _children
          expected_amount.equal?(1) ? 'child' : 'children'
        end

      end # NodeChildren

      # Error raised on compiling unknown nodes
      class UnknownNode < self
        include Concord.new(:type)

        # Return exception error message
        #
        # @return [String]
        #
        # @api private
        #
        def message
          "Node type: #{type.inspect} is unknown"
        end

      end # UnknownNode

    end # Error
  end # Compiler
end # Morpher