rouge 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ require 'rouge/lexers/sass/common'
2
+
1
3
  module Rouge
2
4
  module Lexers
3
5
  class Sass < RegexLexer
@@ -65,175 +67,7 @@ module Rouge
65
67
  rule(/\n/) { token 'Text'; reset_stack }
66
68
  end
67
69
 
68
- # shared states with SCSS
69
- # TODO: make this less nasty to do
70
- COMMON = proc do
71
- state :content_common do
72
- rule /@for\b/, 'Keyword', :for
73
- rule /@(debug|warn|if|while)/, 'Keyword', :value
74
- rule /(@mixin)(\s+)(#{id})/ do
75
- group 'Keyword'; group 'Text'; group 'Name.Function'
76
- push :value
77
- end
78
-
79
- rule /@extend\b/, 'Keyword', :selector
80
-
81
- rule /(@include)(\s+)(#{id})/ do
82
- group 'Keyword'; group 'Text'; group 'Name.Decorator'
83
- push :value
84
- end
85
-
86
- rule /@#{id}/, 'Keyword', :selector
87
-
88
- # $variable: assignment
89
- rule /([$]#{id})([ \t]*)(:)/ do
90
- group 'Name.Variable'; group 'Text'; group 'Punctuation'
91
- push :value
92
- end
93
- end
94
-
95
- state :value do
96
- mixin :end_section
97
- rule /[ \t]+/, 'Text'
98
- rule /[$]#{id}/, 'Name.Variable'
99
- rule /url[(]/, 'Literal.String.Other', :string_url
100
- rule /#{id}(?=\s*[(])/, 'Name.Function'
101
- rule /%#{id}/, 'Name.Decorator'
102
-
103
- # named literals
104
- rule /(true|false)\b/, 'Name.Pseudo'
105
- rule /(and|or|not)\b/, 'Operator.Word'
106
-
107
- # colors and numbers
108
- rule /#[a-z0-9]{1,6}/i, 'Literal.Number.Hex'
109
- rule /-?\d+(%|[a-z]+)?/, 'Literal.Number'
110
- rule /-?\d*\.\d+(%|[a-z]+)?/, 'Literal.Number.Integer'
111
-
112
- mixin :has_strings
113
- mixin :has_interp
114
-
115
- rule /[~^*!&%<>\|+=@:,.\/?-]+/, 'Operator'
116
- rule /[\[\]()]+/, 'Punctuation'
117
- rule %r(/[*]), 'Comment.Multiline', :inline_comment
118
- rule %r(//[^\n]*), 'Comment.Single'
119
-
120
- # identifiers
121
- rule(id) do |m|
122
- if CSS.builtins.include? m[0]
123
- token 'Name.Builtin'
124
- elsif CSS.constants.include? m[0]
125
- token 'Name.Constant'
126
- else
127
- token 'Name'
128
- end
129
- end
130
- end
131
-
132
- state :has_interp do
133
- rule /[#][{]/, 'Literal.String.Interpol', :interpolation
134
- end
135
-
136
- state :has_strings do
137
- rule /"/, 'Literal.String.Double', :dq
138
- rule /'/, 'Literal.String.Single', :sq
139
- end
140
-
141
- state :interpolation do
142
- rule /}/, 'Literal.String.Interpol', :pop!
143
- mixin :value
144
- end
145
-
146
- state :selector do
147
- mixin :end_section
148
-
149
- mixin :has_strings
150
- mixin :has_interp
151
- rule /[ \t]+/, 'Text'
152
- rule /:/, 'Name.Decorator', :pseudo_class
153
- rule /[.]/, 'Name.Class', :class
154
- rule /#/, 'Name.Namespace', :id
155
- rule /%/, 'Name.Variable', :placeholder
156
- rule id, 'Name.Tag'
157
- rule /&/, 'Keyword'
158
- rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, 'Operator'
159
- end
160
-
161
- state :dq do
162
- rule /"/, 'Literal.String.Double', :pop!
163
- mixin :has_interp
164
- rule /(\\.|#(?![{])|[^\n"#])+/, 'Literal.String.Double'
165
- end
166
-
167
- state :sq do
168
- rule /'/, 'Literal.String.Single', :pop!
169
- mixin :has_interp
170
- rule /(\\.|#(?![{])|[^\n'#])+/, 'Literal.String.Single'
171
- end
172
-
173
- state :string_url do
174
- rule /[)]/, 'Literal.String.Other', :pop!
175
- rule /(\\.|#(?![{])|[^\n)#])+/, 'Literal.String.Other'
176
- mixin :has_interp
177
- end
178
-
179
- state :selector_piece do
180
- mixin :has_interp
181
- rule(//) { pop! }
182
- end
183
-
184
- state :pseudo_class do
185
- rule id, 'Name.Decorator'
186
- mixin :selector_piece
187
- end
188
-
189
- state :class do
190
- rule id, 'Name.Class'
191
- mixin :selector_piece
192
- end
193
-
194
- state :id do
195
- rule id, 'Name.Namespace'
196
- mixin :selector_piece
197
- end
198
-
199
- state :placeholder do
200
- rule id, 'Name.Variable'
201
- mixin :selector_piece
202
- end
203
-
204
- state :for do
205
- rule /(from|to|through)/, 'Operator.Word'
206
- mixin :value
207
- end
208
-
209
- state :attr_common do
210
- mixin :has_interp
211
- rule id do |m|
212
- if CSS.attributes.include? m[0]
213
- token 'Name.Label'
214
- else
215
- token 'Name.Attribute'
216
- end
217
- end
218
- end
219
-
220
- state :attribute do
221
- mixin :attr_common
222
-
223
- rule /([ \t]*)(:)/ do
224
- group 'Text'; group 'Punctuation'
225
- push :value
226
- end
227
- end
228
-
229
- state :inline_comment do
230
- rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, 'Comment.Multiline'
231
- mixin :has_interp
232
- rule %r([*]/), 'Comment.Multiline', :pop!
233
- end
234
- end
235
-
236
- class_eval(&COMMON)
70
+ instance_eval(&SASS_COMMON)
237
71
  end
238
72
  end
239
73
  end
@@ -0,0 +1,171 @@
1
+ module Rouge
2
+ module Lexers
3
+ # shared states with SCSS
4
+ # TODO: make this less nasty to do
5
+ SASS_COMMON = proc do
6
+ state :content_common do
7
+ rule /@for\b/, 'Keyword', :for
8
+ rule /@(debug|warn|if|while)/, 'Keyword', :value
9
+ rule /(@mixin)(\s+)(#{id})/ do
10
+ group 'Keyword'; group 'Text'; group 'Name.Function'
11
+ push :value
12
+ end
13
+
14
+ rule /@extend\b/, 'Keyword', :selector
15
+
16
+ rule /(@include)(\s+)(#{id})/ do
17
+ group 'Keyword'; group 'Text'; group 'Name.Decorator'
18
+ push :value
19
+ end
20
+
21
+ rule /@#{id}/, 'Keyword', :selector
22
+
23
+ # $variable: assignment
24
+ rule /([$]#{id})([ \t]*)(:)/ do
25
+ group 'Name.Variable'; group 'Text'; group 'Punctuation'
26
+ push :value
27
+ end
28
+ end
29
+
30
+ state :value do
31
+ mixin :end_section
32
+ rule /[ \t]+/, 'Text'
33
+ rule /[$]#{id}/, 'Name.Variable'
34
+ rule /url[(]/, 'Literal.String.Other', :string_url
35
+ rule /#{id}(?=\s*[(])/, 'Name.Function'
36
+ rule /%#{id}/, 'Name.Decorator'
37
+
38
+ # named literals
39
+ rule /(true|false)\b/, 'Name.Pseudo'
40
+ rule /(and|or|not)\b/, 'Operator.Word'
41
+
42
+ # colors and numbers
43
+ rule /#[a-z0-9]{1,6}/i, 'Literal.Number.Hex'
44
+ rule /-?\d+(%|[a-z]+)?/, 'Literal.Number'
45
+ rule /-?\d*\.\d+(%|[a-z]+)?/, 'Literal.Number.Integer'
46
+
47
+ mixin :has_strings
48
+ mixin :has_interp
49
+
50
+ rule /[~^*!&%<>\|+=@:,.\/?-]+/, 'Operator'
51
+ rule /[\[\]()]+/, 'Punctuation'
52
+ rule %r(/[*]), 'Comment.Multiline', :inline_comment
53
+ rule %r(//[^\n]*), 'Comment.Single'
54
+
55
+ # identifiers
56
+ rule(id) do |m|
57
+ if CSS.builtins.include? m[0]
58
+ token 'Name.Builtin'
59
+ elsif CSS.constants.include? m[0]
60
+ token 'Name.Constant'
61
+ else
62
+ token 'Name'
63
+ end
64
+ end
65
+ end
66
+
67
+ state :has_interp do
68
+ rule /[#][{]/, 'Literal.String.Interpol', :interpolation
69
+ end
70
+
71
+ state :has_strings do
72
+ rule /"/, 'Literal.String.Double', :dq
73
+ rule /'/, 'Literal.String.Single', :sq
74
+ end
75
+
76
+ state :interpolation do
77
+ rule /}/, 'Literal.String.Interpol', :pop!
78
+ mixin :value
79
+ end
80
+
81
+ state :selector do
82
+ mixin :end_section
83
+
84
+ mixin :has_strings
85
+ mixin :has_interp
86
+ rule /[ \t]+/, 'Text'
87
+ rule /:/, 'Name.Decorator', :pseudo_class
88
+ rule /[.]/, 'Name.Class', :class
89
+ rule /#/, 'Name.Namespace', :id
90
+ rule /%/, 'Name.Variable', :placeholder
91
+ rule id, 'Name.Tag'
92
+ rule /&/, 'Keyword'
93
+ rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, 'Operator'
94
+ end
95
+
96
+ state :dq do
97
+ rule /"/, 'Literal.String.Double', :pop!
98
+ mixin :has_interp
99
+ rule /(\\.|#(?![{])|[^\n"#])+/, 'Literal.String.Double'
100
+ end
101
+
102
+ state :sq do
103
+ rule /'/, 'Literal.String.Single', :pop!
104
+ mixin :has_interp
105
+ rule /(\\.|#(?![{])|[^\n'#])+/, 'Literal.String.Single'
106
+ end
107
+
108
+ state :string_url do
109
+ rule /[)]/, 'Literal.String.Other', :pop!
110
+ rule /(\\.|#(?![{])|[^\n)#])+/, 'Literal.String.Other'
111
+ mixin :has_interp
112
+ end
113
+
114
+ state :selector_piece do
115
+ mixin :has_interp
116
+ rule(//) { pop! }
117
+ end
118
+
119
+ state :pseudo_class do
120
+ rule id, 'Name.Decorator'
121
+ mixin :selector_piece
122
+ end
123
+
124
+ state :class do
125
+ rule id, 'Name.Class'
126
+ mixin :selector_piece
127
+ end
128
+
129
+ state :id do
130
+ rule id, 'Name.Namespace'
131
+ mixin :selector_piece
132
+ end
133
+
134
+ state :placeholder do
135
+ rule id, 'Name.Variable'
136
+ mixin :selector_piece
137
+ end
138
+
139
+ state :for do
140
+ rule /(from|to|through)/, 'Operator.Word'
141
+ mixin :value
142
+ end
143
+
144
+ state :attr_common do
145
+ mixin :has_interp
146
+ rule id do |m|
147
+ if CSS.attributes.include? m[0]
148
+ token 'Name.Label'
149
+ else
150
+ token 'Name.Attribute'
151
+ end
152
+ end
153
+ end
154
+
155
+ state :attribute do
156
+ mixin :attr_common
157
+
158
+ rule /([ \t]*)(:)/ do
159
+ group 'Text'; group 'Punctuation'
160
+ push :value
161
+ end
162
+ end
163
+
164
+ state :inline_comment do
165
+ rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, 'Comment.Multiline'
166
+ mixin :has_interp
167
+ rule %r([*]/), 'Comment.Multiline', :pop!
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,3 +1,5 @@
1
+ require 'rouge/lexers/sass/common'
2
+
1
3
  module Rouge
2
4
  module Lexers
3
5
  class Scss < RegexLexer
@@ -25,7 +27,7 @@ module Rouge
25
27
  rule(/[;{}]/) { token 'Punctuation'; reset_stack }
26
28
  end
27
29
 
28
- instance_eval(&Sass::COMMON)
30
+ instance_eval(&SASS_COMMON)
29
31
  end
30
32
  end
31
33
  end
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.3.0"
3
+ "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-06 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -56,6 +56,7 @@ files:
56
56
  - lib/rouge/lexers/html.rb
57
57
  - lib/rouge/lexers/smalltalk.rb
58
58
  - lib/rouge/lexers/clojure.rb
59
+ - lib/rouge/lexers/sass/common.rb
59
60
  - lib/rouge/lexers/sass.rb
60
61
  - lib/rouge/lexers/factor.rb
61
62
  - lib/rouge/lexers/csharp.rb