/usr/lib/ruby/vendor_ruby/rugments/lexers/coffeescript.rb is in ruby-rugments 1.0.0~beta8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | module Rugments
module Lexers
class Coffeescript < RegexLexer
tag 'coffeescript'
aliases 'coffee', 'coffee-script'
filenames '*.coffee', 'Cakefile'
mimetypes 'text/coffeescript'
title 'CoffeeScript'
desc 'The Coffeescript programming language (coffeescript.org)'
def self.analyze_text(text)
return 1 if text.shebang? 'coffee'
end
def self.keywords
@keywords ||= Set.new %w(
for in of while break return continue switch when then if else
throw try catch finally new delete typeof instanceof super
extends this class by
)
end
def self.constants
@constants ||= Set.new %w(
true false yes no on off null NaN Infinity undefined
)
end
def self.builtins
@builtins ||= Set.new %w(
Array Boolean Date Error Function Math netscape Number Object
Packages RegExp String sun decodeURI decodeURIComponent
encodeURI encodeURIComponent eval isFinite isNaN parseFloat
parseInt document window
)
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
state :comments_and_whitespace do
rule /\s+/m, Text
rule /###.*?###/m, Comment::Multiline
rule /#.*?\n/, Comment::Single
end
state :multiline_regex do
# this order is important, so that #{ isn't interpreted
# as a comment
mixin :has_interpolation
mixin :comments_and_whitespace
rule %r{///([gim]+\b|\B)}, Str::Regex, :pop!
rule %r{/}, Str::Regex
rule %r{[^/#]+}, Str::Regex
end
state :slash_starts_regex do
mixin :comments_and_whitespace
rule %r{///} do
token Str::Regex
goto :multiline_regex
end
rule %r{
/(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
([gim]+\b|\B)
}x, Str::Regex, :pop!
rule(//) { pop! }
end
state :root do
rule(%r{^(?=\s|/|<!--)}) { push :slash_starts_regex }
mixin :comments_and_whitespace
rule %r{
[+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
[|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
}x, Operator, :slash_starts_regex
rule /[-=]>/, Name::Function
rule /(@)([ \t]*)(#{id})/ do
groups Name::Variable::Instance, Text, Name::Attribute
push :slash_starts_regex
end
rule /([.])([ \t]*)(#{id})/ do
groups Punctuation, Text, Name::Attribute
push :slash_starts_regex
end
rule /#{id}(?=\s*:)/, Name::Attribute, :slash_starts_regex
rule /#{id}/ do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.constants.include? m[0]
token Name::Constant
elsif self.class.builtins.include? m[0]
token Name::Builtin
else
token Name::Other
end
push :slash_starts_regex
end
rule /[{(\[;,]/, Punctuation, :slash_starts_regex
rule /[})\].]/, Punctuation
rule /\d+[.]\d+([eE]\d+)?[fd]?/, Num::Float
rule /0x[0-9a-fA-F]+/, Num::Hex
rule /\d+/, Num::Integer
rule /"""/, Str, :tdqs
rule /'''/, Str, :tsqs
rule /"/, Str, :dqs
rule /'/, Str, :sqs
end
state :strings do
# all coffeescript strings are multi-line
rule /[^#\\'"]+/m, Str
rule /\\./, Str::Escape
rule /#/, Str
end
state :double_strings do
rule /'/, Str
mixin :has_interpolation
mixin :strings
end
state :single_strings do
rule /"/, Str
mixin :strings
end
state :interpolation do
rule /}/, Str::Interpol, :pop!
mixin :root
end
state :has_interpolation do
rule /[#][{]/, Str::Interpol, :interpolation
end
state :dqs do
rule /"/, Str, :pop!
mixin :double_strings
end
state :tdqs do
rule /"""/, Str, :pop!
rule /"/, Str
mixin :double_strings
end
state :sqs do
rule /'/, Str, :pop!
mixin :single_strings
end
state :tsqs do
rule /'''/, Str, :pop!
rule /'/, Str
mixin :single_strings
end
end
end
end
|