[nem-en] change to MainParser

Kamil Dworakowski kamil.dworakowski at googlemail.com
Mon Nov 20 15:03:45 CET 2006


Hi all,

I have made a DSL for NUnit tests.

// file tests.nu
using NemerleUnit
using Nemerle.Collections //because of a bug

setup
    def a = 0

test "failing test that doesn't use variables from setup"
    assert false

test "passing test"
    assert a equals 0

test "failing test"
    assert a equals 1

To make it work, however, I have slightly modified the MainParser class.

Currently, if MainParser doesn't encounter top level declaration (e.g., 
class, module, etc.), but a sequence, it will create a module with a 
static Main method to put the sequence there. I would like to extend it, 
so that:
-- parser creates a class with the same name as file
-- the name of the method to put the sequence into would be determined 
by the extension of the file. If it is .n file it shall put it in static 
Main(), otherwise public static AutoMethod(): void.

This should not brake anything.

I attach the patch. Do you accept the change?

Kamil Dworakowski
-------------- next part --------------
Index: MainParser.n
===================================================================
--- MainParser.n	(revision 6967)
+++ MainParser.n	(working copy)
@@ -217,9 +217,16 @@
           }
           else {
             def seq = parser.parse_expr_sequence (topstream);
+
+            def class_name = System.IO.Path.GetFileNameWithoutExtension(lex.Location.File);
+            def method_name = if (lex.Location.File.EndsWith(".n"))
+                "Main"
+            else
+                "AutoMethod";
+
             def decl = Util.locate (topstream.Location, <[ decl:
-              module $(parser.mkname ("_N_AutoModule") : name) {
-                Main () : void {
+              public class $(parser.mkname (class_name) : name) {
+                public static $(parser.mkname(method_name) : name)() : void {
                   ..$seq
                 }
               }


More information about the devel-en mailing list