liquidscript 0.1.5 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b993303ff76055d48e2917eb3dafc43eb42bbded
4
- data.tar.gz: b58b4343a667bae9cd1291d6102be0c366d078ba
3
+ metadata.gz: 335eefd0c7fa9b7dcecb5de6e94162a43a7b828c
4
+ data.tar.gz: 8da6d806da9bb64dd0a83960e70c7ff845ca5488
5
5
  SHA512:
6
- metadata.gz: d13485994da269958fee2b0fed2eb887a6e515cffaa40aa2b4f47e5ec946075bfa743a184160996680b91ddd6ba696747b61b4e9fc1a1b7d94b3ac8727586b3a
7
- data.tar.gz: 8f4bc24c3c0e6dcb8b15c0b611b78228f659774c48082883f300399341d411c04fe0bf32044926d8e997df9a5e25dee2ae943128cb1bdc4bdb80a040d7a0168f
6
+ metadata.gz: f20c68ea5800a173dbe16aca753b86c313b2738b89ee5d5ec39edb8b44be8ff79210ebd473d7d475a10fd4cd8a7b156bfc2a083f1202d1eb2618f2a2e6e685ca
7
+ data.tar.gz: eef30426a1516cdb88ff954e384ec61937c977fd72e2f4287d0fd9871305ba4051afdc8dd7d3b988a076201e95bb780dce113d5e060e9a5c719134cf45615041
data/bin/lscript CHANGED
@@ -13,5 +13,5 @@ outfile = ARGV.shift || infile.gsub(/\.ls\Z/, ".js")
13
13
  File.open(infile, "r") do |f|
14
14
  out = Liquidscript::Template.new(f.read).render
15
15
 
16
- File.open(outfile, "w") { |f| f.write out }
16
+ File.open(outfile, "w") { |o| o.write out }
17
17
  end
@@ -13,6 +13,10 @@ module Liquidscript
13
13
  self
14
14
  end
15
15
 
16
+ def block(str)
17
+ append str.gsub(/^[ \t]+/, '')
18
+ end
19
+
16
20
  def set_join!(to)
17
21
  @_join = to
18
22
  end
@@ -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(:_) do
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
- if allowable
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 out
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
- :_ => expression
96
+ :_ => expression
90
97
  end
91
98
 
92
99
  code :function, @set.pop
@@ -67,6 +67,10 @@ module Liquidscript
67
67
  "[#{array}]"
68
68
  end
69
69
 
70
+ def generate_newline(_)
71
+ "\n"
72
+ end
73
+
70
74
  def generate_function(code)
71
75
 
72
76
  function = buffer
@@ -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
- "#{class_name} = function #{class_name}(){" <<
51
- "if(this.initialize) {" <<
52
- "this.initialize.apply(this, arguments);" <<
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 |(k, v)|
57
+ code[2].each do |part|
58
+ k, v = part
56
59
  case k.type
57
60
  when :identifier
58
- body <<
59
- "#{class_name}.prototype.#{k.value} =" <<
60
- replace(v) << ";"
61
+ body.block <<-JS
62
+ #{class_name}.prototype.#{k.value} = #{replace(v)};
63
+ JS
61
64
  when :dstring
62
- body <<
63
- "#{class_name}.prototype[#{k.value}] =" <<
64
- replace(v) << ";"
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
- "#{class_name}.#{k[2].value} = " <<
72
- replace(v) << ";"
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
- "#{last_module}.#{class_name} = " <<
79
- "#{class_name};"
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[0]
96
- v = part[1]
103
+ k, v = part
97
104
  case k
98
105
  when :identifier
99
- body <<
100
- "#{module_name}.#{k.value} = " <<
101
- replace(v) << ";"
106
+ body.block <<-JS
107
+ #{module_name}.#{k.value} = #{replace(v)};
108
+ JS
102
109
  when :dstring
103
- body <<
104
- "#{module_name}[#{k.value}] = " <<
105
- replace(v) << ";"
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
- "#{last_module}.#{module_name} = " <<
114
- "#{module_name};"
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 "lib/liquidscript/scanner/lexer.rb"
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 109 "lib/liquidscript/scanner/lexer.rl"
422
+ # line 110 "lib/liquidscript/scanner/lexer.rl"
422
423
 
423
- # line 424 "lib/liquidscript/scanner/lexer.rb"
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 "lib/liquidscript/scanner/lexer.rb"
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 "lib/liquidscript/scanner/lexer.rb"
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 "lib/liquidscript/scanner/lexer.rb"
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 110 "lib/liquidscript/scanner/lexer.rl"
797
+ # line 111 "lib/liquidscript/scanner/lexer.rl"
797
798
 
798
799
  clean!
799
800
 
@@ -103,6 +103,7 @@ module Liquidscript
103
103
  line = proc do
104
104
  @line[:start] = @ts
105
105
  @line[:num] += 1
106
+ emit :newline
106
107
  end
107
108
 
108
109
  %% write init;
@@ -31,6 +31,10 @@ module Liquidscript
31
31
  @type == type
32
32
  end
33
33
 
34
+ def empty?
35
+ false
36
+ end
37
+
34
38
  end
35
39
 
36
40
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Liquidscript
2
2
 
3
3
  # The current version of liquidscript.
4
- VERSION = "0.1.5".freeze
4
+ VERSION = "0.2.0".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi