Skip to content

Commit 1a11681

Browse files
committed
Use keyword attribute for comparing keyword name
We do not uppercase non reserved keywords, so this way we make the comparison properly handle that. Signed-off-by: Michal Čihař <[email protected]>
1 parent 5fdfa5b commit 1a11681

17 files changed

Lines changed: 80 additions & 82 deletions

src/Components/CaseExpression.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,21 @@ public static function parse(Parser $parser, TokensList $list, array $options =
105105

106106
if ($state === 0) {
107107
if ($token->type === Token::TYPE_KEYWORD
108-
&& $token->value === 'WHEN'
108+
&& $token->keyword === 'WHEN'
109109
) {
110110
++$list->idx; // Skip 'WHEN'
111111
$new_condition = Condition::parse($parser, $list);
112112
$type = 1;
113113
$state = 1;
114114
$ret->conditions[] = $new_condition;
115115
} elseif ($token->type === Token::TYPE_KEYWORD
116-
&& $token->value === 'ELSE'
116+
&& $token->keyword === 'ELSE'
117117
) {
118118
++$list->idx; // Skip 'ELSE'
119119
$ret->else_result = Expression::parse($parser, $list);
120120
$state = 0; // last clause of CASE expression
121121
} elseif ($token->type === Token::TYPE_KEYWORD
122-
&& ($token->value === 'END'
123-
|| $token->value === 'end')
122+
&& $token->keyword === 'END'
124123
) {
125124
$state = 3; // end of CASE expression
126125
++$list->idx;
@@ -136,21 +135,20 @@ public static function parse(Parser $parser, TokensList $list, array $options =
136135
} elseif ($state === 1) {
137136
if ($type === 0) {
138137
if ($token->type === Token::TYPE_KEYWORD
139-
&& $token->value === 'WHEN'
138+
&& $token->keyword === 'WHEN'
140139
) {
141140
++$list->idx; // Skip 'WHEN'
142141
$new_value = Expression::parse($parser, $list);
143142
$state = 2;
144143
$ret->compare_values[] = $new_value;
145144
} elseif ($token->type === Token::TYPE_KEYWORD
146-
&& $token->value === 'ELSE'
145+
&& $token->keyword === 'ELSE'
147146
) {
148147
++$list->idx; // Skip 'ELSE'
149148
$ret->else_result = Expression::parse($parser, $list);
150149
$state = 0; // last clause of CASE expression
151150
} elseif ($token->type === Token::TYPE_KEYWORD
152-
&& ($token->value === 'END'
153-
|| $token->value === 'end')
151+
&& $token->keyword === 'END'
154152
) {
155153
$state = 3; // end of CASE expression
156154
++$list->idx;
@@ -161,7 +159,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
161159
}
162160
} else {
163161
if ($token->type === Token::TYPE_KEYWORD
164-
&& $token->value === 'THEN'
162+
&& $token->keyword === 'THEN'
165163
) {
166164
++$list->idx; // Skip 'THEN'
167165
$new_result = Expression::parse($parser, $list);
@@ -175,7 +173,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
175173
} elseif ($state === 2) {
176174
if ($type === 0) {
177175
if ($token->type === Token::TYPE_KEYWORD
178-
&& $token->value === 'THEN'
176+
&& $token->keyword === 'THEN'
179177
) {
180178
++$list->idx; // Skip 'THEN'
181179
$new_result = Expression::parse($parser, $list);

src/Components/CreateDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
204204
break;
205205
}
206206
} elseif ($state === 1) {
207-
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'CONSTRAINT')) {
207+
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'CONSTRAINT') {
208208
$expr->isConstraint = true;
209209
} elseif (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_KEY)) {
210210
$expr->key = Key::parse($parser, $list);
@@ -246,7 +246,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
246246
$expr->options = OptionsArray::parse($parser, $list, static::$FIELD_OPTIONS);
247247
$state = 4;
248248
} elseif ($state === 4) {
249-
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'REFERENCES')) {
249+
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'REFERENCES') {
250250
++$list->idx; // Skipping keyword 'REFERENCES'.
251251
$expr->references = Reference::parse($parser, $list);
252252
} else {

src/Components/Expression.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
216216

217217
if ($token->type === Token::TYPE_KEYWORD) {
218218
if (($brackets > 0) && (empty($ret->subquery))
219-
&& (!empty(Parser::$STATEMENT_PARSERS[$token->value]))
219+
&& (!empty(Parser::$STATEMENT_PARSERS[$token->keyword]))
220220
) {
221221
// A `(` was previously found and this keyword is the
222222
// beginning of a statement, so this is a subquery.
223-
$ret->subquery = $token->value;
223+
$ret->subquery = $token->keyword;
224224
} elseif (($token->flags & Token::FLAG_KEYWORD_FUNCTION)
225225
&& (empty($options['parseField'])
226226
&& !$alias)
@@ -229,13 +229,13 @@ public static function parse(Parser $parser, TokensList $list, array $options =
229229
} elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED)
230230
&& ($brackets === 0)
231231
) {
232-
if (empty(self::$ALLOWED_KEYWORDS[$token->value])) {
232+
if (empty(self::$ALLOWED_KEYWORDS[$token->keyword])) {
233233
// A reserved keyword that is not allowed in the
234234
// expression was found so the expression must have
235235
// ended and a new clause is starting.
236236
break;
237237
}
238-
if ($token->value === 'AS') {
238+
if ($token->keyword === 'AS') {
239239
if (!empty($options['breakOnAlias'])) {
240240
break;
241241
}
@@ -248,7 +248,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
248248
}
249249
$alias = true;
250250
continue;
251-
} elseif ($token->value === 'CASE') {
251+
} elseif ($token->keyword === 'CASE') {
252252
// For a use of CASE like
253253
// 'SELECT a = CASE .... END, b=1, `id`, ... FROM ...'
254254
$tempCaseExpr = CaseExpression::parse($parser, $list);

src/Components/IntoKeyword.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
141141
}
142142

143143
if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED)) {
144-
if (($state === 0) && ($token->value === 'OUTFILE')) {
144+
if (($state === 0) && ($token->keyword === 'OUTFILE')) {
145145
$ret->type = 'OUTFILE';
146146
$state = 2;
147147
continue;
@@ -185,7 +185,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
185185
$ret->parseFileOptions($parser, $list, $token->value);
186186
$state = 4;
187187
} elseif ($state == 4) {
188-
if ($token->type === Token::TYPE_KEYWORD && $token->value !== 'LINES') {
188+
if ($token->type === Token::TYPE_KEYWORD && $token->keyword !== 'LINES') {
189189
break;
190190
}
191191

src/Components/JoinKeyword.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
133133

134134
if ($state === 0) {
135135
if (($token->type === Token::TYPE_KEYWORD)
136-
&& (!empty(static::$JOINS[$token->value]))
136+
&& (!empty(static::$JOINS[$token->keyword]))
137137
) {
138-
$expr->type = static::$JOINS[$token->value];
138+
$expr->type = static::$JOINS[$token->keyword];
139139
$state = 1;
140140
} else {
141141
break;
@@ -145,17 +145,17 @@ public static function parse(Parser $parser, TokensList $list, array $options =
145145
$state = 2;
146146
} elseif ($state === 2) {
147147
if ($token->type === Token::TYPE_KEYWORD) {
148-
if ($token->value === 'ON') {
148+
if ($token->keyword === 'ON') {
149149
$state = 3;
150-
} elseif ($token->value === 'USING') {
150+
} elseif ($token->keyword === 'USING') {
151151
$state = 4;
152152
} else {
153153
if (($token->type === Token::TYPE_KEYWORD)
154-
&& (!empty(static::$JOINS[$token->value]))
154+
&& (!empty(static::$JOINS[$token->keyword]))
155155
) {
156156
$ret[] = $expr;
157157
$expr = new self();
158-
$expr->type = static::$JOINS[$token->value];
158+
$expr->type = static::$JOINS[$token->keyword];
159159
$state = 1;
160160
} else {
161161
/* Next clause is starting */

src/Components/Limit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
8181
break;
8282
}
8383

84-
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'OFFSET')) {
84+
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'OFFSET') {
8585
if ($offset) {
8686
$parser->error('An offset was expected.', $token);
8787
}

src/Components/OrderKeyword.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
9696
$state = 1;
9797
} elseif ($state === 1) {
9898
if (($token->type === Token::TYPE_KEYWORD)
99-
&& (($token->value === 'ASC') || ($token->value === 'DESC'))
99+
&& (($token->keyword === 'ASC') || ($token->keyword === 'DESC'))
100100
) {
101-
$expr->type = $token->value;
101+
$expr->type = $token->keyword;
102102
} elseif (($token->type === Token::TYPE_OPERATOR)
103103
&& ($token->value === ',')
104104
) {

src/Components/PartitionDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
137137
}
138138

139139
if ($state === 0) {
140-
$ret->isSubpartition = ($token->type === Token::TYPE_KEYWORD) && ($token->value === 'SUBPARTITION');
140+
$ret->isSubpartition = ($token->type === Token::TYPE_KEYWORD) && ($token->keyword === 'SUBPARTITION');
141141
$state = 1;
142142
} elseif ($state === 1) {
143143
$ret->name = $token->value;

src/Components/RenameOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
100100
}
101101
$state = 1;
102102
} elseif ($state === 1) {
103-
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'TO')) {
103+
if ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'TO') {
104104
$state = 2;
105105
} else {
106106
$parser->error(

src/Parser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,14 @@ public function parse()
427427
continue;
428428
}
429429

430-
if (($token->value === 'UNION') || ($token->value === 'UNION ALL') || ($token->value === 'UNION DISTINCT')) {
431-
$unionType = $token->value;
430+
if (($token->keyword === 'UNION') || ($token->keyword === 'UNION ALL') || ($token->keyword === 'UNION DISTINCT')) {
431+
$unionType = $token->keyword;
432432
continue;
433433
}
434434

435435
// Checking if it is a known statement that can be parsed.
436-
if (empty(static::$STATEMENT_PARSERS[$token->value])) {
437-
if (!isset(static::$STATEMENT_PARSERS[$token->value])) {
436+
if (empty(static::$STATEMENT_PARSERS[$token->keyword])) {
437+
if (!isset(static::$STATEMENT_PARSERS[$token->keyword])) {
438438
// A statement is considered recognized if the parser
439439
// is aware that it is a statement, but it does not have
440440
// a parser for it yet.
@@ -454,7 +454,7 @@ public function parse()
454454
*
455455
* @var string
456456
*/
457-
$class = static::$STATEMENT_PARSERS[$token->value];
457+
$class = static::$STATEMENT_PARSERS[$token->keyword];
458458

459459
/**
460460
* Processed statement.

0 commit comments

Comments
 (0)