[vala/wip/ricotz/lsp-rev: 11/15] parser: Make parse_argument_list/parse_initializer more robust



commit 8152bf649e06bdc89b5d62b424a836c32196a992
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Jan 18 20:03:37 2020 +0100

    parser: Make parse_argument_list/parse_initializer more robust

 vala/valaparser.vala | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 832eeff16..e862458be 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -579,7 +579,18 @@ public class Vala.Parser : CodeVisitor {
                var list = new ArrayList<Expression> ();
                if (current () != TokenType.CLOSE_PARENS) {
                        do {
-                               list.add (parse_argument ());
+                               try {
+                                       list.add (parse_argument ());
+                               } catch (ParseError e) {
+                                       if (current () == TokenType.CLOSE_PARENS) {
+                                               prev ();
+                                               report_parse_error (new ParseError.SYNTAX ("incomplete 
argument list"));
+                                       } else if (context.keep_going) {
+                                               report_parse_error (e);
+                                       } else {
+                                               throw e;
+                                       }
+                               }
                        } while (accept (TokenType.COMMA));
                }
                expect (TokenType.CLOSE_PARENS);
@@ -2732,7 +2743,18 @@ public class Vala.Parser : CodeVisitor {
                expect (TokenType.OPEN_BRACE);
                var initializer = new InitializerList (get_src (begin));
                while (current () != TokenType.CLOSE_BRACE) {
-                       initializer.append (parse_argument ());
+                       try {
+                               initializer.append (parse_argument ());
+                       } catch (ParseError e) {
+                               if (current () == TokenType.CLOSE_BRACE) {
+                                       prev ();
+                                       report_parse_error (new ParseError.SYNTAX ("incomplete initializer"));
+                               } else if (context.keep_going) {
+                                       report_parse_error (e);
+                               } else {
+                                       throw e;
+                               }
+                       }
 
                        if (!accept (TokenType.COMMA)) {
                                break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]