Simple language for describing data formats, transpilable to RegExp.
Example of advanced formula:
# Variables
define VAL match '[a-f0-9]'
define VAL_3 match(3) VAL
define VAL_6 match(6) VAL
# Tests
test '#fff'
test '#ababab'
test '#000000'
test '#f0f0f0'
# Formula
match START
match '#'
group {
match VAL_3 | VAL_6 # 3 or 6 hex values
}
match END
Formula is gonna be transpiled into following RegExp:
^#((?:[a-f0-9]{3})|(?:[a-f0-9]{6}))$
Install a Formula CLI globally:
npm i formula-cli -g
After installation you can use CLI to compile formula file:
formula compile example.formula
And also you can compile the whole directory:
formula compile src --dir
For running a tests inside formula:
formula test example.formula
You can see examples of formulas in /example
directory in this repository.
- Added lookahead & lookbehind syntax (
match ...'a' | 'a'...
)
- Fixed infinite loop when
#
at the end of file
- Added testing system that allows to test formulas matching
- Added
formula test
CLI command - Added
test
- Added support of both string formats (
'
and"
) - Added support of
+
/(min,max)
and?
to groups - Added
|
operator for matching - Fixed if-else compilation
- Added
formula compile
CLI command - Added
match
- Added
group
- Added
if
andelse
- Added
define