aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-02-13 21:44:22 +0800
committerLi Jin <dragon-fly@qq.com>2020-02-13 21:44:22 +0800
commitb06a818e78d1a26c34f2c87f607e78ad156e4921 (patch)
tree94681ba34e7866686bb0d4f13c83b47779f4b989
parentc241ea241e8e9c152f6eb14f163b2ae39749f7bf (diff)
downloadyuescript-b06a818e78d1a26c34f2c87f607e78ad156e4921.tar.gz
yuescript-b06a818e78d1a26c34f2c87f607e78ad156e4921.tar.bz2
yuescript-b06a818e78d1a26c34f2c87f607e78ad156e4921.zip
update readme and rockspec.
-rw-r--r--README.md83
-rw-r--r--moonplus-0.1-1.rockspec4
-rw-r--r--src/Moonscript.h (renamed from src/MoonPlus.h)21
-rw-r--r--src/StackTracePlus.h4
-rw-r--r--src/moonp.cpp2
5 files changed, 106 insertions, 8 deletions
diff --git a/README.md b/README.md
index 018e6b0..9bfef2d 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,42 @@
1# MoonPlus 1# MoonPlus
2 2
3![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg) 3![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg)
4MoonPlus 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. 4MoonPlus 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
6Since 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
8So 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
19Install [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
27require("moonp")("main") -- require `main.moon`
28
29local moonp = require("moonp")
30print(moonp.to_lua[[
31f = ->
32 print "hello world"
33f!
34]])
35```
12 36
13## Changes 37## Changes
14 38
15The 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 39The 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
179end 203end
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
209f = (x)->
210 "abc",123 -- valid meaningless codes
211 x + 1
212```
213in original Moonscript compiles to:
214```Lua
215local f
216f = function(x)
217 local _ = "abc", 123 -- report error in MoonPlus
218 return x + 1
219end
220```
221
222This feature may lead to some silenced errors. For example:
223```Moonscript
224-- expected codes
225tree\addChild with Node!
226 \addChild subNode
227
228-- in original Moonscript, codes will still run after adding a break
229tree\addChild
230with Node!
231 \addChild subNode
232```
233the original Moonscript will compile these codes to:
234```Lua
235-- expected codes
236tree:addChild((function()
237 do
238 local _with_0 = Node()
239 _with_0:addChild(subNode)
240 return _with_0
241 end
242end)())
243
244-- codes added with a break will still run
245local _ -- report error in MoonPlus instead of creating
246do -- 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
252end
253do
254 local _with_0 = Node()
255 _with_0:addChild(subNode)
256end
257```
258
182## Standalone Compiler Usage 259## Standalone Compiler Usage
183 260
184Test compiler with `make test`. 261Test compiler with `make test`.
diff --git a/moonplus-0.1-1.rockspec b/moonplus-0.1-1.rockspec
index aeebe69..e1dd086 100644
--- a/moonplus-0.1-1.rockspec
+++ b/moonplus-0.1-1.rockspec
@@ -6,8 +6,10 @@ source = {
6description = { 6description = {
7 summary = "MoonPlus is a compiler for Moonscript written in C++.", 7 summary = "MoonPlus is a compiler for Moonscript written in C++.",
8 detailed = [[ 8 detailed = [[
9 MoonPlus is a compiler with features from Moonscript language 0.5.0 and more advanced features. could be faster than the original Moonscript compiler. ]], 9 MoonPlus is a compiler with features from Moonscript language 0.5.0 and implementing new features to make Moonscript more up to date. ]],
10 homepage = "https://github.com/pigpigyyy/MoonPlus", 10 homepage = "https://github.com/pigpigyyy/MoonPlus",
11 maintainer = "Li Jin <dragon-fly@qq.com>",
12 labels = {"moonscript","cpp","transpiler"},
11 license = "MIT" 13 license = "MIT"
12} 14}
13dependencies = { 15dependencies = {
diff --git a/src/MoonPlus.h b/src/Moonscript.h
index da5f3ac..6e84552 100644
--- a/src/MoonPlus.h
+++ b/src/Moonscript.h
@@ -1,4 +1,25 @@
1R"moonscript_codes( 1R"moonscript_codes(
2--[[
3Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE SOFTWARE.]]
22
2import "moonp" 23import "moonp"
3import concat, insert, remove from table 24import concat, insert, remove from table
4unpack = unpack or table.unpack 25unpack = unpack or table.unpack
diff --git a/src/StackTracePlus.h b/src/StackTracePlus.h
index 1a909fd..202ae22 100644
--- a/src/StackTracePlus.h
+++ b/src/StackTracePlus.h
@@ -1,8 +1,6 @@
1R"lua_codes( 1R"lua_codes(
2--[[ 2--[[
3The MIT License 3Copyright (c) 2010 Ignacio Burgueño, modified by Li Jin
4
5Copyright (c) 2010 Ignacio Burgueño
6 4
7Permission is hereby granted, free of charge, to any person obtaining a copy 5Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal 6of this software and associated documentation files (the "Software"), to deal
diff --git a/src/moonp.cpp b/src/moonp.cpp
index a6c99df..cb53b55 100644
--- a/src/moonp.cpp
+++ b/src/moonp.cpp
@@ -182,7 +182,7 @@ extern "C" {
182#include "lauxlib.h" 182#include "lauxlib.h"
183 183
184static const char moonplusCodes[] = 184static const char moonplusCodes[] =
185#include "MoonPlus.h" 185#include "Moonscript.h"
186 186
187static int init_moonplus(lua_State* L) { 187static int init_moonplus(lua_State* L) {
188 MoonP::MoonConfig config; 188 MoonP::MoonConfig config;