-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.bnf
60 lines (47 loc) · 2.68 KB
/
grammar.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Lexical elements */
_digit : '0'-'9' ;
_letter : 'a'-'z' | 'A'-'Z' ;
_alphanumeric : _letter | _digit ;
variable : _letter { _alphanumeric | '.' | '_' } ;
int_lit : _digit {_digit} ;
float_lit : _digit { '.' | _digit } ;
string_lit : '"' {.} '"' | '\'' {.} '\'';
!whitespace : ' ' | '\t' | '\n' | '\r' ;
<<import ( "github.com/sjhitchner/go-decide/expression" )>>
/*
Expression : Expression "and" Expression << expression.NewLogicalAnd($0, $2) >>
| Expression "or" Expression << expression.NewLogicalOr($0, $2) >>
| "not" Expression << expression.NewNegation($1) >>
| Term
;
| "(" Expression ")" << expression.NewClause($1) >>
| empty << expression.NewNull() >>
| "undefined" << expression.NewNull() >>
| "null" << expression.NewNull() >>
*/
Expression : Term "or" Term << expression.NewLogicalOr($0, $2) >>
| Term "and" Term << expression.NewLogicalAnd($0, $2) >>
| "not" Term << expression.NewNegation($1) >>
| Term
;
Term : Factor ">" Factor << expression.NewComparisonGreaterThan($0, $2) >>
| Factor ">=" Factor << expression.NewComparisonGreaterThanEquals($0, $2) >>
| Factor "<" Factor << expression.NewComparisonLessThan($0, $2) >>
| Factor "<=" Factor << expression.NewComparisonLessThanEquals($0, $2) >>
| Factor "=" Factor << expression.NewComparisonEquals($0, $2) >>
| Factor "==" Factor << expression.NewComparisonEquals($0, $2) >>
| Factor "!=" Factor << expression.NewComparisonNotEquals($0, $2) >>
| Factor "is" Factor << expression.NewComparisonIs($0, $2) >>
| Factor "is" "not" Factor << expression.NewComparisonIsNot($0, $3) >>
| Factor "contains" Factor << expression.NewComparisonContains($0, $2) >>
| Factor "matches" Factor << expression.NewMatches($0, $2) >>
| Factor
;
Factor
: variable << expression.NewResolver($0) >>
| string_lit << expression.NewLiteralString($0) >>
| int_lit << expression.NewLiteralInt($0) >>
| float_lit << expression.NewLiteralFloat($0) >>
| "true" << expression.NewLiteralBool(true) >>
| "false" << expression.NewLiteralBool(false) >>
;