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, 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

.builtinsObject



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

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



123
124
125
# File 'lib/rouge/lexers/javascript.rb', line 123

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

.declarationsObject



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

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

.detect?(text) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rouge/lexers/javascript.rb', line 24

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

.id_regexObject



142
143
144
# File 'lib/rouge/lexers/javascript.rb', line 142

def self.id_regex
  /[\p{L}\p{Nl}$_][\p{Word}]*/io
end

.keywordsObject



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

def self.keywords
  @keywords ||= Set.new %w(
    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



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

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