opulent 1.5.5 → 1.6.0

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +13 -0
  3. data/{LICENSE → LICENSE.md} +0 -0
  4. data/bin/opulent +0 -0
  5. data/lib/opulent.rb +10 -10
  6. data/lib/opulent/compiler.rb +15 -9
  7. data/lib/opulent/compiler/buffer.rb +123 -62
  8. data/lib/opulent/compiler/comment.rb +3 -4
  9. data/lib/opulent/compiler/control.rb +20 -26
  10. data/lib/opulent/compiler/define.rb +88 -36
  11. data/lib/opulent/compiler/doctype.rb +20 -22
  12. data/lib/opulent/compiler/eval.rb +23 -2
  13. data/lib/opulent/compiler/filter.rb +4 -5
  14. data/lib/opulent/compiler/node.rb +18 -12
  15. data/lib/opulent/compiler/root.rb +4 -5
  16. data/lib/opulent/compiler/text.rb +7 -2
  17. data/lib/opulent/compiler/yield.rb +2 -3
  18. data/lib/opulent/engine.rb +21 -20
  19. data/lib/opulent/exec.rb +21 -63
  20. data/lib/opulent/logger.rb +230 -3
  21. data/lib/opulent/parser.rb +14 -76
  22. data/lib/opulent/parser/comment.rb +45 -34
  23. data/lib/opulent/parser/control.rb +132 -111
  24. data/lib/opulent/parser/define.rb +15 -12
  25. data/lib/opulent/parser/doctype.rb +15 -15
  26. data/lib/opulent/parser/eval.rb +16 -6
  27. data/lib/opulent/parser/expression.rb +87 -84
  28. data/lib/opulent/parser/filter.rb +31 -25
  29. data/lib/opulent/parser/include.rb +38 -42
  30. data/lib/opulent/parser/node.rb +136 -118
  31. data/lib/opulent/parser/root.rb +24 -18
  32. data/lib/opulent/parser/text.rb +150 -123
  33. data/lib/opulent/parser/yield.rb +23 -23
  34. data/lib/opulent/settings.rb +70 -51
  35. data/lib/opulent/tokens.rb +17 -15
  36. data/lib/opulent/utils.rb +5 -4
  37. data/lib/opulent/version.rb +1 -1
  38. metadata +4 -43
  39. data/.libold/opulent.rb +0 -96
  40. data/.libold/opulent/context.rb +0 -80
  41. data/.libold/opulent/engine.rb +0 -88
  42. data/.libold/opulent/filter.rb +0 -101
  43. data/.libold/opulent/logger.rb +0 -67
  44. data/.libold/opulent/nodes.rb +0 -13
  45. data/.libold/opulent/nodes/block.rb +0 -29
  46. data/.libold/opulent/nodes/comment.rb +0 -35
  47. data/.libold/opulent/nodes/control.rb +0 -230
  48. data/.libold/opulent/nodes/define.rb +0 -42
  49. data/.libold/opulent/nodes/eval.rb +0 -41
  50. data/.libold/opulent/nodes/expression.rb +0 -28
  51. data/.libold/opulent/nodes/filter.rb +0 -70
  52. data/.libold/opulent/nodes/helper.rb +0 -69
  53. data/.libold/opulent/nodes/node.rb +0 -101
  54. data/.libold/opulent/nodes/root.rb +0 -62
  55. data/.libold/opulent/nodes/text.rb +0 -54
  56. data/.libold/opulent/nodes/theme.rb +0 -36
  57. data/.libold/opulent/parser.rb +0 -252
  58. data/.libold/opulent/parser/block.rb +0 -70
  59. data/.libold/opulent/parser/comment.rb +0 -32
  60. data/.libold/opulent/parser/control.rb +0 -83
  61. data/.libold/opulent/parser/define.rb +0 -39
  62. data/.libold/opulent/parser/eval.rb +0 -33
  63. data/.libold/opulent/parser/expression.rb +0 -350
  64. data/.libold/opulent/parser/filter.rb +0 -41
  65. data/.libold/opulent/parser/node.rb +0 -232
  66. data/.libold/opulent/parser/root.rb +0 -96
  67. data/.libold/opulent/parser/text.rb +0 -114
  68. data/.libold/opulent/parser/theme.rb +0 -36
  69. data/.libold/opulent/preprocessor.rb +0 -102
  70. data/.libold/opulent/runtime.rb +0 -144
  71. data/.libold/opulent/template.rb +0 -43
  72. data/.libold/opulent/tokens.rb +0 -276
  73. data/.libold/opulent/version.rb +0 -5
  74. data/.travis.yml +0 -4
  75. data/benchmark/benchmark.rb +0 -57
  76. data/benchmark/cases/node/node.haml +0 -7
  77. data/benchmark/cases/node/node.op +0 -7
  78. data/benchmark/cases/node/node.slim +0 -7
