@@ -64,15 +64,22 @@ public static function parse(Parser $parser, TokensList $list, array $options =
6464 *
6565 * Below are the states of the parser.
6666 *
67- * 0 -------------------[ column name ]-------------------> 1
68- *
67+ * 0 ---------------------[ col_name ]--------------------> 0
68+ * 0 ------------------------[ = ]------------------------> 1
69+ * 1 -----------------------[ value ]---------------------> 1
6970 * 1 ------------------------[ , ]------------------------> 0
70- * 1 ----------------------[ value ]----------------------> 1
7171 *
7272 * @var int
7373 */
7474 $ state = 0 ;
7575
76+ /**
77+ * Token when the parser has seen the latest comma
78+ *
79+ * @var Token
80+ */
81+ $ commaLastSeenAt = null ;
82+
7683 for (; $ list ->idx < $ list ->count ; ++$ list ->idx ) {
7784 /**
7885 * Token parsed at this moment.
@@ -104,6 +111,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
104111 $ state = 1 ;
105112 } elseif ($ token ->value !== ', ' ) {
106113 $ expr ->column .= $ token ->token ;
114+ } elseif ($ token ->value === ', ' ) {
115+ $ commaLastSeenAt = $ token ;
107116 }
108117 } elseif ($ state === 1 ) {
109118 $ tmp = Expression::parse (
@@ -122,11 +131,16 @@ public static function parse(Parser $parser, TokensList $list, array $options =
122131 $ ret [] = $ expr ;
123132 $ expr = new self ();
124133 $ state = 0 ;
134+ $ commaLastSeenAt = null ;
125135 }
126136 }
127-
128137 --$ list ->idx ;
129138
139+ // We saw a comma, but didn't see a column-value pair after it
140+ if ($ commaLastSeenAt !== null ) {
141+ $ parser ->error ('Unexpected token. ' , $ commaLastSeenAt );
142+ }
143+
130144 return $ ret ;
131145 }
132146
0 commit comments