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



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

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



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

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
  )
end

.detect?(text) ⇒ Boolean

Returns:

  • (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



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

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(
    for in of while do break return continue switch case default
    if else throw try catch finally new delete typeof instanceof
    void this yield import export from as async super this
  )
end

.reservedObject



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

def self.reserved
  @reserved ||= Set.new %w(
    abstract boolean byte char debugger double enum
    final float goto implements int interface
    long native package private protected public short static
    synchronized throws transient volatile
    eval arguments await
  )
end