[vala/wip/ricotz/lsp: 8/13] langserver: Introduce incomplete OCE



commit 2be65870569ad2daf57384581f2e7f2d0ad5b9dd
Author: Princeton Ferro <princetonferro gmail com>
Date:   Tue Jan 7 17:27:31 2020 -0500

    langserver: Introduce incomplete OCE

 vala/valaobjectcreationexpression.vala | 34 ++++++++++++++++-----
 vala/valaparser.vala                   | 54 ++++++++++++++++++++++++----------
 2 files changed, 64 insertions(+), 24 deletions(-)
---
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 175f126ba..ef9f288f6 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -55,16 +55,20 @@ public class Vala.ObjectCreationExpression : Expression {
 
        public bool struct_creation { get; set; }
 
-        /**
-         * For language servers, the number of completed arguments from the left.
-         */
-        public int initial_argument_count { get; set; }
+       /**
+        * For language servers, the number of completed arguments from the left.
+        */
+       public int initial_argument_count { get; set; }
 
-        /**
-         * For language servers, whether there is an extra comma at the end of the argument list.
-         */
-        public bool extra_comma { get; set; }
+       /**
+        * For language servers, whether there is an extra comma at the end of the argument list.
+        */
+       public bool extra_comma { get; set; }
 
+       /**
+        * For language servers, whether the object creation expression is incomplete.
+        */
+       public bool is_incomplete { get; set; }
 
        private List<Expression> argument_list = new ArrayList<Expression> ();
 
@@ -85,6 +89,20 @@ public class Vala.ObjectCreationExpression : Expression {
                this.member_name = member_name;
        }
 
+       /**
+        * Creates a new incomplete object creation expression, such as
+        * `new ...'
+        *
+        * @param member_name      object type to create
+        * @param source_reference reference to source code
+        * @return                 newly created object creation expression
+        */
+       public ObjectCreationExpression.incomplete (MemberAccess? member_name, SourceReference? 
source_reference = null) {
+               this.source_reference = source_reference;
+               this.member_name = member_name;
+               this.is_incomplete = true;
+       }
+
        /**
         * Appends the specified expression to the list of arguments.
         *
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index e547927a5..243e6345c 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -903,7 +903,17 @@ public class Vala.Parser : CodeVisitor {
                        return parse_array_creation_expression ();
                }
 
-               var member = parse_member_name ();
+               MemberAccess? member;
+               try {
+                       member = parse_member_name ();
+               } catch (ParseError e) {
+                       if (context.keep_going) {
+                               member = null;
+                               report_parse_error (e);
+                       } else {
+                               throw e;        // rethrow
+                       }
+               }
                if (accept (TokenType.OPEN_PARENS)) {
                        var expr = parse_object_creation_expression (begin, member);
                        return expr;
@@ -919,6 +929,9 @@ public class Vala.Parser : CodeVisitor {
                                rollback (begin);
                                var expr = parse_array_creation_expression ();
                                return expr;
+                       } else if (context.keep_going) {
+                               var expr = new ObjectCreationExpression.incomplete (member, get_src (begin));
+                               return expr;
                        } else {
                                throw new ParseError.SYNTAX ("expected ( or [");
                        }
@@ -3653,25 +3666,34 @@ public class Vala.Parser : CodeVisitor {
                MemberAccess expr = null;
                bool first = true;
                do {
-                       string id = parse_identifier ();
+                       try {
+                               string id = parse_identifier ();
 
-                       // The first member access can be global:: qualified
-                       bool qualified = false;
-                       if (first && id == "global" && accept (TokenType.DOUBLE_COLON)) {
-                               id = parse_identifier ();
-                               qualified = true;
-                       }
+                               // The first member access can be global:: qualified
+                               bool qualified = false;
+                               if (first && id == "global" && accept (TokenType.DOUBLE_COLON)) {
+                                       id = parse_identifier ();
+                                       qualified = true;
+                               }
 
-                       List<DataType> type_arg_list = parse_type_argument_list (false);
-                       expr = new MemberAccess (expr != null ? expr : base_expr, id, get_src (begin));
-                       expr.qualified = qualified;
-                       if (type_arg_list != null) {
-                               foreach (DataType type_arg in type_arg_list) {
-                                       expr.add_type_argument (type_arg);
+                               List<DataType> type_arg_list = parse_type_argument_list (false);
+                               expr = new MemberAccess (expr != null ? expr : base_expr, id, get_src 
(begin));
+                               expr.qualified = qualified;
+                               if (type_arg_list != null) {
+                                       foreach (DataType type_arg in type_arg_list) {
+                                               expr.add_type_argument (type_arg);
+                                       }
                                }
-                       }
 
-                       first = false;
+                               first = false;
+                       } catch (ParseError e) {
+                               if (!context.keep_going || first) {
+                                       throw e;
+                               } else {
+                                       report_parse_error (e);
+                                       return expr;
+                               }
+                       }
                } while (accept (TokenType.DOT));
                return expr;
        }


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