liquidscript 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4ec0aa9bc7b0c5da0b45f80e5853e726757b105
4
- data.tar.gz: f204c630f37a8b1df5e55e546e2d11e518dc2211
3
+ metadata.gz: b457cb6e151caa8e4c94e6c6f6155a6d4fab540d
4
+ data.tar.gz: 2593be00faad038c0c2d17d5457ccadd1c9b2bba
5
5
  SHA512:
6
- metadata.gz: 1eb628d19238d73a22c0b6991535d9bbc9c85ba912b0e9a4d75a6864d5ec7938e5d1c14a1cafa87e8ec534225f2d9e1bf8880d61cbe42099a1914355be3d4b91
7
- data.tar.gz: a6a58bc3a6f3b201b772c8ed42c6967820f5b3765adffc8fb7b5e7bda49b4a5d4a9e5af66885ae1d1957b8470eb7695da0b376f2e1a7232686e929922b307971
6
+ metadata.gz: 1147b9665936ae2f33b883d189a5ba9aee3c758e084fcb4a929cad9bfe5e3cfa0ad3c880f20ca21176751b9646e8622c7fb34e9800e89e4ec533567b41a4a51e
7
+ data.tar.gz: bf1684054f962f5d6ef81b553ec83d5d3995f6ef814ede497d54d53b61fe091f4b5cf33844ab1eed930f57704ecdf9c4a807559f2c59628f3cea32344a490fdf
@@ -90,61 +90,44 @@ module Liquidscript
90
90
  # @return [ICR::Code]
91
91
  def compile_lparen
92
92
  shift :lparen
93
- maybe_func = 1
94
- components = []
95
93
 
96
- unless peek?(:identifier, :rparen)
97
- maybe_func = 0
94
+ if peek?(:identifier)
95
+ _compile_lparen_method
96
+ elsif peek?(:rparen)
97
+ _compile_lparen_method_final
98
+ else
99
+ _compile_lparen_expression
98
100
  end
101
+ end
99
102
 
100
- expression = action do
101
- maybe_func = 0
102
- components << compile_vexpression
103
- end
103
+ def _compile_lparen_method
104
+ ident = shift :identifier
104
105
 
105
- ident = action do |i|
106
- if peek?(:comma)
107
- maybe_func = 2
108
- components << i
109
- elsif peek?(:rparen)
110
- components << i
111
- else
112
- components << value_expect(compile_identifier(i))
113
- end
106
+ if peek?(:comma, :rparen)
107
+ _compile_lparen_method_final(ident)
108
+ else
109
+ value_expect(ident)
114
110
  end
111
+ end
115
112
 
116
- loop do
117
- case maybe_func
118
- when 0
119
- expect :rparen => action.end_loop,
120
- :_ => expression
121
- when 1
122
- expect :rparen => action.end_loop,
123
- :comma => action { maybe_func = 2 },
124
- :identifier => ident,
125
- :_ => expression
126
- when 2
127
- expect :rparen => action.end_loop,
128
- :comma => action.shift,
129
- :identifier => action { |i| components << i }
130
- end
113
+ def _compile_lparen_method_final(ident = nil)
114
+ components = [ident].compact
115
+
116
+ while peek?(:comma) do
117
+ shift(:comma)
118
+ components << shift(:identifier)
131
119
  end
132
120
 
133
- func_decl = (maybe_func == 1 && peek?(:arrow)) ||
134
- (maybe_func == 2)
121
+ shift :rparen
122
+ compile_function_with_parameters(components)
123
+ end
135
124
 
136
- if func_decl
137
- compile_function_with_parameters(components)
138
- else
139
- code(:expression, components.map do |c|
140
- if c.is_a?(Scanner::Token)
141
- compile_identifier(c)
142
- else
143
- c
144
- end
145
- end)
146
- end
125
+ def _compile_lparen_expression
126
+ out = compile_vexpression
127
+ shift :rparen
128
+ code :expression, out
147
129
  end
130
+
148
131
  end
149
132
  end
150
133
  end
@@ -20,8 +20,7 @@ module Liquidscript
20
20
  continue = [:elsif, :else]
21
21
  end
22
22
 
23
- shift :lbrace
24
- body = collect_compiles(:expression, :rbrace)
23
+ body = _compile_block
25
24
 
26
25
  args = [type]
27
26
  args << conditional if cond
