Class: CodeRay::Encoders::Lint

Inherits:
Debug show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/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

Debug::FILE_EXTENSION

Constants inherited from Encoder

Encoder::DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Encoder

#options, #scanner

Attributes included from Plugin

#plugin_id

Instance Method Summary collapse

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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb', line 28

def begin_group kind
  @opened << kind
end

#begin_line(kind) ⇒ Object



37
38
39
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/lib/coderay/encoders/lint.rb', line 37

def begin_line kind
  @opened << kind
end

#end_group(kind) ⇒ Object



32
33
34
35
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/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

Raises:



23
24
25
26
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/coderay-1.1.3/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