public object Askfor(String typeName)
        {
            if (typeName == null)
            {
                UserInterface.ShowMsgAskForEnter("Pause..");
                return(null);
            }

            if (TypesHelper.GetNodeOrEdgeType(typeName, impl.curShellProcEnv.ProcEnv.NamedGraph.Model) != null) // if type is node/edge type let the user select the element in yComp
            {
                if (!CheckDebuggerAlive())
                {
                    impl.errOut.WriteLine("debug mode must be enabled (yComp available) for asking for a node/edge type");
                    return(null);
                }

                impl.debugOut.WriteLine("Select an element of type " + typeName + " by double clicking in yComp (ESC for abort)...");

                String id = debugger.ChooseGraphElement();
                if (id == null)
                {
                    return(null);
                }

                impl.debugOut.WriteLine("Received @(\"" + id + "\")");

                IGraphElement elem = impl.curShellProcEnv.ProcEnv.NamedGraph.GetGraphElement(id);
                if (elem == null)
                {
                    impl.errOut.WriteLine("Graph element does not exist (anymore?).");
                    return(null);
                }
                if (!TypesHelper.IsSameOrSubtype(elem.Type.PackagePrefixedName, typeName, impl.curShellProcEnv.ProcEnv.NamedGraph.Model))
                {
                    impl.errOut.WriteLine(elem.Type.PackagePrefixedName + " is not the same type as/a subtype of " + typeName + ".");
                    return(null);
                }
                return(elem);
            }
            else // else let the user type in the value
            {
                String       inputValue      = UserInterface.ShowMsgAskForString("Enter a value of type " + typeName + ": ");
                StringReader reader          = new StringReader(inputValue);
                GrShell      shellForParsing = new GrShell(reader);
                shellForParsing.SetImpl(impl.GetGrShellImpl());
                object val         = shellForParsing.Constant();
                String valTypeName = TypesHelper.XgrsTypeOfConstant(val, impl.curShellProcEnv.ProcEnv.NamedGraph.Model);
                if (!TypesHelper.IsSameOrSubtype(valTypeName, typeName, impl.curShellProcEnv.ProcEnv.NamedGraph.Model))
                {
                    impl.errOut.WriteLine(valTypeName + " is not the same type as/a subtype of " + typeName + ".");
                    return(null);
                }
                return(val);
            }
        }
Пример #2
0
        static int Main(string[] args)
        {
            String        command                   = null;
            List <String> scriptFilename            = new List <String>();
            bool          showUsage                 = false;
            bool          nonDebugNonGuiExitOnError = false;
            bool          showIncludes              = false;
            int           errorCode                 = 0; // 0==success, the return value

            PrintVersion();

            ParseArguments(args,
                           out command, out scriptFilename, out showUsage,
                           out nonDebugNonGuiExitOnError, out showIncludes, out errorCode);

            if (showUsage)
            {
                PrintUsage();
                return(errorCode);
            }

            TextReader reader;
            bool       showPrompt;
            bool       readFromConsole;

            errorCode = DetermineAndOpenInputSource(command, scriptFilename,
                                                    out reader, out showPrompt, out readFromConsole);
            if (errorCode != 0)
            {
                return(errorCode);
            }

            GrShell               shell     = new GrShell(reader);
            GrShellImpl           shellImpl = new GrShellImpl();
            IGrShellImplForDriver impl      = shellImpl;
            GrShellDriver         driver    = new GrShellDriver(shell, impl);

            shell.SetImpl(shellImpl);
            shell.SetDriver(driver);
            driver.tokenSources.Push(shell.token_source);
            driver.showIncludes            = showIncludes;
            impl.nonDebugNonGuiExitOnError = nonDebugNonGuiExitOnError;

            try
            {
                driver.conditionalEvaluationResults.Push(true);

                while (!driver.Quitting && !driver.Eof)
                {
                    driver.ShowPromptAsNeeded(showPrompt);

                    bool success = shell.ParseShellCommand();

                    errorCode = HandleEofOrErrorIfNonConsoleShell(scriptFilename, success, nonDebugNonGuiExitOnError,
                                                                  shell, driver,
                                                                  ref reader, ref showPrompt, ref readFromConsole);
                    if (errorCode != 0)
                    {
                        return(errorCode);
                    }
                }

                driver.conditionalEvaluationResults.Pop();
            }
            catch (Exception e)
            {
                Console.WriteLine("exit due to " + e.Message);
                errorCode = -2;
            }
            finally
            {
                impl.Cleanup();
            }

            return(errorCode);
        }