liquidscript 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lscript +2 -30
- data/lib/liquidscript/cli.rb +53 -0
- data/lib/liquidscript/compiler/icr/expressions.rb +1 -1
- data/lib/liquidscript/compiler/icr/functions.rb +0 -21
- data/lib/liquidscript/compiler/icr/helpers.rb +19 -0
- data/lib/liquidscript/errors.rb +5 -3
- data/lib/liquidscript/scanner/token.rb +1 -1
- data/lib/liquidscript/version.rb +1 -1
- data/liquidscript.gemspec +1 -0
- data/spec/fixtures/underscore.js +1 -1
- data/spec/fixtures/underscore.liq +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31e6b59cd1bc0b5b1f61bb0514831a060b516c7
|
4
|
+
data.tar.gz: 1d85d0be0209027858d030cc9c8cda978e68b95d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 948fb308df1606bf6ce3d11bd6cda543dbdc321b9fa913ef0ad7e568850f3c7bb01e3a736cf055210ffab8cf1cc1069be2fefac015ca060591bc748a2ef5bcbe
|
7
|
+
data.tar.gz: 5d28502b4a07f1ddaf96840c017f6c88e2a27f944dcf17060f795768d82264b6aa8d2f6b0a94ba85a4c8d0efe89389da869ca3c659a760d12c7777accf9334bb
|
data/bin/lscript
CHANGED
@@ -1,34 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "liquidscript"
|
4
|
+
require "liquidscript/cli"
|
4
5
|
|
5
|
-
|
6
|
-
puts "Usage: #{File.basename($0)} infile [outfile]"
|
7
|
-
exit 1
|
8
|
-
end
|
9
|
-
|
10
|
-
infile = ARGV.shift
|
11
|
-
outfile = ARGV.shift || infile.gsub(/\.liq\Z/, ".js")
|
12
|
-
|
13
|
-
if infile == '-'
|
14
|
-
infile = $stdin
|
15
|
-
else
|
16
|
-
infile = File.open(infile, "r")
|
17
|
-
end
|
18
|
-
|
19
|
-
if outfile == '-'
|
20
|
-
outfile = $stdout
|
21
|
-
else
|
22
|
-
outfile = File.open(outfile, "w")
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
out = Liquidscript.compile(infile.read)
|
27
|
-
outfile.write(out)
|
28
|
-
rescue StandardError => e
|
29
|
-
$stderr.puts "ERROR: #{e.class}: #{e.message}"
|
30
|
-
$stderr.puts e.backtrace[0..5].map { |s| "\t#{s.gsub(/^.*?\/lib\/liquidscript\//, "")}" }.join("\n")
|
31
|
-
ensure
|
32
|
-
[infile, outfile].each(&:close)
|
33
|
-
end
|
34
|
-
|
6
|
+
Liquidscript::CLI.start(ARGV)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module Liquidscript
|
4
|
+
class CLI < Thor
|
5
|
+
|
6
|
+
desc "compile FILES", "Compile the given file to javascript."
|
7
|
+
long_desc <<-LONGDESC
|
8
|
+
It will compile each file listed to javascript. If the file
|
9
|
+
given is `-`, it will check the standard input for file data.
|
10
|
+
By default, this will output to standard output - if this isn't
|
11
|
+
what you want, use the -o option to change it.
|
12
|
+
|
13
|
+
Note that if you pass in multiple files,
|
14
|
+
the last file's compiled output will be in this file (i.e.
|
15
|
+
multiple output files are not yet supported). If you want the
|
16
|
+
output to go to standard output, use `-` as the value.
|
17
|
+
|
18
|
+
> $ lscript compile test.liq
|
19
|
+
LONGDESC
|
20
|
+
option :out, :aliases => :o, :desc => "The output file."
|
21
|
+
def compile(*files)
|
22
|
+
files.each do |file|
|
23
|
+
puts "COMPILING: #{file}"
|
24
|
+
perform_compiliation(file,
|
25
|
+
options[:out] || file.gsub('.liq', '.js'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def perform_compiliation(file, out)
|
32
|
+
infile = if file == '-'
|
33
|
+
$stdin
|
34
|
+
else
|
35
|
+
File.open(file, "r")
|
36
|
+
end
|
37
|
+
|
38
|
+
outfile = if out == '-'
|
39
|
+
$stdout
|
40
|
+
else
|
41
|
+
File.open(out, "w")
|
42
|
+
end
|
43
|
+
|
44
|
+
out = Liquidscript.compile(infile.read)
|
45
|
+
outfile.write(out)
|
46
|
+
rescue StandardError => e
|
47
|
+
$stderr.puts "ERROR: #{e.class}: #{e.message}"
|
48
|
+
$stderr.puts e.backtrace[0..5].map { |s| "\t#{s.gsub(/^.*?\/lib\/liquidscript\//, "")}" }.join("\n")
|
49
|
+
ensure
|
50
|
+
([infile, outfile] - [$stdin, $stdout]).each(&:close)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -39,27 +39,6 @@ module Liquidscript
|
|
39
39
|
call = code :call, subject, *arguments
|
40
40
|
call
|
41
41
|
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
|
45
|
-
def value_expect(v, &default)
|
46
|
-
out = expect \
|
47
|
-
:lparen => action { compile_call(v) },
|
48
|
-
:equal => action { compile_assignment(v) },
|
49
|
-
:prop => action { compile_property(v) },
|
50
|
-
:lbrack => action { compile_access(v) },
|
51
|
-
[:binop,
|
52
|
-
:minus,
|
53
|
-
:plus] => action { compile_binop(v) },
|
54
|
-
:unop => action { |o| code :op, v, o },
|
55
|
-
:_ => default || action { v }
|
56
|
-
|
57
|
-
if out != v
|
58
|
-
value_expect(out)
|
59
|
-
else
|
60
|
-
out
|
61
|
-
end
|
62
|
-
end
|
63
42
|
end
|
64
43
|
end
|
65
44
|
end
|
@@ -14,6 +14,25 @@ module Liquidscript
|
|
14
14
|
def code(type, *args)
|
15
15
|
Liquidscript::ICR::Code.new type, *args
|
16
16
|
end
|
17
|
+
|
18
|
+
def value_expect(v, &default)
|
19
|
+
out = expect \
|
20
|
+
:lparen => action { compile_call(v) },
|
21
|
+
:equal => action { compile_assignment(v) },
|
22
|
+
:prop => action { compile_property(v) },
|
23
|
+
:lbrack => action { compile_access(v) },
|
24
|
+
[:binop,
|
25
|
+
:minus,
|
26
|
+
:plus] => action { compile_binop(v) },
|
27
|
+
:unop => action { |o| code :op, v, o },
|
28
|
+
:_ => default || action { v }
|
29
|
+
|
30
|
+
if out != v
|
31
|
+
value_expect(out)
|
32
|
+
else
|
33
|
+
out
|
34
|
+
end
|
35
|
+
end
|
17
36
|
end
|
18
37
|
end
|
19
38
|
end
|
data/lib/liquidscript/errors.rb
CHANGED
@@ -31,18 +31,20 @@ module Liquidscript
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def build_error_message
|
34
|
-
str = "Expected one of %{expected}, got %{type}"
|
34
|
+
str = "Expected one of %{expected}, got %{type}(%{value})"
|
35
35
|
hash = {
|
36
36
|
:expected => @expected.map { |e| e.to_s.upcase }.join(', ')
|
37
37
|
}
|
38
38
|
|
39
39
|
if @got.is_a? Symbol
|
40
|
-
hash[:type]
|
40
|
+
hash[:type] = @got.to_s.upcase
|
41
|
+
hash[:value] = ""
|
41
42
|
else
|
42
43
|
str << " (line %{line}, column %{column})"
|
43
44
|
hash.merge! :type => @got.type.to_s.upcase,
|
44
45
|
:line => @got.line,
|
45
|
-
:column => @got.column
|
46
|
+
:column => @got.column,
|
47
|
+
:value => @got.value
|
46
48
|
end
|
47
49
|
|
48
50
|
sprintf(str, hash)
|
data/lib/liquidscript/version.rb
CHANGED
data/liquidscript.gemspec
CHANGED
data/spec/fixtures/underscore.js
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
nativeEvery = ArrayProto.every;
|
22
22
|
nativeSome = ArrayProto.some;
|
23
23
|
nativeIndexOf = ArrayProto.indexOf;
|
24
|
-
nativeLastIndexOf =
|
24
|
+
nativeLastIndexOf = ArrayProto.lastIndexOf;
|
25
25
|
nativeIsArray = Array.isArray;
|
26
26
|
nativeKeys = Object.keys;
|
27
27
|
nativeBind = FuncProto.bind;
|
@@ -25,7 +25,7 @@
|
|
25
25
|
nativeEvery = ArrayProto.every
|
26
26
|
nativeSome = ArrayProto.some
|
27
27
|
nativeIndexOf = ArrayProto.indexOf
|
28
|
-
nativeLastIndexOf =
|
28
|
+
nativeLastIndexOf = ArrayProto.lastIndexOf
|
29
29
|
nativeIsArray = Array.isArray
|
30
30
|
nativeKeys = Object.keys
|
31
31
|
nativeBind = FuncProto.bind
|
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.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Rodi
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: thor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: A javascript-based language that compiles to javascript.
|
98
112
|
email:
|
99
113
|
- redjazz96@gmail.com
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- bin/lscript
|
115
129
|
- lib/liquidscript.rb
|
116
130
|
- lib/liquidscript/buffer.rb
|
131
|
+
- lib/liquidscript/cli.rb
|
117
132
|
- lib/liquidscript/compiler.rb
|
118
133
|
- lib/liquidscript/compiler/base.rb
|
119
134
|
- lib/liquidscript/compiler/base/action.rb
|