https://github.com/marihachi/luna-parse
A code generator of recursive descent parser and lexer.
https://github.com/marihachi/luna-parse
code-generator expression-parser lexer ll-parser modifiable parser recursive-descent-parser
Last synced: 3 months ago
JSON representation
A code generator of recursive descent parser and lexer.
- Host: GitHub
- URL: https://github.com/marihachi/luna-parse
- Owner: marihachi
- License: mit
- Created: 2025-08-30T19:37:12.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-09-29T18:27:10.000Z (3 months ago)
- Last Synced: 2025-09-29T18:42:19.112Z (3 months ago)
- Topics: code-generator, expression-parser, lexer, ll-parser, modifiable, parser, recursive-descent-parser
- Language: TypeScript
- Homepage:
- Size: 198 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.ja.md
- License: LICENSE
Awesome Lists containing this project
README
# luna-parse
[English](https://github.com/marihachi/luna-parse/blob/main/README.md) | [日本語](https://github.com/marihachi/luna-parse/blob/main/README.ja.md)
luna-parseはパーサージェネレーターです。\
仕様ファイルを記述することでコードを生成します。
luna-parseはPEG(Parsing Expression Grammar)の思想から影響を受けています。\
しかし、バックトラックを行わない点はPEGとは異なります。
luna-parseが生成するパーサーは、必要に応じて手作業で変更可能であるように設計されています。\
これはパーサジェネレーターが現実のパーサーを完全に生成することは困難であるためです。
現在開発を進めています!
仕様ファイルの例:
```
parser ExampleParser {
root = topLevel+ ;
topLevel = declareVar / show ;
declareVar = VAR IDENT EQUAL expr SEMI ;
show = SHOW expr SEMI ;
term = NUMBER / IDENT ;
expr = expression {
atom term ;
operator group {
infix operator ASTA ;
infix operator SLASH ;
}
operator group {
infix operator PLUS ;
infix operator MINUS ;
}
};
}
lexer ExampleLexer {
ignored token SPACING = SPACE / LF ;
SPACE = " " ;
LF = "\r\n" / "\n" ;
token ASTA = "*" ;
token SLASH = "/" ;
token PLUS = "+" ;
token MINUS = "-" ;
token EQUAL = "=" ;
token SEMI = ";" ;
token SHOW = "show" ;
token VAR = "var" ;
token NUMBER = [1-9] [0-9]* => { token.value = text(); };
token IDENT = [a-zA-Z] [a-zA-Z0-9_]* => { token.value = text(); };
}
```
パーサーへの入力:
```
var n1 = 2;
var n2 = 3;
show n1 * n2 + 1;
```
## Get started
## luna-parseって何?
luna-parseはBNFから派生した言語を用いて文法を記述します。\
一般的に、従来のパーサージェネレータは生成されたパーサーを手動で変更しやすくは作られていません。そのため、パーサージェネレータを使わずにパーサーを手書きする方がメンテナンスがしやすくなっていました。\
しかし、luna-parseは再帰下降パーサを生成するので、後から容易に修正できます。\
luna-parseは式を効率的に解析できる式パーサも提供します。式パーサとしてはOperator-precedence parser (Precedence Climbing method)に基づくパーサーが生成されます。
## License
MIT