summaryrefslogtreecommitdiffstats
path: root/src/Components/SetOperation.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Components/SetOperation.php')
-rw-r--r--src/Components/SetOperation.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php
index 7dab0a1..2945a8e 100644
--- a/src/Components/SetOperation.php
+++ b/src/Components/SetOperation.php
@@ -64,15 +64,22 @@ class SetOperation extends Component
*
* Below are the states of the parser.
*
- * 0 -------------------[ column name ]-------------------> 1
- *
+ * 0 ---------------------[ col_name ]--------------------> 0
+ * 0 ------------------------[ = ]------------------------> 1
+ * 1 -----------------------[ value ]---------------------> 1
* 1 ------------------------[ , ]------------------------> 0
- * 1 ----------------------[ value ]----------------------> 1
*
* @var int
*/
$state = 0;
+ /**
+ * Token when the parser has seen the latest comma
+ *
+ * @var Token
+ */
+ $commaLastSeenAt = null;
+
for (; $list->idx < $list->count; ++$list->idx) {
/**
* Token parsed at this moment.
@@ -104,6 +111,8 @@ class SetOperation extends Component
$state = 1;
} elseif ($token->value !== ',') {
$expr->column .= $token->token;
+ } elseif ($token->value === ',') {
+ $commaLastSeenAt = $token;
}
} elseif ($state === 1) {
$tmp = Expression::parse(
@@ -122,11 +131,16 @@ class SetOperation extends Component
$ret[] = $expr;
$expr = new self();
$state = 0;
+ $commaLastSeenAt = null;
}
}
-
--$list->idx;
+ // We saw a comma, but didn't see a column-value pair after it
+ if ($commaLastSeenAt !== null) {
+ $parser->error('Unexpected token.', $commaLastSeenAt);
+ }
+
return $ret;
}