rouge 4.0.1 → 4.1.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.
@@ -8,228 +8,164 @@ module Rouge
8
8
  desc 'Liquid is a templating engine for Ruby (liquidmarkup.org)'
9
9
  tag 'liquid'
10
10
  filenames '*.liquid'
11
+ mimetypes 'text/html+liquid'
11
12
 
12
13
  state :root do
13
14
  rule %r/[^\{]+/, Text
14
15
 
15
16
  rule %r/(\{%-?)(\s*)/ do
16
- groups Punctuation, Text::Whitespace
17
- push :tag_or_block
17
+ groups Comment::Preproc, Text::Whitespace
18
+ push :logic
18
19
  end
19
20
 
20
21
  rule %r/(\{\{-?)(\s*)/ do
21
- groups Punctuation, Text::Whitespace
22
+ groups Comment::Preproc, Text::Whitespace
22
23
  push :output
23
24
  end
24
25
 
25
26
  rule %r/\{/, Text
26
27
  end
27
28
 
28
- state :tag_or_block do
29
+ state :end_logic do
30
+ rule(/(\s*)(-?%\})/) do
31
+ groups Text::Whitespace, Comment::Preproc
32
+ reset_stack
33
+ end
34
+
35
+ rule(/\n\s*/) do
36
+ token Text::Whitespace
37
+ if in_state? :liquid
38
+ pop! until state? :liquid
39
+ end
40
+ end
41
+
42
+ mixin :whitespace
43
+ end
44
+
45
+ state :end_output do
46
+ rule(/(\s*)(-?\}\})/) do
47
+ groups Text::Whitespace, Comment::Preproc
48
+ reset_stack
49
+ end
50
+ end
51
+
52
+ state :liquid do
53
+ mixin :end_logic
54
+ mixin :logic
55
+ end
56
+
57
+ state :logic do
58
+ rule %r/(liquid)\b/, Name::Tag, :liquid
59
+
29
60
  # builtin logic blocks
30
- rule %r/(if|elsif|unless|case)\b/, Keyword::Reserved, :condition
31
- rule %r/(when)\b/, Keyword::Reserved, :when
61
+ rule %r/(if|elsif|unless|case)\b/, Name::Tag, :condition
62
+ rule %r/(when)\b/, Name::Tag, :value
63
+ rule %r/(else|ifchanged|end\w+)\b/, Name::Tag, :end_logic
64
+ rule %r/(break|continue)\b/, Keyword::Reserved, :end_logic
32
65
 
33
- rule %r/(else)(\s*)(-?%\})/ do
34
- groups Keyword::Reserved, Text::Whitespace, Punctuation
35
- pop!
66
+ # builtin iteration blocks
67
+ rule %r/(for|tablerow)(\s+)(\S+)(\s+)(in)(\s+)/ do
68
+ groups Name::Tag, Text::Whitespace, Name::Variable, Text::Whitespace,
69
+ Name::Tag, Text::Whitespace
70
+ push :iteration_args
36
71
  end
37
72
 
38
73
  # other builtin blocks
39
- rule %r/(capture|(?:in|de)crement)(\s+)([^\s%]+)(\s*)(-?%\})/ do
40
- groups Name::Tag, Text::Whitespace, Name::Variable, Text::Whitespace, Punctuation
41
- pop!
74
+ rule %r/(capture|(?:in|de)crement)(\s+)([a-zA-Z_](?:\w|-(?!%))*)/ do
75
+ groups Name::Tag, Text::Whitespace, Name::Variable
76
+ push :end_logic
42
77
  end
43
78
 
44
79
  rule %r/(comment)(\s*)(-?%\})/ do
45
- groups Name::Tag, Text::Whitespace, Punctuation
80
+ groups Name::Tag, Text::Whitespace, Comment::Preproc
46
81
  push :comment
47
82
  end
48
83
 
49
84
  rule %r/(raw)(\s*)(-?%\})/ do
50
- groups Name::Tag, Text::Whitespace, Punctuation
85
+ groups Name::Tag, Text::Whitespace, Comment::Preproc
51
86
  push :raw
52
87
  end
53
88
 
