]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
WIP girparser: Allow typeof() expressions in metadata
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Aug 2023 05:32:15 +0000 (07:32 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 31 Jan 2024 17:51:29 +0000 (18:51 +0100)
vala/valagirparser.vala

index 7b44705450f931fbdcc186f4005e07f011d442ec..660141aa57e8f059f92595eaf1f3f5260673c9ab 100644 (file)
@@ -414,6 +414,16 @@ public class Vala.GirParser : CodeVisitor {
                        return metadata;
                }
 
+               UnresolvedSymbol parse_symbol_name () {
+                       var begin = this.begin;
+                       UnresolvedSymbol sym = null;
+                       do {
+                               next ();
+                               sym = new UnresolvedSymbol (sym, get_string (), get_src (begin));
+                       } while (current == TokenType.DOT);
+                       return sym;
+               }
+
                Expression? parse_expression () {
                        var begin = this.begin;
                        var src = get_current_src ();
@@ -464,6 +474,16 @@ public class Vala.GirParser : CodeVisitor {
                                }
                                expr = new Tuple (src);
                                break;
+                       case TokenType.TYPEOF:
+                               if (next () != TokenType.OPEN_PARENS) {
+                                       Report.error (get_current_src (), "expected `(', got `%s'", current.to_string ());
+                                       break;
+                               }
+                               expr = new TypeofExpression (new UnresolvedType.from_symbol (parse_symbol_name (), src), src);
+                               if (next () != TokenType.CLOSE_PARENS) {
+                                       Report.error (get_current_src (), "expected `)', got `%s'", current.to_string ());
+                               }
+                               break;
                        default:
                                Report.error (src, "expected literal or symbol got %s", current.to_string ());
                                break;