[vala/wip/lsp-rev: 3/7] parser: Make parse_argument_list/parse_initializer more robust



commit 236ca4adaa0994ddaf9bb936e042f623b54c3ebb
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]