nitrestful: detect the async keyword
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 14 Oct 2016 13:29:38 +0000 (09:29 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 3 Feb 2017 22:45:03 +0000 (17:45 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/nitrestful.nit

index 2b118a3..68e8258 100644 (file)
@@ -37,6 +37,12 @@ private class RestfulPhase
                        return
                end
 
+               var mpropdef = node.mpropdef
+               if mpropdef == null then return
+               var mproperty = mpropdef.mproperty
+               var mclassdef = mpropdef.mclassdef
+               var mmodule = mclassdef.mmodule
+
                var http_resources = new Array[String]
                var http_methods = new Array[String]
                for arg in nat.n_args do
@@ -48,6 +54,8 @@ private class RestfulPhase
                        else if arg isa ATypeExpr and not id.chars.has("[") then
                                # Class id -> HTTP method
                                http_methods.add id
+                       else if id == "async" then
+                               mproperty.restful_async = true
                        else
                                toolcontext.error(nat.location,
                                        "Syntax Error: `restful` expects String literals or ids as arguments.")
@@ -55,13 +63,6 @@ private class RestfulPhase
                        end
                end
 
-               var mpropdef = node.mpropdef
-               if mpropdef == null then return
-
-               var mproperty = mpropdef.mproperty
-               var mclassdef = mpropdef.mclassdef
-               var mmodule = mclassdef.mmodule
-
                # Test subclass of `RestfulAction`
                var sup_class_name = "RestfulAction"
                var sup_class = toolcontext.modelbuilder.try_get_mclass_by_name(
@@ -97,6 +98,9 @@ redef class MMethod
 
        # Associated resources within an action, e.g. `foo` in `http://localhost/foo?arg=bar`
        private var restful_resources: Array[String] = [name] is lazy
+
+       # Is this a `restful` method to be executed asynchronously
+       private var restful_async = false
 end
 
 redef class ToolContext