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 HandleEofOrErrorIfNonConsoleShell(List <String> scriptFilename, bool success, bool nonDebugNonGuiExitOnError,
                                                     GrShell shell, GrShellDriver driver,
                                                     ref TextReader reader, ref bool showPrompt, ref bool readFromConsole)
        {
            if (readFromConsole || (!driver.Eof && success))
            {
                return(0);
            }

            if (nonDebugNonGuiExitOnError && !success)
            {
                return(-1);
            }

            if (scriptFilename.Count != 0)
            {
                TextReader newReader;
                try
                {
                    newReader = new StreamReader((String)scriptFilename[0]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to read file \"" + scriptFilename[0] + "\": " + e.Message);
                    return(-1);
                }
                scriptFilename.RemoveAt(0);
                shell.ReInit(newReader);
                driver.Eof = false;
                reader.Close();
                reader = newReader;
            }
            else
            {
                shell.ReInit(WorkaroundManager.Workaround.In);
                driver.tokenSources.Pop();
                driver.tokenSources.Push(shell.token_source);
                showPrompt      = true;
                readFromConsole = true;
                driver.Eof      = false;
                reader.Close();
            }

            return(0);
        }
Пример #3
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);
        }
Пример #4
0
 GrShellDriver(GrShell grShell, IGrShellImplForDriver impl)
 {
     this.grShell = grShell;
     this.impl    = impl;
 }