Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diasbruno/cl-bnf
A simple BNF parser.
https://github.com/diasbruno/cl-bnf
ast bnf common-lisp parser
Last synced: about 2 months ago
JSON representation
A simple BNF parser.
- Host: GitHub
- URL: https://github.com/diasbruno/cl-bnf
- Owner: diasbruno
- License: mit
- Created: 2018-05-07T05:28:26.000Z (almost 7 years ago)
- Default Branch: development
- Last Pushed: 2023-11-15T18:37:08.000Z (about 1 year ago)
- Last Synced: 2024-12-09T01:35:28.694Z (about 2 months ago)
- Topics: ast, bnf, common-lisp, parser
- Language: Common Lisp
- Homepage:
- Size: 38.1 KB
- Stars: 10
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# cl-bnf
[![CI](https://github.com/diasbruno/cl-bnf/actions/workflows/ci.yml/badge.svg)](https://github.com/diasbruno/cl-bnf/actions/workflows/ci.yml)A simple BNF.
`(:char . #\a)` matches the given char.
`(:string . "abc")` matches the given string.
`(:and exp ...)` all expressions must match.
`(:or exp ...)` returns the first expression that matches.
`(:* . exp)` collect all strings matches the expression, if any.
`(:? . exp)` optional match.
`#'some-function` execute the function with the current char. must return boolean.
`and` can also be written in a form of sequence `rule-c := rule-a rule-b`.
`or` can also be written using `:/`, for example: `rule-c := rule-a :/ rule-b`.
## rules & grammars
You can define a single rule using `define-rule`
```lisp
(cl-bnf:define-rule word (:* . #'alpha-char-p) :call #'stringify)
```...or using the `define-grammar`
```lisp
(cl-bnf:define-grammar (abc . parser)
abc := #\a #\b #\c
cba := "cba"
abc-cba := abc :/ cba
parser := abc-cba)(abc "abc") ;; (#\a #\b #\c)
(abc "cba") ;; "cba"
```#### transformations
- `:call` apply a function to the results using `funcall`.
- `:apply` apply a function to the results using `apply`.
- `:tag` return a cons like `(cons TAG RESULTS)`.
- If none where specified, it return all matches.## License
This project is released under the MIT License.
See `license`.