Skip to content

Commit

Permalink
Adding detailed readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikunjy committed Apr 18, 2019
1 parent 82daff8 commit a417092
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
Rules engine written with the help of antlr and golang
# Golang Rules Engine
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:

```
type obj map[string]interface{}
parser.Evaluate("x eq 1", obj{"x": 1})
parser.Evaluate("x lt 1", obj{"x": 1})
parser.Evaluate("x gt 1", obj{"x": 1})
parser.Evaluate("x.a eq 1 and x.b.c le 2", obj{
"x": obj{
"a": 1,
"b": obj{
"c": 2,
},
},
})
parser.Evaluate("y eq 4 and (x gt 1)", obj{"x": 1})
parser.Evaluate("y eq 4 and (x IN [1 2 3])", obj{"x": 1})
parser.Evaluate("y eq 4 and (x eq 1.2.3)", obj{"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:
```
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
```


0 comments on commit a417092

Please sign in to comment.