test_phase: provide a simpler way to implement POC of nit tools
authorJean Privat <jean@pryen.org>
Thu, 20 Mar 2014 21:09:53 +0000 (17:09 -0400)
committerJean Privat <jean@pryen.org>
Fri, 21 Mar 2014 13:22:43 +0000 (09:22 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/test_phase.nit

index 292ba0e..8fd5908 100644 (file)
 
 # Stub for loading a runing phases on a bunch of modules
 #
-# The point is to refine this module is executable that does things.
-# One simple way is to use the `-m` option of engines plug various phases.
+# The point is to refine this module in executable that does things.
+# One simple way is to use the `-m` option of engines to plug various phases.
+#
+# One other way is to redefine `do_work`. See `test_test_phase.nit`.
 module test_phase
 
 import modelbuilder
 
+redef class ToolContext
+       var default_phase = new DefaultPhase(self, null)
+end
+
+# Empty phase that delegates `process_mainmodule` to the global `do_work`.
+class DefaultPhase
+       super Phase
+       redef fun process_mainmodule(mainmodule, given_mmodules) do
+               do_work(mainmodule, given_mmodules, toolcontext.modelbuilder)
+       end
+end
+
+# Easy entry point to prototype a specific work or proof-of-concept.
+#
+# Complex or mature work should use the full `phase` framework to enable
+# combination and orcherstration of works.
+#
+# * `mainmodule` is the bottom main module (possibly implicit).
+# * `given_mmodules` is the exact list of module from the command line.
+# * `modelbuilder` is the context that contains a lot of things.
+#
+# @toimplement
+fun do_work(mainmodule: MModule, given_mmodules: SequenceRead[MModule], modelbuilder: ModelBuilder) do end
+
 # Create a tool context to handle options and paths
 var toolcontext = new ToolContext
 toolcontext.tooldescription = "Usage: [OPTION]... <file.nit>..."