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
.
You can define a single rule using define-rule
(cl-bnf:define-rule word (:* . #'alpha-char-p) :call #'stringify)
...or using the define-grammar
(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"
:call
apply a function to the results usingfuncall
.:apply
apply a function to the results usingapply
.:tag
return a cons like(cons TAG RESULTS)
.- If none where specified, it return all matches.
This project is released under the MIT License.
See license
.