class CodeRay::Encoders::Lint
Lint Encoder¶ ↑
Checks for:
-
empty tokens
-
incorrect nesting
It will raise an InvalidTokenStream exception when any of the above occurs.
See also: Encoders::DebugLint
Constants
- EmptyToken
- IncorrectTokenGroupNesting
- InvalidTokenStream
- UnknownTokenKind
Public Instance Methods
begin_group(kind)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 28 def begin_group kind @opened << kind end
begin_line(kind)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 37 def begin_line kind @opened << kind end
end_group(kind)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 32 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
end_line(kind)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 41 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
text_token(text, kind)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 23 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
Protected Instance Methods
finish(options)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 52 def finish options raise 'Some tokens still open at end of token stream: %p' % [@opened] unless @opened.empty? end
setup(options)
click to toggle source
# File lib/coderay/encoders/lint.rb, line 48 def setup options @opened = [] end