54
- # end of block
55
- rule %r/(end(?:if|unless|case))(\s*)(-?%\})/ do
56
- groups Keyword::Reserved, Text::Whitespace, Punctuation
57
- pop!
58
- end
59
-
60
- rule %r/(end(?:[^\s%]+))(\s*)(-?%\})/ do
61
- groups Name::Tag, Text::Whitespace, Punctuation
62
- pop!
63
- end
64
-
65
89
  # builtin tags
66
90
  rule %r/(assign|echo)\b/, Name::Tag, :assign
67
- rule %r/(include|render)\b/, Name::Tag, :include
68
91
 
69
- rule %r/(cycle)(\s+)(?:([^\s:]*)(\s*)(:))?(\s*)/ do |m|
92
+ rule %r/(include|render)(\s+)([\/\w-]+(?:\.[\w-]+)+\b)?/ do
93
+ groups Name::Tag, Text::Whitespace, Text
94
+ push :include
95
+ end
96
+
97
+ rule %r/(cycle)(\s+)(?:([\w-]+|'[^']*'|"[^"]*")(\s*)(:))?(\s*)/ do |m|
70
98
  token_class = case m[3]
71
99
  when %r/'[^']*'/ then Str::Single
72
100
  when %r/"[^"]*"/ then Str::Double
73
101
  else
74
102
  Name::Attribute
75
103
  end
76
-
77
104
  groups Name::Tag, Text::Whitespace, token_class,
78
105
  Text::Whitespace, Punctuation, Text::Whitespace
79
-
80
- push :variable_tag_markup
106
+ push :tag_args
81
107
  end
82
108
 
83
- # iteration
84
- rule %r/
85
- (for|tablerow)(\s+)
86
- ([\w-]+)(\s+)
87
- (in)(\s+)
88
- (
89
- (?: [^\s%,\|'"] | (?:"[^"]*"|'[^']*') )+
90
- )(\s*)
91
- /x do |m|
92
- groups Name::Tag, Text::Whitespace, Name::Variable, Text::Whitespace,
93
- Name::Tag, Text::Whitespace
94
-
95
- token_class = case m[7]
96
- when %r/'[^']*'/ then Str::Single
97
- when %r/"[^"]*"/ then Str::Double
98
- else
99
- Name::Variable
100
- end
101
- token token_class, m[7]
102
- token Text::Whitespace, m[8]
103
- push :tag_markup
104
- end
109
+ # custom tags or blocks
110
+ rule %r/(\w+)\b/, Name::Tag, :block_args
105
111
 
106
- # other tags or blocks
107
- rule %r/([^\s%]+)(\s*)/ do
108
- groups Name::Tag, Text::Whitespace
109
- push :tag_markup
110
- end
112
+ mixin :end_logic
111
113
  end
112
114
 
113
115
  state :output do
114
- rule %r/(\|)(\s*)([a-zA-Z_][^\s}\|:]*)/ do
115
- groups Punctuation, Text::Whitespace, Name::Function
116
+ rule %r/(\|)(\s*)/ do
117
+ groups Punctuation, Text::Whitespace
116
118
  push :filters
119
+ push :filter
117
120
  end
118
121
 
119
- mixin :end_of_tag
120
- mixin :generic
121
- end
122
-
123
- state :filters do
124
- rule %r/(\|)(\s*)([a-zA-Z_][^\s%}\|:]*)/ do
125
- groups Punctuation, Text::Whitespace, Name::Function
126
- end
127
-
128
- mixin :end_of_tag
129
- mixin :end_of_block
130
- mixin :variable_param_markup
122
+ mixin :end_output
123
+ mixin :static
124
+ mixin :variable
131
125
  end
132
126
 
133
127
  state :condition do
134
128
  rule %r/([=!]=|[<>]=?)/, Operator
135
129
  rule %r/(and|or|contains)\b/, Operator::Word
136
130
 
137
- mixin :end_of_block
138
- mixin :generic
139
- end
140
-
141
- state :when do
142
- mixin :end_of_block
143
- mixin :generic
144
- end
145
-
146
- state :end_of_tag do
147
- rule(/-?\}\}/) { token Punctuation; reset_stack }
131
+ mixin :value
148
132
  end
149
133
 