@@ -15,6 +15,15 @@ module Liquidscript
15
15
  Liquidscript::ICR::Code.new type, *args
16
16
  end
17
17
 
18
+ def _compile_block
19
+ if peek?(:lbrace)
20
+ shift :lbrace
21
+ collect_compiles(:expression, :rbrace)
22
+ else
23
+ compile_expression
24
+ end
25
+ end
26
+
18
27
  def value_expect(v, &default)
19
28
  out = expect \
20
29
  :lparen => action { compile_call(v) },
@@ -16,8 +16,7 @@ module Liquidscript
16
16
  shift :lparen
17
17
  conditional = compile_vexpression
18
18
  shift :rparen
19
- shift :lbrace
20
- body = collect_compiles(:expression, :rbrace)
19
+ body = _compile_block
21
20
  code :while, conditional, body
22
21
  end
23
22
 
@@ -44,10 +43,9 @@ module Liquidscript
44
43
 
45
44
  obj = shift :identifier
46
45
  shift :rparen
47
- shift :lbrace
48
46
 
49
47
  set ident
50
- body = collect_compiles(:expression, :rbrace)
48
+ body = _compile_block
51
49
  code :for_in, ident, ref(obj), body
52
50
  end
53
51
 
@@ -58,9 +56,8 @@ module Liquidscript
58
56
  shift :comma
59
57
  third = compile_vexpression
60
58
  shift :rparen
61
- shift :lbrace
62
59
 
63
- body = collect_compiles(:expression, :rbrace)
60
+ body = _compile_block
64
61
  code :for_seg, first, second, third, body
65
62
  end
66
63
 
@@ -136,11 +136,10 @@ module Liquidscript
136
136
  def generate_object(code)
137
137
 
138
138
  object = buffer
139
- object.set_join! ', '
140
- indent!
139
+ object.set_join! ",\n#{indent!}"
141
140
 
142
141
  code[1].inject(object) do |buf, part|
143
- buf << "#{indent_level}\"#{part[0].value}\": #{replace(part[1])}"
142
+ buf << "\"#{part[0].value}\": #{replace(part[1])}"
144
143
  end
145
144
 
146
145
  unindent!
@@ -4,7 +4,7 @@ module Liquidscript
4
4
  module Objects
5
5
 
6
6
  def generate_expression(code)
7
- "(#{replace(code[1].first)})"
7
+ "(#{replace(code[1])})"
8
8
  end
9
9
 
10
10
  def generate_call(code)
@@ -107,14 +107,14 @@ module Liquidscript
107
107
  on(:string) { |m| emit :sstring, m }
108
108
  on(:keywords) { |m| emit :keyword, m }
109
109
  on(:actions) { |m| emit :action, m }
110
+ on(:binops) { |m| emit :binop, m }
111
+ on(:preunops) { |m| emit :preunop, m }
112
+ on(:unops) { |m| emit :unop, m }
110
113
  on(%r{<<([A-Z]+)}, :heredoc)
111
114
  on(%r{<<-([A-Z]+)}, :iheredoc)
112
- on(%r{/(.*?)/([a-z]*)}, :regex)
115
+ on(%r{r/(.*?)/([gimy]*)}, :regex)
113
116
  on(%r{"} => :istring)
114
117
  on("///" => :block_regex)
115
- on(:binops) { |m| emit :binop, m }
116
- on(:preunops) { |m| emit :preunop, m }
117
- on(:unops) { |m| emit :unop, m }
118
118
  on("->") { emit :arrow }
119
119
  on("=") { emit :equal }
120
120
  on("{") { emit :lbrace }
@@ -1,5 +1,5 @@
1
1
  module Liquidscript
2
2
 
3
3
  # The current version of liquidscript.
4
- VERSION = "0.8.2".freeze
4
+ VERSION = "0.9.0".freeze
5
5
  end
@@ -1,4 +1,7 @@
1
1
  data: |
2
2
  (2)
3
+ #! allow Math
4
+ Math.round(5 / (10 / 100) * 100)
3
5
 
4
- compiled: "(2);"
6
+
7
+ compiled: "(2); Math.round(5 / (10 / 100) * 100);"
@@ -1,7 +1,7 @@
1
1
  data: |
2
2
  object = { hello: "world" }
3
3
  test = [1, 2]
4
- regex = /^test/
4
+ regex = r/^test/
5
5
  block = ///
6
6
  ^test # comment
7
7
  ///
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler