Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 122 lines (83 sloc) 3.462 kb
05eedb5 @itod initial add
authored
1 /*
2 A Grammar for Apple's NSPredicate String Format Syntax
3
4 See: http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html
5
6 */
7
8 @wordState = '#';
9 @wordChars = '.' '[' ']';
10
11 @symbols = '==' '>=' '=>' '<=' '=<' '!=' '<>' '&&' '||';
12
13 @start = expr;
14
15 // Expressions
16 expr = orTerm orOrTerm*;
17 orOrTerm = or orTerm;
18 orTerm = andTerm andAndTerm*;
19 andAndTerm = and andTerm;
20 andTerm = primaryExpr | compoundExpr;
21 compoundExpr = '('! expr ')'!;
22 primaryExpr = predicate | negatedPredicate;
23 negatedPredicate = not predicate;
24
25 predicate = boolPredicate | comparisonPredicate | stringTestPredicate | collectionTestPredicate;
26
27
28 // values
29 value = keyPath | string | num | bool | array;
30
31 string = QuotedString;
32 num = Number;
33 bool = true | false;
34 true = 'true'!;
35 false = 'false'!;
36
37 // arrays
38 array = '{' arrayContentsOpt '}'!;
39 arrayContentsOpt = Empty | arrayContents;
40 arrayContents = value commaValue*;
41 commaValue = ','! value;
42
43
44 // keyPaths
45 keyPath = Word;
46
47 // keyPath = key dotKey*;
48 // key = name memberAccess?;
49 // name = Word;
50 // dotKey = '.' key;
51 // memberAccess = '[' (num | 'FIRST' | 'LAST' | 'SIZE') ']';
52
53
54 // Comparison Tests
55 comparisonPredicate = numComparisonPredicate | collectionComparisonPredicate;
56
57 numComparisonPredicate = numComparisonValue comparisonOp numComparisonValue;
58 numComparisonValue = keyPath | num;
59
60 comparisonOp = eq | gt | lt | gtEq | ltEq | notEq | between;
61
62 eq = '=' | '==';
63 gt = '>';
64 lt = '<';
65 gtEq = '>=' | '=>';
66 ltEq = '<=' | '=<';
67 notEq = '!=' | '<>';
68 between = 'BETWEEN';
69
70 // breaking these out to make the assembler callbacks simpler
71 collectionComparisonPredicate = collectionLtPredicate | collectionGtPredicate | collectionLtEqPredicate | collectionGtEqPredicate | collectionEqPredicate | collectionNotEqPredicate;
72
73 collectionLtPredicate = aggregateOp collection lt value;
74 collectionGtPredicate = aggregateOp collection gt value;
75 collectionLtEqPredicate = aggregateOp collection ltEq value;
76 collectionGtEqPredicate = aggregateOp collection gtEq value;
77 collectionEqPredicate = aggregateOp collection eq value;
78 collectionNotEqPredicate = aggregateOp collection notEq value;
79
80
81
82 // Boolean Value Predicates
83 boolPredicate = truePredicate | falsePredicate;
84
85 truePredicate = 'TRUEPREDICATE'!;
86 falsePredicate = 'FALSEPREDICATE'!;
87
88
89
90 // Compound Expressions
91 and = 'AND'! | '&&'!;
92 or = 'OR'! | '||'!;
93 not = 'NOT'! | '!'!;
94
95
96
97 // String Tests
98 stringTestPredicate = string stringTestOp value;
99
100 stringTestOp = beginswith | contains | endswith | like | matches;
101
102 beginswith = 'BEGINSWITH';
103 contains = 'CONTAINS';
104 endswith = 'ENDSWITH';
105 like = 'LIKE';
106 matches = 'MATCHES';
107
108
109 // Collection Tests
110 collectionTestPredicate = value in collection;
111 collection = keyPath | array;
112 in = 'IN'!;
113
114
115 // Aggregate Operators
116 aggregateOp = any | some | all | none;
117 any = 'ANY';
118 some = 'SOME';
119 all = 'ALL';
120 none = 'NONE';
121
Something went wrong with that request. Please try again.