function parse_pattern($source, \ArrayIterator $options) { $tokens = Tokens::fromPattern($source); $result = parse_expr($tokens, $options); if ($tokens->current() != null) { $tokens->raiseException('unexpected ending: ' . implode(' ', $tokens->left())); } return new Required($result); }