Sha256: 066994504734fe8ba9354f5dac47e16c97756f8da7b03ecc3660f8137231ed6c

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module Gherkin
  class ParserError < StandardError; end
  class AstNodeNotLocatedException < StandardError; end
  class DoubleIterationException < StandardError; end

  class ParserException < ParserError
    attr_reader :location

    def initialize(message, location)
      @location = location
      super("(#{location[:line]}:#{location[:column] || 0}): #{message}")
    end
  end

  class NoSuchLanguageException < ParserException
    def initialize(language, location)
      super "Language not supported: #{language}", location
    end
  end

  class AstBuilderException < ParserException; end

  class CompositeParserException < ParserError
    attr_reader :errors

    def initialize(errors)
      @errors = errors
      super "Parser errors:\n" + errors.map(&:message).join("\n")
    end
  end

  class UnexpectedTokenException < ParserException
    def initialize(received_token, expected_token_types, state_comment)
      message = "expected: #{expected_token_types.join(", ")}, got '#{received_token.token_value.strip}'"
      column = received_token.location[:column]
      location = (column.nil? || column.zero?) ? { line: received_token.location[:line], column: received_token.line.indent + 1 } : received_token.location
      super(message, location)
    end
  end

  class UnexpectedEOFException < ParserException
    def initialize(received_token, expected_token_types, state_comment)
      message = "unexpected end of file, expected: #{expected_token_types.join(", ")}"
      super(message, received_token.location)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cucumber-gherkin-30.0.0 lib/gherkin/errors.rb