nscript 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -39
- data/examples/code.js +231 -0
- data/examples/code.ns +48 -48
- data/examples/helloworld.js +36 -0
- data/examples/helloworld.ns +21 -4
- data/lib/nscript/lexer/lexer.rb +2 -2
- data/lib/nscript/lexer/rewriter.rb +2 -2
- data/lib/nscript/parser/grammar.y +2 -2
- data/lib/nscript/parser/parser.rb +2 -2
- data/lib/nscript/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125322d11e31a3976f010f737cb393e5fe5cb46d35c8be9fd9e1a08a937389ac
|
4
|
+
data.tar.gz: 1645bbe93bd86812037c8062503fd3d057e5511c461c040d61f7557a3b006137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9083e1d9f8b584060d577c1ee8b93bd471c4ce7f0d01d266b30dcba349b241d8aab725942f9fb58a20e34c1c744558db7d5ba134d93f47eb9f84e346d0e335f
|
7
|
+
data.tar.gz: af02179710eecc5e09b49e9b73751a1877db287624527d2a400801602edda95f6672c70811b584b319df0c62a14b095e3ba22adffb7cf339ebf4fe6adbea8215
|
data/README.md
CHANGED
@@ -1,43 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# NScript
|
2
2
|
|
3
|
-
|
3
|
+
NScript is a little language that compiles into JavaScript
|
4
4
|
|
5
|
-
|
5
|
+
To install the compiler
|
6
|
+
```sh
|
7
|
+
gem install nscript
|
8
|
+
```
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'nscript'
|
10
|
+
Compile a script
|
11
|
+
```sh
|
12
|
+
nscript /path/to/script.ns
|
13
13
|
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install nscript
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nscript. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the Nscript project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nscript/blob/master/CODE_OF_CONDUCT.md).
|
data/examples/code.js
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
(function(){
|
2
|
+
var Animal, Horse, Snake, __a, __b, __c, __d, __e, __f, a, a_googol, activity, b, bottle, c, change_a_and_set_b, decoration, dense_object_literal, eldest, empty, even, exponents, food, good, hex, i, infinity, multiline, nan, negative, odd, race, run_loop, sam, spaced_out_multiline_object, square, stooges, story, sum, supper, three_to_six, tom, v_1, v_2, wednesday, wine, zero_to_nine;
|
3
|
+
// Functions:
|
4
|
+
square = function square(x) {
|
5
|
+
return x * x;
|
6
|
+
};
|
7
|
+
sum = function sum(x, y) {
|
8
|
+
return x + y;
|
9
|
+
};
|
10
|
+
odd = function odd(x) {
|
11
|
+
return x % 2 !== 0;
|
12
|
+
};
|
13
|
+
even = function even(x) {
|
14
|
+
return x % 2 === 0;
|
15
|
+
};
|
16
|
+
run_loop = function run_loop() {
|
17
|
+
fire_events(function(e) {
|
18
|
+
return e.stopPropagation();
|
19
|
+
});
|
20
|
+
listen();
|
21
|
+
return wait();
|
22
|
+
};
|
23
|
+
// Objects:
|
24
|
+
dense_object_literal = {
|
25
|
+
one: 1,
|
26
|
+
two: 2,
|
27
|
+
three: 3
|
28
|
+
};
|
29
|
+
spaced_out_multiline_object = {
|
30
|
+
pi: 3.14159,
|
31
|
+
list: [1, 2, 3, 4],
|
32
|
+
regex: /match[ing](every|thing|\/)/gi,
|
33
|
+
three: new Idea(),
|
34
|
+
inner_obj: {
|
35
|
+
freedom: function freedom() {
|
36
|
+
return _.freedom();
|
37
|
+
}
|
38
|
+
}
|
39
|
+
};
|
40
|
+
// Arrays:
|
41
|
+
stooges = [{
|
42
|
+
moe: 45
|
43
|
+
}, {
|
44
|
+
curly: 43
|
45
|
+
}, {
|
46
|
+
larry: 46
|
47
|
+
}
|
48
|
+
];
|
49
|
+
exponents = [function(x) {
|
50
|
+
return x;
|
51
|
+
}, function(x) {
|
52
|
+
return x * x;
|
53
|
+
}, function(x) {
|
54
|
+
return x * x * x;
|
55
|
+
}
|
56
|
+
];
|
57
|
+
empty = [];
|
58
|
+
multiline = ['line one', 'line two'];
|
59
|
+
// Conditionals and ternaries.
|
60
|
+
if (submarine.shields_up) {
|
61
|
+
full_speed_ahead();
|
62
|
+
fire_torpedos();
|
63
|
+
} else if (submarine.sinking) {
|
64
|
+
abandon_ship();
|
65
|
+
} else {
|
66
|
+
run_away();
|
67
|
+
}
|
68
|
+
eldest = 25 > 21 ? liz : marge;
|
69
|
+
if (war_hero) {
|
70
|
+
decoration = medal_of_honor;
|
71
|
+
}
|
72
|
+
if (!(coffee)) {
|
73
|
+
go_to_sleep();
|
74
|
+
}
|
75
|
+
// Returning early:
|
76
|
+
race = function race() {
|
77
|
+
run();
|
78
|
+
walk();
|
79
|
+
crawl();
|
80
|
+
if (tired) {
|
81
|
+
return sleep();
|
82
|
+
}
|
83
|
+
return race();
|
84
|
+
};
|
85
|
+
// Conditional assignment:
|
86
|
+
good = good || evil;
|
87
|
+
wine = wine && cheese;
|
88
|
+
// Nested property access and calls.
|
89
|
+
((moon.turn(360))).shapes[3].move({
|
90
|
+
x: 45,
|
91
|
+
y: 30
|
92
|
+
}).position['top'].offset('x');
|
93
|
+
a = (b = (c = 5));
|
94
|
+
// Embedded JavaScript.
|
95
|
+
callback(function(e) { e.stop(); });
|
96
|
+
// Try/Catch/Finally/Throw.
|
97
|
+
try {
|
98
|
+
all_hell_breaks_loose();
|
99
|
+
dogs_and_cats_living_together();
|
100
|
+
throw "up";
|
101
|
+
} catch (error) {
|
102
|
+
print(error);
|
103
|
+
} finally {
|
104
|
+
clean_up();
|
105
|
+
}
|
106
|
+
try {
|
107
|
+
all_hell_breaks_loose();
|
108
|
+
} catch (error) {
|
109
|
+
print(error);
|
110
|
+
} finally {
|
111
|
+
clean_up();
|
112
|
+
}
|
113
|
+
// While loops, break and continue.
|
114
|
+
while (demand > supply) {
|
115
|
+
sell();
|
116
|
+
restock();
|
117
|
+
}
|
118
|
+
while (supply > demand) {
|
119
|
+
buy();
|
120
|
+
}
|
121
|
+
while (true) {
|
122
|
+
if (broken) {
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
if (continuing) {
|
126
|
+
continue;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
// Unary operators.
|
130
|
+
!!true;
|
131
|
+
// Lexical scoping.
|
132
|
+
v_1 = 5;
|
133
|
+
change_a_and_set_b = function change_a_and_set_b() {
|
134
|
+
var v_2;
|
135
|
+
v_1 = 10;
|
136
|
+
return v_2 = 15;
|
137
|
+
};
|
138
|
+
v_2 = 20;
|
139
|
+
// Array comprehensions.
|
140
|
+
supper = (function() {
|
141
|
+
__a = []; __b = ['toast', 'cheese', 'wine'];
|
142
|
+
for (__c = 0; __c < __b.length; __c++) {
|
143
|
+
food = __b[__c];
|
144
|
+
__a.push(food.capitalize());
|
145
|
+
}
|
146
|
+
return __a;
|
147
|
+
}).call(this);
|
148
|
+
__d = ['soda', 'wine', 'lemonade'];
|
149
|
+
for (i = 0; i < __d.length; i++) {
|
150
|
+
bottle = __d[i];
|
151
|
+
even(i) ? drink(bottle) : null;
|
152
|
+
}
|
153
|
+
// Switch statements ("else" serves as a default).
|
154
|
+
activity = (function() {
|
155
|
+
if (day === "Tuesday") {
|
156
|
+
return eat_breakfast();
|
157
|
+
} else if (day === "Sunday") {
|
158
|
+
return go_to_church();
|
159
|
+
} else if (day === "Saturday") {
|
160
|
+
return go_to_the_park();
|
161
|
+
} else if (day === "Wednesday") {
|
162
|
+
if (day === bingo_day) {
|
163
|
+
return go_to_bingo();
|
164
|
+
} else {
|
165
|
+
eat_breakfast();
|
166
|
+
go_to_work();
|
167
|
+
return eat_dinner();
|
168
|
+
}
|
169
|
+
} else {
|
170
|
+
return go_to_work();
|
171
|
+
}
|
172
|
+
}).call(this);
|
173
|
+
// Semicolons can optionally be used instead of newlines.
|
174
|
+
wednesday = function wednesday() {
|
175
|
+
eat_breakfast();
|
176
|
+
go_to_work();
|
177
|
+
return eat_dinner();
|
178
|
+
};
|
179
|
+
// Array slice literals.
|
180
|
+
zero_to_nine = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
181
|
+
three_to_six = zero_to_nine.slice(3, 6 + 1);
|
182
|
+
// Multiline strings with inner quotes.
|
183
|
+
story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit, \
|
184
|
+
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna \
|
185
|
+
aliquam erat volutpat. Ut wisi enim ad.";
|
186
|
+
// Inheritance and calling super.
|
187
|
+
Animal = function Animal() { };
|
188
|
+
Animal.prototype.move = function move(meters) {
|
189
|
+
return alert(this.name + " moved " + meters + "m.");
|
190
|
+
};
|
191
|
+
Snake = function Snake(name) {
|
192
|
+
var __e;
|
193
|
+
__e = this.name = name;
|
194
|
+
return Snake === this.constructor ? this : __e;
|
195
|
+
};
|
196
|
+
__e = function(){};
|
197
|
+
__e.prototype = Animal.prototype;
|
198
|
+
Snake.__superClass__ = Animal.prototype;
|
199
|
+
Snake.prototype = new __e();
|
200
|
+
Snake.prototype.constructor = Snake;
|
201
|
+
Snake.prototype.move = function move() {
|
202
|
+
alert('Slithering...');
|
203
|
+
return Snake.__superClass__.move.call(this, 5);
|
204
|
+
};
|
205
|
+
Horse = function Horse(name) {
|
206
|
+
var __f;
|
207
|
+
__f = this.name = name;
|
208
|
+
return Horse === this.constructor ? this : __f;
|
209
|
+
};
|
210
|
+
__f = function(){};
|
211
|
+
__f.prototype = Animal.prototype;
|
212
|
+
Horse.__superClass__ = Animal.prototype;
|
213
|
+
Horse.prototype = new __f();
|
214
|
+
Horse.prototype.constructor = Horse;
|
215
|
+
Horse.prototype.move = function move() {
|
216
|
+
alert('Galloping...');
|
217
|
+
return Horse.__superClass__.move.call(this, 45);
|
218
|
+
};
|
219
|
+
sam = new Snake("Sammy the Snake");
|
220
|
+
tom = new Horse("Tommy the Horse");
|
221
|
+
sam.move();
|
222
|
+
tom.move();
|
223
|
+
// Numbers.
|
224
|
+
a_googol = 1e100;
|
225
|
+
hex = 0xff0000;
|
226
|
+
negative = -1.0;
|
227
|
+
infinity = Infinity;
|
228
|
+
nan = NaN;
|
229
|
+
// Deleting.
|
230
|
+
delete secret.identity;
|
231
|
+
})();
|
data/examples/code.ns
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
# Functions:
|
2
|
-
square
|
2
|
+
square -> (x): x * x
|
3
3
|
|
4
|
-
sum
|
4
|
+
sum -> (x, y): x + y
|
5
5
|
|
6
|
-
odd
|
6
|
+
odd -> (x): x % 2 isnt 0
|
7
7
|
|
8
|
-
even
|
8
|
+
even -> (x): x % 2 is 0
|
9
9
|
|
10
|
-
run_loop
|
11
|
-
fire_events((e)
|
10
|
+
run_loop -> :
|
11
|
+
fire_events((e): e.stopPropagation())
|
12
12
|
listen()
|
13
13
|
wait()
|
14
14
|
|
15
15
|
# Objects:
|
16
|
-
dense_object_literal
|
16
|
+
dense_object_literal -> {one -> 1, two -> 2, three -> 3}
|
17
17
|
|
18
|
-
spaced_out_multiline_object
|
19
|
-
pi
|
20
|
-
list
|
21
|
-
regex
|
22
|
-
three
|
18
|
+
spaced_out_multiline_object -> {
|
19
|
+
pi -> 3.14159
|
20
|
+
list -> [1, 2, 3, 4]
|
21
|
+
regex -> /match[ing](every|thing|\/)/gi
|
22
|
+
three -> new Idea()
|
23
23
|
|
24
|
-
inner_obj
|
25
|
-
freedom
|
24
|
+
inner_obj -> {
|
25
|
+
freedom -> : _.freedom()
|
26
26
|
}
|
27
27
|
}
|
28
28
|
|
29
29
|
# Arrays:
|
30
|
-
stooges
|
30
|
+
stooges -> [{moe -> 45}, {curly -> 43}, {larry -> 46}]
|
31
31
|
|
32
|
-
exponents
|
32
|
+
exponents -> [(x): x, (x): x * x, (x): x * x * x]
|
33
33
|
|
34
|
-
empty
|
34
|
+
empty -> []
|
35
35
|
|
36
|
-
multiline
|
36
|
+
multiline -> [
|
37
37
|
'line one'
|
38
38
|
'line two'
|
39
39
|
]
|
@@ -47,14 +47,14 @@ else if submarine.sinking
|
|
47
47
|
else
|
48
48
|
run_away()
|
49
49
|
|
50
|
-
eldest
|
50
|
+
eldest -> if 25 > 21 then liz else marge
|
51
51
|
|
52
|
-
decoration
|
52
|
+
decoration -> medal_of_honor if war_hero
|
53
53
|
|
54
54
|
go_to_sleep() unless coffee
|
55
55
|
|
56
56
|
# Returning early:
|
57
|
-
race
|
57
|
+
race -> :
|
58
58
|
run()
|
59
59
|
walk()
|
60
60
|
crawl()
|
@@ -66,9 +66,9 @@ good ||= evil
|
|
66
66
|
wine &&= cheese
|
67
67
|
|
68
68
|
# Nested property access and calls.
|
69
|
-
((moon.turn(360))).shapes[3].move({x
|
69
|
+
((moon.turn(360))).shapes[3].move({x -> 45, y -> 30}).position['top'].offset('x')
|
70
70
|
|
71
|
-
a
|
71
|
+
a -> b -> c -> 5
|
72
72
|
|
73
73
|
# Embedded JavaScript.
|
74
74
|
callback(
|
@@ -102,19 +102,19 @@ while true
|
|
102
102
|
!!true
|
103
103
|
|
104
104
|
# Lexical scoping.
|
105
|
-
v_1
|
106
|
-
change_a_and_set_b
|
107
|
-
v_1
|
108
|
-
v_2
|
109
|
-
v_2
|
105
|
+
v_1 -> 5
|
106
|
+
change_a_and_set_b -> :
|
107
|
+
v_1 -> 10
|
108
|
+
v_2 -> 15
|
109
|
+
v_2 -> 20
|
110
110
|
|
111
111
|
# Array comprehensions.
|
112
|
-
supper
|
112
|
+
supper -> food.capitalize() for food in ['toast', 'cheese', 'wine']
|
113
113
|
|
114
114
|
drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] when even(i)
|
115
115
|
|
116
116
|
# Switch statements ("else" serves as a default).
|
117
|
-
activity
|
117
|
+
activity -> switch day
|
118
118
|
when "Tuesday" then eat_breakfast()
|
119
119
|
when "Sunday" then go_to_church()
|
120
120
|
when "Saturday" then go_to_the_park()
|
@@ -128,46 +128,46 @@ activity: switch day
|
|
128
128
|
else go_to_work()
|
129
129
|
|
130
130
|
# Semicolons can optionally be used instead of newlines.
|
131
|
-
wednesday
|
131
|
+
wednesday -> : eat_breakfast(); go_to_work(); eat_dinner()
|
132
132
|
|
133
133
|
# Array slice literals.
|
134
|
-
zero_to_nine
|
135
|
-
three_to_six
|
134
|
+
zero_to_nine -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
135
|
+
three_to_six -> zero_to_nine[3..6]
|
136
136
|
|
137
137
|
# Multiline strings with inner quotes.
|
138
|
-
story
|
138
|
+
story -> "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
|
139
139
|
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
|
140
140
|
aliquam erat volutpat. Ut wisi enim ad."
|
141
141
|
|
142
142
|
# Inheritance and calling super.
|
143
|
-
Animal
|
144
|
-
Animal::move
|
143
|
+
Animal -> :
|
144
|
+
Animal::move -> (meters):
|
145
145
|
alert(this.name + " moved " + meters + "m.")
|
146
146
|
|
147
|
-
Snake
|
147
|
+
Snake -> (name): this.name -> name
|
148
148
|
Snake extends Animal
|
149
|
-
Snake::move
|
149
|
+
Snake::move -> :
|
150
150
|
alert('Slithering...')
|
151
151
|
super(5)
|
152
152
|
|
153
|
-
Horse
|
153
|
+
Horse -> (name): this.name -> name
|
154
154
|
Horse extends Animal
|
155
|
-
Horse::move
|
155
|
+
Horse::move -> :
|
156
156
|
alert('Galloping...')
|
157
157
|
super(45)
|
158
158
|
|
159
|
-
sam
|
160
|
-
tom
|
159
|
+
sam -> new Snake("Sammy the Snake")
|
160
|
+
tom -> new Horse("Tommy the Horse")
|
161
161
|
|
162
162
|
sam.move()
|
163
163
|
tom.move()
|
164
164
|
|
165
165
|
# Numbers.
|
166
|
-
a_googol
|
167
|
-
hex
|
168
|
-
negative
|
169
|
-
infinity
|
170
|
-
nan
|
166
|
+
a_googol -> 1e100
|
167
|
+
hex -> 0xff0000
|
168
|
+
negative -> -1.0
|
169
|
+
infinity -> Infinity
|
170
|
+
nan -> NaN
|
171
171
|
|
172
172
|
# Deleting.
|
173
|
-
delete secret.identity
|
173
|
+
delete secret.identity #114 lines of code
|
@@ -0,0 +1,36 @@
|
|
1
|
+
(function(){
|
2
|
+
var Hello, __a, __b, asquare, hello, log, message, singleline, square, xa;
|
3
|
+
square = function square(x) {
|
4
|
+
return x * x;
|
5
|
+
};
|
6
|
+
// not anonymous ie asquare = function asquare(x)
|
7
|
+
asquare = (function(x) {
|
8
|
+
return x * x;
|
9
|
+
});
|
10
|
+
// anonymous function i.e asquare = function(x)
|
11
|
+
Hello = function Hello() { };
|
12
|
+
Hello.prototype.world = function world() {
|
13
|
+
return console.log("Hello, World!");
|
14
|
+
};
|
15
|
+
hello = new Hello();
|
16
|
+
hello.world();
|
17
|
+
log = function log(message) {
|
18
|
+
return console.log(message);
|
19
|
+
};
|
20
|
+
__a = ['Hello,', 'World!'];
|
21
|
+
for (__b = 0; __b < __a.length; __b++) {
|
22
|
+
message = __a[__b];
|
23
|
+
log(message);
|
24
|
+
}
|
25
|
+
singleline = function singleline() {
|
26
|
+
log("This is a single line");
|
27
|
+
log("Function! Saves so much time");
|
28
|
+
return hello.world();
|
29
|
+
};
|
30
|
+
singleline();
|
31
|
+
log("you don't need to use parenthesis");
|
32
|
+
log(asquare(5));
|
33
|
+
xa = ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"];
|
34
|
+
log(xa.slice(0, 4 + 1));
|
35
|
+
((typeof d !== "undefined" && d !== null)) ? log("the d does exist") : log("the d does not exist");
|
36
|
+
})();
|
data/examples/helloworld.ns
CHANGED
@@ -1,6 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
square -> (x): x * x # not anonymous ie asquare = function asquare(x)
|
2
|
+
asquare -> ((x): x * x) # anonymous function i.e asquare = function(x)
|
3
|
+
Hello -> :
|
4
|
+
Hello::world -> :
|
3
5
|
console.log("Hello, World!")
|
4
|
-
|
5
|
-
hello: new Hello()
|
6
|
+
hello -> new Hello()
|
6
7
|
hello.world()
|
8
|
+
log -> (message): console.log(message)
|
9
|
+
log(message) for message in ['Hello,', 'World!']
|
10
|
+
|
11
|
+
singleline -> : log("This is a single line"); log("Function! Saves so much time"); hello.world()
|
12
|
+
singleline()
|
13
|
+
|
14
|
+
log "you don't need to use parenthesis"
|
15
|
+
log asquare 5
|
16
|
+
|
17
|
+
xa -> ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
|
18
|
+
log xa[0..4]
|
19
|
+
|
20
|
+
if(d?)
|
21
|
+
log("the variable 'd' does exist")
|
22
|
+
else
|
23
|
+
log("the variable 'd' does not exist")
|
data/lib/nscript/lexer/lexer.rb
CHANGED
@@ -21,11 +21,11 @@ module NScript
|
|
21
21
|
OPERATOR = /\A([+\*&|\/\-%=<>:!?]+)/
|
22
22
|
WHITESPACE = /\A([ \t]+)/
|
23
23
|
COMMENT = /\A(((\n?[ \t]*)?#.*$)+)/
|
24
|
-
CODE = /\A((
|
24
|
+
CODE = /\A((:|=>))/
|
25
25
|
REGEX = /\A(\/(.*?)([^\\]|\\\\)\/[imgy]{0,4})/
|
26
26
|
MULTI_DENT = /\A((\n([ \t]*))+)(\.)?/
|
27
27
|
LAST_DENT = /\n([ \t]*)/
|
28
|
-
ASSIGNMENT = /\A(
|
28
|
+
ASSIGNMENT = /\A(->|=)\Z/
|
29
29
|
|
30
30
|
JS_CLEANER = /(\A`|`\Z)/
|
31
31
|
MULTILINER = /\n/
|
@@ -14,7 +14,7 @@ module NScript
|
|
14
14
|
IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM_START,
|
15
15
|
:TRY, :DELETE, :TYPEOF, :SWITCH,
|
16
16
|
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT,
|
17
|
-
'@', '
|
17
|
+
'@', ':', '=>', '[', '(', '{']
|
18
18
|
|
19
19
|
INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair|
|
20
20
|
memo[pair.first] = pair.last
|
@@ -22,7 +22,7 @@ module NScript
|
|
22
22
|
memo
|
23
23
|
end
|
24
24
|
|
25
|
-
SINGLE_LINERS = [:ELSE, "
|
25
|
+
SINGLE_LINERS = [:ELSE, ":", "=>", :TRY, :FINALLY, :THEN]
|
26
26
|
SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE, :OUTDENT, :LEADING_WHEN, :PARAM_START]
|
27
27
|
|
28
28
|
def rewrite(tokens)
|
@@ -37,7 +37,7 @@ prechigh
|
|
37
37
|
right THROW FOR NEW SUPER
|
38
38
|
left EXTENDS
|
39
39
|
right ASSIGN RETURN
|
40
|
-
right '
|
40
|
+
right ':' '=>' UNLESS IF ELSE WHILE
|
41
41
|
preclow
|
42
42
|
|
43
43
|
rule
|
@@ -206,7 +206,7 @@ rule
|
|
206
206
|
|
207
207
|
# The symbols to signify functions, and bound functions.
|
208
208
|
FuncGlyph:
|
209
|
-
'
|
209
|
+
':' { result = :func }
|
210
210
|
| '=>' { result = :boundfunc }
|
211
211
|
;
|
212
212
|
|
@@ -1255,7 +1255,7 @@ racc_token_table = {
|
|
1255
1255
|
"||=" => 91,
|
1256
1256
|
"&&=" => 92,
|
1257
1257
|
"?=" => 93,
|
1258
|
-
"
|
1258
|
+
":" => 94,
|
1259
1259
|
"=>" => 95,
|
1260
1260
|
"\n" => 96,
|
1261
1261
|
";" => 97,
|
@@ -1383,7 +1383,7 @@ Racc_token_to_s_table = [
|
|
1383
1383
|
"\"||=\"",
|
1384
1384
|
"\"&&=\"",
|
1385
1385
|
"\"?=\"",
|
1386
|
-
"\"
|
1386
|
+
"\":\"",
|
1387
1387
|
"\"=>\"",
|
1388
1388
|
"\"\\n\"",
|
1389
1389
|
"\";\"",
|
data/lib/nscript/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Storm Burpee
|
@@ -74,7 +74,9 @@ files:
|
|
74
74
|
- README.md
|
75
75
|
- Rakefile
|
76
76
|
- bin/nscript
|
77
|
+
- examples/code.js
|
77
78
|
- examples/code.ns
|
79
|
+
- examples/helloworld.js
|
78
80
|
- examples/helloworld.ns
|
79
81
|
- lib/nscript.rb
|
80
82
|
- lib/nscript/command_line.rb
|