150
- state :end_of_block do
151
- rule(/-?%\}/) { token Punctuation; reset_stack }
152
- end
153
-
154
- # states for unknown markup
155
- state :param_markup do
156
- mixin :whitespace
157
- mixin :keyword
158
- mixin :string
159
- mixin :number
160
-
161
- rule %r/([^\s=:]+)(\s*)(=|:)/ do
162
- groups Name::Attribute, Text::Whitespace, Operator
163
- end
164
-
165
- rule %r/[,:]/, Punctuation
166
- end
167
-
168
- state :default_param_markup do
169
- mixin :param_markup
170
-
171
- rule %r/\S+/, Text
172
- end
173
-
174
- state :variable_param_markup do
175
- mixin :param_markup
134
+ state :value do
135
+ mixin :end_logic
136
+ mixin :static
176
137
  mixin :variable
177
-
178
- rule %r/\S+/, Text
179
- end
180
-
181
- state :tag_markup do
182
- rule %r/(reversed)\b/, Name::Attribute
183
-
184
- mixin :end_of_block
185
- mixin :default_param_markup
186
- end
187
-
188
- state :variable_tag_markup do
189
- mixin :end_of_block
190
- mixin :variable_param_markup
191
138
  end
192
139
 
193
- # states for different values types
194
- state :keyword do
195
- rule %r/(false|true|nil)\b/, Keyword::Constant
196
- end
140
+ state :iteration_args do
141
+ rule %r/(reversed|continue)\b/, Name::Attribute
142
+ rule %r/\(/, Punctuation, :range
197
143
 
198
- state :variable do
199
- rule %r/(empty|blank|forloop\.[^\s%}\|:]+)\b/, Name::Builtin
200
- rule %r/\.(?=\w)|\[|\]/, Punctuation
201
- rule %r/(first|last|size)\b/, Name::Function
202
- rule %r/[a-zA-Z_][\w-]*\??/, Name::Variable
144
+ mixin :tag_args
203
145
  end
204
146
 
