Class: Rouge::Lexers::J

Inherits:
RegexLexer show all
Defined in:
lib/rouge/lexers/j.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

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, #continue_lex, continue_lex, debug_enabled?, demo, demo_file, desc, detect?, detectable?, 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, lookup_fancy, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, tag, #tag, title, #token_option, #with

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.control_wordsObject



77
78
79
80
81
82
# File 'lib/rouge/lexers/j.rb', line 77

def self.control_words
  @control_words ||= Set.new %w(
    assert break case catch catchd catcht continue do else elseif end
    fcase for if return select throw try while whilst
  )
end

.control_words_idObject



84
85
86
# File 'lib/rouge/lexers/j.rb', line 84

def self.control_words_id
  @control_words_id ||= Set.new %w(for goto label)
end

.inflection_listObject



30
31
32
# File 'lib/rouge/lexers/j.rb', line 30

def self.inflection_list
  @inflection_list ||= ['', '.', ':', '..', '.:', ':.', '::']
end

.primitive(char, inflection) ⇒ Object



72
73
74
75
# File 'lib/rouge/lexers/j.rb', line 72

def self.primitive(char, inflection)
  i = inflection_list.index(inflection) or return Error
  token_map[primitive_table[char][i]]
end

.primitive_tableObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rouge/lexers/j.rb', line 34

def self.primitive_table
  @primitive_table ||= Hash.new([:name]).tap do |h|
    {
      '()' => [:other],
      '=' => [:verb, :other, :other],
      '<>+-*%$|,#' => [:verb, :verb, :verb],
      '^' => [:verb, :verb, :modifier],
      '~"' => [:modifier, :verb, :verb],
      '.:@' => [:modifier, :modifier, :modifier],
      ';' => [:verb, :modifier, :verb],
      '!' => [:verb, :modifier, :modifier],
      '/\\' => [:modifier, :modifier, :verb],
      '[' => [:verb, nil, :verb],
      ']' => [:verb],
      '{' => [:verb, :verb, :verb, nil, nil, nil, :verb],
      '}' => [:modifier, :verb, :verb, nil, nil, nil, :modifier],
      '`' => [:modifier, nil, :modifier],
      '&' => [:modifier, :modifier, :modifier, nil, :modifier],
      '?' => [:verb, :verb],
      'a' => [:name, :noun, :noun],
      'ACeEIjorv' => [:name, :verb],
      'bdfHMT' => [:name, :modifier],
      'Dt' => [:name, :modifier, :modifier],
      'F' => [:name, :modifier, :modifier, :modifier, :modifier,
              :modifier, :modifier],
      'iu' => [:name, :verb, :verb],
      'L' => [:name, :verb, :modifier],
      'mny' => [:param],
      'p' => [:name, :verb, :verb, :verb],
      'qsZ' => [:name, nil, :verb],
      'S' => [:name, nil, :modifier],
      'u' => [:param, :verb, :verb],
      'v' => [:param, :verb],
      'x' => [:param, nil, :verb],
    }.each {|k, v| k.each_char {|c| h[c] = v } }
  end
end

.token_mapObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rouge/lexers/j.rb', line 17

def self.token_map
  @token_map ||= {
    noun: Keyword::Constant,
    verb: Name::Function,
    modifier: Operator,
    name: Name,
    param: Name::Builtin::Pseudo,
    other: Punctuation,
    nil => Error,
  }
end