lib/dentaku/exceptions.rb in dentaku-2.0.11 vs lib/dentaku/exceptions.rb in dentaku-3.0.0
- old
+ new
@@ -4,20 +4,94 @@
attr_reader :unbound_variables
def initialize(unbound_variables)
@unbound_variables = unbound_variables
- super("no value provided for variables: #{ unbound_variables.join(', ') }")
end
end
+ class NodeError < StandardError
+ attr_reader :child, :expect, :actual
+
+ def initialize(expect, actual, child)
+ @expect = Array(expect)
+ @actual = actual
+ @child = child
+ end
+ end
+
class ParseError < StandardError
+ attr_reader :reason, :meta
+
+ def initialize(reason, **meta)
+ @reason = reason
+ @meta = meta
+ end
+
+ private_class_method :new
+
+ VALID_REASONS = %i[
+ node_invalid too_few_operands undefined_function
+ unprocessed_token unknown_case_token unbalanced_bracket
+ unbalanced_parenthesis unknown_grouping_token not_implemented_token_category
+ invalid_statement
+ ].freeze
+
+ def self.for(reason, **meta)
+ unless VALID_REASONS.include?(reason)
+ raise ::ArgumentError, "Unhandled #{reason}"
+ end
+
+ new reason, meta
+ end
end
class TokenizerError < StandardError
+ attr_reader :reason, :meta
+
+ def initialize(reason, **meta)
+ @reason = reason
+ @meta = meta
+ end
+
+ private_class_method :new
+
+ VALID_REASONS = %i[
+ parse_error too_many_opening_parentheses too_many_closing_parentheses
+ unexpected_zero_width_match
+ ].freeze
+
+ def self.for(reason, **meta)
+ unless VALID_REASONS.include?(reason)
+ raise ::ArgumentError, "Unhandled #{reason}"
+ end
+
+ new reason, meta
+ end
end
class ArgumentError < ::ArgumentError
+ attr_reader :reason, :meta
+
+ def initialize(reason, **meta)
+ @reason = reason
+ @meta = meta
+ end
+
+ private_class_method :new
+
+ VALID_REASONS = %i[
+ invalid_operator invalid_value too_few_arguments
+ too_much_arguments incompatible_type
+ ].freeze
+
+ def self.for(reason, **meta)
+ unless VALID_REASONS.include?(reason)
+ raise ::ArgumentError, "Unhandled #{reason}"
+ end
+
+ new reason, meta
+ end
end
class ZeroDivisionError < ::ZeroDivisionError
attr_accessor :recipient_variable
end