diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 83 |
1 files changed, 80 insertions, 3 deletions
@@ -1,18 +1,42 @@ | |||
1 | # MoonPlus | 1 | # MoonPlus |
2 | 2 | ||
3 |  | 3 |  |
4 | MoonPlus is a compiler with features from [Moonscript language](https://github.com/leafo/moonscript) 0.5.0 and could be faster than the original Moonscript compiler. | 4 | MoonPlus is a compiler with features from [Moonscript language](https://github.com/leafo/moonscript) 0.5.0 and implementing new features to make Moonscript more up to date. |
5 | |||
6 | Since original Moonscript has been used to write web framework [lapis](https://github.com/leafo/lapis) and run a few business web sites like [itch.io](https://itch.io) and [streak.club](https://streak.club) with some large code bases. The original language is getting too hard to adopt new language features for those may break the stablility for existing applications. | ||
7 | |||
8 | So MoonPlus is a new code base for pushing the language to go forward and may be a playground to try introducing new language syntax or programing paradigms to make Moonscript language more expressive and productive. | ||
5 | 9 | ||
6 | ## Features | 10 | ## Features |
7 | 11 | ||
8 | * No other dependencies needed except modified **parserlib** library from Achilleas Margaritis with some performance enhancement. **lpeg** library is no longer needed. | 12 | * No other dependencies needed except modified **parserlib** library from Achilleas Margaritis with some performance enhancement. **lpeg** library is no longer needed. |
9 | * Written in C++17. | 13 | * Written in C++17. |
10 | * Support full Moonscript language features, generate the same Lua codes with original compiler. | 14 | * Support full Moonscript language features, generate the same Lua codes with original compiler. |
11 | * Reserve line numbers from source Moonscript codes in compiled Lua codes to help with debugging. | 15 | * Reserve line numbers from Moonscript sources in compiled Lua codes to help with debugging. |
16 | |||
17 | ## Installation | ||
18 | |||
19 | Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install Lua module with | ||
20 | ```sh | ||
21 | > luarocks install moonplus | ||
22 | ``` | ||
23 | |||
24 | ## Usage | ||
25 | |||
26 | ```Lua | ||
27 | require("moonp")("main") -- require `main.moon` | ||
28 | |||
29 | local moonp = require("moonp") | ||
30 | print(moonp.to_lua[[ | ||
31 | f = -> | ||
32 | print "hello world" | ||
33 | f! | ||
34 | ]]) | ||
35 | ``` | ||
12 | 36 | ||
13 | ## Changes | 37 | ## Changes |
14 | 38 | ||
15 | The original Moonscript language 0.5.0 support can be found in the `0.5.0` branch. Moonscript with new features is in the master branch. Here are the new features introduced in MoonPlus | 39 | The original Moonscript language 0.5.0 support can be found in the `0.5.0` branch. Moonscript with new features is in the master branch. Here are the new features introduced in MoonPlus. |
16 | 40 | ||
17 | * Multi-line comment. | 41 | * Multi-line comment. |
18 | * Usage for symbol `\` to escape new line. Will compile codes: | 42 | * Usage for symbol `\` to escape new line. Will compile codes: |
@@ -179,6 +203,59 @@ for _index_0 = 1, #_list_0 do | |||
179 | end | 203 | end |
180 | ``` | 204 | ``` |
181 | 205 | ||
206 | * Expression list appears at the middle of code block is not allowed. For codes like: | ||
207 | ```Moonscript | ||
208 | -- Moonscript 0.5.0 | ||
209 | f = (x)-> | ||
210 | "abc",123 -- valid meaningless codes | ||
211 | x + 1 | ||
212 | ``` | ||
213 | in original Moonscript compiles to: | ||
214 | ```Lua | ||
215 | local f | ||
216 | f = function(x) | ||
217 | local _ = "abc", 123 -- report error in MoonPlus | ||
218 | return x + 1 | ||
219 | end | ||
220 | ``` | ||
221 | |||
222 | This feature may lead to some silenced errors. For example: | ||
223 | ```Moonscript | ||
224 | -- expected codes | ||
225 | tree\addChild with Node! | ||
226 | \addChild subNode | ||
227 | |||
228 | -- in original Moonscript, codes will still run after adding a break | ||
229 | tree\addChild | ||
230 | with Node! | ||
231 | \addChild subNode | ||
232 | ``` | ||
233 | the original Moonscript will compile these codes to: | ||
234 | ```Lua | ||
235 | -- expected codes | ||
236 | tree:addChild((function() | ||
237 | do | ||
238 | local _with_0 = Node() | ||
239 | _with_0:addChild(subNode) | ||
240 | return _with_0 | ||
241 | end | ||
242 | end)()) | ||
243 | |||
244 | -- codes added with a break will still run | ||
245 | local _ -- report error in MoonPlus instead of creating | ||
246 | do -- an anonymous function to bind the object method | ||
247 | local _base_0 = tree | ||
248 | local _fn_0 = _base_0.addChild | ||
249 | _ = function(...) | ||
250 | return _fn_0(_base_0, ...) | ||
251 | end | ||
252 | end | ||
253 | do | ||
254 | local _with_0 = Node() | ||
255 | _with_0:addChild(subNode) | ||
256 | end | ||
257 | ``` | ||
258 | |||
182 | ## Standalone Compiler Usage | 259 | ## Standalone Compiler Usage |
183 | 260 | ||
184 | Test compiler with `make test`. | 261 | Test compiler with `make test`. |