/** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. * @param array $options Parameters for parsing. * * @return CallKeyword */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { $ret = new CallKeyword(); /** * The state of the parser. * * Below are the states of the parser. * * 0 ----------------------[ name ]-----------------------> 1 * * 1 --------------------[ parameters ]-------------------> -1 * * @var int */ $state = 0; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. * @var Token */ $token = $list->tokens[$list->idx]; // End of statement. if ($token->type === Token::TYPE_DELIMITER) { break; } // Skipping whitespaces and comments. if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { continue; } if ($state === 0) { $ret->name = $token->value; $state = 1; } elseif ($state === 1) { if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') { $ret->parameters = ArrayFragment::parse($parser, $list)->values; } break; } } return $ret; }
/** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. * @param array $options Parameters for parsing. * * @return ReferencesKeyword */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { $ret = new ReferencesKeyword(); /** * The state of the parser. * * Below are the states of the parser. * * 0 ----------------------[ table ]---------------------> 1 * * 1 ---------------------[ columns ]--------------------> 2 * * 2 ---------------------[ options ]--------------------> -1 * * @var int */ $state = 0; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. * @var Token */ $token = $list->tokens[$list->idx]; // End of statement. if ($token->type === Token::TYPE_DELIMITER) { break; } // Skipping whitespaces and comments. if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { continue; } if ($state === 0) { $ret->table = $token->value; $state = 1; } else { if ($state === 1) { $ret->columns = ArrayFragment::parse($parser, $list)->values; $state = 2; } else { if ($state === 2) { $ret->options = OptionsFragment::parse($parser, $list, static::$REFERENCES_OPTIONS); ++$list->idx; break; } } } } --$list->idx; return $ret; }
/** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. * @param array $options Parameters for parsing. * * @return DataTypeFragment[] */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { $ret = new DataTypeFragment(); /** * The state of the parser. * * Below are the states of the parser. * * 0 -------------------[ data type ]--------------------> 1 * * 1 ----------------[ size and options ]----------------> 2 * * @var int */ $state = 0; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. * @var Token */ $token = $list->tokens[$list->idx]; // Skipping whitespaces and comments. if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { continue; } if ($state === 0) { $ret->name = strtoupper($token->value); if ($token->type !== Token::TYPE_KEYWORD || !($token->flags & Token::FLAG_KEYWORD_DATA_TYPE)) { $parser->error('Unrecognized data type.', $token); } $state = 1; } elseif ($state === 1) { if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') { $size = ArrayFragment::parse($parser, $list); ++$list->idx; $ret->parameters = $ret->name === 'ENUM' || $ret->name === 'SET' ? $size->raw : $size->values; } $ret->options = OptionsFragment::parse($parser, $list, static::$DATA_TYPE_OPTIONS); ++$list->idx; break; } } if (empty($ret->name)) { return null; } --$list->idx; return $ret; }
/** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. * @param array $options Parameters for parsing. * * @return IntoKeyword */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { $ret = new IntoKeyword(); /** * The state of the parser. * * Below are the states of the parser. * * 0 -----------------------[ name ]----------------------> 1 * 0 ---------------------[ OUTFILE ]---------------------> 2 * * 1 ------------------------[ ( ]------------------------> -1 * * 2 ---------------------[ filename ]--------------------> 1 * * @var int */ $state = 0; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. * @var Token */ $token = $list->tokens[$list->idx]; // End of statement. if ($token->type === Token::TYPE_DELIMITER) { break; } // Skipping whitespaces and comments. if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) { continue; } if ($token->type === Token::TYPE_KEYWORD && $token->flags & Token::FLAG_KEYWORD_RESERVED) { if ($state === 0 && $token->value === 'OUTFILE') { $ret->type = 'OUTFILE'; $state = 2; continue; } // No other keyword is expected. break; } if ($state === 0) { $ret->name = $token->value; $state = 1; } else { if ($state === 1) { if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') { $ret->fields = ArrayFragment::parse($parser, $list)->values; ++$list->idx; } break; } else { if ($state === 2) { $ret->name = $token->value; ++$list->idx; break; } } } } --$list->idx; return $ret; }