1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
|
# Changelog
The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version.
## v0.20.2
### Added Features
* Added chaining comparisons and list syntax [] with disallowing key value pairs in it.
```moonscript
x = 2
res = 1 < x < 3 -- true in Yuescript, like Python.
print res
list_with_only_one_element = [1,]
list = [
1
2
3
abc: 123 -- will report error here
]
[a = 1, b = 2] = tab_to_be_destructured
```
* Added `from "module" import ...` syntax.
```moonscript
from "CS" import
System
UnityEngine
from UnityEngine import
Object
GameObject
Transform
MonoBehaviour
Vector3
Quaternion
```
* Added `import ... from "module"` syntax.
```moonscript
import a, b, c from "module"
```
### Fixed Issues
* Fixed issue #150. Cannot use pipes on new line with const declarations.
* Fixed issue #148. No output when running code in online compiler.
* Fixed inline variable renaming rule to prevent naming conflicts.
## v0.19.1
### Added Features
* Added unicode identifier support.
```moonscript
π = π·οΈ: "ζδΉθζ¬"
print π.π·οΈ
```
* Implemented '...' for variable declaration within scope using anonymous functions.
```moonscript
ok, ... = fn!
if ok
print select '#', ...
print select 1, ...
```
* Added close-variables support for Lua version targets below 5.4.
## v0.17.10
### Added Features
* Added In-expression syntax to do range checking. In-expression can be used in switch statement as a new clause.
```moonscript
a = 5
if a in [1, 10] or a in (20, 30) or a in {77, 88} or a not in {100, 200}
print "(1 <= a <= 10) or (20 < a < 30) or (a == 77 or a == 88) or not (a == 100 or a == 200)"
switch a when not in [1, 10]
print "not (1 <= a <= 10)"
if item in list
print "item existed in a list"
```
* Added metamethod name checking for chain expression.
* Added feature to reformat the expressions passed as macro function arguments to the formated code strings.
* Added -r option to rewrite compiled Lua code output to match original Yuescript code line numbers.
### Fixed Issues
* Fixed a LuaJIT module loading issue.
* Fixed built-in $FILE macro does not escape backslash on Windows.
* Fixed more ambiguous Lua codes generation cases.
* Fixed syntax error should throw for invalid interpolation.
* Fixed an AST object life expired before accessing issue.
## v0.16.4
### Added Features
* Added -w option for Yuescript tool to recursively watch file changes under a target path and get codes recompiled.
* Added different metamethod name literals checking for different Lua target versions.
* Added checks for not using `break` statement in a for-loop scope.
* Added compiler option for preserving comments before statements. Using command line tool:
```sh
yue -c file.yue
```
Using Lua lib:
```lua
local yue = require("yue")
print yue.to_lua([[
-- a comment
f = ->
]], {reserve_comment = true})
```
* Added `yue.check()` function to get compile errors in Lua table {{type, msg, line, col}}.
* Added support for extending script search paths using `yue.options.path`.
* Added new module export syntax for exporting items without creating local variables.
```moonscript
export.<name> = "My module"
export.<call> = (...) -> -- ...
```
compiles to:
```lua
local _module_0 = setmetatable({ }, { })
getmetatable(_module_0).__name = "My module"
getmetatable(_module_0).__call = function(...) end
return _module_0
```
### Fixed Issues
* Reduced max parser call stack size.
* Refactored some syntax rules to speed up parsing.
* Fixed default value issue when doing metatable destructuring.
* Fixed a class syntax ambiguous issue when writting table block after a class declaration.
* Improve number literal syntax to support hexadecimal point values, positive decimal exponents and hexadecimal exponents.
* Prevented accessing scoped declared global variables multiple times when generating Lua codes.
* Fixed parser running exponentially slow issue when parsing nested expressions.
* Fixed exposing `yue` module as global variable by default.
* Fixed a stack overflow issue in `yue.to_ast()`.
* Fixed flatten level > 0 getting wrong AST issue in `yue.to_ast()` function.
* Fixed missing indent check for comments in the beginning of `in_block` syntax rule.
* Prevented `yue.loadfile()` throwing errors to match Lua `loadfile()` function behavior.
* Fixed `yue` module registering issue for Lua 5.1 and LuaJIT.
## v0.15.12
### Added Features
* yue.to_ast(): Reserve comment nodes followed by a statement in AST structures.
* Added `while` clause line decorator.
```moonscript
reader\parse_line! until reader\eof!
```
compiles to:
```lua
while not reader:eof() do
reader:parse_line()
end
```
* Supported underscores in number literal. `1_000_000`, `0xFF_EF_06`
* Refactored some error messages with details instead of just "syntax error".
* Added chaining assignment. `a = b = c = 0`
### Fixed Issues
* Change metable accessing operator to `<>` instead of postfix `#`.
```moonscript
<>: mt = tb
mt = tb.<>
a = <>: mt, value: 1
b = :<add>, value: 2
close _ = <close>: -> print "out of scope"
```
compiles to:
```lua
local mt = getmetatable(tb)
mt = getmetatable(tb)
local a = setmetatable({
value = 1
}, mt)
local b = setmetatable({
value = 2
}, {
__add = add
})
local _ <close> = setmetatable({ }, {
__close = function()
return print("out of scope")
end
})
```
* Refactor `continue` keyword implementation with goto statement when targeting Lua version 5.2 and higher.
* Skip utf-8 bom in parser.
* Fixed classes don't inherits metamethods properly.
## v0.14.5
### Added Features
* Added -g option for Yuescript CMD tool.
* Added option `--target=5.1` to generate Lua 5.1 compatible codes.
* Added const destructuring and imported item is now const by default.
```moonscript
const :width, :height = View.size
const {:x = 0.0, :y = 0.0} = point
import a from b
-- report compiler error when doing width = nil or x = nil or a = nil
```
* Added left and right side item numbers check in assignments.
```moonscript
a, b, c = 1 -- report error instead of implicitly assigning nil to extra variables
a, b, c = f! -- expecting function call to return multiple values is accepted
a = 1, 2 -- report error instead of ignoring extra values
```
### Fixed Issues
* Fix missing checks and issues related to doing destrucuring to if/switch expressions that returns values in multiple clauses.
## v0.13.4
### Added Features
* Added update syntax support for `var //= 5`.
* Added metamethod syntax support for class block.
```moonscript
class Foo
new: (x) => @x = x
mul#: (y) => @x * y
["abc"]#: 123
:add
:add#
```
* Added support `with` block access with `[key]` syntax.
```moonscript
with tb
[1] = [2]\func!
print [3]
with [abc]
[4] = 1
[] = "abc"
```
* Added table pattern matching syntax.
```moonscript
items =
* x: 100
y: 200
* width: 300
height: 400
for item in *items
switch item
when :x, :y
print "Vec2 #{x}, #{y}"
when :width, :height
print "size #{width}, #{height}"
```
### Fixed Issues
* Fix `import X as {_}` generates invalid Lua code.
* Fix attribute syntax with line decorator compiles to unexpected codes.
```moonscript
const a = 1 if true
```
now compiles to:
```lua
local a <const> = (function()
if true then
return 1
end
end)()
```
* Fix continue in `repeat` loop gives invalid code.
* Fix variables with attributes "const" and "close" should both get constant check in compiler.
* Fix ambiguous syntax starting with `[[`. Expressions starting with `[[` will now be always treated like raw strings other than nested list comprehensions.
* Fix module can export both macros and normal values. The macro exporting module can now only allow macro definition, macro importing and macro expansion in place for better compiler performance.
## v0.10.17
### Added Features
* Yuescript to AST function (`yue.to_ast`)
```moonscript
yue.p yue.to_ast(
"print 123"
2 --[[ast flatten level, can only be 0, 1, 2]]
)
```
Prints:
```
{
[1] = "file"
[2] = {
[1] = "callable"
[2] = "print"
}
[3] = {
[1] = "invoke_args"
[2] = "123"
}
}
```
## v0.10.16
### Fixed Issues
* Prevent text mode macros from inserting line numbers into generated code.
```moonscript
macro text = (code) -> {
:code
type: "text"
}
$text[[#!yue -e]]
nil
```
Compiles to:
```
#!yue -e
return nil -- 8
```
## v0.10.15
### Fixed Issues
* Fix ambiguous syntax caused by argument table block.
* Fix an issue using import as table destructuring with meta methods.
* Fix a case combining the use of existential operator and metatable operator.
* Raise error when use existential operator in the left part of an assignment.
* Fix the way update assignment is implemented to reduce unnecessary table indexing.
* Fix more cases that global variables are not being cached.
* Fix Yuescript loader insertion order.
* Fix Yuescript not found error messages.
### Added Features
* Builtin macros `$FILE`, `$LINE` to get the source file names and code line numbers.
* Table appending operator.
```moonscript
tb = {}
tb[] = 1
```
Compiles to:
```lua
local tb = { }
tb[#tb + 1] = 1
```
* Class mixing function by keyword `using`.
```moonscript
class A using B
-- If B is a Yuescript class object (which has a field named __base),
-- only fields that are not meta method will be added to class object A
-- If B is a plain table, all the fields will be added to class object A
-- so that you can change the behavior of Yuescript class' meta method __index.
```
* Try catch syntax.
```moonscript
try
func 1, 2, 3
catch err
print yue.traceback err
success, result = try func 1, 2, 3
```
Compiles to:
```lua
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end)
local success, result = pcall(func, 1, 2, 3)
```
* Add nil coalescing operator.
```moonscript
local a, b, c
a = b ?? c
a ??= false
```
Compiles to:
```lua
local a, b, c
if b ~= nil then
a = b
else
a = c
end
if a == nil then
a = false
end
```
* Add a global variable "arg" for Yuescipt tool CLI execution.
* Add placeholder support for list destructuring.
```moonscript
{_, b, _, d} = tb
```
Compiles to:
```lua
local b, d
do
local _obj_0 = tb
b, d = _obj_0[2], _obj_0[4]
end
```
* Add table spread syntax.
```moonscript
copy = {...other}
```
Compiles to:
```lua
local copy
do
local _tab_0 = { }
local _idx_0 = 1
for _key_0, _value_0 in pairs(other) do
if _idx_0 == _key_0 then
_tab_0[#_tab_0 + 1] = _value_0
_idx_0 = _idx_0 + 1
else
_tab_0[_key_0] = _value_0
end
end
copy = _tab_0
end
```
## v0.8.5
### Fixed Issues
* Simplify and extend import syntax.
* Report an error when destructuring nil item.
### Added Features
* Nil coalescing operator.
```moonscript
local a, b, c, d
a = b ?? c ?? d
func a ?? {}
a ??= false
```
Compiles to:
```lua
local a, b, c, d
if b ~= nil then
a = b
else
if c ~= nil then
a = c
else
a = d
end
end
func((function()
if a ~= nil then
return a
else
return { }
end
end)())
if a == nil then
a = false
end
```
* New metatable syntax.
```moonscript
#: mt = tb
mt = tb.#
a = #: mt, value: 1
b = :add#, value: 2
close _ = close#: -> print "out of scope"
```
compiles to:
```lua
local mt = getmetatable(tb)
mt = getmetatable(tb)
local a = setmetatable({
value = 1
}, mt)
local b = setmetatable({
value = 2
}, {
__add = add
})
local _ <close> = setmetatable({ }, {
__close = function()
return print("out of scope")
end
})
```
* Aliasing symbol :: with \ for writing colon chain items.
```moonscript
tb\func1()::func2()
```
compiles to:
```lua
tb:func1():func2()
```
* Add until statement.
```moonscript
a = 3
until a == 0
a -= 1
```
compiles to:
```lua
local a = 3
while not (a == 0) do
a = a - 1
end
```
* Add existential check syntax for function argument as a shortcut feature to assign self field.
```moonscript
tb\func1()::func2()
```
compiles to:
```lua
tb:func1():func2()
```
* Add default value support for destructure syntax.
```moonscript
{:name = "nameless", :job = "jobless"} = person
```
compiles to:
```lua
local name, job
do
local _obj_0 = person
name, job = _obj_0.name, _obj_0.job
end
if name == nil then
name = "nameless"
end
if job == nil then
job = "jobless"
end
```
## v0.6.7
### Fixed Issues
* Simplify macro syntax. A macro function can either return a Yuescript string or a config table containing Lua codes.
```moonscript
macro localFunc = (var)-> "local #{var} = ->"
$localFunc f1
f1 = -> "another function"
-- or
macro localFunc = (var)->
{
codes: "local function #{var}() end"
type: "lua"
locals: {var}
}
$localFunc f2
f2 = -> "another function"
```
Compiles to:
```Lua
local f1
f1 = function() end
f1 = function()
return "another function"
end
local function f2() end
f2 = function()
return "another function"
end
```
* Change the Yuescript file extension to '.yue' because some of the Moonscript syntax is no longer supported and some codes written in Yuescript syntax won't be accepted by the Moonscript compiler.
* Disable the use of local and global statements with wildcard operators.
* Change the backcall operator syntax, extra parentheses for multiline chains are no longer needed.
```moonscript
readFile "example.txt"
|> extract language, {}
|> parse language
|> emit
|> render
|> print
```
Compiles to:
```Lua
return print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
```
### Added Features
* Supporting multiline chaining function call syntax.
```Moonscript
result = origin
.transform.root
.gameObject
\Parents!
\Descendants!
\SelectEnable!
\SelectVisible!
\TagEqual "fx"
\Where (x)->
if x\IsTargeted!
return false
x.name\EndsWith "(Clone)"
\Destroy!
origin.transform.root.gameObject
\Parents!\Descendants!
\SelectEnable!
\SelectVisible!
\TagEqual "fx"
\Where (x)-> x.name\EndsWith "(Clone)"
\Destroy!
```
Compiles to:
```Lua
local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x)
if x:IsTargeted() then
return false
end
return x.name:EndsWith("(Clone)")
end):Destroy()
return origin.transform.root.gameObject:Parents():Descendants():SelectEnable(): SelectVisible():TagEqual("fx"):Where(function(x)
return x.name:EndsWith("(Clone)")
end):Destroy()
```
## v0.4.16
### Fixed Issues
* Remove support for escape newline symbol, binary operator expressions can now be written multiline without escape newline symbol.
* Fix an issue when extending class without a name.
* Fix an issue when using return with an export statement.
* Fix issues when declaring table key with Lua multiline string and indexing expressions with Lua multiline string.
* Make simple table and table block appear at the end of function arguments merged into one table.
```Moonscript
-- function arguments end with a simple table followed by table block
another hello, one,
two, three, four, yeah: man
okay: yeah
fine: alright
```
```Lua
-- compiled in original Moonscript compiler
-- get two tables as arguments
another(hello, one, two, three, four, {
yeah = man
}, {
okay = yeah,
fine = alright
})
-- compiled in fixed Yuescript compiler
-- get one table as argument
another(hello, one, two, three, four, {
yeah = man,
okay = yeah,
fine = alright
})
```
### Added Features
* Add implicit objects support for table block syntax.
```Moonscript
inventory =
equipment:
* "sword"
* "shield"
items:
* name: "potion"
count: 10
* name: "bread"
count: 3
```
Compiles to:
```Lua
local inventory = {
equipment = {
"sword",
"shield"
},
items = {
{
name = "potion",
count = 10
},
{
name = "bread",
count = 3
}
}
}
```
* Add support for local variable declared with attribute 'close' and 'const' for Lua 5.4.
```moonscript
close a = setmetatable {}, __close: =>
const b = if var then 123 else 'abc'
```
Compiles to:
```Lua
local a <close> = setmetatable({ }, {
__close = function(self) end
})
local b <const> = (function()
if var then
return 123
else
return 'abc'
end
end)()
```
## v0.4.0
### Fixed Issues
* Fix issues of the unary and binary operator "~".
* Fix Moonscript issue 416: ambiguous Lua output in some cases.
* Fix errors when explicitly declaring global or local variable initialized with table block.
* Fix macro type mismatch issue.
* Fix line break issue in macro, disable macro declaration outside the root scope.
* Fix existential operator issue when used in an operator-valued list.
* Fix assignment with backcall expressions in not well-handled cases.
* Fix destructure case assigning one table variable to an operator-valued expression.
* Fix simple chain value with Lua keyword colon chain item.
### Added Features
* Change operator precedence to
* [1] ^
* [2] unary operators (not, #, -, ~)
* [3] |>
* [4] *, /, //, %, ...
* Add existential operator support for `with` statement.
```Moonscript
with? io.open "test.txt", "w"
\write "hello"
\close!
```
Compiles to:
```Lua
local _with_0 = io.open("test.txt", "w")
if _with_0 ~= nil then
_with_0:write("hello")
_with_0:close()
end
```
* Add repeat until statement support.
* Allow implicitly returning block macro.
* Add support for macro system expanding to Lua codes directly.
* Add goto statement support.
* Add variadic arguments declaration check.
* `yue` now supports recursively traversing any directory and compiling any moon file in the path.
* `yue` now supports REPL functions for Moonscript.
* Add `useSpaceOverTab` function to `yue`.
* Add Lua codes minify function to `yue`.
### Changed Behaviors
* Remove else clause support from if-else line decorator syntax which makes users confused.
## v0.3.0
### Added Features
* Add macro functions.
```Moonscript
-- file 'macro.mp'
export macro config = (debugging = true)->
global debugMode = debugging == "true"
""
export macro asserts = (cond)->
debugMode and "assert #{cond}" or ""
export macro assert = (cond)->
debugMode and "assert #{cond}" or "#{cond}"
$config!
-- file 'main.mp'
import 'macro' as {:$config, :$assert, :$asserts}
macro and = (...)-> "#{ table.concat {...}, ' and ' }"
$asserts item ~= nil
$config false
value = $assert item
if $and f1!, f2!, f3!
print "OK"
```
Compiles to:
```Lua
-- file 'macro.mp'
local _module_0 = { }
return _module_0
-- file 'main.mp'
assert(item ~= nil)
local value = item
if (f1() and f2() and f3()) then
print("OK")
end
```
## v0.2.0
### Fixed Issues
* Fix some cases when using backcall with an assignment.
* Fix a case that complier crashes with an empty code body.
* Force forward declaration of a variable for assigning local function.
From the original Moonscript compiler:
* [#390](https://github.com/leafo/moonscript/issues/390) Many lists are not allowed to be multiline
### Added Features
* Allow value lists in for and local statement to be multiline.
* `yue` now compiles source files in multiple threads to speed up compilation.
* Add placeholder support for backcall operator.
* Add placeholder support for backcall statement.
* Add fat arrow support for backcall statement.
* Add option to compile Yuescript as a Lua C lib. Got Yuescript released to `Luarocks`.
* Move old `export` statement functions to `global` statement to match the `local` statement.
* Change `export` statement behavior to support module management. Moon codes with `export` statements can not explicitly return values in the root scope. And codes with `export default` can export only one value as the module content. Use cases:
```Moonscript
-- file 'Config.mp'
export default {flag:1, value:"x"}
-- file 'Utils.mp'
export map = (items, func)-> [func item for item in *items]
export filter = (items, func)-> [item for item in *items when func item]
-- file 'main.mp'
import 'Config' as {:flag, :value}
import 'Utils' as {:map, :filter}
```
Compiles to:
```Lua
-- file 'Config.mp'
local _module_0 = nil
_module_0 = {
flag = 1,
value = "x"
}
return _module_0
-- file 'Utils.mp'
local _module_0 = { }
local map
map = function(items, func)
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #items do
local item = items[_index_0]
_accum_0[_len_0] = func(item)
_len_0 = _len_0 + 1
end
return _accum_0
end
_module_0["map"] = map
local filter
filter = function(items, func)
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #items do
local item = items[_index_0]
if func(item) then
_accum_0[_len_0] = item
_len_0 = _len_0 + 1
end
end
return _accum_0
end
_module_0["filter"] = filter
return _module_0
-- file 'main.mp'
local flag, value
do
local _obj_0 = require('Config')
flag, value = _obj_0.flag, _obj_0.value
end
local map, filter
do
local _obj_0 = require('Utils')
map, filter = _obj_0.map, _obj_0.filter
end
```
## v0.1.0
### Fixed Issues
Fix issues in original Moonscript compiler:
* [#122](https://github.com/leafo/moonscript/issues/122) use of ? symbol
* [#155](https://github.com/leafo/moonscript/issues/151) wish moon could support: function?()
* [#156](https://github.com/leafo/moonscript/issues/156) About the 'import' statement
* [#375](https://github.com/leafo/moonscript/issues/375) assignment in line decorators
* [#384](https://github.com/leafo/moonscript/issues/384) The @ and @@ accessors do not escape Lua keywords
### Added Features
* Multi-line comment support.
* Back call features with new operator and syntax. For example:
```Moonscript
{1,2,3}
|> map((x)-> x * 2)
|> filter((x)-> x > 4)
|> reduce(0, (a,b)-> a + b)
|> print
do
(data) <- http.get "ajaxtest"
body[".result"]\html data
(processed) <- http.post "ajaxprocess", data
body[".result"]\append processed
print "done"
```
will be compiled to:
```Lua
print(reduce(filter(map({
1,
2,
3
}, function(x)
return x * 2
end), function(x)
return x > 4
end), 0, function(a, b)
return a + b
end))
do
http.get("ajaxtest", function(data)
body[".result"]:html(data)
return http.post("ajaxprocess", data, function(processed)
body[".result"]:append(processed)
return print("done")
end)
end)
end
```
* Existential operator support. Generate codes from:
```Moonscript
func?!
x = tab?.value
print abc?["hello world"]?.xyz
if print and x?
print x
```
to:
```Lua
if func ~= nil then
func()
end
local x
if tab ~= nil then
x = tab.value
end
print((function()
if abc ~= nil then
local _obj_0 = abc["hello world"]
if _obj_0 ~= nil then
return _obj_0.xyz
end
return nil
end
return nil
end)())
if print and (x ~= nil) then
print(x)
end
```
* More usages for `import` keyword. Will compile codes from:
```Moonscript
import 'module'
import "module.part"
import "d-a-s-h-e-s"
import "player" as Player
import "lpeg" as {:C, :Ct, :Cmt}
```
to:
```Lua
local module = require('module')
local part = require("module.part")
local d_a_s_h_e_s = require("d-a-s-h-e-s")
local Player = require("player")
local C, Ct, Cmt
do
local _obj_0 = require("lpeg")
C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
end
```
* Can do slash call with Lua keywords. Generate codes from:
```Moonscript
c.repeat.if\then("xyz")\else res
```
to:
```Lua
local _call_3 = c["repeat"]["if"]
local _call_4 = _call_3["then"](_call_3, "xyz")
_call_4["else"](_call_4, res)
```
### Changed Behaviors
* Left part of update statement will now accept only one assignable expression.
* Expression list appears in the middle of the code block is not allowed. For codes like:
```Moonscript
-- Moonscript 0.5.0
f = (x)->
"abc",123 -- valid meaningless codes
x + 1
```
in original Moonscript compiles to:
```Lua
local f
f = function(x)
local _ = "abc", 123 -- report error in Yuescript
return x + 1
end
```
This feature may lead to some silenced errors. For example:
```Moonscript
-- expected codes
tree\addChild with Node!
\addChild subNode
-- in original Moonscript, codes will still run
-- after adding a break by mistake
tree\addChild
with Node!
\addChild subNode
```
The original Moonscript will compile these codes to:
```Lua
-- expected codes
tree:addChild((function()
do
local _with_0 = Node()
_with_0:addChild(subNode)
return _with_0
end
end)())
-- codes added with a break will still run
local _ -- report error in Yuescript instead of creating
do -- an anonymous function to bind the object method
local _base_0 = tree
local _fn_0 = _base_0.addChild
_ = function(...)
return _fn_0(_base_0, ...)
end
end
do
local _with_0 = Node()
_with_0:addChild(subNode)
end
```
* Reusing variables which help generate reduced Lua codes.
For example, Yuescript will generate codes from:
```Moonscript
with leaf
.world 1,2,3
with leaf
g = .what.is.this
print g
for x in *something
print x
```
to:
```Lua
leaf.world(1, 2, 3)
do
local g = leaf.what.is.this
print(g)
end
for _index_0 = 1, #something do
local x = something[_index_0]
print(x)
end
```
instead of:
```lua
do
local _with_0 = leaf
_with_0.world(1, 2, 3)
end
do
local _with_0 = leaf
local g = _with_0.what.is.this
end
local _list_0 = something
for _index_0 = 1, #_list_0 do
local x = _list_0[_index_0]
print(x)
end
```
## v0.0.1
Implemented full features from Moonscript 0.5.0.
|