nitin: add optional source name in error messages (for tests)
authorJean Privat <jean@pryen.org>
Tue, 21 Nov 2017 16:17:05 +0000 (11:17 -0500)
committerJean Privat <jean@pryen.org>
Tue, 21 Nov 2017 16:17:05 +0000 (11:17 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

contrib/nitin/nitin.nit
tests/tests.sh

index 9e75b28..ae2c030 100644 (file)
@@ -28,9 +28,12 @@ redef class ToolContext
        # --no-prompt
        var opt_no_prompt = new OptionBool("Disable writing a prompt.", "--no-prompt")
 
+       # --source-name
+       var opt_source_name = new OptionString("Set a name for the input source.", "--source-name")
+
        redef init do
                super
-               option_context.add_option(opt_no_prompt)
+               option_context.add_option(opt_no_prompt, opt_source_name)
        end
 
        # Parse a full module given as a string
@@ -38,7 +41,8 @@ redef class ToolContext
        # Return a AModule or a AError
        fun p_module(string: String): ANode
        do
-               var source = new SourceFile.from_string("", string)
+               var source_name = opt_source_name.value or else ""
+               var source = new SourceFile.from_string(source_name, string)
                var lexer = new Lexer(source)
                var parser = new Parser(lexer)
                var tree = parser.parse
index a402eb2..eb9cc1a 100755 (executable)
@@ -636,7 +636,7 @@ END
                        echo 0.0 > "$ff.time.out"
                elif [ -n "$isinteractive" ]; then
                        cat > "$ff.bin" <<END
-exec $NITC --no-color --no-prompt $OPT $includes < $(printf '%q' "$i") "\$@"
+exec $NITC --no-color --no-prompt --source-name $(printf '%q' "$i") $OPT $includes < $(printf '%q' "$i") "\$@"
 END
                        chmod +x "$ff.bin"
                        > "$ff.cmp.err"