Определение BNF предикатов какао

Эта статья определяет предикаты Какао в нотации Формы Бэкуса-Наура.

NSPredicate

NSPredicate ::= NSComparisonPredicate | NSCompoundPredicate
    | "(" NSPredicate ")" | TRUEPREDICATE | FALSEPREDICATE 

NSCompoundPredicate

NSCompoundPredicate ::= NSPredicate "AND" NSPredicate
    | NSPredicate "OR" NSPredicate
    | "NOT" NSPredicate

NSComparisonPredicate

NSComparisonPredicate ::= expression operation expression
    | aggregate_qualifier NSComparisonPredicate

Операции

CONTAINS и IN служите и в качестве агрегатных операторов и строковых операторов, в зависимости от типов их параметров.

operation ::= "=" | "!=" | "<" | ">" | "<=" | ">="
    | BETWEEN
    | aggregate_operations [ "[" string_options "]" ]
 
aggregate_operations ::= CONTAINS | IN | string_operations
 
string_operations ::= BEGINSWITH | ENDSWITH | LIKE | MATCHES
 
string_options ::= c | d | cd

Совокупный спецификатор

aggregate_qualifier ::= ANY | ALL | NONE | SOME

Выражение

expression ::= "(" expression ")"
    | binary_expression
    | function_expression
    | assignment_expression
    | index_expression
    | keypath_expression
    | value_expression
 

Выражение

value_expression ::= literal_value | literal_aggregate

Литеральное значение

literal_value ::= string_value
    | numeric_value
    | predicate_argument
    | predicate_variable
    | NULL
    | TRUE
    | FALSE
    | SELF

Строковое значение

string_value ::= "text" | 'text'

Параметр предиката

predicate_argument ::= "%" format_argument

Параметр формата

format_argument ::= "@" | "%" | "K"
    printf style conversion character

Предикатная переменная

predicate_variable ::= "$" identifier

Выражение Keypath

keypath_expression ::= identifier | "@" identifier
    | expression "." expression

Литеральный агрегат

literal_aggregate ::= "{" [ expression [ "," expression ... ] ] "}"

Индексное выражение

index_expression ::= array_expression "[" integer_expression "]"
    | dictionary_expression   "[" expression "]"
    | aggregate_expression "[" FIRST "]" 
    | aggregate_expression "[" LAST "]" 
    | aggregate_expression "[" SIZE "]" 

Составное выражение

aggregate_expression ::= array_expression | dictionary_expression

Выражение присваивания

assignment_expression ::= predicate_variable ":=" expression

Двоичное выражение

binary_expression ::= expression binary_operator expression
    | "-" expression

Бинарный оператор

binary_operator ::= "+" | "-" | "*" | "/" | "**"

Выражение function

function_expression ::= function_name "(" [ expression [ "," expression ... ] ] ")"

Имя функции

function_name ::= "sum" | "count" | "min" | "max"
    | "average" | "median" | "mode" | "stddev"
    | "sqrt" | "log" | "ln" | "exp"
    | "floor" | "ceiling" | "abs" | "trunc"
    | "random" | "randomn" | "now"

Выражение с массивами

array_expression ::= any expression that evaluates to an NSArray object

Выражение словаря

dictionary_expression ::= any expression that evaluates to an NSDictionary object

Целое выражение

integer_expression ::= any expression that evaluates to an integral value

Числовое значение

numeric_value ::= C style numeric constant

Идентификатор

identifier ::= C style identifier | "#" reserved_word