lib/herb/errors.rb



# frozen_string_literal: true

# NOTE: This file is generated by the templates/template.rb script and should not be
# modified manually. See /Users/marcoroth/Development/herb-release/templates/lib/herb/errors.rb.erb

module Herb
  module Errors
    class Error
      attr_reader :type
      attr_reader :location
      attr_reader :message

      def initialize(type, location, message)
        @type = type
        @location = location
        @message = message
      end

      def to_hash
        {
          type: type,
          location: location&.to_hash,
          message: message,
        }
      end

      def error_name
        self.class.name.split("::").last
      end

      def to_json(*args)
        to_hash.to_json(*args)
      end
    end

    class UnexpectedError < Error
      attr_reader :description
      attr_reader :expected
      attr_reader :found

      def initialize(type, location, message, description, expected, found)
        super(type, location, message)

        @description = description
        @expected = expected
        @found = found
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          description: description,
          expected: expected,
          found: found,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── description: #{description.inspect}\n)
        output += %(├── expected: #{expected.inspect}\n)
        output += %(└── found: #{found.inspect}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class UnexpectedTokenError < Error
      attr_reader :expected_type
      attr_reader :found

      def initialize(type, location, message, expected_type, found)
        super(type, location, message)

        @expected_type = expected_type
        @found = found
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          expected_type: expected_type,
          found: found,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── expected_type: #{expected_type.inspect}\n)
        output += %(└── found: #{found ? found.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class MissingOpeningTagError < Error
      attr_reader :closing_tag

      def initialize(type, location, message, closing_tag)
        super(type, location, message)

        @closing_tag = closing_tag
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          closing_tag: closing_tag,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(└── closing_tag: #{closing_tag ? closing_tag.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class MissingClosingTagError < Error
      attr_reader :opening_tag

      def initialize(type, location, message, opening_tag)
        super(type, location, message)

        @opening_tag = opening_tag
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          opening_tag: opening_tag,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(└── opening_tag: #{opening_tag ? opening_tag.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class TagNamesMismatchError < Error
      attr_reader :opening_tag
      attr_reader :closing_tag

      def initialize(type, location, message, opening_tag, closing_tag)
        super(type, location, message)

        @opening_tag = opening_tag
        @closing_tag = closing_tag
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          opening_tag: opening_tag,
          closing_tag: closing_tag,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── opening_tag: #{opening_tag ? opening_tag.tree_inspect : "∅"}\n)
        output += %(└── closing_tag: #{closing_tag ? closing_tag.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class QuotesMismatchError < Error
      attr_reader :opening_quote
      attr_reader :closing_quote

      def initialize(type, location, message, opening_quote, closing_quote)
        super(type, location, message)

        @opening_quote = opening_quote
        @closing_quote = closing_quote
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          opening_quote: opening_quote,
          closing_quote: closing_quote,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── opening_quote: #{opening_quote ? opening_quote.tree_inspect : "∅"}\n)
        output += %(└── closing_quote: #{closing_quote ? closing_quote.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class VoidElementClosingTagError < Error
      attr_reader :tag_name
      attr_reader :expected
      attr_reader :found

      def initialize(type, location, message, tag_name, expected, found)
        super(type, location, message)

        @tag_name = tag_name
        @expected = expected
        @found = found
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          tag_name: tag_name,
          expected: expected,
          found: found,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── tag_name: #{tag_name ? tag_name.tree_inspect : "∅"}\n)
        output += %(├── expected: #{expected.inspect}\n)
        output += %(└── found: #{found.inspect}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class UnclosedElementError < Error
      attr_reader :opening_tag

      def initialize(type, location, message, opening_tag)
        super(type, location, message)

        @opening_tag = opening_tag
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          opening_tag: opening_tag,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(└── opening_tag: #{opening_tag ? opening_tag.tree_inspect : "∅"}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

    class RubyParseError < Error
      attr_reader :error_message
      attr_reader :diagnostic_id
      attr_reader :level

      def initialize(type, location, message, error_message, diagnostic_id, level)
        super(type, location, message)

        @error_message = error_message
        @diagnostic_id = diagnostic_id
        @level = level
      end

      def inspect
        tree_inspect.rstrip.gsub(/\s+$/, "")
      end

      def to_hash
        super.merge({
          error_message: error_message,
          diagnostic_id: diagnostic_id,
          level: level,
        })
      end

      def tree_inspect(indent = 0)
        output = +""

        output += %(@ #{error_name} #{location.tree_inspect}\n)
        output += %(├── message: #{message.inspect}\n)
        output += %(├── error_message: #{error_message.inspect}\n)
        output += %(├── diagnostic_id: #{diagnostic_id.inspect}\n)
        output += %(└── level: #{level.inspect}\n)
        output += %(\n)

        output.gsub(/^/, "    " * indent)
      end
    end

  end
end