Class: Rouge::Lexers::VimL
- Inherits:
-
RegexLexer
- Object
- Rouge::Lexer
- RegexLexer
- Rouge::Lexers::VimL
- Defined in:
- lib/rouge/lexers/viml.rb,
lib/rouge/lexers/viml/keywords.rb
Constant Summary
Constants inherited from RegexLexer
Class Method Summary collapse
Instance Method Summary collapse
-
#find_likely_mapping(mapping, word) ⇒ Object
binary search through the mappings to find the one that’s likely to actually work.
- #mapping_contains?(mapping, word) ⇒ Boolean
Methods inherited from RegexLexer
#delegate, get_state, #get_state, #group, #in_state?, #pop!, #push, #reset!, #reset_stack, #run_callback, #run_rule, #stack, start, start_procs, #state, state, #state?, 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
Constructor Details
This class inherits a constructor from Rouge::Lexer
Class Method Details
.keywords ⇒ Object
12 13 14 15 |
# File 'lib/rouge/lexers/viml.rb', line 12 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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rouge/lexers/viml.rb', line 72 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
63 64 65 66 67 68 |
# File 'lib/rouge/lexers/viml.rb', line 63 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 |