Skip to content

Commit 36b12fa

Browse files
author
Bart Koelman
committed
Added filter grammar to documentation
1 parent d8fb8c3 commit 36b12fa

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

docs/usage/reading/filtering.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ If you want to use the new filter notation in that case, prefix the parameter va
125125
GET /articles?filter[caption]=tech&filter=expr:equals(caption,'cooking')) HTTP/1.1
126126
```
127127

128-
## Custom Filters
128+
# Custom Filters
129129

130130
There are multiple ways you can add custom filters:
131131

@@ -134,3 +134,62 @@ There are multiple ways you can add custom filters:
134134
3. Add an implementation of `IQueryConstraintProvider` to supply additional `FilterExpression`s, which are combined with existing filters using AND operator
135135
4. Override `EntityFrameworkCoreRepository.ApplyQueryLayer` to adapt the `IQueryable<T>` expression just before execution
136136
5. Take a deep dive and plug into reader/parser/tokenizer/visitor/builder for adding additional general-purpose filter operators
137+
138+
# Filter syntax
139+
140+
For reference, we provide the EBNF grammar for filter expressions below (in [ANTLR4](https://github.com/antlr/antlr4) style):
141+
142+
```ebnf
143+
grammar Filter;
144+
145+
filterExpression:
146+
notExpression
147+
| logicalExpression
148+
| comparisonExpression
149+
| matchTextExpression
150+
| anyExpression
151+
| hasExpression;
152+
153+
notExpression:
154+
'not' LPAREN filterExpression RPAREN;
155+
156+
logicalExpression:
157+
( 'and' | 'or' ) LPAREN filterExpression ( COMMA filterExpression )* RPAREN;
158+
159+
comparisonExpression:
160+
( 'equals' | 'greaterThan' | 'greaterOrEqual' | 'lessThan' | 'lessOrEqual' ) LPAREN (
161+
countExpression | fieldChain
162+
) COMMA (
163+
countExpression | literalConstant | 'null' | fieldChain
164+
) RPAREN;
165+
166+
matchTextExpression:
167+
( 'contains' | 'startsWith' | 'endsWith' ) LPAREN fieldChain COMMA literalConstant RPAREN;
168+
169+
anyExpression:
170+
'any' LPAREN fieldChain COMMA literalConstant ( COMMA literalConstant )+ RPAREN;
171+
172+
hasExpression:
173+
'has' LPAREN fieldChain ( COMMA filterExpression )? RPAREN;
174+
175+
countExpression:
176+
'count' LPAREN fieldChain RPAREN;
177+
178+
fieldChain:
179+
FIELD ( '.' FIELD )*;
180+
181+
literalConstant:
182+
ESCAPED_TEXT;
183+
184+
LPAREN: '(';
185+
RPAREN: ')';
186+
COMMA: ',';
187+
188+
fragment OUTER_FIELD_CHARACTER: [A-Za-z0-9];
189+
fragment INNER_FIELD_CHARACTER: [A-Za-z0-9_-];
190+
FIELD: OUTER_FIELD_CHARACTER ( INNER_FIELD_CHARACTER* OUTER_FIELD_CHARACTER )?;
191+
192+
ESCAPED_TEXT: '\'' ( ~['] | '\'\'' )* '\'' ;
193+
194+
LINE_BREAKS: [\r\n]+ -> skip;
195+
```

0 commit comments

Comments
 (0)