@@ -1,39 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Parser
4
- module Parser
5
- # @Define
6
- module Define
7
- # Match a definition node with its parameters and body
8
- #
9
- # def node_name[ parameters ]
10
- # body nodes
11
- #
12
- # @param parent [Node] Parent node to which we append the definition
13
- #
14
- def define(parent)
15
- if lookahead :def_lookahead
16
- # Get current line's indentation
17
- indent = accept_unstripped(:indent) || ""
18
-
19
- if accept :def
20
- # Get definition name
21
- def_name = accept :identifier, :*
22
-
23
- # Get element attributes
24
- atts = attributes({}) || {}
25
-
26
- # Create a new node
27
- node = @create.definition def_name.to_sym, atts, parent, indent.size
28
-
29
- # Consume the newline from the end of the element
30
- error :define unless accept_unstripped(:line_feed).strip.empty?
31
- accept_unstripped :newline
32
-
33
- return node
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,33 +0,0 @@
1
- # @SugarCube
2
- module Opulent
3
- # @Parser
4
- module Parser
5
- # @Text
6
- module Evaluate
7
- # Match one line or multiline, escaped or unescaped text
8
- #
9
- def evaluate(parent)
10
- indent = indent || accept_unstripped(:indent) || ""
11
-
12
- # Accept eval or multiline eval syntax and return a new node,
13
- if (evaluate = accept_unstripped(:eval))
14
- eval_node = @create.evaluate(evaluate.strip, parent, indent.size)
15
- accept_unstripped :newline
16
- elsif (evaluate = accept_unstripped(:eval_multiline))
17
- # Get all the lines which are more indented than the current one
18
- eval_node = @create.evaluate(evaluate.strip, parent, indent.size)
19
- eval_node.value += accept_unstripped(:newline) || ""
20
- eval_node.value += get_indented_lines(indent.size)
21
- end
22
-
23
- if eval_node
24
- # Return the found eval node
25
- return eval_node
26
- else
27
- # Undo by adding the found intentation back
28
- return undo indent
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,350 +0,0 @@
1
- # @Opulent
2
- module Opulent
3
- # @Parser
4
- module Parser
5
- # @Expression
6
- module Expression
7
- # Check if the parser matches an expression node
8
- #
9
- def expression(allow_assignments = true, wrapped = true)
10
- buffer = ""
11
-
12
- # Build a ruby expression out of accepted literals
13
- while (term = whitespace ||
14
- modifier ||
15
- identifier ||
16
- method_call ||
17
- paranthesis ||
18
- array ||
19
- hash ||
20
- symbol ||
21
- percent ||
22
- primary_term ||
23
- (allow_assignments ? accept(:exp_assignment) : nil))
24
- buffer += term
25
-
26
- # Accept operations which have a right term and raise an error if
27
- # we have an unfinished expression such as "a +", "b - 1 >" and other
28
- # expressions following the same pattern
29
- if wrapped && (op = operation)
30
- buffer += op
31
- if (right_term = expression(allow_assignments, wrapped)).nil?
32
- error :expression
33
- else
34
- buffer += right_term.value
35
- end
36
- elsif (conditional = ternary_operator allow_assignments, wrapped)
37
- buffer += conditional
38
- end
39
-
40
- # Do not continue if the expression has whitespace method calls in
41
- # an unwrapped context because this will confuse the parser
42
- unless buffer.strip.empty?
43
- break unless wrapped || lookahead(:exp_identifier_lookahead, false)
44
- end
45
- end
46
-
47
- if buffer.strip.empty?
48
- return undo buffer
49
- else
50
- return @create.expression buffer
51
- end
52
- end
53
-
54
- # Check if it's possible to parse a ruby array literal. First, try to see
55
- # if the next sequence is a hash_open token: "[", and if it is, then a
56
- # hash_close: "]" token is required next
57
- #
58
- # [array_elements]
59
- #
60
- def array
61
- if (buffer = accept :array_open)
62
- accept_unstripped :newline
63
- buffer += array_elements
64
- buffer += accept :array_close, :*
65
- end
66
- end
67
-
68
- # Recursively gather expressions separated by a comma and add them to the
69
- # expression buffer
70
- #
71
- # experssion1, experssion2, experssion3
72
- #
73
- # @param buffer [String] Accumulator for the array elements
74
- #
75
- def array_elements(buffer = '')
76
- if (term = expression)
77
- buffer += term.value
78
- # If there is an array_terminator ",", recursively gather the next
79
- # array element into the buffer
80
- if (terminator = accept :array_terminator) then
81
- accept_unstripped :newline
82
- buffer += array_elements terminator
83
- end
84
- end
85
-
86
- # Array ended prematurely with a trailing comma, therefore the current
87
- # parsing process will stop
88
- if buffer.strip[-1] == ','
89
- error :array_elements_terminator
90
- end
91
-
92
- buffer
93
- end
94
-
95
- # Check if it's possible to parse a ruby hash literal. First, try to see
96
- # if the next sequence is a hash_open token: "{", and if it is, then a
97
- # hash_close: "}" token is required next
98
- #
99
- # { hash_elements }
100
- #
101
- def hash
102
- if (buffer = accept :hash_open)
103
- accept_unstripped :newline
104
- buffer += hash_elements
105
- buffer += accept :hash_close, :*
106
- end
107
- end
108
-
109
- # Recursively gather expression attributions separated by a comma and add
110
- # them to the expression buffer
111
- #
112
- # key1: experssion1, key2 => experssion2, :key3 => experssion3
113
- #
114
- # @param buffer [String] Accumulator for the hash elements
115
- #
116
- def hash_elements(buffer = '')
117
- value = Proc.new do
118
- # Get the value associated to the current hash key
119
- if (exp = expression)
120
- buffer += exp.value
121
- else
122
- error :hash_elements
123
- end
124
-
125
- # If there is an hash_terminator ",", recursively gather the next
126
- # array element into the buffer
127
- if (terminator = accept :hash_terminator) then
128
- accept_unstripped :newline
129
- buffer += hash_elements terminator
130
- end
131
- end
132
-
133
- # Accept both shorthand and default ruby hash style. Following DRY
134
- # principles, a Proc is used to assign the value to the current key
135
- #
136
- # key:
137
- # :key =>
138
- if (symbol = accept :hash_symbol)
139
- buffer += symbol
140
- value[]
141
- elsif (exp = expression)
142
- buffer += exp.value
143
- if(assign = accept :hash_assignment)
144
- buffer += assign
145
- value[]
146
- else
147
- error :hash_assignment
148
- end
149
- end
150
-
151
- # Array ended prematurely with a trailing comma, therefore the current
152
- # parsing process will stop
153
- if buffer.strip[-1] == ','
154
- error :hash_elements_terminator
155
- end
156
-
157
- buffer
158
- end
159
-
160
- # Accept a ruby identifier such as a class, module, method or variable
161
- #
162
- def identifier
163
- if (buffer = accept_line_unstripped :exp_identifier)
164
- if (args = call)
165
- buffer += args
166
- end
167
- return buffer
168
- end
169
- end
170
-
171
- # Check if it's possible to parse a ruby paranthesis expression wrapper.
172
- #
173
- def paranthesis
174
- if (buffer = accept :round_bracket_open)
175
- accept_unstripped :newline
176
- buffer += expression.to_s
177
- buffer += accept :round_bracket_close, :*
178
- end
179
- end
180
-
181
- # Check if it's possible to parse a ruby call literal. First, try to see
182
- # if the next sequence is a hash_open token: "(", and if it is, then a
183
- # hash_close: ")" token is required next
184
- #
185
- # ( call_elements )
186
- #
187
- def call
188
- if (buffer = accept_unstripped :round_bracket_open)
189
- accept_unstripped :newline
190
- buffer += call_elements
191
- buffer += accept :round_bracket_close, :*
192
- end
193
- end
194
-
195
- # Recursively gather expression attributes separated by a comma and add
196
- # them to the expression buffer
197
- #
198
- # expression1, a: expression2, expression3
199
- #
200
- # @param buffer [String] Accumulator for the call elements
201
- #
202
- def call_elements(buffer = '')
203
- # Accept both shorthand and default ruby hash style. Following DRY
204
- # principles, a Proc is used to assign the value to the current key
205
- #
206
- # key: value
207
- # :key => value
208
- # value
209
- if (symbol = accept :hash_symbol)
210
- buffer += symbol
211
-
212
- # Get the value associated to the current hash key
213
- if (exp = expression(true))
214
- buffer += exp.value
215
- else
216
- error :call_elements
217
- end
218
-
219
- # If there is an comma ",", recursively gather the next
220
- # array element into the buffer
221
- if (terminator = accept :comma) then
222
- accept_unstripped :newline
223
- buffer += call_elements terminator
224
- end
225
- elsif (exp = expression(true))
226
- buffer += exp.value
227
-
228
- if(assign = accept :hash_assignment)
229
- buffer += assign
230
-
231
- # Get the value associated to the current hash key
232
- if (exp = expression(true))
233
- buffer += exp.value
234
- else
235
- error :call_elements
236
- end
237
- end
238
-
239
- # If there is an comma ",", recursively gather the next
240
- # array element into the buffer
241
- if (terminator = accept :comma) then
242
- accept_unstripped :newline
243
- buffer += call_elements terminator
244
- end
245
- end
246
-
247
- buffer
248
- end
249
-
250
- # Accept a ruby symbol defined through a colon and a trailing expression
251
- #
252
- # :'symbol'
253
- # :symbol
254
- #
255
- def symbol
256
- if (colon = accept :colon)
257
- return undo colon if lookahead(:whitespace_lookahead, false)
258
-
259
- if (exp = expression).nil?
260
- error :symbol
261
- else
262
- colon + exp.to_s
263
- end
264
- end
265
- end
266
-
267
- # Accept a ruby module, method or context modifier
268
- #
269
- # Module::
270
- # @, @@, $
271
- #
272
- def modifier
273
- accept(:exp_context) || accept(:exp_module)
274
- end
275
-
276
-
277
- # Accept a ruby percentage operator for arrays of strings, symbols and
278
- # simple escaped strings
279
- #
280
- # %w(word1 word2 word3)
281
- #
282
- def percent
283
- if (buffer = accept :exp_percent)
284
- match_start = buffer[-1]
285
- match_name = :"percent#{match_start}"
286
-
287
- unless Tokens[match_name]
288
- match_end = Tokens.bracket(match_start) || match_start
289
-
290
- match_inner = "\\#{match_start}"
291
- match_inner += "\\#{match_end}" unless match_end == match_start
292
-
293
- pattern = /(((?:[^#{match_inner}\\]|\\.)*?)#{'\\' + match_end})/
294
-
295
- Tokens[match_name] = Tokens::Token.new pattern
296
- end
297
-
298
- buffer += accept match_name
299
- end
300
- end
301
-
302
- # Accept any primary term and return it without the leading whitespace to
303
- # the expression buffer
304
- #
305
- # "string"
306
- # 123
307
- # 123.456
308
- # nil
309
- # true
310
- # false
311
- # /.*/
312
- #
313
- def primary_term
314
- accept(:exp_string) ||
315
- accept(:exp_fixnum) ||
316
- accept(:exp_double) ||
317
- accept(:exp_nil) ||
318
- accept(:exp_regex) ||
319
- accept(:exp_boolean)
320
- end
321
-
322
- # Accept an operation between two or more expressions
323
- #
324
- def operation
325
- accept_unstripped(:exp_operation)
326
- end
327
-
328
- # Accept a ruby method call modifier
329
- #
330
- def method_call
331
- accept_unstripped(:exp_method_call)
332
- end
333
-
334
- # Accept ternary operator syntax
335
- #
336
- # condition ? expression1 : expression2
337
- #
338
- def ternary_operator(allow_assignments, wrapped)
339
- if (buffer = accept_line_unstripped :exp_ternary)
340
- buffer += expression(allow_assignments, wrapped).to_s
341
- if (else_branch = accept_line_unstripped :exp_ternary_else)
342
- buffer += else_branch
343
- buffer += expression(allow_assignments, wrapped).to_s
344
- end
345
- return buffer
346
- end
347
- end
348
- end
349
- end
350
- end
@@ -1,41 +0,0 @@
1
- # @SugarCube
2
- module Opulent
3
- # @Parser
4
- module Parser
5
- # @Text
6
- module Filter
7
- # Check if we match an compile time filter
8
- #
9
- # :filter
10
- #
11
- # @param parent [Node] Parent node to which we append the element
12
- #
13
- def filter_element(parent)
14
- if lookahead :filter_lookahead
15
- # Get current line's indentation
16
- indent = accept_unstripped(:indent) || ""
17
-
18
- if (filter_name = accept :filter)
19
- # Get element attributes
20
- atts = attributes({}) || {}
21
-
22
- # Create a new node and set its extension
23
- filter_node = @create.filter filter_name.to_sym, atts, parent, indent.size
24
-
25
- # Accept inline text or multiline text feed as first child
26
- if(text_node = text filter_node, indent, true)
27
- #filter_node.atts = accept_unstripped(:line_feed)
28
- error :fiter unless accept_line(:line_feed).strip.empty?
29
- end
30
- accept_unstripped(:newline)
31
-
32
- # Get everything under the filter and set it as the node value
33
- filter_node.value += get_indented_lines(indent.size)
34
-
35
- return filter_node
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end