haparanda 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +4 -2
- data/lib/haparanda/compiler.rb +50 -10
- data/lib/haparanda/content_combiner.rb +7 -0
- data/lib/haparanda/handlebars_parser.rb +63 -57
- data/lib/haparanda/handlebars_parser.y +20 -14
- data/lib/haparanda/handlebars_processor.rb +551 -126
- data/lib/haparanda/parser.rb +28 -0
- data/lib/haparanda/standalone_whitespace_handler.rb +223 -0
- data/lib/haparanda/template.rb +34 -3
- data/lib/haparanda/version.rb +1 -1
- data/lib/haparanda/whitespace_stripper.rb +135 -0
- data/lib/haparanda.rb +0 -1
- metadata +19 -4
- data/lib/haparanda/handlebars_compiler.rb +0 -18
- data/lib/haparanda/whitespace_handler.rb +0 -168
|
@@ -20,8 +20,10 @@ start root
|
|
|
20
20
|
# for details.
|
|
21
21
|
|
|
22
22
|
root
|
|
23
|
-
: program {
|
|
24
|
-
|
|
23
|
+
: program {
|
|
24
|
+
result = s(:root, val[0])
|
|
25
|
+
result.line(val[0].line) if val[0]
|
|
26
|
+
};
|
|
25
27
|
|
|
26
28
|
program
|
|
27
29
|
: none
|
|
@@ -30,7 +32,7 @@ program
|
|
|
30
32
|
|
|
31
33
|
# Extra rule needed for racc to parse list of one or more statements
|
|
32
34
|
statements
|
|
33
|
-
: statement { result = s(:statements, val[0]) }
|
|
35
|
+
: statement { result = s(:statements, val[0]).line(val[0].line) }
|
|
34
36
|
| statements statement { result << val[1] }
|
|
35
37
|
;
|
|
36
38
|
|
|
@@ -108,14 +110,16 @@ optInverseAndProgram
|
|
|
108
110
|
;
|
|
109
111
|
|
|
110
112
|
inverseAndProgram
|
|
111
|
-
: INVERSE program {
|
|
112
|
-
|
|
113
|
+
: INVERSE program {
|
|
114
|
+
result = s(:inverse, nil, val[1], strip_flags(val[0], val[0]), nil)
|
|
115
|
+
result.line(val[1].line) if val[1]
|
|
116
|
+
};
|
|
113
117
|
|
|
114
118
|
inverseChain
|
|
115
119
|
: none
|
|
116
120
|
| openInverseChain program inverseChain {
|
|
117
121
|
block = prepare_block(val[0], val[1], val[2], nil, false)
|
|
118
|
-
result = s(:inverse, nil, block, nil, nil)
|
|
122
|
+
result = s(:inverse, nil, block, nil, nil).line(block.line)
|
|
119
123
|
}
|
|
120
124
|
| inverseAndProgram
|
|
121
125
|
;
|
|
@@ -131,7 +135,7 @@ mustache
|
|
|
131
135
|
|
|
132
136
|
partial
|
|
133
137
|
: OPEN_PARTIAL expr exprs hash CLOSE {
|
|
134
|
-
result = s(:partial, val[1], val[2], val[3], strip_flags(val[0], val[4]))
|
|
138
|
+
result = s(:partial, val[1], val[2], val[3], nil, strip_flags(val[0], val[4]))
|
|
135
139
|
.line(self.lexer.lineno)
|
|
136
140
|
}
|
|
137
141
|
;
|
|
@@ -263,8 +267,7 @@ end
|
|
|
263
267
|
|
|
264
268
|
def id(val)
|
|
265
269
|
if (match = /\A\[(.*)\]\Z/.match val)
|
|
266
|
-
|
|
267
|
-
s(:id, match[1])
|
|
270
|
+
s(:id, match[1], true)
|
|
268
271
|
else
|
|
269
272
|
s(:id, val)
|
|
270
273
|
end
|
|
@@ -278,19 +281,19 @@ def interpret_open_token(open)
|
|
|
278
281
|
end
|
|
279
282
|
|
|
280
283
|
def prepare_path(data, sexpr, parts, loc)
|
|
281
|
-
|
|
284
|
+
prefix = []
|
|
282
285
|
parts.each_slice(2) do |part, sep|
|
|
283
286
|
if ["..", ".", "this"].include? part[1]
|
|
284
|
-
unless
|
|
285
|
-
path =
|
|
287
|
+
unless prefix.empty? || part[2]
|
|
288
|
+
path = prefix.map { _1[1] }.join + part[1]
|
|
286
289
|
# TODO: keep track of the position in the line as well
|
|
287
290
|
raise ParseError, "Invalid path: #{path} - #{loc}"
|
|
288
291
|
end
|
|
289
292
|
next
|
|
290
293
|
end
|
|
291
294
|
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
prefix << part
|
|
296
|
+
prefix << sep if sep
|
|
294
297
|
end
|
|
295
298
|
# TODO: Handle sexpr
|
|
296
299
|
s(:path, data, *parts).line loc
|
|
@@ -333,12 +336,15 @@ def prepare_block(open, program, inverse_chain, close, inverted)
|
|
|
333
336
|
|
|
334
337
|
# TODO: Get close_strip from inverse_chain if close is nil
|
|
335
338
|
|
|
339
|
+
program_line = program&.line
|
|
336
340
|
if inverted
|
|
337
341
|
raise NotImplementedError if inverse_chain
|
|
338
342
|
inverse_chain = s(:inverse, block_params, program, open_strip, close_strip)
|
|
343
|
+
inverse_chain.line program_line if program_line
|
|
339
344
|
program = nil
|
|
340
345
|
else
|
|
341
346
|
program = s(:program, block_params, program)
|
|
347
|
+
program.line program_line if program_line
|
|
342
348
|
end
|
|
343
349
|
|
|
344
350
|
type = directive ? :directive_block : :block
|