Merge pull request #507 from MauricioFauth/token-type-enum · phpmyadmin/sql-parser@61baa39

@@ -9,6 +9,7 @@

99

use PhpMyAdmin\SqlParser\Parser;

1010

use PhpMyAdmin\SqlParser\Token;

1111

use PhpMyAdmin\SqlParser\TokensList;

12+

use PhpMyAdmin\SqlParser\TokenType;

12131314

use function count;

1415

@@ -98,12 +99,12 @@ public static function parse(Parser $parser, TokensList $list, array $options =

9899

$token = $list->tokens[$list->idx];

99100100101

// Skipping whitespaces and comments.

101-

if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {

102+

if (($token->type === TokenType::Whitespace) || ($token->type === TokenType::Comment)) {

102103

continue;

103104

}

104105105106

if ($state === 0) {

106-

if ($token->type === Token::TYPE_KEYWORD) {

107+

if ($token->type === TokenType::Keyword) {

107108

switch ($token->keyword) {

108109

case 'WHEN':

109110

++$list->idx; // Skip 'WHEN'

@@ -132,7 +133,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

132133

}

133134

} elseif ($state === 1) {

134135

if ($type === 0) {

135-

if ($token->type === Token::TYPE_KEYWORD) {

136+

if ($token->type === TokenType::Keyword) {

136137

switch ($token->keyword) {

137138

case 'WHEN':

138139

++$list->idx; // Skip 'WHEN'

@@ -154,23 +155,23 @@ public static function parse(Parser $parser, TokensList $list, array $options =

154155

break 2;

155156

}

156157

}

157-

} elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'THEN') {

158+

} elseif ($token->type === TokenType::Keyword && $token->keyword === 'THEN') {

158159

++$list->idx; // Skip 'THEN'

159160

$newResult = Expression::parse($parser, $list);

160161

$state = 0;

161162

$ret->results[] = $newResult;

162-

} elseif ($token->type === Token::TYPE_KEYWORD) {

163+

} elseif ($token->type === TokenType::Keyword) {

163164

$parser->error('Unexpected keyword.', $token);

164165

break;

165166

}

166167

} elseif ($state === 2) {

167168

if ($type === 0) {

168-

if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'THEN') {

169+

if ($token->type === TokenType::Keyword && $token->keyword === 'THEN') {

169170

++$list->idx; // Skip 'THEN'

170171

$newResult = Expression::parse($parser, $list);

171172

$ret->results[] = $newResult;

172173

$state = 1;

173-

} elseif ($token->type === Token::TYPE_KEYWORD) {

174+

} elseif ($token->type === TokenType::Keyword) {

174175

$parser->error('Unexpected keyword.', $token);

175176

break;

176177

}

@@ -187,17 +188,17 @@ public static function parse(Parser $parser, TokensList $list, array $options =

187188

$token = $list->tokens[$list->idx];

188189189190

// End of statement.

190-

if ($token->type === Token::TYPE_DELIMITER) {

191+

if ($token->type === TokenType::Delimiter) {

191192

break;

192193

}

193194194195

// Skipping whitespaces and comments.

195-

if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) {

196+

if (($token->type === TokenType::Whitespace) || ($token->type === TokenType::Comment)) {

196197

continue;

197198

}

198199199200

// Handle optional AS keyword before alias

200-

if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'AS') {

201+

if ($token->type === TokenType::Keyword && $token->keyword === 'AS') {

201202

if ($asFound || ! empty($ret->alias)) {

202203

$parser->error('Potential duplicate alias of CASE expression.', $token);

203204

break;

@@ -209,7 +210,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =

209210210211

if (

211212

$asFound

212-

&& $token->type === Token::TYPE_KEYWORD

213+

&& $token->type === TokenType::Keyword

213214

&& ($token->flags & Token::FLAG_KEYWORD_RESERVED || $token->flags & Token::FLAG_KEYWORD_FUNCTION)

214215

) {

215216

$parser->error('An alias expected after AS but got ' . $token->value, $token);

@@ -219,9 +220,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =

219220220221

if (

221222

$asFound

222-

|| $token->type === Token::TYPE_STRING

223-

|| ($token->type === Token::TYPE_SYMBOL && ! $token->flags & Token::FLAG_SYMBOL_VARIABLE)

224-

|| $token->type === Token::TYPE_NONE

223+

|| $token->type === TokenType::String

224+

|| ($token->type === TokenType::Symbol && ! $token->flags & Token::FLAG_SYMBOL_VARIABLE)

225+

|| $token->type === TokenType::None

225226

) {

226227

// An alias is expected (the keyword `AS` was previously found).

227228

if (! empty($ret->alias)) {