Skip to content

✨ Simple Regex alternative. More readable and easy-to-support.

License

Notifications You must be signed in to change notification settings

qrailibs/Formula

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 END

Formula 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 -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

Examples

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 test CLI 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 compile CLI command
  • Added match
  • Added group
  • Added if and else
  • Added define

About

✨ Simple Regex alternative. More readable and easy-to-support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published