liquidscript 0.7.9 → 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DOCS.md +38 -38
- data/README.md +3 -3
- data/Rakefile +1 -12
- data/lib/liquidscript/scanner/base.rb +0 -10
- data/lib/liquidscript/scanner/base/builder.rb +10 -3
- data/lib/liquidscript/scanner/base/context.rb +11 -3
- data/lib/liquidscript/scanner/base/dsl.rb +6 -0
- data/lib/liquidscript/scanner/liquidscript.rb +9 -179
- data/lib/liquidscript/scanner/liquidscript/heredocs.rb +48 -0
- data/lib/liquidscript/scanner/liquidscript/interpolations.rb +29 -0
- data/lib/liquidscript/scanner/liquidscript/main.rb +143 -0
- data/lib/liquidscript/scanner/liquidscript/regexs.rb +23 -0
- data/lib/liquidscript/version.rb +1 -1
- data/liquidscript.gemspec +1 -1
- data/spec/fixtures/loop.generate.yml +4 -4
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa6813dd7423118bc79edd0654d2c926aea7cc4
|
4
|
+
data.tar.gz: bc2d4a9cdb74029426eb4a7ae2e0477a6f747b97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3727c77d679eedf9345c64706dbdebe34bd341cb347f620af008797b5bafec07c8cc66e4faa1af62dff9459e2317400e661499a704ed8743f1afe148449ed752
|
7
|
+
data.tar.gz: b12d5d6667cb08cda48577141ec3bfcbb186b2c5e7106917db2ab1d8cca37b2a8d7c62d6d4212800e1934571fc36eb0b735a118ca1a6603f2982f5a2ad61ee5a
|
data/DOCS.md
CHANGED
@@ -23,11 +23,11 @@ Liquidscript has a very similar syntax to Javascript.
|
|
23
23
|
# This is a comment
|
24
24
|
something = 2
|
25
25
|
some_string = something.toString()
|
26
|
-
|
26
|
+
|
27
27
|
if(some_string == '2) {
|
28
28
|
console.log("It lives!")
|
29
29
|
}
|
30
|
-
|
30
|
+
|
31
31
|
The thing that should stand out to you the most there is the lack of an end quote to the single quotes in the if conditional. This is on purpose - a ending single quote is optional.
|
32
32
|
|
33
33
|
Note that there are also no semicolons (they don't exist in the language), and no `var` statement. The `var` statement is made automagically by liquidscript, so you don't have to.
|
@@ -39,11 +39,11 @@ Note that there are also no semicolons (they don't exist in the language), and n
|
|
39
39
|
Liquidscript has a very finite set of string literals - the only two options (so far) are double quotes and single quotes. There are plans to introduce heredocs. Double quotes are multiline, whereas **single quotes are limited to the same characters that identifiers are limited to**. This is so that keys for objects (in the `object[key]` syntax feels more natural (i.e., `object['key]`). Some examples:
|
40
40
|
|
41
41
|
string = "hello
|
42
|
-
|
42
|
+
|
43
43
|
world" # this'll translate to "hello\n\nworld"
|
44
|
-
|
44
|
+
|
45
45
|
single = 'test # there doesn't need to be an endquote here.
|
46
|
-
|
46
|
+
|
47
47
|
That's it!
|
48
48
|
|
49
49
|
#### Functions
|
@@ -51,22 +51,22 @@ That's it!
|
|
51
51
|
Functions are defined using the arrow syntax:
|
52
52
|
|
53
53
|
some_function = -> {}
|
54
|
-
|
54
|
+
|
55
55
|
Brackets are **not** optional. The parameter list before the arrow, however, is. If you want something like coffeescript's fat arrow syntax, something like the following would have to be done:
|
56
56
|
|
57
57
|
self = this
|
58
|
-
|
58
|
+
|
59
59
|
some_function = -> {
|
60
60
|
# Change this to whatever property you wanted.
|
61
61
|
self.whatever
|
62
62
|
}
|
63
|
-
|
63
|
+
|
64
64
|
A parameter list works exactly like you'd expect:
|
65
65
|
|
66
66
|
some_function = (a, b, c)-> {
|
67
67
|
console.log(a, b, c)
|
68
68
|
}
|
69
|
-
|
69
|
+
|
70
70
|
some_function(1, 2, 3)
|
71
71
|
|
72
72
|
#### Numeric
|
@@ -80,16 +80,16 @@ There are numbers in liquidscript as well. It follows the JSON spec on this to
|
|
80
80
|
Arrays and objects are exactly like in javascript:
|
81
81
|
|
82
82
|
array = [1, "test", 'foo, bar]
|
83
|
-
|
83
|
+
|
84
84
|
object = {
|
85
85
|
test: "hello",
|
86
86
|
foo: "world" # a colon here is allowed
|
87
87
|
}
|
88
|
-
|
88
|
+
|
89
89
|
### Controls
|
90
90
|
|
91
91
|
Liquidscript has control statements like `if`, and `else`. Liquidscript uses `elsif` instead of `else if`.
|
92
|
-
|
92
|
+
|
93
93
|
if(some_variable == 2) {
|
94
94
|
console.log("It's 2!")
|
95
95
|
} elsif(some_variable == 3) {
|
@@ -108,18 +108,18 @@ This is where liquidscript gets interesting, in my opinion. Modules are extreme
|
|
108
108
|
module SomeModule {
|
109
109
|
VERSION: "1.7.0"
|
110
110
|
}
|
111
|
-
|
111
|
+
|
112
112
|
SomeModule.VERSION # => 1.7.0
|
113
|
-
|
113
|
+
|
114
114
|
That compiles directly to:
|
115
115
|
|
116
116
|
var SomeModule;
|
117
117
|
SomeModule = {
|
118
118
|
VERSION: "1.7.0"
|
119
119
|
};
|
120
|
-
|
120
|
+
|
121
121
|
SomeModule.VERSION; // => 1.7.0
|
122
|
-
|
122
|
+
|
123
123
|
The point of modules, however, is to bind code together into units, in an easier to read syntax. Commas are not needed between definitions, and other modules and classes can be defined within modules.
|
124
124
|
|
125
125
|
module SomeModule {
|
@@ -128,17 +128,17 @@ The point of modules, however, is to bind code together into units, in an easier
|
|
128
128
|
VERSION_MAJOR: 1
|
129
129
|
VERSION_MINOR: 7
|
130
130
|
VERSION_PATCH: 0
|
131
|
-
|
131
|
+
|
132
132
|
version: -> {
|
133
133
|
return SomeModule.OtherModule.VERSION.split('.')
|
134
134
|
}
|
135
135
|
}
|
136
136
|
}
|
137
|
-
|
137
|
+
|
138
138
|
Which compiles directly to:
|
139
139
|
|
140
140
|
var SomeModule, OtherModule;
|
141
|
-
|
141
|
+
|
142
142
|
SomeModule = {
|
143
143
|
OtherModule: {
|
144
144
|
VERSION: "1.7.0",
|
@@ -150,79 +150,79 @@ Which compiles directly to:
|
|
150
150
|
}
|
151
151
|
}
|
152
152
|
};
|
153
|
-
|
153
|
+
|
154
154
|
#### Classes
|
155
155
|
|
156
156
|
Classes are meant to be instantized with the `new` keyword. They are defined very similarly to modules, but when values are defined, they default to being defined on the instance of the class:
|
157
157
|
|
158
158
|
class Greeter {
|
159
|
-
# This is a special function that is called whenever a
|
159
|
+
# This is a special function that is called whenever a
|
160
160
|
# new greeter is created.
|
161
161
|
initialize: (name)-> {
|
162
162
|
this.name = name
|
163
163
|
}
|
164
|
-
|
164
|
+
|
165
165
|
greet: -> {
|
166
166
|
console.log("Hello %s!", this.name)
|
167
167
|
}
|
168
168
|
}
|
169
|
-
|
169
|
+
|
170
170
|
new Greeter("Alice").greet()
|
171
|
-
|
171
|
+
|
172
172
|
This would translate directly to this:
|
173
173
|
|
174
174
|
var Greeter;
|
175
|
-
|
175
|
+
|
176
176
|
Greeter = function Greeter() {
|
177
177
|
if(this.initialize) {
|
178
178
|
this.initialize.apply(this, arguments);
|
179
179
|
}
|
180
180
|
};
|
181
|
-
|
181
|
+
|
182
182
|
Greeter.prototype.initialize = function(name) {
|
183
183
|
this.name = name;
|
184
184
|
};
|
185
|
-
|
185
|
+
|
186
186
|
Greeter.prototype.greet = function() {
|
187
187
|
console.log("Hello %s!", this.name);
|
188
188
|
};
|
189
|
-
|
189
|
+
|
190
190
|
new Greeter("Alice").greet()
|
191
|
-
|
191
|
+
|
192
192
|
This uses the functional prototype system in order to create instances of classes. Inheritance is not yet supported, but there will be progress towards it.
|
193
193
|
|
194
194
|
If you want a method defined on the class itself instead of the instance, prefix the function name with `this`:
|
195
195
|
|
196
196
|
class Greeter {
|
197
|
-
# This is a special function that is called whenever a
|
197
|
+
# This is a special function that is called whenever a
|
198
198
|
# new greeter is created.
|
199
199
|
initialize: (name)-> {
|
200
200
|
this.name = name
|
201
201
|
}
|
202
|
-
|
202
|
+
|
203
203
|
greet: -> {
|
204
204
|
console.log("Hello %s!", this.name)
|
205
205
|
}
|
206
|
-
|
206
|
+
|
207
207
|
self.meet: (first, second)-> {
|
208
208
|
new Greeter(first).greet()
|
209
209
|
new Greeter(second).greet()
|
210
210
|
}
|
211
211
|
}
|
212
|
-
|
212
|
+
|
213
213
|
Greeter.meet("Alice", "Bob")
|
214
|
-
|
214
|
+
|
215
215
|
This translates roughly to:
|
216
216
|
|
217
217
|
// ...
|
218
|
-
|
218
|
+
|
219
219
|
Greeter.meet = function(first, second) {
|
220
220
|
new Greeter(first).greet()
|
221
221
|
new Greeter(second).greet()
|
222
222
|
}
|
223
|
-
|
223
|
+
|
224
224
|
// ...
|
225
|
-
|
225
|
+
|
226
226
|
# The End!
|
227
227
|
|
228
|
-
That wraps it all up! If you're interested in more, checkout the [github repository](https://github.com/
|
228
|
+
That wraps it all up! If you're interested in more, checkout the [github repository](https://github.com/medcat/liquidscript) and read the documentation.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ![Liquidscript](http://i.imgur.com/xbdhTsr.png)
|
2
2
|
|
3
|
-
[![Build Status](http://img.shields.io/travis/
|
3
|
+
[![Build Status](http://img.shields.io/travis/medcat/liquidscript.svg)](https://travis-ci.org/medcat/liquidscript) [![Coverage Status](http://img.shields.io/coveralls/medcat/liquidscript.svg)](https://coveralls.io/r/medcat/liquidscript?branch=master) [![Code Climate](http://img.shields.io/codeclimate/github/medcat/liquidscript.svg)](https://codeclimate.com/github/medcat/liquidscript) [![Gem Version](http://img.shields.io/gem/v/liquidscript.svg)](http://badge.fury.io/rb/liquidscript) [![Dependency Status](https://gemnasium.com/medcat/liquidscript.svg)](https://gemnasium.com/medcat/liquidscript) [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://choosealicense.com/licenses/mit/)
|
4
4
|
|
5
5
|
A javascript-based language that compiles to javascript.
|
6
6
|
|
@@ -17,7 +17,7 @@ And then execute:
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
19
|
$ gem install liquidscript
|
20
|
-
|
20
|
+
|
21
21
|
If you're using Sprockets in your application, place this in
|
22
22
|
your Gemfile:
|
23
23
|
|
@@ -57,7 +57,7 @@ func()
|
|
57
57
|
|
58
58
|
## Contributing
|
59
59
|
|
60
|
-
1. Fork it ( http://github.com/
|
60
|
+
1. Fork it ( http://github.com/medcat/liquidscript/fork )
|
61
61
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
62
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
63
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -5,21 +5,10 @@ require "rspec/core/rake_task"
|
|
5
5
|
RSpec::Core::RakeTask.new('spec')
|
6
6
|
|
7
7
|
namespace :ls do
|
8
|
-
rule '.rb' => ['.rl'] do |t|
|
9
|
-
sh "ragel -R #{t.source}"
|
10
|
-
end
|
11
|
-
|
12
|
-
#desc "Builds the ragel parser."
|
13
|
-
#task :ragel => ["lib/liquidscript/scanner/lexer.rb"]
|
14
|
-
|
15
8
|
desc "Opens up a pry session."
|
16
|
-
task :pry
|
9
|
+
task :pry do
|
17
10
|
require "pry"
|
18
11
|
require File.expand_path("../lib/liquidscript", __FILE__)
|
19
12
|
Pry.start
|
20
13
|
end
|
21
|
-
|
22
|
-
task :clean do
|
23
|
-
File.unlink("lib/liquidscript/scanner/lexer.rb")
|
24
|
-
end
|
25
14
|
end
|
@@ -22,9 +22,16 @@ module Liquidscript
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def context(name)
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
case name
|
26
|
+
when Symbol
|
27
|
+
context = Context.new(name)
|
28
|
+
context.instance_exec(&Proc.new)
|
29
|
+
contexts << context
|
30
|
+
when Module
|
31
|
+
name.contexts.each do |context|
|
32
|
+
contexts << context
|
33
|
+
end
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def reset!
|
@@ -6,9 +6,14 @@ module Liquidscript
|
|
6
6
|
attr_reader :name
|
7
7
|
|
8
8
|
def initialize(name)
|
9
|
-
@name
|
9
|
+
@name = name
|
10
10
|
@matches = {}
|
11
|
-
@temps
|
11
|
+
@temps = {}
|
12
|
+
@actions = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def action(name, &block)
|
16
|
+
@actions[name] = block
|
12
17
|
end
|
13
18
|
|
14
19
|
def find_matcher(with)
|
@@ -42,13 +47,16 @@ module Liquidscript
|
|
42
47
|
normalize_matcher @temps[key]
|
43
48
|
end
|
44
49
|
|
45
|
-
def on(matcher)
|
50
|
+
def on(matcher, action = nil)
|
46
51
|
key = nil
|
47
52
|
value = nil
|
48
53
|
|
49
54
|
if block_given?
|
50
55
|
key = normalize_matcher matcher
|
51
56
|
value = Proc.new
|
57
|
+
elsif action
|
58
|
+
key = normalize_matcher matcher
|
59
|
+
value = @actions.fetch(action)
|
52
60
|
else
|
53
61
|
key = normalize_matcher matcher.keys.first
|
54
62
|
value = matcher.values.first
|
@@ -1,3 +1,8 @@
|
|
1
|
+
require "liquidscript/scanner/liquidscript/main"
|
2
|
+
require "liquidscript/scanner/liquidscript/regexs"
|
3
|
+
require "liquidscript/scanner/liquidscript/heredocs"
|
4
|
+
require "liquidscript/scanner/liquidscript/interpolations"
|
5
|
+
|
1
6
|
module Liquidscript
|
2
7
|
module Scanner
|
3
8
|
class Liquidscript < Base
|
@@ -9,185 +14,10 @@ module Liquidscript
|
|
9
14
|
define do
|
10
15
|
default_context :main
|
11
16
|
|
12
|
-
context
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
([eE][+-]?[0-9]+)? # scientific notation
|
17
|
-
}x
|
18
|
-
|
19
|
-
set :string, %r{
|
20
|
-
'
|
21
|
-
[A-Za-z0-9_$\-\/\.]+
|
22
|
-
'?
|
23
|
-
}x
|
24
|
-
|
25
|
-
set :unops, %w(
|
26
|
-
++
|
27
|
-
--
|
28
|
-
)
|
29
|
-
|
30
|
-
set :preunops, %w(
|
31
|
-
!
|
32
|
-
~
|
33
|
-
new
|
34
|
-
return
|
35
|
-
typeof
|
36
|
-
throw
|
37
|
-
)
|
38
|
-
|
39
|
-
set :actions, %w(
|
40
|
-
break
|
41
|
-
continue
|
42
|
-
)
|
43
|
-
|
44
|
-
set :binops, %w(
|
45
|
-
* / ^
|
46
|
-
<< >> >>>
|
47
|
-
=== ==
|
48
|
-
!== !=
|
49
|
-
>= >
|
50
|
-
<= <
|
51
|
-
&& ||
|
52
|
-
& |
|
53
|
-
instanceof
|
54
|
-
or and
|
55
|
-
)
|
56
|
-
|
57
|
-
set :keywords, %w(
|
58
|
-
undefined
|
59
|
-
null
|
60
|
-
true
|
61
|
-
false
|
62
|
-
)
|
63
|
-
|
64
|
-
set :identifier, %r{[A-Za-z_$]([A-Za-z0-9_$-]*[A-Za-z0-9_$])?}
|
65
|
-
|
66
|
-
on("class") { emit :class }
|
67
|
-
on("module") { emit :module }
|
68
|
-
on("if") { emit :if }
|
69
|
-
on("unless") { emit :unless }
|
70
|
-
on("elsif") { emit :elsif }
|
71
|
-
on("else") { emit :else }
|
72
|
-
on("for") { emit :for }
|
73
|
-
on("while") { emit :while }
|
74
|
-
on("try") { emit :try }
|
75
|
-
on("catch") { emit :catch }
|
76
|
-
on("finally") { emit :finally }
|
77
|
-
on(:number) { |m| emit :number, m }
|
78
|
-
on(:string) { |m| emit :sstring, m }
|
79
|
-
on(:keywords) { |m| emit :keyword, m }
|
80
|
-
on(:actions) { |m| emit :action, m }
|
81
|
-
on("->") { emit :arrow }
|
82
|
-
on("=") { emit :equal }
|
83
|
-
on("{") { emit :lbrace }
|
84
|
-
on("(") { emit :lparen }
|
85
|
-
on("[") { emit :lbrack }
|
86
|
-
on("}") { emit :rbrace }
|
87
|
-
on(")") { emit :rparen }
|
88
|
-
on("]") { emit :rbrack }
|
89
|
-
on(":") { emit :colon }
|
90
|
-
on(".") { emit :prop }
|
91
|
-
on(",") { emit :comma }
|
92
|
-
on("-") { emit :minus }
|
93
|
-
on("+") { emit :plus }
|
94
|
-
on("\n") { line! }
|
95
|
-
on(%r{"} => :istring)
|
96
|
-
on(%r{<<([A-Z]+)}) do |_, s|
|
97
|
-
emit :heredoc_ref, s
|
98
|
-
@lexes << [:heredoc, s]
|
99
|
-
end
|
100
|
-
on(%r{<<-([A-Z]+)}) do |_, s|
|
101
|
-
emit :iheredoc_ref, s
|
102
|
-
@lexes << [:iheredoc, s]
|
103
|
-
end
|
104
|
-
on(%r{/(.*?)/([a-z]*)}) { |_, m, b|
|
105
|
-
emit :regex, [m, b]
|
106
|
-
}
|
107
|
-
on("///" => :block_regex)
|
108
|
-
on(:binops) { |m| emit :binop, m }
|
109
|
-
on(:preunops) { |m| emit :preunop, m }
|
110
|
-
on(:unops) { |m| emit :unop, m }
|
111
|
-
|
112
|
-
on(:identifier) { |m| emit :identifier, m.gsub(/\-[a-z]/) { |p| p[1].upcase } }
|
113
|
-
|
114
|
-
on(%r{#! ([A-Za-z]+) ?(.*?)\n}) do |_, c, a|
|
115
|
-
metadata[:directives] ||= []
|
116
|
-
metadata[:directives].push :command => c,
|
117
|
-
:args => a
|
118
|
-
end
|
119
|
-
|
120
|
-
on(%r{#.*?\n}) { }
|
121
|
-
on(%r{\s}) { }
|
122
|
-
on(:_) { |m| error }
|
123
|
-
end
|
124
|
-
|
125
|
-
context :istring do
|
126
|
-
init { @buffer = [] }
|
127
|
-
|
128
|
-
on('\\"') { |m| @buffer << m }
|
129
|
-
on('"') do
|
130
|
-
emit :istring, @buffer.join
|
131
|
-
exit
|
132
|
-
end
|
133
|
-
|
134
|
-
on(%r{\#\{(.*?)\}}) do |_, b|
|
135
|
-
emit :istring_begin, @buffer.join
|
136
|
-
lex :main => b
|
137
|
-
@buffer = []
|
138
|
-
end
|
139
|
-
|
140
|
-
on(:_) { |m| @buffer << m }
|
141
|
-
end
|
142
|
-
|
143
|
-
context :heredoc do
|
144
|
-
init { @buffer = [] }
|
145
|
-
|
146
|
-
on(%r{\n\s*([A-Z]+)\s*\n}) do |_, s|
|
147
|
-
if @start == s
|
148
|
-
emit :heredoc, @buffer.join
|
149
|
-
exit
|
150
|
-
else
|
151
|
-
@buffer << _
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
on(:_) { |m| @buffer << m }
|
156
|
-
end
|
157
|
-
|
158
|
-
context :iheredoc do
|
159
|
-
init { @buffer = [] }
|
160
|
-
|
161
|
-
on(%r{\n\s*([A-Z]+)\s*\n}) do |_, s|
|
162
|
-
if @start == s
|
163
|
-
emit :iheredoc, @buffer.join
|
164
|
-
@start = nil
|
165
|
-
exit
|
166
|
-
else
|
167
|
-
@buffer << _
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
on(%r{\#\{(.*?)\}}) do |_, b|
|
172
|
-
emit :iheredoc_begin, @buffer.join
|
173
|
-
lex :main => b
|
174
|
-
@buffer = []
|
175
|
-
end
|
176
|
-
|
177
|
-
on(:_) { |m| @buffer << m }
|
178
|
-
end
|
179
|
-
|
180
|
-
context :block_regex do
|
181
|
-
init { @buffer = [] }
|
182
|
-
|
183
|
-
on(%r{///([a-z]*)}) do |_, m|
|
184
|
-
emit :regex, [@buffer.join, m]
|
185
|
-
exit
|
186
|
-
end
|
187
|
-
on(%r{#.*?\n}) { }
|
188
|
-
on("\n") { }
|
189
|
-
on(:_) { |m| @buffer << m }
|
190
|
-
end
|
17
|
+
context Main
|
18
|
+
context Regexs
|
19
|
+
context Heredocs
|
20
|
+
context Interpolations
|
191
21
|
end
|
192
22
|
|
193
23
|
def initialize(*)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Liquidscript
|
2
|
+
module Scanner
|
3
|
+
class Liquidscript < Base
|
4
|
+
module Heredocs
|
5
|
+
include Base::DSL
|
6
|
+
|
7
|
+
define do
|
8
|
+
context :heredoc do
|
9
|
+
init { @buffer = [] }
|
10
|
+
|
11
|
+
on(%r{\n\s*([A-Z]+)\s*\n}) do |_, s|
|
12
|
+
if @start == s
|
13
|
+
emit :heredoc, @buffer.join
|
14
|
+
exit
|
15
|
+
else
|
16
|
+
@buffer << _
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
on(:_) { |m| @buffer << m }
|
21
|
+
end
|
22
|
+
|
23
|
+
context :iheredoc do
|
24
|
+
init { @buffer = [] }
|
25
|
+
|
26
|
+
on(%r{\n\s*([A-Z]+)\s*\n}) do |_, s|
|
27
|
+
if @start == s
|
28
|
+
emit :iheredoc, @buffer.join
|
29
|
+
@start = nil
|
30
|
+
exit
|
31
|
+
else
|
32
|
+
@buffer << _
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
on(%r{\#\{(.*?)\}}) do |_, b|
|
37
|
+
emit :iheredoc_begin, @buffer.join
|
38
|
+
lex :main => b
|
39
|
+
@buffer = []
|
40
|
+
end
|
41
|
+
|
42
|
+
on(:_) { |m| @buffer << m }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Liquidscript
|
2
|
+
module Scanner
|
3
|
+
class Liquidscript < Base
|
4
|
+
module Interpolations
|
5
|
+
include Base::DSL
|
6
|
+
|
7
|
+
define do
|
8
|
+
context :istring do
|
9
|
+
init { @buffer = [] }
|
10
|
+
|
11
|
+
on('\\"') { |m| @buffer << m }
|
12
|
+
on('"') do
|
13
|
+
emit :istring, @buffer.join
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
on(%r{\#\{(.*?)\}}) do |_, b|
|
18
|
+
emit :istring_begin, @buffer.join
|
19
|
+
lex :main => b
|
20
|
+
@buffer = []
|
21
|
+
end
|
22
|
+
|
23
|
+
on(:_) { |m| @buffer << m }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module Liquidscript
|
2
|
+
module Scanner
|
3
|
+
class Liquidscript < Base
|
4
|
+
module Main
|
5
|
+
include Base::DSL
|
6
|
+
|
7
|
+
define do
|
8
|
+
context :main do
|
9
|
+
set :number, %r{
|
10
|
+
-? (
|
11
|
+
( # hex notation
|
12
|
+
0x([0-9a-f]+)
|
13
|
+
)
|
14
|
+
|
|
15
|
+
( # decimal or octal notation
|
16
|
+
([1-9][0-9]* | 0) # the base of the number
|
17
|
+
(\.[0-9]+)? # decmial portion, if needed
|
18
|
+
([eE][+-]?[0-9]+)? # scientific notation
|
19
|
+
)
|
20
|
+
)
|
21
|
+
}x
|
22
|
+
|
23
|
+
set :string, %r{
|
24
|
+
'
|
25
|
+
[A-Za-z0-9_$\-\/\.]+
|
26
|
+
'?
|
27
|
+
}x
|
28
|
+
|
29
|
+
set :unops, %w(
|
30
|
+
++
|
31
|
+
--
|
32
|
+
)
|
33
|
+
|
34
|
+
set :preunops, %w(
|
35
|
+
!
|
36
|
+
~
|
37
|
+
new
|
38
|
+
return
|
39
|
+
typeof
|
40
|
+
throw
|
41
|
+
)
|
42
|
+
|
43
|
+
set :actions, %w(
|
44
|
+
break
|
45
|
+
continue
|
46
|
+
)
|
47
|
+
|
48
|
+
set :binops, %w(
|
49
|
+
* / ^
|
50
|
+
<< >> >>>
|
51
|
+
=== ==
|
52
|
+
!== !=
|
53
|
+
>= >
|
54
|
+
<= <
|
55
|
+
&& ||
|
56
|
+
+= -= /= *=
|
57
|
+
& |
|
58
|
+
instanceof
|
59
|
+
or and
|
60
|
+
)
|
61
|
+
|
62
|
+
set :keywords, %w(
|
63
|
+
undefined
|
64
|
+
null
|
65
|
+
true
|
66
|
+
false
|
67
|
+
)
|
68
|
+
|
69
|
+
action :heredoc do |_, s|
|
70
|
+
emit :heredoc_ref, s
|
71
|
+
@lexes << [:heredoc, s]
|
72
|
+
end
|
73
|
+
|
74
|
+
action :iheredoc do |_, s|
|
75
|
+
emit :iheredoc_ref, s
|
76
|
+
@lexes << [:iheredoc, s]
|
77
|
+
end
|
78
|
+
|
79
|
+
action :regex do |_, m, b|
|
80
|
+
emit :regex, [m, b]
|
81
|
+
end
|
82
|
+
|
83
|
+
action :directive do |_, c, a|
|
84
|
+
metadata[:directives] ||= []
|
85
|
+
metadata[:directives].push :command => c,
|
86
|
+
:args => a
|
87
|
+
end
|
88
|
+
|
89
|
+
action :identifier do |m|
|
90
|
+
emit :identifier, m.gsub(/\-[a-z]/) { |p| p[1].upcase }
|
91
|
+
end
|
92
|
+
|
93
|
+
set :identifier, %r{[A-Za-z_$]([A-Za-z0-9_$-]*[A-Za-z0-9_$])?}
|
94
|
+
|
95
|
+
on("class") { emit :class }
|
96
|
+
on("module") { emit :module }
|
97
|
+
on("if") { emit :if }
|
98
|
+
on("unless") { emit :unless }
|
99
|
+
on("elsif") { emit :elsif }
|
100
|
+
on("else") { emit :else }
|
101
|
+
on("for") { emit :for }
|
102
|
+
on("while") { emit :while }
|
103
|
+
on("try") { emit :try }
|
104
|
+
on("catch") { emit :catch }
|
105
|
+
on("finally") { emit :finally }
|
106
|
+
on(:number) { |m| emit :number, m }
|
107
|
+
on(:string) { |m| emit :sstring, m }
|
108
|
+
on(:keywords) { |m| emit :keyword, m }
|
109
|
+
on(:actions) { |m| emit :action, m }
|
110
|
+
on(%r{<<([A-Z]+)}, :heredoc)
|
111
|
+
on(%r{<<-([A-Z]+)}, :iheredoc)
|
112
|
+
on(%r{/(.*?)/([a-z]*)}, :regex)
|
113
|
+
on(%r{"} => :istring)
|
114
|
+
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
|
+
on("->") { emit :arrow }
|
119
|
+
on("=") { emit :equal }
|
120
|
+
on("{") { emit :lbrace }
|
121
|
+
on("(") { emit :lparen }
|
122
|
+
on("[") { emit :lbrack }
|
123
|
+
on("}") { emit :rbrace }
|
124
|
+
on(")") { emit :rparen }
|
125
|
+
on("]") { emit :rbrack }
|
126
|
+
on(":") { emit :colon }
|
127
|
+
on(".") { emit :prop }
|
128
|
+
on(",") { emit :comma }
|
129
|
+
on("-") { emit :minus }
|
130
|
+
on("+") { emit :plus }
|
131
|
+
on("\n") { line! }
|
132
|
+
on(:identifier, :identifier)
|
133
|
+
on(%r{#! ([A-Za-z]+) ?(.*?)\n}, :directive)
|
134
|
+
|
135
|
+
on(%r{#.*?\n}) { }
|
136
|
+
on(%r{\s}) { }
|
137
|
+
on(:_) { |m| error }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Liquidscript
|
2
|
+
module Scanner
|
3
|
+
class Liquidscript < Base
|
4
|
+
module Regexs
|
5
|
+
include Base::DSL
|
6
|
+
|
7
|
+
define do
|
8
|
+
context :block_regex do
|
9
|
+
init { @buffer = [] }
|
10
|
+
|
11
|
+
on(%r{///([a-z]*)}) do |_, m|
|
12
|
+
emit :regex, [@buffer.join, m]
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
on(%r{#.*?\n}) { }
|
16
|
+
on("\n") { }
|
17
|
+
on(:_) { |m| @buffer << m }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/liquidscript/version.rb
CHANGED
data/liquidscript.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["redjazz96@gmail.com"]
|
11
11
|
spec.summary = %q{A javascript-based language that compiles to javascript.}
|
12
12
|
spec.description = %q{A javascript-based language that compiles to javascript.}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/medcat/liquidscript"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -1,16 +1,16 @@
|
|
1
1
|
data: |
|
2
|
-
t =
|
2
|
+
t = 0x5
|
3
3
|
|
4
4
|
while(t > 0) {
|
5
5
|
t--
|
6
6
|
}
|
7
7
|
|
8
|
-
for(t = 0, t < 5, t
|
8
|
+
for(t = 0, t < 5, t += 1) {
|
9
9
|
console.log(t)
|
10
10
|
}
|
11
11
|
|
12
12
|
compiled: |
|
13
13
|
var t;
|
14
|
-
t =
|
14
|
+
t = 0x5;
|
15
15
|
while(t > 0) { t--; };
|
16
|
-
for(t = 0; t < 5; t
|
16
|
+
for(t = 0; t < 5; t += 1) { console.log(t); };
|
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.7.
|
4
|
+
version: 0.7.10
|
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-03-
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -167,6 +167,10 @@ files:
|
|
167
167
|
- lib/liquidscript/scanner/base/dsl.rb
|
168
168
|
- lib/liquidscript/scanner/base/lexer.rb
|
169
169
|
- lib/liquidscript/scanner/liquidscript.rb
|
170
|
+
- lib/liquidscript/scanner/liquidscript/heredocs.rb
|
171
|
+
- lib/liquidscript/scanner/liquidscript/interpolations.rb
|
172
|
+
- lib/liquidscript/scanner/liquidscript/main.rb
|
173
|
+
- lib/liquidscript/scanner/liquidscript/regexs.rb
|
170
174
|
- lib/liquidscript/scanner/token.rb
|
171
175
|
- lib/liquidscript/template.rb
|
172
176
|
- lib/liquidscript/version.rb
|
@@ -207,7 +211,7 @@ files:
|
|
207
211
|
- spec/support/matchers/compile.rb
|
208
212
|
- spec/support/matchers/generate.rb
|
209
213
|
- spec/support/matchers/run.rb
|
210
|
-
homepage: https://github.com/
|
214
|
+
homepage: https://github.com/medcat/liquidscript
|
211
215
|
licenses:
|
212
216
|
- MIT
|
213
217
|
metadata: {}
|