/**
* @param Parser $parser The instance that requests parsing.
* @param TokensList $list The list of tokens to be parsed.
*
* @return void
*/
public function parse(Parser $parser, TokensList $list)
{
++$list->idx;
// Skipping `CREATE`.
// Parsing options.
$this->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
++$list->idx;
// Skipping last option.
// Parsing the field name.
$this->name = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
if (empty($this->name)) {
$parser->error(__('The name of the entity was expected.'), $list->tokens[$list->idx]);
} else {
++$list->idx;
// Skipping field.
}
if ($this->options->has('DATABASE')) {
$this->entityOptions = OptionsArray::parse($parser, $list, static::$DB_OPTIONS);
} elseif ($this->options->has('TABLE')) {
$this->fields = CreateDefinition::parse($parser, $list);
if (empty($this->fields)) {
$parser->error(__('At least one column definition was expected.'), $list->tokens[$list->idx]);
}
++$list->idx;
$this->entityOptions = OptionsArray::parse($parser, $list, static::$TABLE_OPTIONS);
} elseif ($this->options->has('PROCEDURE') || $this->options->has('FUNCTION')) {
$this->parameters = ParameterDefinition::parse($parser, $list);
if ($this->options->has('FUNCTION')) {
$token = $list->getNextOfType(Token::TYPE_KEYWORD);
if ($token->value !== 'RETURNS') {
$parser->error(__('A "RETURNS" keyword was expected.'), $token);
} else {
++$list->idx;
$this->return = DataType::parse($parser, $list);
}
}
++$list->idx;
$this->entityOptions = OptionsArray::parse($parser, $list, static::$FUNC_OPTIONS);
++$list->idx;
for (; $list->idx < $list->count; ++$list->idx) {
$token = $list->tokens[$list->idx];
$this->body[] = $token;
}
} else {
if ($this->options->has('VIEW')) {
$token = $list->getNext();
// Skipping whitespaces and comments.
// Parsing columns list.
if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
--$list->idx;
// getNext() also goes forward one field.
$this->fields = ArrayObj::parse($parser, $list);
++$list->idx;
// Skipping last token from the array.
$list->getNext();
}
// Parsing the `AS` keyword.
for (; $list->idx < $list->count; ++$list->idx) {
$token = $list->tokens[$list->idx];
if ($token->type === Token::TYPE_DELIMITER) {
break;
}
$this->body[] = $token;
}
} else {
if ($this->options->has('TRIGGER')) {
// Parsing the time and the event.
$this->entityOptions = OptionsArray::parse($parser, $list, static::$TRIGGER_OPTIONS);
++$list->idx;
$list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'ON');
++$list->idx;
// Skipping `ON`.
// Parsing the name of the table.
$this->table = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
++$list->idx;
$list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'FOR EACH ROW');
++$list->idx;
// Skipping `FOR EACH ROW`.
for (; $list->idx < $list->count; ++$list->idx) {
$token = $list->tokens[$list->idx];
$this->body[] = $token;
}
}
}
}
}