Class: Rouge::Lexers::VimL

Inherits:
RegexLexer show all
Defined in:
lib/rouge/lexers/viml.rb,
lib/rouge/lexers/viml/keywords.rb
more...

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegexLexer

append, #delegate, get_state, #get_state, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, #state, state, #state?, state_definitions, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, analyze_text, assert_utf8!, #debug, default_options, demo, demo_file, desc, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #initialize, lex, #lex, mimetypes, #option, #options, #reset!, #stream_tokens, tag, #tag, title

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.keywordsObject

[View source]

15
16
17
18
# File 'lib/rouge/lexers/viml.rb', line 15

def self.keywords
  load Pathname.new(__FILE__).dirname.join('viml/keywords.rb')
  self.keywords
end

Instance Method Details

#find_likely_mapping(mapping, word) ⇒ Object

binary search through the mappings to find the one that’s likely to actually work.

[View source]

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rouge/lexers/viml.rb', line 75

def find_likely_mapping(mapping, word)
  min = 0
  max = mapping.size

  until max == min
    mid = (max + min) / 2

    cmp, _ = mapping[mid]

    case word <=> cmp
    when 1
      # too low
      min = mid + 1
    when -1
      # too high
      max = mid
    when 0
      # just right, abort!
      return mapping[mid]
    end
  end

  mapping[max - 1]
end

#mapping_contains?(mapping, word) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

66
67
68
69
70
71
# File 'lib/rouge/lexers/viml.rb', line 66

def mapping_contains?(mapping, word)
  shortest, longest = find_likely_mapping(mapping, word)

  shortest and word.start_with?(shortest) and
  longest and longest.start_with?(word)
end