Sha256: e47ebe3364dff2dc9a7f74808e2e8a08829a5d21f1e9ddd61817e21e5b92aec3

Contents?: true

Size: 1.5 KB

Versions: 6630

Compression:

Stored size: 1.5 KB

Contents

module CodeRay
module Encoders
  
  # = Lint Encoder
  #
  # Checks for:
  # 
  # - empty tokens
  # - incorrect nesting
  # 
  # It will raise an InvalidTokenStream exception when any of the above occurs.
  # 
  # See also: Encoders::DebugLint
  class Lint < Debug
    
    register_for :lint
    
    InvalidTokenStream         = Class.new StandardError
    EmptyToken                 = Class.new InvalidTokenStream
    UnknownTokenKind           = Class.new InvalidTokenStream
    IncorrectTokenGroupNesting = Class.new InvalidTokenStream
    
    def text_token text, kind
      raise EmptyToken,       'empty token for %p' % [kind] if text.empty?
      raise UnknownTokenKind, 'unknown token kind %p (text was %p)' % [kind, text] unless TokenKinds.has_key? kind
    end
    
    def begin_group kind
      @opened << kind
    end
    
    def end_group kind
      raise IncorrectTokenGroupNesting, 'We are inside %s, not %p (end_group)' % [@opened.reverse.map(&:inspect).join(' < '), kind] if @opened.last != kind
      @opened.pop
    end
    
    def begin_line kind
      @opened << kind
    end
    
    def end_line kind
      raise IncorrectTokenGroupNesting, 'We are inside %s, not %p (end_line)' % [@opened.reverse.map(&:inspect).join(' < '), kind] if @opened.last != kind
      @opened.pop
    end
    
    protected
    
    def setup options
      @opened = []
    end
    
    def finish options
      raise 'Some tokens still open at end of token stream: %p' % [@opened] unless @opened.empty?
    end
    
  end
  
end
end

Version data entries

6,630 entries across 6,618 versions & 69 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
ory-client-1.15.12 vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_bank_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_organization_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb
cybrid_api_id_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb