aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 5d699cda13b8089e4de34ddc766d798c227b2f11 (plain)
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
# MoonPlus

|macOS|Linux|Windows|
|:---:|:---:|:-----:|
|![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg)|![CI](https://github.com/pigpigyyy/MoonPlus/workflows/build-test/badge.svg)|[![Build status](https://ci.appveyor.com/api/projects/status/4nbkye9mx9b3bf83/branch/master?svg=true)](https://ci.appveyor.com/project/pigpigyyy/moonplus/branch/master)|

MoonPlus is a compiler with features from [Moonscript language](https://github.com/leafo/moonscript) 0.5.0 and adopting new features to make Moonscript more up to date. 

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 features for those may break the stablility for existing applications.

So MoonPlus is a new code base for pushing the language to go forward and being a playground to try introducing new language syntax or programing paradigms to make Moonscript language more expressive and productive.



## Features

* No other dependencies needed except modified **parserlib** library from Achilleas Margaritis with some performance enhancement. **lpeg** library is no longer needed.
* Written in C++17.
* Support full Moonscript language features, generate the same Lua codes with original compiler.
* Reserve line numbers from Moonscript sources in compiled Lua codes to help with debugging.
* See other details in the [changelog](./CHANGELOG.md).



## Installation & Usage

* **Lua Module**

  Build `moonp.so` file with

```sh
> make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua
```

  Then get the binary file from path `bin/shared/moonp.so`.

  Or you can install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module with

```sh
> luarocks install moonplus
```

  Then require the MoonPlus module in Lua:

```Lua
require("moonp")("main") -- require `main.mp`

local moonp = require("moonp")
local codes, err, globals = moonp.to_lua([[
f = ->
  print "hello world"
f!
]],{
  implicit_return_root = true,
  reserve_line_number = true,
  lint_global = true
})
```



* **Binary Tool**

  Clone this repo, then build and install executable with:
```sh
> make install
```

  Build MoonPlus tool without macro feature:
```sh
> make install NO_MACRO=true
```

  Build MoonPlus tool without built-in Lua binary:
```sh
> make install NO_LUA=true
```

  Use MoonPlus tool with:

```sh
> moonp -h
Usage: moonp [options|files|directories] ...

   -h       Print this message
   -e str   Execute a file or raw codes
   -t path  Specify where to place compiled files
   -o file  Write output to file
   -s       Use spaces in generated codes instead of tabs
   -m       Generate minified codes
   -p       Write output to standard out
   -b       Dump compile time (doesn't write output)
   -l       Write line numbers from source codes
   -v       Print version
   --       Read from standard in, print to standard out
            (Must be first and only argument)

   Execute without options to enter REPL, type symbol '$'
   in a single line to start/stop multi-line mode
```
  Use cases:  
  Recursively compile every moon+ file with extension `.mp` under current path:  `moonp .`  
  Compile and save results to a target path:  `moonp -t /target/path/ .`  
  Compile and reserve debug info:  `moonp -l .`  
  Compile and generate minified codes:  `moonp -m .`  
  Execute raw codes:  `moonp -e 'print 123'`  
  Execute a moon+ file:  `moonp -e main.mp`



* **Docker Hub**
  Try moonp in another easy way: https://hub.docker.com/r/moonplus/moonplus.
  ```bash
  docker run -it moonplus/moonplus:0.4.19
  ```

  The REPL console should be ready,
  ```bash
  Moonscript+ 0.4.19
  > 
  ```

## Editor Support

* [Vim](https://github.com/pigpigyyy/MoonPlus-vim)



## License

MIT