liquidscript 0.10.4 → 0.11.0.rc1

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: 0c2c527652bdb7ece680508921dffafff168c7cb
4
- data.tar.gz: 9d0c2a6c28d59681080a62cca518ff53f55d00aa
3
+ metadata.gz: 3659bbe0464cee916b09fbfb082e40cbd630c63b
4
+ data.tar.gz: c7708c7a59d1b5ac56edecc2babcd545b21d8321
5
5
  SHA512:
6
- metadata.gz: 2f3e290757fcfb60f4c021d0f0613f0eddbbcf4df8e1b3d81b6d8d8fb6390b2c153be261692ede6961273218f1fdef63581548bc3324798ca7a3a505cf8e5347
7
- data.tar.gz: 970b9501c509db02bcfcebf9fcb93ed11a5603ca7f71bfb5cb3a19357e49bf6fe0f726d7c9ef03421c15188e658ade3d90e612277f070bb66d249de6a389a6ef
6
+ metadata.gz: b0fb9dc4ef32911b666bc9914f64ae198e79be36f6dfad11814671717227d9e5b04b9cfd17868caa3ce40af91a81fe90a17e7333d1ecc4ff8eeb5a5391040364
7
+ data.tar.gz: 4323533b81a1fba55e715b89a5ffa3b8b369c8c46dce386fdf190fda4d4cb8ccf7204e406960848e7ad23a70ffdc765c74d156eb31b27e576d60a0ad7b8259a4
@@ -23,13 +23,13 @@ module Liquidscript
23
23
  puts "COMPILING: #{file}"
24
24
  perform_compiliation(file,
25
25
  options[:out] || file.gsub('.liq', '.js'))
26
- end
26
+ end
27
27
  end
28
28
 
29
29
  desc "syntax FILES", "Syntax check given file"
30
30
  long_desc <<-LONGDESC
31
31
  It will run a syntax check on the file listed. If the file does
32
- not pass the syntax check it will return the error code 1. If
32
+ not pass the syntax check it will return the error code 1. If
33
33
  the file give is - it will check the standard input.
34
34
  LONGDESC
35
35
  def syntax(*files)
@@ -47,45 +47,42 @@ module Liquidscript
47
47
  private
48
48
 
49
49
  def perform_compiliation(file, out)
50
- infile = if file == '-'
51
- $stdin
52
- else
53
- File.open(file, "r")
50
+ open_files(file, out) do |infile, outfile|
51
+ out = Liquidscript.compile(infile.read)
52
+ outfile.write(out)
54
53
  end
54
+ end
55
55
 
56
- outfile = if out == '-'
57
- $stdout
58
- else
59
- File.open(out, "w")
56
+ def preform_syntax_check(file)
57
+ open_files(file) do |infile|
58
+ Liquidscript.compile(infile.read)
59
+ puts "OK"
60
60
  end
61
-
62
- out = Liquidscript.compile(infile.read)
63
- outfile.write(out)
64
- rescue StandardError => e
65
- $stderr.puts "ERROR: #{e.class}: #{e.message}"
66
-
67
- $stderr.puts e.backtrace[0..5].map { |s| "\t#{s.gsub(/^.*?\/lib\/liquidscript\//, "")}" }.join("\n")
68
- exit 1
69
- ensure
70
- ([infile, outfile] - [$stdin, $stdout]).each(&:close)
71
61
  end
72
62
 
73
- def preform_syntax_check(file)
74
- infile = if file == '-'
63
+ def open_files(inf, outf = nil)
64
+ inf = if inf == '-'
75
65
  $stdin
76
66
  else
77
- File.open(file, "r")
67
+ File.open(inf, 'r')
78
68
  end
79
69
 
80
- Liquidscript.compile(infile.read)
81
- puts "OK"
82
- return true
83
- rescue StandardError => e
84
- puts "FAIL"
70
+ outf = if outf == '-'
71
+ $stdout
72
+ elsif outf
73
+ File.open(outf, 'w')
74
+ end
75
+
76
+ begin
77
+ yield inf, outf
78
+ rescue StandardError => e
85
79
  $stderr.puts "ERROR: #{e.class}: #{e.message}"
