Sha256: ed9186811fd8d57a24530385fc8ccb012b7e227041b00c6598e305d770eb7f75

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'core_ext'

require 'puffy/parser.tab'
require 'puffy/formatters/base'
require 'puffy/formatters/netfilter'
require 'puffy/formatters/netfilter4'
require 'puffy/formatters/netfilter6'
require 'puffy/formatters/pf'
require 'puffy/puppet'
require 'puffy/resolver'
require 'puffy/rule'
require 'puffy/rule_factory'
require 'puffy/version'

module Puffy
  class PuffyError < RuntimeError
    def initialize(message, token)
      super(message)
      @token = token
    end

    def filename
      @token[:filename]
    end

    def lineno
      @token[:lineno]
    end

    def line
      @token[:line]
    end

    def position
      @token[:position]
    end

    def length
      @token.fetch(:length, 1)
    end

    def extra
      '~' * (length - 1)
    end

    def to_s
      <<~MESSAGE
        #{filename}:#{lineno}:#{position + 1}: #{super}
        #{line}
        #{' ' * position}^#{extra}
      MESSAGE
    end
  end

  class ParseError < PuffyError
  end

  class SyntaxError < PuffyError
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puffy-0.1.0 lib/puffy.rb