From: Juerg Billeter Date: Tue, 15 Apr 2008 19:01:12 +0000 (+0000) Subject: improve error handling X-Git-Tag: VALA_0_3_1~66 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45cf05ee7223b01a7a7c10b3539243335b0cba1e;p=platform%2Fupstream%2Fvala.git improve error handling 2008-04-15 Juerg Billeter * vala/valaparser.vala: improve error handling svn path=/trunk/; revision=1236 --- diff --git a/ChangeLog b/ChangeLog index d720cff..d9821b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-04-15 Jürg Billeter + + * vala/valaparser.vala: improve error handling + 2008-04-14 Jürg Billeter * vala/valaparser.vala: set transfers_ownership of delegate diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 1d98b66..49e1d40 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -442,6 +442,11 @@ public class Vala.Parser : CodeVisitor { break; } + if (expr == null) { + // workaround for current limitation of exception handling + throw new ParseError.SYNTAX ("syntax error in primary expression"); + } + // process primary expressions that start with an inner primary expression bool found = true; while (found) { @@ -608,9 +613,11 @@ public class Vala.Parser : CodeVisitor { expect (TokenType.NEW); var member = parse_member_name (); if (accept (TokenType.OPEN_PARENS)) { - return parse_object_creation_expression (begin, member); + var expr = parse_object_creation_expression (begin, member); + return expr; } else if (accept (TokenType.OPEN_BRACKET)) { - return parse_array_creation_expression (begin, member); + var expr = parse_array_creation_expression (begin, member); + return expr; } else { throw new ParseError.SYNTAX (get_error ("expected ( or [")); } @@ -773,7 +780,8 @@ public class Vala.Parser : CodeVisitor { return context.create_addressof_expression (op, get_src (begin)); } - return parse_primary_expression (); + var expr = parse_primary_expression (); + return expr; } BinaryOperator get_binary_operator (TokenType token_type) { @@ -1061,7 +1069,8 @@ public class Vala.Parser : CodeVisitor { if (current () == TokenType.LAMBDA) { rollback (begin); - return parse_lambda_expression (); + var lambda = parse_lambda_expression (); + return lambda; } while (true) { @@ -1180,13 +1189,19 @@ public class Vala.Parser : CodeVisitor { Block parse_embedded_statement () throws ParseError { if (current () == TokenType.OPEN_BRACE) { - return parse_block (); + var block = parse_block (); + return block; } comment = scanner.pop_comment (); var block = context.create_block (); - block.add_statement (parse_embedded_statement_without_block ()); + var stmt = parse_embedded_statement_without_block (); + if (stmt == null) { + // workaround for current limitation of exception handling + throw new ParseError.SYNTAX ("syntax error in embedded statement"); + } + block.add_statement (stmt); return block; } @@ -1286,7 +1301,8 @@ public class Vala.Parser : CodeVisitor { Expression parse_statement_expression () throws ParseError { // invocation expression, assignment, // or pre/post increment/decrement expression - return parse_expression (); + var expr = parse_expression (); + return expr; } Statement parse_if_statement () throws ParseError { @@ -1505,7 +1521,8 @@ public class Vala.Parser : CodeVisitor { Block parse_finally_clause () throws ParseError { expect (TokenType.FINALLY); - return parse_block (); + var block = parse_block (); + return block; } Statement parse_lock_statement () throws ParseError { @@ -2010,9 +2027,11 @@ public class Vala.Parser : CodeVisitor { Expression parse_variable_initializer () throws ParseError { if (current () == TokenType.OPEN_BRACE) { - return parse_initializer (); + var expr = parse_initializer (); + return expr; } else { - return parse_expression (); + var expr = parse_expression (); + return expr; } }