emphasis added for clarity.
The predicate is a piece of JavaScript code that is executed as if it was inside a function. It gets the match results of labeled expressions in preceding expression as its arguments. It should return some JavaScript value using the return statement. If the returned value evaluates to true in boolean context, just return undefined and do not advance the parser position; otherwise consider the match failed.
The code inside the predicate can access all variables and functions defined in the initializer at the beginning of the grammar.
The code inside the predicate can also access location information using the location function. It returns an object like this:
{
start: { offset: 23, line: 5, column: 6 },
end: { offset: 23, line: 5, column: 6 }
}
The start and end properties both refer to the current parse position. The offset property contains an offset as a zero-based index and line and column properties contain a line and a column as one-based indices.
The code inside the predicate can also access the parser object using the parser variable and options passed to the parser using the options variable.
The code inside the predicate can also access the current parse position using the offset function. It returns a zero-based character index into the input string. The code can also access the current line and column using the line and column functions. Both return one-based indexes.
The code inside the predicate can also access options passed to the parser using the options variable.
Note that curly braces in the predicate code must be balanced.