@@ -177,24 +177,43 @@ void Parser::parseTypedef()
177177void Parser::parseItem ()
178178{
179179 Expr* notImplementedExpr = NULL ;
180+ std::string onError;
180181
181- lexer->getToken (token);
182-
183- if (token.type == TOKEN (' [' ))
182+ while (lexer->getToken (token).type == TOKEN (' [' ))
184183 {
185- getToken (token, Token::TYPE_NOT_IMPLEMENTED); // This is the only attribute we allow now.
186- getToken (token, TOKEN (' (' ));
187- notImplementedExpr = parseExpr ();
188- getToken (token, TOKEN (' )' ));
189- getToken (token, TOKEN (' ]' ));
184+ lexer->getToken (token);
185+ switch (token.type )
186+ {
187+ case Token::TYPE_NOT_IMPLEMENTED:
188+ if (notImplementedExpr)
189+ syntaxError (token);
190+ getToken (token, TOKEN (' (' ));
191+ notImplementedExpr = parseExpr ();
192+ getToken (token, TOKEN (' )' ));
193+ getToken (token, TOKEN (' ]' ));
194+ break ;
195+
196+ case Token::TYPE_ON_ERROR:
197+ if (onError.length ())
198+ syntaxError (token);
199+ lexer->getToken (token);
200+ if (token.type != Token::TYPE_IDENTIFIER)
201+ syntaxError (token);
202+ onError = token.text ;
203+ getToken (token, TOKEN (' ]' ));
204+ break ;
205+
206+ default :
207+ syntaxError (token);
208+ break ;
209+ }
190210 }
191- else
192- lexer->pushToken (token);
211+ lexer->pushToken (token);
193212
194213 TypeRef typeRef (parseTypeRef ());
195214 string name (getToken (token, Token::TYPE_IDENTIFIER).text );
196215
197- if (! notImplementedExpr && typeRef.isConst )
216+ if ((!( notImplementedExpr || onError. length ())) && typeRef.isConst )
198217 {
199218 if (lexer->getToken (token).type == TOKEN (' =' ))
200219 {
@@ -207,7 +226,7 @@ void Parser::parseItem()
207226 }
208227
209228 getToken (token, TOKEN (' (' ));
210- parseMethod (typeRef, name, notImplementedExpr);
229+ parseMethod (typeRef, name, notImplementedExpr, onError );
211230}
212231
213232void Parser::parseConstant (const TypeRef& typeRef, const string& name)
@@ -222,7 +241,7 @@ void Parser::parseConstant(const TypeRef& typeRef, const string& name)
222241 getToken (token, TOKEN (' ;' ));
223242}
224243
225- void Parser::parseMethod (const TypeRef& returnTypeRef, const string& name, Expr* notImplementedExpr)
244+ void Parser::parseMethod (const TypeRef& returnTypeRef, const string& name, Expr* notImplementedExpr, const string& onError )
226245{
227246 Method* method = new Method ();
228247 interface->methods .push_back (method);
@@ -231,6 +250,7 @@ void Parser::parseMethod(const TypeRef& returnTypeRef, const string& name, Expr*
231250 method->name = name;
232251 method->version = interface->version ;
233252 method->notImplementedExpr = notImplementedExpr;
253+ method->onErrorFunction = onError;
234254
235255 if (lexer->getToken (token).type != TOKEN (' )' ))
236256 {
0 commit comments