Class: Rouge::Lexers::VimL

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

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

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

Instance Attribute Summary

Attributes inherited from Rouge::Lexer

#options

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, #as_bool, #as_lexer, #as_list, #as_string, #as_token, assert_utf8!, #bool_option, debug_enabled?, demo, demo_file, desc, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #initialize, #lex, lex, #lexer_option, #list_option, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, tag, #tag, title, #token_option

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.keywordsObject


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.


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)

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