205
- state :string do
206
- rule %r/'[^']*'/, Str::Single
207
- rule %r/"[^"]*"/, Str::Double
208
- end
147
+ state :block_args do
148
+ rule %r/(\{\{-?)/, Comment::Preproc, :output_embed
209
149
 
210
- state :number do
211
- rule %r/-/, Operator
212
- rule %r/\d+\.\d+/, Num::Float
213
- rule %r/\d+/, Num::Integer
214
- end
150
+ rule %r/(\|)(\s*)/ do
151
+ groups Punctuation, Text::Whitespace
152
+ push :filters
153
+ push :filter
154
+ end
215
155
 
216
- state :generic do
217
- mixin :whitespace
218
- mixin :keyword
219
- mixin :string
220
- mixin :number
221
- mixin :variable
156
+ mixin :tag_args
222
157
  end
223
158
 
224
- state :whitespace do
225
- rule %r/[ \t]+/, Text::Whitespace
159
+ state :tag_args do
160
+ mixin :end_logic
161
+ mixin :args
226
162
  end
227
163
 
228
164
  state :comment do
229
165
  rule %r/[^\{]+/, Comment
230
166
 
231
167
  rule %r/(\{%-?)(\s*)(endcomment)(\s*)(-?%\})/ do
232
- groups Punctuation, Text::Whitespace, Name::Tag, Text::Whitespace, Punctuation
168
+ groups Comment::Preproc, Text::Whitespace, Name::Tag, Text::Whitespace, Comment::Preproc
233
169
  reset_stack
234
170
  end
235
171
 
@@ -240,7 +176,7 @@ module Rouge
240
176
  rule %r/[^\{]+/, Text
241
177
 
242
178
  rule %r/(\{%-?)(\s*)(endraw)(\s*)(-?%\})/ do
243
- groups Punctuation, Text::Whitespace, Name::Tag, Text::Whitespace, Punctuation
179
+ groups Comment::Preproc, Text::Whitespace, Name::Tag, Text::Whitespace, Comment::Preproc
244
180
  reset_stack
245
181
  end
246
182
 
@@ -249,36 +185,100 @@ module Rouge
249
185
 
250
186
  state :assign do
251
187
  rule %r/=/, Operator
188
+ rule %r/\(/, Punctuation, :range
252
189
 
253
- rule %r/(\|)(\s*)([a-zA-Z_][^\s%\|:]*)/ do
254
- groups Punctuation, Text::Whitespace, Name::Function
190
+ rule %r/(\|)(\s*)/ do
191
+ groups Punctuation, Text::Whitespace
255
192
  push :filters
193
+ push :filter
256
194
  end
257
195
 
258
- mixin :end_of_block
259
- mixin :generic
196
+ mixin :value
260
197
  end
261
198
 
262
199
  state :include do
263
- rule %r/(\{\{-?)(\s*)/ do
200
+ rule %r/(\{\{-?)/, Comment::Preproc, :output_embed
201
+ rule %r/(with|for|as)\b/, Keyword::Reserved
202
+
203
+ mixin :tag_args
204
+ end
205
+
206
+ state :output_embed do
207
+ rule %r/(\|)(\s*)([a-zA-Z_](?:\w|-(?!}))*)/ do
208
+ groups Punctuation, Text::Whitespace, Name::Function
209
+ end
210
+
211
+ rule %r/-?\}\}/, Comment::Preproc, :pop!
212
+
213
+ mixin :args
214
+ end
215
+
216
+ state :range do
217
+ rule %r/\.\./, Punctuation
218
+ rule %r/\)/, Punctuation, :pop!
219
+
220
+ mixin :whitespace
221
+ mixin :number
222
+ mixin :variable
223
+ end
224
+
225
+ state :filters do
226
+ rule %r/(\|)(\s*)/ do
264
227
  groups Punctuation, Text::Whitespace
265
- push :output_embed
228
+ push :filter
266
229
  end
267
230
 
268
- rule %r/(with|for)\b/, Name::Tag
269
- rule %r/[\/\w-]+(\.[\w-]+)+\b/, Text
231
+ mixin :end_logic
232
+ mixin :end_output
233
+ mixin :args
234
+ end
270
235
 
271
- mixin :variable_tag_markup
236
+ state :filter do
237
+ rule %r/[a-zA-Z_](?:\w|-(?![%}]))*/, Name::Function, :pop!
238
+
239
+ mixin :whitespace
272
240
  end
273
241
 
274
- state :output_embed do
275
- rule %r/(\|)(\s*)([a-zA-Z_][^\s}\|:]*)/ do
276
- groups Punctuation, Text::Whitespace, Name::Function
242
+ state :args do
243
+ mixin :static
244
+
245
+ rule %r/([a-zA-Z_][\w-]*)(\s*)(=|:)/ do
246
+ groups Name::Attribute, Text::Whitespace, Operator
277
247
  end
278
248
 
279
- rule %r/-?\}\}/, Punctuation, :pop!
249
+ mixin :variable
250
+ end
280
251
 
281
- mixin :variable_param_markup
252
+ state :static do
253
+ rule %r/(false|true|nil)\b/, Keyword::Constant
254
+ rule %r/'[^']*'/, Str::Single
255
+ rule %r/"[^"]*"/, Str::Double
256
+ rule %r/[,:]/, Punctuation
257
+
258
+ mixin :whitespace
259
+ mixin :number
260
+ end
261
+
262
+ state :whitespace do
263
+ rule %r/\s+/, Text::Whitespace
264
+ rule %r/#.*?(?=$|-?[}%]})/, Comment
265
+ end
266
+
267
+ state :number do
268
+ rule %r/-/, Operator
269
+ rule %r/\d+\.\d+/, Num::Float
270
+ rule %r/\d+/, Num::Integer
271
+ end
272
+
273
+ state :variable do
274
+ rule %r/(\.)(\s*)(first|last|size)\b(?![?!\/])/ do
275
+ groups Punctuation, Text::Whitespace, Name::Function
276
+ end
277
+
278
+ rule %r/\.(?= *\w)|\[|\]/, Punctuation
279
+ rule %r/(empty|blank|(for|tablerow)loop\.(parentloop\.)*\w+)\b(?![?!\/])/, Name::Builtin
280
+ rule %r/[a-zA-Z_][\w-]*\b-?(?![?!\/])/, Name::Variable
281
+ rule %r/\S+/, Text
282
282
  end
283
283
  end
284
284
  end
@@ -13,10 +13,6 @@ module Rouge
13
13
 
14
14
  mimetypes 'text/x-mosel'
15
15
 
16
- def self.detect?(text)
17
- return true if text =~ /^\s*(model|package)\s+/
18
- end
19
-
20
16
  id = /[a-zA-Z_][a-zA-Z0-9_]*/
21
17
 
22
18
  ############################################################################################################################