Sha256: 9384dd46c45814dc74e4817ab13ed7ced5b989e12913772ea5e5526f28159628
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 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 IncorrectTokenGroupNesting = Class.new InvalidTokenStream def text_token text, kind raise EmptyToken, 'empty token' if text.empty? 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
coderay-1.1.0.rc2 | lib/coderay/encoders/lint.rb |
coderay-1.1.0.rc1 | lib/coderay/encoders/lint.rb |