@@ -95,6 +95,13 @@ public static function parse(Parser $parser, TokensList $list, array $options =
9595 {
9696 $ ret = new Key ();
9797
98+ /**
99+ * Last parsed column.
100+ *
101+ * @var array
102+ */
103+ $ lastColumn = array ();
104+
98105 /**
99106 * The state of the parser.
100107 *
@@ -135,12 +142,31 @@ public static function parse(Parser $parser, TokensList $list, array $options =
135142 $ state = 1 ;
136143 } elseif ($ state === 1 ) {
137144 if (($ token ->type === Token::TYPE_OPERATOR ) && ($ token ->value === '( ' )) {
138- $ ret ->columns = ArrayObj::parse ($ parser , $ list )->values ;
139145 $ state = 2 ;
140146 } else {
141147 $ ret ->name = $ token ->value ;
142148 }
143149 } elseif ($ state === 2 ) {
150+ if ($ token ->type === Token::TYPE_OPERATOR ) {
151+ if ($ token ->value === '( ' ) {
152+ $ state = 3 ;
153+ } elseif (($ token ->value === ', ' ) || ($ token ->value === ') ' )) {
154+ $ state = ($ token ->value === ', ' ) ? 2 : 4 ;
155+ if (!empty ($ lastColumn )) {
156+ $ ret ->columns [] = $ lastColumn ;
157+ $ lastColumn = array ();
158+ }
159+ }
160+ } else {
161+ $ lastColumn ['name ' ] = $ token ->value ;
162+ }
163+ } elseif ($ state === 3 ) {
164+ if (($ token ->type === Token::TYPE_OPERATOR ) && ($ token ->value === ') ' )) {
165+ $ state = 2 ;
166+ } else {
167+ $ lastColumn ['length ' ] = $ token ->value ;
168+ }
169+ } elseif ($ state === 4 ) {
144170 $ ret ->options = OptionsArray::parse ($ parser , $ list , static ::$ KEY_OPTIONS );
145171 ++$ list ->idx ;
146172 break ;
@@ -163,8 +189,17 @@ public static function build($component, array $options = array())
163189 if (!empty ($ component ->name )) {
164190 $ ret .= Context::escape ($ component ->name ) . ' ' ;
165191 }
166- $ ret .= '( ' . implode (', ' , Context::escape ($ component ->columns )) . ') '
167- . $ component ->options ;
192+
193+ $ columns = array ();
194+ foreach ($ component ->columns as $ column ) {
195+ $ tmp = Context::escape ($ column ['name ' ]);
196+ if (isset ($ column ['length ' ])) {
197+ $ tmp .= '( ' . $ column ['length ' ] . ') ' ;
198+ }
199+ $ columns [] = $ tmp ;
200+ }
201+
202+ $ ret .= '( ' . implode (', ' , $ columns ) . ') ' . $ component ->options ;
168203 return trim ($ ret );
169204 }
170205}
0 commit comments