rouge 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/bin/rougify +1 -1
- data/lib/rouge/demos/{text → plaintext} +0 -0
- data/lib/rouge/formatters/html.rb +13 -8
- data/lib/rouge/formatters/terminal256.rb +15 -11
- data/lib/rouge/lexer.rb +3 -1
- data/lib/rouge/lexers/c.rb +65 -55
- data/lib/rouge/lexers/clojure.rb +19 -19
- data/lib/rouge/lexers/coffeescript.rb +42 -42
- data/lib/rouge/lexers/common_lisp.rb +49 -48
- data/lib/rouge/lexers/conf.rb +6 -6
- data/lib/rouge/lexers/cpp.rb +48 -48
- data/lib/rouge/lexers/csharp.rb +25 -25
- data/lib/rouge/lexers/css.rb +32 -33
- data/lib/rouge/lexers/diff.rb +8 -8
- data/lib/rouge/lexers/elixir.rb +30 -30
- data/lib/rouge/lexers/erb.rb +5 -5
- data/lib/rouge/lexers/erlang.rb +38 -38
- data/lib/rouge/lexers/factor.rb +56 -56
- data/lib/rouge/lexers/gherkin.rb +27 -27
- data/lib/rouge/lexers/go.rb +21 -21
- data/lib/rouge/lexers/groovy.rb +32 -32
- data/lib/rouge/lexers/haml.rb +35 -35
- data/lib/rouge/lexers/handlebars.rb +27 -27
- data/lib/rouge/lexers/haskell.rb +78 -79
- data/lib/rouge/lexers/html.rb +28 -28
- data/lib/rouge/lexers/http.rb +13 -13
- data/lib/rouge/lexers/ini.rb +13 -13
- data/lib/rouge/lexers/io.rb +19 -19
- data/lib/rouge/lexers/java.rb +29 -29
- data/lib/rouge/lexers/javascript.rb +49 -52
- data/lib/rouge/lexers/literate_haskell.rb +5 -5
- data/lib/rouge/lexers/llvm.rb +14 -14
- data/lib/rouge/lexers/lua.rb +33 -33
- data/lib/rouge/lexers/make.rb +26 -26
- data/lib/rouge/lexers/markdown.rb +49 -49
- data/lib/rouge/lexers/nginx.rb +19 -19
- data/lib/rouge/lexers/perl.rb +53 -54
- data/lib/rouge/lexers/php.rb +42 -43
- data/lib/rouge/lexers/{text.rb → plain_text.rb} +3 -2
- data/lib/rouge/lexers/prolog.rb +19 -19
- data/lib/rouge/lexers/puppet.rb +40 -40
- data/lib/rouge/lexers/python.rb +63 -63
- data/lib/rouge/lexers/r.rb +15 -15
- data/lib/rouge/lexers/racket.rb +29 -29
- data/lib/rouge/lexers/ruby.rb +94 -97
- data/lib/rouge/lexers/rust.rb +37 -37
- data/lib/rouge/lexers/sass.rb +15 -15
- data/lib/rouge/lexers/sass/common.rb +144 -136
- data/lib/rouge/lexers/scheme.rb +25 -25
- data/lib/rouge/lexers/scss.rb +7 -7
- data/lib/rouge/lexers/sed.rb +39 -39
- data/lib/rouge/lexers/shell.rb +45 -45
- data/lib/rouge/lexers/smalltalk.rb +36 -36
- data/lib/rouge/lexers/sql.rb +27 -27
- data/lib/rouge/lexers/tcl.rb +34 -34
- data/lib/rouge/lexers/tex.rb +24 -24
- data/lib/rouge/lexers/toml.rb +18 -18
- data/lib/rouge/lexers/viml.rb +19 -19
- data/lib/rouge/lexers/xml.rb +16 -16
- data/lib/rouge/lexers/yaml.rb +78 -81
- data/lib/rouge/plugins/redcarpet.rb +1 -1
- data/lib/rouge/regex_lexer.rb +31 -14
- data/lib/rouge/template_lexer.rb +1 -1
- data/lib/rouge/theme.rb +12 -10
- data/lib/rouge/themes/thankful_eyes.rb +43 -43
- data/lib/rouge/token.rb +145 -148
- data/lib/rouge/version.rb +1 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/bin/rougify
CHANGED
File without changes
|
@@ -22,9 +22,9 @@ module Rouge
|
|
22
22
|
# Content will be wrapped in a `<pre>` tag with the given
|
23
23
|
# `:css_class` unless `:wrap` is set to `false`.
|
24
24
|
def initialize(opts={})
|
25
|
-
@css_class = opts
|
26
|
-
@line_numbers = opts.fetch(:line_numbers
|
27
|
-
@inline_theme = opts.fetch(:inline_theme
|
25
|
+
@css_class = opts.fetch(:css_class, 'highlight')
|
26
|
+
@line_numbers = opts.fetch(:line_numbers, false)
|
27
|
+
@inline_theme = opts.fetch(:inline_theme, nil)
|
28
28
|
@wrap = opts.fetch(:wrap, true)
|
29
29
|
end
|
30
30
|
|
@@ -48,15 +48,20 @@ module Rouge
|
|
48
48
|
|
49
49
|
def stream_tableized(tokens, &b)
|
50
50
|
num_lines = 0
|
51
|
-
|
51
|
+
last_val = ''
|
52
|
+
formatted = ''
|
52
53
|
|
53
54
|
tokens.each do |tok, val|
|
55
|
+
last_val = val
|
54
56
|
num_lines += val.scan(/\n/).size
|
55
|
-
span(tok, val) { |str|
|
57
|
+
span(tok, val) { |str| formatted << str }
|
56
58
|
end
|
57
59
|
|
58
|
-
# add an extra line
|
59
|
-
|
60
|
+
# add an extra line for non-newline-terminated strings
|
61
|
+
if last_val[-1] != "\n"
|
62
|
+
num_lines += 1
|
63
|
+
span(Token::Tokens::Text::Whitespace, "\n") { |str| formatted << str }
|
64
|
+
end
|
60
65
|
|
61
66
|
# generate a string of newline-separated line numbers for the gutter
|
62
67
|
numbers = num_lines.times.map do |x|
|
@@ -72,7 +77,7 @@ module Rouge
|
|
72
77
|
yield '</td>'
|
73
78
|
|
74
79
|
yield '<td class="code">'
|
75
|
-
yield
|
80
|
+
yield formatted
|
76
81
|
yield '</td>'
|
77
82
|
|
78
83
|
yield '</tr></tbody></table>'
|
@@ -118,7 +118,7 @@ module Rouge
|
|
118
118
|
when 3
|
119
119
|
color.chars.map { |c| "#{c}#{c}" }
|
120
120
|
when 6
|
121
|
-
color.scan
|
121
|
+
color.scan(/../)
|
122
122
|
else
|
123
123
|
raise "invalid color: #{color}"
|
124
124
|
end
|
@@ -127,19 +127,23 @@ module Rouge
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def self.closest_color(r, g, b)
|
130
|
-
|
130
|
+
@@colors_cache ||= {}
|
131
|
+
key = (r << 16) + (g << 8) + b
|
132
|
+
@@colors_cache.fetch(key) do
|
133
|
+
distance = 257 * 257 * 3 # (max distance, from #000000 to #ffffff)
|
131
134
|
|
132
|
-
|
135
|
+
match = 0
|
133
136
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
+
xterm_colors.each_with_index do |(cr, cg, cb), i|
|
138
|
+
d = (r - cr)**2 + (g - cg)**2 + (b - cb)**2
|
139
|
+
next if d >= distance
|
137
140
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
+
match = i
|
142
|
+
distance = d
|
143
|
+
end
|
141
144
|
|
142
|
-
|
145
|
+
match
|
146
|
+
end
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
@@ -151,7 +155,7 @@ module Rouge
|
|
151
155
|
end
|
152
156
|
|
153
157
|
def get_style(token)
|
154
|
-
return text_style if token
|
158
|
+
return text_style if token == Token::Tokens::Text
|
155
159
|
|
156
160
|
theme.get_own_style(token) || text_style
|
157
161
|
end
|
data/lib/rouge/lexer.rb
CHANGED
@@ -6,6 +6,8 @@ module Rouge
|
|
6
6
|
# @abstract
|
7
7
|
# A lexer transforms text into a stream of `[token, chunk]` pairs.
|
8
8
|
class Lexer
|
9
|
+
include Token::Tokens
|
10
|
+
|
9
11
|
class << self
|
10
12
|
# Lexes `stream` with the given options. The lex is delegated to a
|
11
13
|
# new instance.
|
@@ -141,7 +143,7 @@ module Rouge
|
|
141
143
|
def guess(info={})
|
142
144
|
lexers = guesses(info)
|
143
145
|
|
144
|
-
return Lexers::
|
146
|
+
return Lexers::PlainText if lexers.empty?
|
145
147
|
return lexers[0] if lexers.size == 1
|
146
148
|
|
147
149
|
raise AmbiguousGuess.new(lexers)
|
data/lib/rouge/lexers/c.rb
CHANGED
@@ -34,53 +34,63 @@ module Rouge
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rule
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
start { push :bol }
|
38
|
+
|
39
|
+
state :bol do
|
40
|
+
mixin :inline_whitespace
|
41
|
+
|
42
|
+
rule /#if\s0/, Comment::Preproc, :if_0
|
43
|
+
|
44
|
+
rule /#/, Comment::Preproc, :macro
|
45
|
+
|
46
|
+
rule /#{id}:(?!:)/, Name::Label
|
46
47
|
|
47
|
-
rule
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
rule(//) { pop! }
|
49
|
+
end
|
50
|
+
|
51
|
+
state :inline_whitespace do
|
52
|
+
rule /[ \t\r]+/, Text
|
53
|
+
rule /\\\n/, Text # line continuation
|
54
|
+
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
|
55
|
+
end
|
56
|
+
|
57
|
+
state :whitespace do
|
58
|
+
rule /\n+/, Text, :bol
|
59
|
+
rule %r(//(\\.|.)*?\n), Comment::Single, :bol
|
60
|
+
mixin :inline_whitespace
|
51
61
|
end
|
52
62
|
|
53
63
|
state :statements do
|
54
|
-
rule /\s+/m,
|
55
|
-
|
56
|
-
rule /L?"/,
|
57
|
-
rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i,
|
58
|
-
rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i,
|
59
|
-
rule /0x[0-9a-f]+[lu]*/i,
|
60
|
-
rule /0[0-7]+[lu]*/i,
|
61
|
-
rule /\d+[lu]*/i,
|
62
|
-
rule %r(\*/),
|
63
|
-
rule %r([~!%^&*+=\|?:<>/-]),
|
64
|
-
rule /[()\[\],.]/,
|
65
|
-
rule /\bcase\b/,
|
66
|
-
rule /(?:true|false|NULL)\b/,
|
64
|
+
rule /\s+/m, Text
|
65
|
+
|
66
|
+
rule /L?"/, Str, :string
|
67
|
+
rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
|
68
|
+
rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i, Num::Float
|
69
|
+
rule /0x[0-9a-f]+[lu]*/i, Num::Hex
|
70
|
+
rule /0[0-7]+[lu]*/i, Num::Oct
|
71
|
+
rule /\d+[lu]*/i, Num::Integer
|
72
|
+
rule %r(\*/), Error
|
73
|
+
rule %r([~!%^&*+=\|?:<>/-]), Operator
|
74
|
+
rule /[()\[\],.]/, Punctuation
|
75
|
+
rule /\bcase\b/, Keyword, :case
|
76
|
+
rule /(?:true|false|NULL)\b/, Name::Builtin
|
67
77
|
rule id do |m|
|
68
78
|
name = m[0]
|
69
79
|
|
70
80
|
if self.class.keywords.include? name
|
71
|
-
token
|
81
|
+
token Keyword
|
72
82
|
elsif self.class.keywords_type.include? name
|
73
|
-
token
|
83
|
+
token Keyword::Type
|
74
84
|
elsif self.class.reserved.include? name
|
75
|
-
token
|
85
|
+
token Keyword::Reserved
|
76
86
|
else
|
77
|
-
token
|
87
|
+
token Name
|
78
88
|
end
|
79
89
|
end
|
80
90
|
end
|
81
91
|
|
82
92
|
state :case do
|
83
|
-
rule /:/,
|
93
|
+
rule /:/, Punctuation, :pop!
|
84
94
|
mixin :statements
|
85
95
|
end
|
86
96
|
|
@@ -96,10 +106,10 @@ module Rouge
|
|
96
106
|
)mx do |m|
|
97
107
|
# TODO: do this better.
|
98
108
|
delegate C, m[1]
|
99
|
-
token
|
109
|
+
token Name::Function, m[2]
|
100
110
|
delegate C, m[3]
|
101
111
|
delegate C, m[4]
|
102
|
-
token
|
112
|
+
token Punctuation, m[5]
|
103
113
|
push :function
|
104
114
|
end
|
105
115
|
|
@@ -112,10 +122,10 @@ module Rouge
|
|
112
122
|
)mx do |m|
|
113
123
|
# TODO: do this better.
|
114
124
|
delegate C, m[1]
|
115
|
-
token
|
125
|
+
token Name::Function
|
116
126
|
delegate C, m[3]
|
117
127
|
delegate C, m[4]
|
118
|
-
token
|
128
|
+
token Punctuation
|
119
129
|
push :statement
|
120
130
|
end
|
121
131
|
|
@@ -123,42 +133,42 @@ module Rouge
|
|
123
133
|
end
|
124
134
|
|
125
135
|
state :statement do
|
126
|
-
rule /;/,
|
136
|
+
rule /;/, Punctuation, :pop!
|
127
137
|
mixin :whitespace
|
128
138
|
mixin :statements
|
129
|
-
rule /[{}]/,
|
139
|
+
rule /[{}]/, Punctuation
|
130
140
|
end
|
131
141
|
|
132
142
|
state :function do
|
133
143
|
mixin :whitespace
|
134
144
|
mixin :statements
|
135
|
-
rule /;/,
|
136
|
-
rule /{/,
|
137
|
-
rule /}/,
|
145
|
+
rule /;/, Punctuation
|
146
|
+
rule /{/, Punctuation, :function
|
147
|
+
rule /}/, Punctuation, :pop!
|
138
148
|
end
|
139
149
|
|
140
150
|
state :string do
|
141
|
-
rule /"/,
|
142
|
-
rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/,
|
143
|
-
rule /[^\\"\n]+/,
|
144
|
-
rule /\\\n/,
|
145
|
-
rule /\\/,
|
151
|
+
rule /"/, Str, :pop!
|
152
|
+
rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
|
153
|
+
rule /[^\\"\n]+/, Str
|
154
|
+
rule /\\\n/, Str
|
155
|
+
rule /\\/, Str # stray backslash
|
146
156
|
end
|
147
157
|
|
148
158
|
state :macro do
|
149
|
-
rule %r([^/\n]+),
|
150
|
-
rule %r(/[*].*?[*]/)m,
|
151
|
-
rule %r(//.*$),
|
152
|
-
rule %r(/),
|
153
|
-
rule /(?<=\\)\n/,
|
154
|
-
rule /\n/,
|
159
|
+
rule %r([^/\n]+), Comment::Preproc
|
160
|
+
rule %r(/[*].*?[*]/)m, Comment::Multiline
|
161
|
+
rule %r(//.*$), Comment::Single
|
162
|
+
rule %r(/), Comment::Preproc
|
163
|
+
rule /(?<=\\)\n/, Comment::Preproc
|
164
|
+
rule /\n/, Comment::Preproc, :pop!
|
155
165
|
end
|
156
166
|
|
157
167
|
state :if_0 do
|
158
|
-
rule /^\s*#if.*?(?<!\\)\n/,
|
159
|
-
rule /^\s*#el(?:se|if).*\n/,
|
160
|
-
rule /^\s*#endif.*?(?<!\\)\n/,
|
161
|
-
rule /.*?\n/,
|
168
|
+
rule /^\s*#if.*?(?<!\\)\n/, Comment, :if_0
|
169
|
+
rule /^\s*#el(?:se|if).*\n/, Comment::Preproc, :pop!
|
170
|
+
rule /^\s*#endif.*?(?<!\\)\n/, Comment, :pop!
|
171
|
+
rule /.*?\n/, Comment
|
162
172
|
end
|
163
173
|
end
|
164
174
|
end
|
data/lib/rouge/lexers/clojure.rb
CHANGED
@@ -64,45 +64,45 @@ module Rouge
|
|
64
64
|
keyword = %r([\w!\#$%*+,<=>?/.-]+)
|
65
65
|
|
66
66
|
def name_token(name)
|
67
|
-
return
|
68
|
-
return
|
67
|
+
return Keyword if self.class.keywords.include?(name)
|
68
|
+
return Name::Builtin if self.class.builtins.include?(name)
|
69
69
|
nil
|
70
70
|
end
|
71
71
|
|
72
72
|
state :root do
|
73
|
-
rule /;.*?\n/,
|
74
|
-
rule /\s+/m,
|
73
|
+
rule /;.*?\n/, Comment::Single
|
74
|
+
rule /\s+/m, Text::Whitespace
|
75
75
|
|
76
|
-
rule /-?\d+\.\d+/,
|
77
|
-
rule /-?\d+/,
|
78
|
-
rule /0x-?[0-9a-fA-F]+/,
|
76
|
+
rule /-?\d+\.\d+/, Num::Float
|
77
|
+
rule /-?\d+/, Num::Integer
|
78
|
+
rule /0x-?[0-9a-fA-F]+/, Num::Hex
|
79
79
|
|
80
|
-
rule /"(\\.|[^"])*"/,
|
81
|
-
rule /'#{keyword}/,
|
82
|
-
rule /:#{keyword}/,
|
83
|
-
rule /\\(.|[a-z]+)/i,
|
80
|
+
rule /"(\\.|[^"])*"/, Str
|
81
|
+
rule /'#{keyword}/, Str::Symbol
|
82
|
+
rule /:#{keyword}/, Name::Constant
|
83
|
+
rule /\\(.|[a-z]+)/i, Str::Char
|
84
84
|
|
85
85
|
|
86
|
-
rule /~@|[`\'#^~&]/,
|
86
|
+
rule /~@|[`\'#^~&]/, Operator
|
87
87
|
|
88
88
|
rule /(\()(\s*)(#{identifier})/m do |m|
|
89
|
-
token
|
90
|
-
token
|
91
|
-
token(name_token(m[3]) ||
|
89
|
+
token Punctuation, m[1]
|
90
|
+
token Text::Whitespace, m[2]
|
91
|
+
token(name_token(m[3]) || Name::Function, m[3])
|
92
92
|
end
|
93
93
|
|
94
94
|
rule identifier do |m|
|
95
|
-
token name_token(m[0]) ||
|
95
|
+
token name_token(m[0]) || Name
|
96
96
|
end
|
97
97
|
|
98
98
|
# vectors
|
99
|
-
rule /[\[\]]/,
|
99
|
+
rule /[\[\]]/, Punctuation
|
100
100
|
|
101
101
|
# maps
|
102
|
-
rule /[{}]/,
|
102
|
+
rule /[{}]/, Punctuation
|
103
103
|
|
104
104
|
# parentheses
|
105
|
-
rule /[()]/,
|
105
|
+
rule /[()]/, Punctuation
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -38,9 +38,9 @@ module Rouge
|
|
38
38
|
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
|
39
39
|
|
40
40
|
state :comments_and_whitespace do
|
41
|
-
rule /\s+/m,
|
42
|
-
rule /###.*?###/m,
|
43
|
-
rule /#.*?\n/,
|
41
|
+
rule /\s+/m, Text
|
42
|
+
rule /###.*?###/m, Comment::Multiline
|
43
|
+
rule /#.*?\n/, Comment::Single
|
44
44
|
end
|
45
45
|
|
46
46
|
state :multiline_regex do
|
@@ -49,22 +49,22 @@ module Rouge
|
|
49
49
|
mixin :has_interpolation
|
50
50
|
mixin :comments_and_whitespace
|
51
51
|
|
52
|
-
rule %r(///([gim]+\b|\B)),
|
53
|
-
rule %r(/),
|
54
|
-
rule %r([^/#]+),
|
52
|
+
rule %r(///([gim]+\b|\B)), Str::Regex, :pop!
|
53
|
+
rule %r(/), Str::Regex
|
54
|
+
rule %r([^/#]+), Str::Regex
|
55
55
|
end
|
56
56
|
|
57
57
|
state :slash_starts_regex do
|
58
58
|
mixin :comments_and_whitespace
|
59
59
|
rule %r(///) do
|
60
|
-
token
|
61
|
-
|
60
|
+
token Str::Regex
|
61
|
+
goto :multiline_regex
|
62
62
|
end
|
63
63
|
|
64
64
|
rule %r(
|
65
65
|
/(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
|
66
66
|
([gim]+\b|\B)
|
67
|
-
)x,
|
67
|
+
)x, Str::Regex, :pop!
|
68
68
|
|
69
69
|
rule(//) { pop! }
|
70
70
|
end
|
@@ -75,97 +75,97 @@ module Rouge
|
|
75
75
|
rule %r(
|
76
76
|
[+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
|
77
77
|
[|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
|
78
|
-
)x,
|
78
|
+
)x, Operator, :slash_starts_regex
|
79
79
|
|
80
|
-
rule /[-=]>/,
|
80
|
+
rule /[-=]>/, Name::Function
|
81
81
|
|
82
82
|
rule /(@)([ \t]*)(#{id})/ do
|
83
|
-
group
|
84
|
-
group
|
83
|
+
group Name::Variable::Instance; group Text
|
84
|
+
group Name::Attribute
|
85
85
|
push :slash_starts_regex
|
86
86
|
end
|
87
87
|
|
88
88
|
rule /([.])([ \t]*)(#{id})/ do
|
89
|
-
group
|
90
|
-
group
|
89
|
+
group Punctuation; group Text
|
90
|
+
group Name::Attribute
|
91
91
|
push :slash_starts_regex
|
92
92
|
end
|
93
93
|
|
94
|
-
rule /#{id}(?=\s*:)/,
|
94
|
+
rule /#{id}(?=\s*:)/, Name::Attribute, :slash_starts_regex
|
95
95
|
|
96
96
|
rule /#{id}/ do |m|
|
97
97
|
if self.class.keywords.include? m[0]
|
98
|
-
token
|
98
|
+
token Keyword
|
99
99
|
elsif self.class.constants.include? m[0]
|
100
|
-
token
|
100
|
+
token Name::Constant
|
101
101
|
elsif self.class.builtins.include? m[0]
|
102
|
-
token
|
102
|
+
token Name::Builtin
|
103
103
|
else
|
104
|
-
token
|
104
|
+
token Name::Other
|
105
105
|
end
|
106
106
|
|
107
107
|
push :slash_starts_regex
|
108
108
|
end
|
109
109
|
|
110
|
-
rule /[{(\[;,]/,
|
111
|
-
rule /[})\].]/,
|
110
|
+
rule /[{(\[;,]/, Punctuation, :slash_starts_regex
|
111
|
+
rule /[})\].]/, Punctuation
|
112
112
|
|
113
|
-
rule /\d+[.]\d+([eE]\d+)?[fd]?/,
|
114
|
-
rule /0x[0-9a-fA-F]+/,
|
115
|
-
rule /\d+/,
|
116
|
-
rule /"""/,
|
117
|
-
rule /'''/,
|
118
|
-
rule /"/,
|
119
|
-
rule /'/,
|
113
|
+
rule /\d+[.]\d+([eE]\d+)?[fd]?/, Num::Float
|
114
|
+
rule /0x[0-9a-fA-F]+/, Num::Hex
|
115
|
+
rule /\d+/, Num::Integer
|
116
|
+
rule /"""/, Str, :tdqs
|
117
|
+
rule /'''/, Str, :tsqs
|
118
|
+
rule /"/, Str, :dqs
|
119
|
+
rule /'/, Str, :sqs
|
120
120
|
end
|
121
121
|
|
122
122
|
state :strings do
|
123
123
|
# all coffeescript strings are multi-line
|
124
|
-
rule /[^#\\'"]+/m,
|
124
|
+
rule /[^#\\'"]+/m, Str
|
125
125
|
|
126
|
-
rule /\\./,
|
127
|
-
rule /#/,
|
126
|
+
rule /\\./, Str::Escape
|
127
|
+
rule /#/, Str
|
128
128
|
end
|
129
129
|
|
130
130
|
state :double_strings do
|
131
|
-
rule /'/,
|
131
|
+
rule /'/, Str
|
132
132
|
mixin :has_interpolation
|
133
133
|
mixin :strings
|
134
134
|
end
|
135
135
|
|
136
136
|
state :single_strings do
|
137
|
-
rule /"/,
|
137
|
+
rule /"/, Str
|
138
138
|
mixin :strings
|
139
139
|
end
|
140
140
|
|
141
141
|
state :interpolation do
|
142
|
-
rule /}/,
|
142
|
+
rule /}/, Str::Interpol, :pop!
|
143
143
|
mixin :root
|
144
144
|
end
|
145
145
|
|
146
146
|
state :has_interpolation do
|
147
|
-
rule /[#][{]/,
|
147
|
+
rule /[#][{]/, Str::Interpol, :interpolation
|
148
148
|
end
|
149
149
|
|
150
150
|
state :dqs do
|
151
|
-
rule /"/,
|
151
|
+
rule /"/, Str, :pop!
|
152
152
|
mixin :double_strings
|
153
153
|
end
|
154
154
|
|
155
155
|
state :tdqs do
|
156
|
-
rule /"""/,
|
157
|
-
rule /"/,
|
156
|
+
rule /"""/, Str, :pop!
|
157
|
+
rule /"/, Str
|
158
158
|
mixin :double_strings
|
159
159
|
end
|
160
160
|
|
161
161
|
state :sqs do
|
162
|
-
rule /'/,
|
162
|
+
rule /'/, Str, :pop!
|
163
163
|
mixin :single_strings
|
164
164
|
end
|
165
165
|
|
166
166
|
state :tsqs do
|
167
|
-
rule /'''/,
|
168
|
-
rule /'/,
|
167
|
+
rule /'''/, Str, :pop!
|
168
|
+
rule /'/, Str
|
169
169
|
mixin :single_strings
|
170
170
|
end
|
171
171
|
end
|