]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added total hack version of struct member access and UFCS
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 29 Mar 2019 18:34:04 +0000 (14:34 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 29 Mar 2019 18:34:04 +0000 (14:34 -0400)
example.src
source/parser.c

index 0c6e5131fc2eee7c798c7f220d71ea3790b4f9b7..b60c809b2f5bfc773adf48ba83dc74c226eb15d0 100644 (file)
@@ -46,5 +46,10 @@ fun main(args string[]) int {
     fun submain(args string[]) int {
         123
     }
+    # UFCS call (call regular function like a method)
     foo.bar()
+#    foo.bar.baz()
+    # Struct/Union field access
+    foo.bar
+#    foo.bar.baz
 }
index 55a0ecc780f8436b50aae4c4e70ffe50c95a8437..9192190d37bc75fb6afeb6abc550ce3dcc686664 100644 (file)
@@ -170,15 +170,19 @@ static AST* expression(Parser* p) {
         exp = constant(p);
     }
 
-    /* determine if this is a function call */
-    if (matches(p, '(')) {
-        exp = Apply(exp, expr_list(p, '(', ')'));
-    } else if (accept(p, '.')) {
-        AST* func = identifier(p);
-        AST* args = expr_list(p, '(', ')');
-        explist_prepend(args, exp);
-        exp = Apply(func, args);
-    }
+    /* check for member reference or UFCS call */
+    AST *member = NULL, *args = NULL;
+    if (accept(p, '.'))
+        member = identifier(p);
+    if (matches(p, '('))
+        args = expr_list(p, '(', ')');
+
+    if (member && !args)
+        exp = exp; // ??? AST for struct reference
+    else if (member && args)
+        exp = Apply(member, args);
+    else if (!member && args)
+        exp = args;
 
     return exp;
 }