liquidscript 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lscript +1 -1
- data/lib/liquidscript/buffer.rb +4 -0
- data/lib/liquidscript/compiler/base/helpers.rb +2 -29
- data/lib/liquidscript/compiler/icr/classes.rb +3 -3
- data/lib/liquidscript/compiler/icr/expressions.rb +2 -1
- data/lib/liquidscript/compiler/icr/literals.rb +8 -1
- data/lib/liquidscript/generator/javascript/literals.rb +4 -0
- data/lib/liquidscript/generator/javascript/objects.rb +39 -30
- data/lib/liquidscript/scanner/lexer.rb +8 -7
- data/lib/liquidscript/scanner/lexer.rl +1 -0
- data/lib/liquidscript/scanner/token.rb +4 -0
- data/lib/liquidscript/template.rb +4 -0
- data/lib/liquidscript/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 335eefd0c7fa9b7dcecb5de6e94162a43a7b828c
|
4
|
+
data.tar.gz: 8da6d806da9bb64dd0a83960e70c7ff845ca5488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f20c68ea5800a173dbe16aca753b86c313b2738b89ee5d5ec39edb8b44be8ff79210ebd473d7d475a10fd4cd8a7b156bfc2a083f1202d1eb2618f2a2e6e685ca
|
7
|
+
data.tar.gz: eef30426a1516cdb88ff954e384ec61937c977fd72e2f4287d0fd9871305ba4051afdc8dd7d3b988a076201e95bb780dce113d5e060e9a5c719134cf45615041
|
data/bin/lscript
CHANGED
data/lib/liquidscript/buffer.rb
CHANGED
@@ -3,25 +3,6 @@ module Liquidscript
|
|
3
3
|
class Base
|
4
4
|
module Helpers
|
5
5
|
|
6
|
-
module ClassMethods
|
7
|
-
def allowable
|
8
|
-
@_allowable ||= {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def always(type)
|
12
|
-
case type
|
13
|
-
when Hash
|
14
|
-
allowable.merge!(type)
|
15
|
-
when Symbol
|
16
|
-
allowable[type] = type
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.included(base)
|
22
|
-
base.extend ClassMethods
|
23
|
-
end
|
24
|
-
|
25
6
|
# Normalizes an action for the hash passed to {#expect}. If
|
26
7
|
# a block is given, it returns that block. If the argument is
|
27
8
|
# a proc, it returns that proc. If none of those conditions are
|
@@ -202,13 +183,9 @@ module Liquidscript
|
|
202
183
|
# @return [Object] the result of the block/method call.
|
203
184
|
def expect(*args)
|
204
185
|
hash = normalize_arguments(args)
|
205
|
-
allowable = false
|
206
186
|
|
207
187
|
block = hash.fetch(peek.type) do
|
208
|
-
hash.fetch(:_)
|
209
|
-
allowable = true
|
210
|
-
self.allowable.fetch(peek.type)
|
211
|
-
end
|
188
|
+
hash.fetch(:_)
|
212
189
|
end
|
213
190
|
|
214
191
|
out = if block.arity == 1
|
@@ -217,11 +194,7 @@ module Liquidscript
|
|
217
194
|
block.call
|
218
195
|
end
|
219
196
|
|
220
|
-
|
221
|
-
expect(*args)
|
222
|
-
else
|
223
|
-
out
|
224
|
-
end
|
197
|
+
out
|
225
198
|
|
226
199
|
rescue KeyError
|
227
200
|
raise UnexpectedError.new(hash.keys, peek)
|
@@ -6,18 +6,18 @@ module Liquidscript
|
|
6
6
|
def compile_class
|
7
7
|
shift :class
|
8
8
|
name = shift :identifier
|
9
|
+
set name
|
9
10
|
body = _compile_class_body(false)
|
10
11
|
|
11
|
-
set name
|
12
12
|
code :class, name, body
|
13
13
|
end
|
14
14
|
|
15
15
|
def compile_module
|
16
16
|
shift :module
|
17
17
|
name = shift :identifier
|
18
|
+
set name
|
18
19
|
body = _compile_class_body(true)
|
19
20
|
|
20
|
-
set name
|
21
21
|
code :module, name, body
|
22
22
|
end
|
23
23
|
|
@@ -34,7 +34,7 @@ module Liquidscript
|
|
34
34
|
end
|
35
35
|
|
36
36
|
loop do
|
37
|
-
expect :rbrack => action.end_loop,
|
37
|
+
expect :newline, :rbrack => action.end_loop,
|
38
38
|
:comma => action.shift,
|
39
39
|
:module => action { components << compile_module },
|
40
40
|
:class => action { components << compile_class },
|
@@ -19,12 +19,13 @@ module Liquidscript
|
|
19
19
|
:dstring, :lparen,
|
20
20
|
:sstring, :operator,
|
21
21
|
:keyword, :unop,
|
22
|
+
:newline,
|
22
23
|
:lbrack => :object,
|
23
24
|
:lbrace => :array,
|
24
25
|
:arrow => :function
|
25
26
|
|
26
27
|
if peek? :binop
|
27
|
-
compile_binop
|
28
|
+
compile_binop(out)
|
28
29
|
elsif peek? :prop
|
29
30
|
compile_property(out)
|
30
31
|
else
|
@@ -65,6 +65,13 @@ module Liquidscript
|
|
65
65
|
compile_function_with_parameters([])
|
66
66
|
end
|
67
67
|
|
68
|
+
def compile_newline
|
69
|
+
if peek?(:newline)
|
70
|
+
pop
|
71
|
+
code :newline
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
68
75
|
def compile_function_with_parameters(parameters)
|
69
76
|
shift :arrow
|
70
77
|
shift :lbrack
|
@@ -86,7 +93,7 @@ module Liquidscript
|
|
86
93
|
|
87
94
|
loop do
|
88
95
|
expect :rbrack => action.end_loop,
|
89
|
-
|
96
|
+
:_ => expression
|
90
97
|
end
|
91
98
|
|
92
99
|
code :function, @set.pop
|
@@ -46,37 +46,45 @@ module Liquidscript
|
|
46
46
|
class_name = code[1].value
|
47
47
|
|
48
48
|
in_module(class_name) do |last_module|
|
49
|
-
body
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
body.block <<-JS
|
50
|
+
#{class_name} ||= function #{class_name}() {
|
51
|
+
if(this.initialize) {
|
52
|
+
this.initialize.apply(this, arguments);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
JS
|
54
56
|
|
55
|
-
code[2].each do |
|
57
|
+
code[2].each do |part|
|
58
|
+
k, v = part
|
56
59
|
case k.type
|
57
60
|
when :identifier
|
58
|
-
body
|
59
|
-
|
60
|
-
|
61
|
+
body.block <<-JS
|
62
|
+
#{class_name}.prototype.#{k.value} = #{replace(v)};
|
63
|
+
JS
|
61
64
|
when :dstring
|
62
|
-
body
|
63
|
-
|
64
|
-
|
65
|
+
body.block <<-JS
|
66
|
+
#{class_name}.prototype[#{k.value}] = #{replace(v)};
|
67
|
+
JS
|
65
68
|
when :property
|
66
69
|
if k[1].name != :this
|
67
70
|
raise InvalidCodeError.new(v[1].name)
|
68
71
|
end
|
69
72
|
|
70
|
-
body
|
71
|
-
|
72
|
-
|
73
|
+
body.block <<-JS
|
74
|
+
#{class_name}.#{k[2].value} =
|
75
|
+
#{replace(v)};
|
76
|
+
JS
|
77
|
+
when :class
|
78
|
+
body << generate_class(part)
|
79
|
+
when :module
|
80
|
+
body << generate_module(part)
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
76
84
|
if last_module
|
77
|
-
body
|
78
|
-
|
79
|
-
|
85
|
+
body.block <<-JS
|
86
|
+
#{last_module}.#{class_name} = #{class_name};
|
87
|
+
JS
|
80
88
|
end
|
81
89
|
|
82
90
|
end
|
@@ -89,29 +97,30 @@ module Liquidscript
|
|
89
97
|
module_name = code[1].value
|
90
98
|
|
91
99
|
in_module(module_name) do |last_module|
|
92
|
-
body << "#{module_name}
|
100
|
+
body << "#{module_name} ||= {};"
|
93
101
|
|
94
102
|
code[2].each do |part|
|
95
|
-
k = part
|
96
|
-
v = part[1]
|
103
|
+
k, v = part
|
97
104
|
case k
|
98
105
|
when :identifier
|
99
|
-
body
|
100
|
-
|
101
|
-
|
106
|
+
body.block <<-JS
|
107
|
+
#{module_name}.#{k.value} = #{replace(v)};
|
108
|
+
JS
|
102
109
|
when :dstring
|
103
|
-
body
|
104
|
-
|
105
|
-
|
110
|
+
body.block <<-JS
|
111
|
+
#{module_name}[#{k.value}] = #{replace(v)};
|
112
|
+
JS
|
106
113
|
when :class
|
107
114
|
body << generate_class(part)
|
115
|
+
when :module
|
116
|
+
body << generate_module(part)
|
108
117
|
end
|
109
118
|
end
|
110
119
|
|
111
120
|
if last_module
|
112
|
-
body
|
113
|
-
|
114
|
-
|
121
|
+
body.block <<-JS
|
122
|
+
#{last_module}.#{module_name} = #{module_name};
|
123
|
+
JS
|
115
124
|
end
|
116
125
|
end
|
117
126
|
|
@@ -405,10 +405,11 @@ self.lexer_en_main = 5;
|
|
405
405
|
line = proc do
|
406
406
|
@line[:start] = @ts
|
407
407
|
@line[:num] += 1
|
408
|
+
emit :newline
|
408
409
|
end
|
409
410
|
|
410
411
|
|
411
|
-
# line
|
412
|
+
# line 413 "lib/liquidscript/scanner/lexer.rb"
|
412
413
|
begin
|
413
414
|
@p ||= 0
|
414
415
|
@pe ||= @data.length
|
@@ -418,9 +419,9 @@ begin
|
|
418
419
|
@act = 0
|
419
420
|
end
|
420
421
|
|
421
|
-
# line
|
422
|
+
# line 110 "lib/liquidscript/scanner/lexer.rl"
|
422
423
|
|
423
|
-
# line
|
424
|
+
# line 425 "lib/liquidscript/scanner/lexer.rb"
|
424
425
|
begin
|
425
426
|
_klen, _trans, _keys, _acts, _nacts = nil
|
426
427
|
_goto_level = 0
|
@@ -450,7 +451,7 @@ begin
|
|
450
451
|
begin
|
451
452
|
@ts = @p
|
452
453
|
end
|
453
|
-
# line
|
454
|
+
# line 455 "lib/liquidscript/scanner/lexer.rb"
|
454
455
|
end # from state action switch
|
455
456
|
end
|
456
457
|
if _trigger_goto
|
@@ -746,7 +747,7 @@ when 37 then
|
|
746
747
|
error end
|
747
748
|
end
|
748
749
|
end
|
749
|
-
# line
|
750
|
+
# line 751 "lib/liquidscript/scanner/lexer.rb"
|
750
751
|
end # action switch
|
751
752
|
end
|
752
753
|
end
|
@@ -766,7 +767,7 @@ when 0 then
|
|
766
767
|
# line 1 "NONE"
|
767
768
|
begin
|
768
769
|
@ts = nil; end
|
769
|
-
# line
|
770
|
+
# line 771 "lib/liquidscript/scanner/lexer.rb"
|
770
771
|
end # to state action switch
|
771
772
|
end
|
772
773
|
if _trigger_goto
|
@@ -793,7 +794,7 @@ end
|
|
793
794
|
end
|
794
795
|
end
|
795
796
|
|
796
|
-
# line
|
797
|
+
# line 111 "lib/liquidscript/scanner/lexer.rl"
|
797
798
|
|
798
799
|
clean!
|
799
800
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'liquidscript/icr/sexp'
|
2
|
+
|
1
3
|
module Liquidscript
|
2
4
|
class Template
|
3
5
|
|
@@ -7,8 +9,10 @@ module Liquidscript
|
|
7
9
|
|
8
10
|
def render
|
9
11
|
@_render ||= begin
|
12
|
+
p Scanner.new(@data).each
|
10
13
|
compiler = Compiler::ICR.new(Scanner.new(@data))
|
11
14
|
compiler.compile
|
15
|
+
puts ICR::Sexp.new(compiler.top).output
|
12
16
|
Generator::Javascript.new(compiler.top).generate
|
13
17
|
end
|
14
18
|
end
|
data/lib/liquidscript/version.rb
CHANGED