1.3.5 • Published 2 years ago
formula-cli v1.3.5
Formula
Simple language for describing data formats, transpilable to RegExp.
Syntax
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 ENDFormula is gonna be transpiled into following RegExp:
^#((?:[a-f0-9]{3})|(?:[a-f0-9]{6}))$Usage
Install a Formula CLI globally:
npm i formula-cli -gAfter installation you can use CLI to compile formula file:
formula compile example.formulaAnd also you can compile the whole directory:
formula compile src --dirFor running a tests inside formula:
formula test example.formulaExamples
You can see examples of formulas in /example directory in this repository.
Changelog
v1.2.2
- Added lookahead & lookbehind syntax (
match ...'a' | 'a'...)
v1.2.1
- Fixed infinite loop when
#at the end of file
v1.2.0
- Added testing system that allows to test formulas matching
- Added
formula testCLI command - Added
test
v1.1.1
- Added support of both string formats (
'and") - Added support of
+/(min,max)and?to groups - Added
|operator for matching - Fixed if-else compilation
v1.1.0
- Added
formula compileCLI command - Added
match - Added
group - Added
ifandelse - Added
define