Sha256: 966265aebdf6aa557a8111f7944fdaf78d3898abe9242710dc95d53ea715b06c

Contents?: true

Size: 677 Bytes

Versions: 14

Compression:

Stored size: 677 Bytes

Contents

# frozen_string_literal: true

class Language
  class Parser
    class Interuption < StandardError
      def initialize(parser, atom = Atom.new)
        @parser = parser
        @atom = atom
      end

      def message
        "\n#{line}#{" " * column_index}^\n"
      end

      def line
        l = input.lines[line_index]
        l += "\n" if l[-1] != "\n"
        l
      end

      def line_index
        input[...cursor].count("\n")
      end

      def column_index
        cursor - input.lines[...line_index].map(&:size).sum
      end

      private

      def cursor
        @parser.cursor
      end

      def input
        @parser.input
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
language-ruby-1.0.1 lib/language/parser/interuption.rb
language-ruby-1.0.0 lib/language/parser/interuption.rb
language-ruby-0.9.3 lib/language/parser/interuption.rb
language-ruby-0.9.2 lib/language/parser/interuption.rb
language-ruby-0.9.0 lib/language/parser/interuption.rb
language-ruby-0.8.4 lib/language/parser/interuption.rb
language-ruby-0.8.3 lib/language/parser/interuption.rb
language-ruby-0.8.2 lib/language/parser/interuption.rb
language-ruby-0.8.1 lib/language/parser/interuption.rb
language-ruby-0.8.0 lib/language/parser/interuption.rb
language-ruby-0.7.0 lib/language/parser/interuption.rb
language-ruby-0.6.2 lib/language/parser/interuption.rb
language-ruby-0.6.1 lib/language/parser/interuption.rb
language-ruby-0.6.0 lib/language/parser/interuption.rb