-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
matching-rule-definition.g4
68 lines (59 loc) · 2.04 KB
/
matching-rule-definition.g4
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
61
62
63
64
65
66
67
68
grammar MatchingRuleDefinition;
/**
* Parse a matcher expression into a MatchingRuleDefinition containing the example value, matching rules and any generator.
* The following are examples of matching rule definitions:
* * `matching(type,'Name')` - type matcher
* * `matching(number,100)` - number matcher
* * `matching(datetime, 'yyyy-MM-dd','2000-01-01')` - datetime matcher with format string
**/
matchingDefinition :
matchingDefinitionExp ( COMMA matchingDefinitionExp )* EOF
;
matchingDefinitionExp :
(
'matching' LEFT_BRACKET matchingRule RIGHT_BRACKET
| 'notEmpty' LEFT_BRACKET primitiveValue RIGHT_BRACKET
| 'eachKey' LEFT_BRACKET matchingDefinitionExp RIGHT_BRACKET
| 'eachValue' LEFT_BRACKET matchingDefinitionExp RIGHT_BRACKET
| 'atLeast' LEFT_BRACKET DIGIT+ RIGHT_BRACKET
| 'atMost' LEFT_BRACKET DIGIT+ RIGHT_BRACKET
)
;
matchingRule :
(
( 'equalTo' | 'type' ) COMMA primitiveValue )
| 'number' COMMA ( DECIMAL_LITERAL | INTEGER_LITERAL | 'fromProviderState' fromProviderState )
| 'integer' COMMA ( INTEGER_LITERAL | 'fromProviderState' fromProviderState )
| 'decimal' COMMA ( DECIMAL_LITERAL | 'fromProviderState' fromProviderState )
| matcherType=( 'datetime' | 'date' | 'time' ) COMMA string COMMA ( string | 'fromProviderState' fromProviderState )
| 'regex' COMMA string COMMA string
| 'include' COMMA string
| 'boolean' COMMA BOOLEAN_LITERAL
| 'semver' COMMA string
| 'contentType' COMMA string COMMA string
| DOLLAR string
;
primitiveValue :
string
| DECIMAL_LITERAL
| INTEGER_LITERAL
| BOOLEAN_LITERAL
| 'fromProviderState' fromProviderState
;
fromProviderState :
LEFT_BRACKET string COMMA primitiveValue RIGHT_BRACKET
;
string :
STRING_LITERAL
| 'null'
;
INTEGER_LITERAL : '-'? DIGIT+ ;
DECIMAL_LITERAL : '-'? DIGIT+ '.' DIGIT+ ;
fragment DIGIT : [0-9] ;
LEFT_BRACKET : '(' ;
RIGHT_BRACKET : ')' ;
STRING_LITERAL : '\'' (~['])* '\'' ;
BOOLEAN_LITERAL : 'true' | 'false' ;
COMMA : ',' ;
DOLLAR : '$';
WS : [ \t\n\r] + -> skip ;