All Projects → nikunjy → Rules

nikunjy / Rules

Licence: mit
Generic Rules engine in golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Rules

Nrules
Rules engine for .NET, based on the Rete matching algorithm, with internal DSL in C#.
Stars: ✭ 1,003 (+944.79%)
Mutual labels:  rules, rules-engine
Roulette
A text/template based rules engine
Stars: ✭ 32 (-66.67%)
Mutual labels:  rules, rules-engine
Rulebook
100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
Stars: ✭ 562 (+485.42%)
Mutual labels:  rules, rules-engine
Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (+1107.29%)
Mutual labels:  rules, rules-engine
rools
A small rule engine for Node.
Stars: ✭ 118 (+22.92%)
Mutual labels:  rules, rules-engine
powerflows-dmn
Power Flows DMN - Powerful decisions and rules engine
Stars: ✭ 46 (-52.08%)
Mutual labels:  rules, rules-engine
Node Rules
Node-rules is a light weight forward chaining rule engine written in JavaScript.
Stars: ✭ 481 (+401.04%)
Mutual labels:  rules, rules-engine
Rulerz
Powerful implementation of the Specification pattern in PHP
Stars: ✭ 827 (+761.46%)
Mutual labels:  rules, rules-engine
Rulette
A pragmatic business rule management system
Stars: ✭ 91 (-5.21%)
Mutual labels:  rules, rules-engine
Nrules.language
Business rules language for NRules rules engine.
Stars: ✭ 55 (-42.71%)
Mutual labels:  rules, rules-engine
Precept
A declarative programming framework
Stars: ✭ 621 (+546.88%)
Mutual labels:  rules
Postcss At Rules Variables
PostCss plugin to use CSS Custom Properties in at-rule @each, @for, @if, @else and more...
Stars: ✭ 52 (-45.83%)
Mutual labels:  rules
Ultimateapplockerbypasslist
The goal of this repository is to document the most common techniques to bypass AppLocker.
Stars: ✭ 1,186 (+1135.42%)
Mutual labels:  rules
Chn Iplist
Chnroutes rules for routers、Shadowrocket、Quantumult、Kitsunebi、acl、BifrostV、v2rayNG、v2rayN、clash、pac、Qv2ray、v2ray config file.
Stars: ✭ 469 (+388.54%)
Mutual labels:  rules
Rules
Stick Rules -- Quantumult X / Loon / ClashX Rules \ Quantumult back to CN Rules
Stars: ✭ 458 (+377.08%)
Mutual labels:  rules
Firestore Security Tests
Setup and run tests to verify Firestore security rules
Stars: ✭ 40 (-58.33%)
Mutual labels:  rules
Peasy.net
A business logic micro-framework for .NET and .NET Core
Stars: ✭ 406 (+322.92%)
Mutual labels:  rules-engine
White Book
有关于 CNBlackListR 项目的说明
Stars: ✭ 94 (-2.08%)
Mutual labels:  rules
Grules
A simple, but expandable, rules engine for Go
Stars: ✭ 65 (-32.29%)
Mutual labels:  rules-engine
Android Udev Rules
Android udev rules list aimed to be the most comprehensive on the net
Stars: ✭ 810 (+743.75%)
Mutual labels:  rules

Golang Rules Engine Build Status codecov

Rules engine written in golang with the help of antlr.

This package will be very helpful in situations where you have a generic rule and want to verify if your values (specified using map[string]interface{}) satisfy the rule.

Here are some examples:

  parser.Evaluate("x eq 1", map[string]interface{}{"x": 1})
  parser.Evaluate("x == 1", map[string]interface{}{"x": 1})
  parser.Evaluate("x lt 1", map[string]interface{}{"x": 1})
  parser.Evaluate("x < 1", map[string]interface{}{"x": 1})
  parser.Evaluate("x gt 1", map[string]interface{}{"x": 1})
  
  parser.Evaluate("x.a == 1 and x.b.c <= 2", map[string]interface{}{
    "x": map[string]interface{}{
       "a": 1,
       "b": map[string]interface{}{
          "c": 2,
       },
    },
  })
  

  parser.Evaluate("y == 4 and (x > 1)", map[string]interface{}{"x": 1})

  parser.Evaluate("y == 4 and (x IN [1,2,3])", map[string]interface{}{"x": 1})

  parser.Evaluate("y == 4 and (x eq 1.2.3)", map[string]interface{}{"x": "1.2.3"})
  

Operations

All the operations can be written capitalized or lowercase (ex: eq or EQ can be used)

Logical Operations supported are AND OR

Compare Expression and their definitions (a|b means you can use either one of the two a or b):

eq|==: equals to 
ne|!=: not equals to
lt|<: less than 
gt|>: greater than
le|<=: less than equal to
ge|>=: greater than equal to 
co: contains 
sw: starts with 
ew: ends with
in: in a list
pr: present
not: not of a logical expression

How to use it

Use your dependency manager to import github.com/nikunjy/rules/parser. This will let you parse a rule and keep the parsed representation around. Alternatively, you can also use github.com/nikunjy/rules directly to call the root Evaluate(string, map[string]interface{}) method.

I would recommend importing github.com/nikunjy/rules/parser

How to extend the grammar

  1. Please look at this antlr tutorial, the link will show you how to setup antlr. The article has a whole lot of detail about antlr I encourage you to read it, you might also like my blog post about this repo.
  2. After taking a look at the antlr tutorial, you can extend the JsonQuery.g4 file.
  3. Compile the parser antlr4 -Dlanguage=Go -visitor -no-listener JsonQuery.g4 -o ./ (Note: -o is the output directory, make sure all the stuff it generates is in the parser directory of the root repo folder)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].