86
- return false
87
- ensure
88
- ([infile] - [$stdin]).each(&:close)
80
+ $stderr.puts e.backtrace[0..5].map { |s| "\t" +
81
+ s.gsub(/^lib\/liquidscript\//, "") }.join("\n")
82
+ false
83
+ ensure
84
+ ( [ inf, outf].compact - [$stdin, $stdout]).each(&:close)
85
+ end
89
86
  end
90
87
  end
91
88
  end
@@ -3,16 +3,18 @@ module Liquidscript
3
3
  class Base
4
4
  class Callable
5
5
 
6
+ attr_accessor :bind
7
+
6
8
  # Initialize the callable.
7
9
  #
8
10
  # @param bind [Object] the object that holds the method (if
9
11
  # this represents a method call).
10
12
  # @param block [Symbol, Block] if it's a Symbol, it represents
11
13
  # a method on bind; otherwise, it's a pure block.
12
- def initialize(bind, block)
14
+ def initialize(bind, block, prefix = "compile_")
13
15
  @bind = bind
14
16
  @block = if block.is_a? Symbol
15
- :"compile_#{block}"
17
+ :"#{prefix}#{block}"
16
18
  else
17
19
  block
18
20
  end
@@ -1,4 +1,5 @@
1
1
  require "liquidscript/compiler/icr/expressions"
2
+ require "liquidscript/compiler/icr/directives"
2
3
  require "liquidscript/compiler/icr/functions"
3
4
  require "liquidscript/compiler/icr/literals"
4
5
  require "liquidscript/compiler/icr/classes"
@@ -8,9 +9,49 @@ require "liquidscript/compiler/icr/groups"
8
9
 
9
10
  module Liquidscript
10
11
  module Compiler
12
+
13
+ # A list of codes:
14
+ #
15
+ # - :class
16
+ # - :module
17
+ # - :neg
18
+ # - :pos
19
+ # - :binop
20
+ # - :unop
21
+ # - :set
22
+ # - :expression
23
+ # - :property
24
+ # - :access
25
+ # - :call
26
+ # - :function
27
+ # - :if
28
+ # - :elsif
29
+ # - :unless
30
+ # - :else
31
+ # - :try
32
+ # - :catch
33
+ # - :finally
34
+ # - :nrange
35
+ # - :number
36
+ # - :action
37
+ # - :range
38
+ # - :while
39
+ # - :for_in
40
+ # - :for_seg
41
+ # - :regex
42
+ # - :href
43
+ # - :interop
44
+ # - :istring
45
+ # - :sstring
46
+ # - :operator
47
+ # - :keyword
48
+ # - :object
49
+ # - :array
50
+ # - :newline (depricated)
11
51
  class ICR < Base
12
52
 
13
53
  include Expressions
54
+ include Directives
14
55
  include Functions
15
56
  include Literals
16
57
  include Classes
@@ -20,8 +61,6 @@ module Liquidscript
20
61
  # (see Base#initialize)
21
62
  def initialize(*)
22
63
  super
23
-
24
- handle_directives
25
64
  end
26
65
 
27
66
  # (see Base#reset!)
@@ -45,30 +84,8 @@ module Liquidscript
45
84
  compile_expression
46
85
  end
47
86
 
48
- private
49
-
50
- def handle_directives
51
- return unless @scanner.metadata[:directives]
52
-
53
- @scanner.metadata[:directives].each do |meta|
54
- case meta[:command].downcase
55
- when "allow"
56
- variables = meta[:args].split(' ')
57
- variables.map {|x| normalize(x) }.each { |v|
58
- top.context.allow(v.intern) }
59
- when "cvar"
60
- variables = meta[:args].split(' ')
61
- variables.map {|x| normalize(x) }.each { |v|
62
- top.context.set(v.intern,
63
- :class => true).parameter! }
64
- else
65
- raise UnknownDirectiveError.new(meta[:command])
66
- end
67
- end
68
- end
69
-
70
87
  def normalize(s)
71
- s.gsub(/\-[a-z]/) { |p| p[1].upcase }
88
+ s.map { |x| x.gsub(/\-[a-z]/) { |p| p[1].upcase } }
72
89
  end
73
90
  end
74
91
  end
@@ -0,0 +1,79 @@
1
+ module Liquidscript
2
+ module Compiler
3
+ class ICR < Base
4
+ module Directives
5
+ module ClassMethods
6
+
7
+ def directives
8
+ @_directives ||= {}
9
+ end
10
+
11
+ def define_directive(name, body)
12
+ directives[name] = Base::Callable.new(nil, body, "")
13
+ end
14
+
15
+ end
16
+
17
+ module InstanceMethods
18
+
19
+ extend Forwardable
20
+
21
+ def handle_directive(directive)
22
+ command, args = directive[:command], directive[:arguments]
23
+
24
+ callable = directives.fetch(command)
25
+
26
+ callable.bind = self
27
+ callable.call(*args)
28
+
29
+ rescue KeyError
30
+ raise UnknownDirectiveError.new(command)
31
+ end
32
+
33
+ def directives
34
+ @_directives ||= self.class.directives.dup
35
+ end
36
+
37
+ def define_directive(name, body)
38
+ directives[name] = Base::Callable.new(nil, body, "")
39
+ end
40
+
41
+ def directive_allow(*args)
42
+ args.each do |a|
43
+ top.context.allow(a.value.intern)
44
+ end
45
+
46
+ nil
47
+ end
48
+
49
+ def directive_cvar(*args)
50
+ args.each do |a|
51
+ top.context.set(a.value.intern, :class => true).parameter!
52
+ end
53
+
54
+ nil
55
+ end
56
+
57
+ def directive_strict
58
+ top.metadata[:strict] = true
59
+
60
+ nil
61
+ end
62
+
63
+ end
64
+
65
+ def self.included(receiver)
66
+ receiver.extend ClassMethods
67
+ receiver.send :include, InstanceMethods
68
+
69
+ InstanceMethods.instance_methods.each do |m|
70
+ if m.to_s =~ /\A_?directive_([A-Za-z0-9]+)\z/
71
+ receiver.define_directive($1, m)
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -9,7 +9,8 @@ module Liquidscript
9
9
  # @return [ICR::Code]
10
10
  def compile_expression
11
11
  expect :if, :unless, :class, :module, :loop, :for,
12
- :while, :action, :try, :_ => :vexpression
12
+ :while, :action, :try, :return,
13
+ :colon => :directive, :_ => :vexpression
13
14
  end
14
15
 
15
16
  # Compiles an expression that returns a value.
@@ -62,6 +63,11 @@ module Liquidscript
62
63
  code :unop, shift(:unop, :preunop), compile_vexpression
63
64
  end
64
65
 
66
+ def compile_return
67
+ shift :return
68
+ code :return, compile_vexpression
69
+ end
70
+
65
71
  # Handles an assignment of the form `identifier = expression`,
66
72
  # with the argument being the identifier, and the position of
67
73
  # the compiler being after it.
@@ -100,6 +106,30 @@ module Liquidscript
100
106
  end
101
107
  end
102
108
 
109
+ def compile_directive
110
+ shift :colon
111
+ shift :lbrack
112
+ command = shift(:identifier).value
113
+ old, @in_directive = @in_directive, true
114
+ arguments = collect_compiles :rbrack do
115
+ expect :lbrace => action { _compile_block },
116
+ :identifier => action.shift,
117
+ :_ => :vexpression
118
+ end
119
+
120
+ directive = {
121
+ :command => command,
122
+ :arguments => arguments }
123
+
124
+ @in_directive = old
125
+
126
+ if @in_directive
127
+ directive
128
+ else
129
+ handle_directive(directive)
130
+ end
131
+ end
132
+
103
133
  def _compile_lparen_method
104
134
  ident = shift :identifier
105
135
 
@@ -112,6 +142,7 @@ module Liquidscript
112
142
  end
113
143
  end
114
144
 
145
+
115
146
  def _compile_lparen_method_final(ident = nil)
116
147
  components = [ident].compact
117
148
 
@@ -7,6 +7,8 @@ module Liquidscript
7
7
  class GeneratorError < Error; end
8
8
 
9
9
  class UnexpectedEndError < CompileError; end
10
+ class DirectiveError < CompileError; end
11
+
10
12
  class InvalidReferenceError < CompileError
11
13
 
12
14
  def initialize(name)
@@ -14,7 +16,8 @@ module Liquidscript
14
16
  end
15
17
  end
16
18
 
17
- class UnknownDirectiveError < CompileError
19
+
20
+ class UnknownDirectiveError < DirectiveError
18
21
  def initialize(directive)
19
22
  super "Unkown directive: #{directive}"
20
23
  end
@@ -8,12 +8,17 @@ module Liquidscript
8
8
  #
9
9
  # @param code [ICR::Code, #type]
10
10
  # @param context [Hash]
11
- def replace(code)
12
- send(:"generate_#{code.type}",
13
- code)
11
+ def replace(code, options = {})
12
+ method_name = :"generate_#{code.type}"
13
+
14
+ if method(method_name).arity.abs == 1
15
+ send(method_name, code)
16
+ else
17
+ send(method_name, code, options)
18
+ end
14
19
 
15
20
  rescue NoMethodError => e
16
- if e.name == :"generate_#{code.type}"
21
+ if e.name == method_name
17
22
  raise InvalidCodeError.new(code.type)
18
23
  else
19
24
  raise
@@ -21,9 +21,9 @@ module Liquidscript
21
21
  def generate_nrange(code)
22
22
  start = code[1]
23
23
  ending = code[2]
24
-
24
+
25
25
  if (start.to_i - ending.to_i).abs > 50
26
- generate_range(code, true)
26
+ generate_range(code, {}, true)
27
27
  elsif ending > start
28
28
  buffer << "[" << (start..ending).to_a.join(', ') << "]"
29
29
  else
@@ -31,7 +31,7 @@ module Liquidscript
31
31
  end
32
32
  end
33
33
 
34
- def generate_range(code, norep=false)
34
+ def generate_range(code, options = {}, norep = false)
35
35
  out = buffer
36
36
  a = norep ? code[1] : replace(code[1])
37
37
  b = norep ? code[2] : replace(code[2])
@@ -46,7 +46,7 @@ module Liquidscript
46
46
  unindent! << "};\n" <<
47
47
  indent << "return t === undefined ?" <<
48
48
  "out : out.reverse();\n" <<
49
- unindent! << "})(" << a << ", " << b << ")"
49
+ unindent! << "})(" << a << ", " << b << ")"
50
50
  out
51
51
  end
52
52
 
@@ -130,6 +130,10 @@ module Liquidscript
130
130
  "#{code[1].value} #{replace(code[2])}"
131
131
  end
132
132
 
133
+ def generate_return(code)
134
+ "return #{replace(code[1])}"
135
+ end
136
+
133
137
  def generate_href(code)
134
138
  heredoc = code[1]
135
139
  hbuf = buffer
@@ -207,7 +211,7 @@ module Liquidscript
207
211
  "function(" <<
208
212
  code[1].parameters.join(', ') <<
209
213
  ") {\n" <<
210
- replace(code[1])
214
+ replace(code[1], :final_return => true)
211
215
  unindent!
212
216
 
213
217
  function << indent_level << "}"
@@ -3,10 +3,18 @@ module Liquidscript
3
3
  class Javascript
4
4
  module Metas
5
5
 
6
- def generate_exec(code)
6
+ def generate_exec(code, options)
7
7
  exec = buffer
8
+ return exec if code.codes.length == 0
8
9
  exec << _exec_context(code)
9
- insert_into(code.codes, exec)
10
+ insert_into(code.codes[0..-2], exec)
11
+ last = code.codes.last
12
+
13
+ if last.value? && options[:final_return]
14
+ exec << indent << "return #{replace(last)};\n"
15
+ else
16
+ exec << indent << replace(last) << ";\n"
17
+ end
10
18
  end
11
19
 
12
20
  def generate_set(code)
@@ -59,9 +67,11 @@ module Liquidscript
59
67
  protected
60
68
 
61
69
  def _exec_context(code)
70
+ out = buffer
62
71
 
72
+ out << "#{indent}\"use strict\";\n" if code[:strict]
63
73
  unless code.locals.empty?
64
- "#{indent_level}var #{code.locals.join(', ')};\n"
74
+ out << "#{indent_level}var #{code.locals.join(', ')};\n"
65
75
  end
66
76
  end
67
77
  end
@@ -43,6 +43,18 @@ module Liquidscript
43
43
  [@action, *@arguments]
44
44
  end
45
45
 
46
+ # If this code respresents something with a definite
47
+ # value.
48
+ #
49
+ # @return [Boolean]
50
+ def value?
51
+ @_value ||= ![
52
+ :class, :module, :if, :elseif, :unless,
53
+ :else, :try, :catch, :finally, :while, :for_in,
54
+ :for_seg, :return
55
+ ].include?(@action)
56
+ end
57
+
46
58
  # If we don't respond to it, the @arguments array
47
59
  # might. Ask them if they do, and if they don't,
48
60
  # respond accordingly.
@@ -37,6 +37,10 @@ module Liquidscript
37
37
  end
38
38
  end
39
39
 
40
+ def normalize_identifier(ident)
41
+ ident.gsub(/\-[a-z]/) { |p| p[1].upcase }
42
+ end
43
+
40
44
  def line
41
45
  @line
42
46
  end
@@ -35,7 +35,6 @@ module Liquidscript
35
35
  !
36
36
  ~
37
37
  new
38
- return
39
38
  typeof
40
39
  throw
41
40
  )
@@ -82,13 +81,11 @@ module Liquidscript
82
81
  end
83
82
 
84
83
  action :directive do |_, c, a|
85
- metadata[:directives] ||= []
86
- metadata[:directives].push :command => c,
87
- :args => a
84
+ emit :directive, [c, a]
88
85
  end
89
86
 
90
87
  action :identifier do |m|
91
- emit :identifier, m.gsub(/\-[a-z]/) { |p| p[1].upcase }
88
+ emit :identifier, normalize_identifier(m)
92
89
  end
93
90
 
94
91
  set :identifier, %r{[A-Za-z_$]([A-Za-z0-9_$-]*[A-Za-z0-9_$])?}
@@ -104,13 +101,14 @@ module Liquidscript
104
101
  on("try") { emit :try }
105
102
  on("catch") { emit :catch }
106
103
  on("finally") { emit :finally }
104
+ on("return") { emit :return }
107
105
  on(:number) { |m| emit :number, m }
108
106
  on(:string) { |m| emit :sstring, m }
109
107
  on(:keywords) { |m| emit :keyword, m }
110
108
  on(:actions) { |m| emit :action, m }
111
- on(:binops) { |m| emit :binop, m }
112
- on(:preunops) { |m| emit :preunop, m }
113
- on(:unops) { |m| emit :unop, m }
109
+ on(:binops) { |m| emit :binop, m }
110
+ on(:preunops) { |m| emit :preunop, m }
111
+ on(:unops) { |m| emit :unop, m }
114
112
  on(%r{<<([A-Z]+)}, :heredoc)
115
113
  on(%r{<<-([A-Z]+)}, :iheredoc)
116
114
  on(%r{r/((?:.|\/)*)/([gimy]*)}, :regex)
@@ -132,7 +130,7 @@ module Liquidscript
132
130
  on("+") { emit :plus }
133
131
  on("\n") { line! }
134
132
  on(:identifier, :identifier)
135
- on(%r{#! ([A-Za-z]+) ?(.*?)\n}, :directive)
133
+ on(%r{!\[\s*([A-Za-z]+)\s*(.*?)\s*\]\n}, :directive)
136
134
 
137
135
  on(%r{#.*?\n}) { }
138
136
  on(%r{\s}) { }
@@ -13,7 +13,7 @@ module Liquidscript
13
13
  exit
14
14
  end
15
15
  on(%r{#.*?\n}) { }
16
- on("\n") { }
16
+ on(/\s/) { }
17
17
  on(:_) { |m| @buffer << m }
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module Liquidscript
2
2
 
3
3
  # The current version of liquidscript.
4
- VERSION = "0.10.4".freeze
4
+ VERSION = "0.11.0.rc1".freeze
5
5
  end
@@ -1,5 +1,5 @@
1
1
  data: |
2
- #! allow require set-timeout
2
+ :[allow require set-timeout]
3
3
 
4
4
  assert = require('assert)
5
5
 
@@ -52,15 +52,15 @@ compiled: |
52
52
 
53
53
  Test.prototype.initialize = function() {
54
54
  "this should be init";
55
- this.wee();
55
+ return this.wee();
56
56
  };
57
57
 
58
58
  Test.prototype.wee = function() {
59
- console.log(this.someNumber);
59
+ return console.log(this.someNumber);
60
60
  };
61
61
 
62
62
  Test.test = function() {
63
- "class method!";
63
+ return "class method!";
64
64
  };
65
65
  Something.Test = Test;
66
66
 
@@ -73,7 +73,7 @@ compiled: |
73
73
  AnotherTest.prototype.__proto__ = Test.prototype;
74
74
 
75
75
  AnotherTest.prototype.thing = function() {
76
- console.log("[another test]", this.someNumber, this.anotherThing);
76
+ return console.log("[another test]", this.someNumber, this.anotherThing);
77
77
  };
78
78
 
79
79
  Something.AnotherTest = AnotherTest;;
@@ -1,5 +1,5 @@
1
1
  data: |
2
- #! allow require
2
+ :[allow require]
3
3
  Test = require("assert")
4
4
 
5
5
  module SomeModule {
@@ -25,7 +25,7 @@ compiled: |
25
25
  };
26
26
 
27
27
  Thing.prototype.initialize = function() {
28
- this.test = new Test();
28
+ return this.test = new Test();
29
29
  };
30
30
 
31
31
  Thing.prototype.do = function(thing) {
@@ -25,16 +25,16 @@ compiled: |
25
25
  };
26
26
 
27
27
  Greeter.prototype.initialize = function(name) {
28
- this.name = name;
28
+ return this.name = name;
29
29
  };
30
30
 
31
31
  Greeter.prototype.greet = function() {
32
- console.log("Hello " + (this.name) + "!");
32
+ return console.log("Hello " + (this.name) + "!");
33
33
  };
34
34
 
35
35
  Greeter.meet = function(first, second) {
36
36
  new Greeter(first).greet();
37
- new Greeter(second).greet();
37
+ return new Greeter(second).greet();
38
38
  };;
39
39
 
40
40
  Greeter.meet("Alice", "Bob");
@@ -1,6 +1,7 @@
1
1
  data: |
2
2
  console = 2
3
3
  some_function = ()-> {
4
+ :[strict]
4
5
  console = 3
5
6
  test = 0..console
6
7
  }
@@ -10,9 +11,10 @@ compiled: |
10
11
  console = 2;
11
12
 
12
13
  some_function = function() {
14
+ "use strict";
13
15
  var test;
14
16
  console = 3;
15
- test = (function(a, b) {
17
+ return test = (function(a, b) {
16
18
  var out, i, t;
17
19
  out = [];
18
20
  if(a > b) {
@@ -5,6 +5,6 @@ data: |
5
5
  compiled: |
6
6
  var someFunction;
7
7
  someFunction = function() {
8
- console.log("test");
8
+ return console.log("test");
9
9
  };
10
10
  someFunction();
@@ -1,6 +1,5 @@
1
1
  (function() {
2
-
3
- var root,breaker,previousUnderscore,ArrayProto,ObjProto,FuncProto,push,slice,concat,toString,hasOwnProperty,nativeForEach,nativeMap,nativeReduce,nativeReduceRight,nativeFilter,nativeEvery,nativeSome,nativeIndexOf,nativeLastIndexOf,nativeIsArray,nativeKeys,nativeBind,_,each;
2
+ var root, breaker, previousUnderscore, ArrayProto, ObjProto, FuncProto, push, slice, concat, toString, hasOwnProperty, nativeForEach, nativeMap, nativeReduce, nativeReduceRight, nativeFilter, nativeEvery, nativeSome, nativeIndexOf, nativeLastIndexOf, nativeIsArray, nativeKeys, nativeBind, _, each;
4
3
  root = this;
5
4
  breaker = {};
6
5
  previousUnderscore = root._;
@@ -26,16 +25,16 @@
26
25
  nativeKeys = Object.keys;
27
26
  nativeBind = FuncProto.bind;
28
27
  _ = function(obj) {
29
- if( obj instanceof _) {
30
- return obj;
28
+ if(obj instanceof _) {
29
+ return obj;
31
30
  };
32
- if( ! ( this instanceof _)) {
33
- return new _(obj);
31
+ if(! (this instanceof _)) {
32
+ return new _(obj);
34
33
  };
35
- this._wrapped = obj;
34
+ return this._wrapped = obj;
36
35
  };
37
- if( typeof exports !== 'undefined') {
38
- if( typeof root.module !== 'undefined' && root.module.exports) {
36
+ if(typeof exports !== 'undefined') {
37
+ if(typeof root.module !== 'undefined' && root.module.exports) {
39
38
  exports = root.module.exports = _;
40
39
  };
41
40
  exports._ = _;
@@ -43,46 +42,44 @@
43
42
  root._ = _;
44
43
  };
45
44
  _.VERSION = "1.6.0";
46
- each = _.each = _.forEach = function(obj,iterator,context) {
47
-
48
- var i,length,keys;
49
- if( obj === null ) {
50
- return obj;
45
+ each = _.each = _.forEach = function(obj, iterator, context) {
46
+ var i, length, keys;
47
+ if(obj === null) {
48
+ return obj;
51
49
  };
52
- if( nativeForEach && obj.forEach === nativeForEach) {
53
- obj.forEach(iterator,context);
54
- }else if( obj.length === (+obj.length)) {
50
+ if(nativeForEach && obj.forEach === nativeForEach) {
51
+ obj.forEach(iterator, context);
52
+ }else if(obj.length === (+obj.length)) {
55
53
  i = 0;
56
54
  length = obj.length;
57
- for(i = 0; i < length;i++) {
58
- if( iterator.call(context,obj[i],i,obj) === breaker) {
59
- return null ;
60
- };
55
+ for(i = 0; i < length; i++) {
56
+ if(iterator.call(context, obj[i], i, obj) === breaker) {
57
+ return null;
58
+ };
61
59
  };
62
60
  } else {
63
61
  keys = _.keys(obj);
64
62
  length = keys.length;
65
- for(i = 0; i < length;i++) {
66
- if( iterator.call(context,obj[keys[i]],keys[i],obj) === breaker) {
67
- return null ;
68
- };
63
+ for(i = 0; i < length; i++) {
64
+ if(iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) {
65
+ return null;
66
+ };
69
67
  };
70
68
  };
71
- return obj;
69
+ return obj;
72
70
  };
73
- _.map = _.collect = function(obj,iterator,context) {
74
-
71
+ return _.map = _.collect = function(obj, iterator, context) {
75
72
  var results;
76
73
  results = [];
77
- if( obj == null ) {
78
- return results;
74
+ if(obj == null) {
75
+ return results;
79
76
  };
80
- if( nativeMap && obj.map === nativeMap) {
81
- return obj.map(iterator,context);
77
+ if(nativeMap && obj.map === nativeMap) {
78
+ return obj.map(iterator, context);
82
79
  };
83
- each(obj,function(value,index,list) {
84
- results.push(iterator.call(context,value,index,list));
80
+ each(obj, function(value, index, list) {
81
+ return results.push(iterator.call(context, value, index, list));
85
82
  });
86
- return results;
83
+ return results;
87
84
  };
88
85
  }).call();
@@ -1,6 +1,6 @@
1
1
  (-> {
2
2
 
3
- #! allow Array Object Function
3
+ ![ allow Array Object Function ]
4
4
 
5
5
  root = this
6
6
  breaker = {}
@@ -32,7 +32,7 @@
32
32
 
33
33
  _ = (obj)-> {
34
34
  if(obj instanceof _) {
35
- return obj
35
+ obj
36
36
  }
37
37
  if(!(this instanceof _)) {
38
38
  return new _(obj)
@@ -143,36 +143,26 @@ describe Compiler::ICR do
143
143
 
144
144
  describe "invalid directives" do
145
145
  let(:scanner) do
146
- scanner = double("scanner")
147
- iterator = double("iterator")
148
- allow(iterator).to receive(:rewind)
149
-
150
- expect(scanner).to receive(:each).once.and_return(iterator)
151
- expect(scanner).to receive(:metadata).twice.and_return(
152
- {:directives =>
153
- [{:command => "test", :args => ""},
154
- {:command => "allow", :args => "test"}]})
155
- scanner
146
+ s = Liquidscript::Scanner::Liquidscript.new(
147
+ ":[test thing]\n:[allow thing]\n")
148
+ s.scan
149
+ s
156
150
  end
157
151
 
158
152
  it "raises an error" do
159
- expect { subject }.to raise_error(Liquidscript::UnknownDirectiveError)
153
+ expect { subject.compile }.to raise_error(Liquidscript::UnknownDirectiveError)
160
154
  end
161
155
  end
162
156
 
163
157
  describe "directives" do
164
158
  let(:scanner) do
165
- scanner = double("scanner")
166
- iterator = double("iterator")
167
- allow(iterator).to receive(:rewind)
168
-
169
- expect(scanner).to receive(:each).once.and_return(iterator)
170
- expect(scanner).to receive(:metadata).twice.and_return(
171
- {:directives => [{:command => "allow", :args => "test"}]})
172
- scanner
159
+ s = Liquidscript::Scanner::Liquidscript.new(":[allow test]\n")
160
+ s.scan
161
+ s
173
162
  end
174
163
 
175
164
  it "raises an error" do
165
+ subject.compile
176
166
  subject.top.context.get(:test)
177
167
  end
178
168
  end
@@ -45,7 +45,7 @@ describe Liquidscript::Scanner::Liquidscript, :lexer_helper do
45
45
 
46
46
  it "scans keywords" do
47
47
  scan("return test = new foo").should eq [
48
- [:preunop, "return"],
48
+ [:return, nil],
49
49
  [:identifier, "test"],
50
50
  [:equal, nil],
51
51
  [:preunop, "new"],
@@ -75,8 +75,8 @@ describe Liquidscript::Scanner::Liquidscript, :lexer_helper do
75
75
  end
76
76
 
77
77
  describe "scanning directives" do
78
- subject { c = described_class.new("#! test thing\n"); c.scan; c }
79
- its(:metadata) { should eq :directives => [{:command => "test", :args => "thing"}] }
78
+ subject { c = described_class.new("![ test thing ]\n"); c.scan; c }
79
+ its(:tokens) { should eq [[:directive, ["test", "thing"]]] }
80
80
  end
81
81
  end
82
82
  end
@@ -32,7 +32,11 @@ RSpec::Matchers.define :compile do
32
32
  end
33
33
 
34
34
  def actual
35
- (@_out || []).to_a!
35
+ if @_out.respond_to?(:to_a!)
36
+ @_out.to_a!
37
+ else
38
+ @_out
39
+ end
36
40
  end
37
41
 
38
42
  def compiler(data)
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.10.4
4
+ version: 0.11.0.rc1
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-15 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - lib/liquidscript/compiler/base/helpers.rb
138
138
  - lib/liquidscript/compiler/icr.rb
139
139
  - lib/liquidscript/compiler/icr/classes.rb
140
+ - lib/liquidscript/compiler/icr/directives.rb
140
141
  - lib/liquidscript/compiler/icr/expressions.rb
141
142
  - lib/liquidscript/compiler/icr/functions.rb
142
143
  - lib/liquidscript/compiler/icr/groups.rb
@@ -228,9 +229,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
229
  version: '0'
229
230
  required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  requirements:
231
- - - ">="
232
+ - - ">"
232
233
  - !ruby/object:Gem::Version
233
- version: '0'
234
+ version: 1.3.1
234
235
  requirements: []
235
236
  rubyforge_project:
236
237
  rubygems_version: 2.2.2