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
Constants included from Token::Tokens
Token::Tokens::Num, Token::Tokens::Str
Instance Attribute Summary
Attributes inherited from Rouge::Lexer
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
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, #as_bool, #as_lexer, #as_list, #as_string, #as_token, assert_utf8!, #bool_option, debug_enabled?, demo, demo_file, desc, detect?, 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
Constructor Details
This class inherits a constructor from Rouge::Lexer
Class Method Details
.keywords ⇒ Object
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
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 |