2019-01-29 10:14:08 +00:00
|
|
|
|
## Requires
|
|
|
|
|
- node
|
|
|
|
|
- npm
|
2019-01-29 10:16:08 +00:00
|
|
|
|
- gcc
|
2019-01-28 12:08:59 +00:00
|
|
|
|
|
2019-01-30 15:05:56 +00:00
|
|
|
|
## Install
|
2019-01-28 12:08:59 +00:00
|
|
|
|
```bash
|
2019-01-30 15:05:56 +00:00
|
|
|
|
# bash
|
|
|
|
|
git clone -- http://git.macaw.me:3000/chichenkov/LemonJS
|
|
|
|
|
cd LemonJS
|
|
|
|
|
|
2019-01-29 08:17:41 +00:00
|
|
|
|
gcc -o ./lemon-src/lemon-js -O2 ./lemon-src/lemon-js.c
|
2019-01-30 15:05:56 +00:00
|
|
|
|
#or
|
2019-01-29 09:13:09 +00:00
|
|
|
|
./build.sh
|
|
|
|
|
```
|
2019-01-28 12:08:59 +00:00
|
|
|
|
|
2019-01-30 15:07:22 +00:00
|
|
|
|
## Start
|
|
|
|
|
```bash
|
|
|
|
|
node main.js --c=<your_config>.js --t=<web|node>
|
|
|
|
|
```
|
|
|
|
|
|
2019-01-30 11:50:02 +00:00
|
|
|
|
## Example (One minute start)
|
2019-01-29 11:04:41 +00:00
|
|
|
|
Also you can build example config
|
|
|
|
|
```bash
|
|
|
|
|
./build-example.sh
|
2019-01-30 15:07:22 +00:00
|
|
|
|
|
2019-01-30 11:50:02 +00:00
|
|
|
|
node main.js
|
|
|
|
|
#or test if want check work
|
|
|
|
|
node test.js
|
2019-01-29 11:04:41 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-01-30 11:50:02 +00:00
|
|
|
|
## Configurate
|
|
|
|
|
You need create your config.js from config.template or config.example
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
var config = {
|
|
|
|
|
lemon_bin: "./lemon-src/lemon-js", // папка с исходниками лемона
|
|
|
|
|
input_path: "parser_template/", // папка с шаблоном парсера
|
|
|
|
|
output_path: "out/", // папка куда будет выгружен файл
|
|
|
|
|
file_name: "parser", // имя файла шаблона
|
|
|
|
|
flags: "-l", // флаги для ./lemon-js
|
|
|
|
|
require_templates: "require_js/" // Папка для шаблона require_js/
|
|
|
|
|
};
|
|
|
|
|
```
|
2019-01-28 12:08:59 +00:00
|
|
|
|
|
|
|
|
|
```bash
|
2019-01-30 11:50:02 +00:00
|
|
|
|
cat config.template > config.js
|
|
|
|
|
# or
|
|
|
|
|
cat config.example > config.js
|
2019-01-28 12:08:59 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-01-29 09:00:02 +00:00
|
|
|
|
## Test
|
|
|
|
|
Also you can test your parser
|
|
|
|
|
```bash
|
|
|
|
|
node test.js --c=<your_config>.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Also
|
2019-01-29 09:09:17 +00:00
|
|
|
|
You can use this syntax for include your *.y file.
|
2019-01-29 09:00:02 +00:00
|
|
|
|
```bash
|
2019-01-29 09:09:17 +00:00
|
|
|
|
<&&REPLACER{<file_path>}&&>
|
2019-01-29 09:00:02 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-01-28 12:08:59 +00:00
|
|
|
|
## Special Directives
|
|
|
|
|
|
|
|
|
|
See lemon.html for additional documentation.
|
|
|
|
|
|
|
|
|
|
- %name - Set parser class name (default is "Parse")
|
|
|
|
|
- %include - Include code in the beginning of file (usefull for imports)
|
|
|
|
|
- %code - Include code in the end of file (usefull for exports or main code)
|
|
|
|
|
- %token_destructor - Define code which will be executed on token destruction.
|
|
|
|
|
- %default_destructor
|
|
|
|
|
- %token_prefix - Define token name prefix.
|
|
|
|
|
- %syntax_error - Define custom error handler for syntax erorrs.
|
|
|
|
|
- %parse_accept - Define handler for all accepted tokens.
|
|
|
|
|
- %parse_failure - Define handler for parse errors.
|
|
|
|
|
- %stack_overflow - Define handler for stack overflow.
|
|
|
|
|
- %extra_argument - **NOT SUPPORTED**
|
|
|
|
|
- %token_type - **NOT SUPPORTED**
|
|
|
|
|
- %default_type - **NOT SUPPORTED**
|
|
|
|
|
- %stack_size - Set default stack size.
|
|
|
|
|
- %start_symbol
|
|
|
|
|
- %left - Set left associative tokens.
|
|
|
|
|
- %right - Set right associative tokens.
|
|
|
|
|
- %nonassoc - Set non associative tokens.
|
|
|
|
|
- %destructor - Define custom parser destructor.
|
|
|
|
|
- %type - **NOT SUPPORTED**
|
|
|
|
|
- %fallback - Define fallback logic for tokens.
|
|
|
|
|
- %wildcard - Define WILDCARD token.
|
|
|
|
|
- %token_class - **NOT SUPPORTED**
|
|
|
|
|
|
2019-01-29 09:15:11 +00:00
|
|
|
|
## Lexer
|
2019-01-29 09:16:11 +00:00
|
|
|
|
Used re2js lexer from: [http://git.macaw.me:3000/chichenkov/re2-js-generator](http://git.macaw.me:3000/chichenkov/re2-js-generator)
|
2019-01-29 09:15:11 +00:00
|
|
|
|
|
2019-01-29 08:17:41 +00:00
|
|
|
|
## Original project
|
2019-01-30 15:03:10 +00:00
|
|
|
|
See https://github.com/sormy/lemon-js
|
|
|
|
|
|
|
|
|
|
## Links
|
|
|
|
|
- Used js-beautify-node from: [https://github.com/rwaldron/js-beautify-node](https://github.com/rwaldron/js-beautify-node)
|
|
|
|
|
- Used args-parser from: [https://www.npmjs.com/package/args-parser](https://www.npmjs.com/package/args-parser)
|