Class: Rouge::Lexers::Javascript

Inherits:
RegexLexer show all
Defined in:
lib/rouge/lexers/javascript.rb

Overview

IMPORTANT NOTICE:

Please do not copy this lexer and open a pull request for a new language. It will not get merged, you will be unhappy, and kittens will cry.

Direct Known Subclasses

JSX, Qml, Typescript

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, #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, #bool_option, continue_lex, #continue_lex, debug_enabled?, demo, demo_file, desc, 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, 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

.builtinsObject


125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/rouge/lexers/javascript.rb', line 125

def self.builtins
  @builtins ||= %w(
    Array Boolean Date Error Function Math netscape
    Number Object Packages RegExp String sun decodeURI
    decodeURIComponent encodeURI encodeURIComponent
    Error eval isFinite isNaN parseFloat parseInt
    document window navigator self global
    Promise Set Map WeakSet WeakMap Symbol Proxy Reflect
    Int8Array Uint8Array Uint8ClampedArray
    Int16Array Uint16Array Uint16ClampedArray
    Int32Array Uint32Array Uint32ClampedArray
    Float32Array Float64Array DataView ArrayBuffer
  )
end

.constantsObject


121
122
123
# File 'lib/rouge/lexers/javascript.rb', line 121

def self.constants
  @constants ||= Set.new %w(true false null NaN Infinity undefined)
end

.declarationsObject


107
108
109
110
111
112
# File 'lib/rouge/lexers/javascript.rb', line 107

def self.declarations
  @declarations ||= Set.new %w(
    var let const with function class
    extends constructor get set static
  )
end

.detect?(text) ⇒ Boolean


22
23
24
25
26
# File 'lib/rouge/lexers/javascript.rb', line 22

def self.detect?(text)
  return 1 if text.shebang?('node')
  return 1 if text.shebang?('jsc')
  # TODO: rhino, spidermonkey, etc
end

.id_regexObject


140
141
142
# File 'lib/rouge/lexers/javascript.rb', line 140

def self.id_regex
  /[$a-z_][a-z0-9_]*/io
end

.keywordsObject


99
100
101
102
103
104
105
# File 'lib/rouge/lexers/javascript.rb', line 99

def self.keywords
  @keywords ||= Set.new %w(
    as async await break case catch continue debugger default delete
    do else export finally from for if import in instanceof new of
    return super switch this throw try typeof void while yield
  )
end

.reservedObject


114
115
116
117
118
119
# File 'lib/rouge/lexers/javascript.rb', line 114

def self.reserved
  @reserved ||= Set.new %w(
    enum implements interface
    package private protected public
  )
end