Class: CodeRay::Encoders::Lint
- Defined in:
- lib/coderay/encoders/lint.rb
Overview
Lint Encoder
Checks for:
-
empty tokens
-
incorrect nesting
It will raise an InvalidTokenStream exception when any of the above occurs.
See also: Encoders::DebugLint
Constant Summary collapse
- InvalidTokenStream =
Class.new StandardError
- EmptyToken =
Class.new InvalidTokenStream
- UnknownTokenKind =
Class.new InvalidTokenStream
- IncorrectTokenGroupNesting =
Class.new InvalidTokenStream
Constants inherited from Debug
Constants inherited from Encoder
Instance Attribute Summary
Attributes inherited from Encoder
Attributes included from Plugin
Instance Method Summary collapse
- #begin_group(kind) ⇒ Object
- #begin_line(kind) ⇒ Object
- #end_group(kind) ⇒ Object
- #end_line(kind) ⇒ Object
- #text_token(text, kind) ⇒ Object
Methods inherited from Encoder
#<<, const_missing, #encode, #encode_tokens, file_extension, #file_extension, #initialize, #token
Methods included from Plugin
#aliases, #plugin_host, #register_for, #title
Constructor Details
This class inherits a constructor from CodeRay::Encoders::Encoder
Instance Method Details
#begin_group(kind) ⇒ Object
28 29 30 |
# File 'lib/coderay/encoders/lint.rb', line 28 def begin_group kind @opened << kind end |
#begin_line(kind) ⇒ Object
37 38 39 |
# File 'lib/coderay/encoders/lint.rb', line 37 def begin_line kind @opened << kind end |
#end_group(kind) ⇒ Object
32 33 34 35 |
# 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) ⇒ Object
41 42 43 44 |
# 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) ⇒ Object
23 24 25 26 |
# 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 |