コード例 #1
0
ファイル: GraphCLI.cs プロジェクト: TheByte/sones
        public void ReadAndExecuteCommand(String InputString)
        {

            // Read and execute commend

            #region Check if valid command
            //has to be done via split, because irony doesn't recognize whitespaces,
            //so "dfgfkgdfgkfd" could be detected as the command "df" with an 
            //strange parameter

            if (!IsQuit && ValidCommandFromInputString(InputString))
            {

            #endregion

                #region Prepare Command Execution

                _Scanner = GraphCLICompiler.Scanner;

                _CompilerContext = new CompilerContext(GraphCLICompiler);

                _SourceFile = new SourceFile(InputString, "Source");

                _Scanner.Prepare(_CompilerContext, _SourceFile);

                _CompilerContext.Tokens.Clear();

                _TokenStream = _Scanner.BeginNonDetermisticScan();

                AstNode ExecutionTree = null;

                ExecutionTree = GraphCLICompiler.Parser.ParseNonDeterministic(_CompilerContext, _TokenStream);

                #region Checkt if valid command is complete

                if (ExecutionTree == null)
                {
                    MarkWrongOption(InputString, GraphCLICompiler.Parser.GetCorrectElements(_CompilerContext, _TokenStream));
                }
                else
                {
                    //Carry on, the command is valid and complete
                #endregion

                    ExtractOptionsFromTree(ExecutionTree);

                #endregion

                    if (Commands[CurrentCommand].CLI_Output == CLI_Output.Standard)
                        WriteLine();

                    #region Handle Command Execution

                    //try
                    //{

                        Stopwatch sw = new Stopwatch();
                        sw.Start();

                        // TODO: what's this doing here? 
                        //if (Parameters.Count > 0)
                        //{
                        #region Execute command...

                        if (_GraphDSSharp != null || CurrentCommand.Equals("MKFS") || CurrentCommand.Equals("MOUNT") || CurrentCommand.Equals("QUIT") || CurrentCommand.Equals("EXIT") || CurrentCommand.Equals("USEHISTORY") || CurrentCommand.Equals("SAVEHISTORY"))
                        {


                            Commands[CurrentCommand].Execute(_GraphDSSharp, ref CurrentPath, Parameters, InputString);

                            //if (CommandCategory.Equals(CLICommandCategory.CLIStandardCommand))
                            //{

                                #region Handle Quit and History

                                switch (CurrentCommand.ToUpper())
                                {

                                    case "QUIT":
                                        IsQuit = true;
                                        break;

                                    case "EXIT":
                                        IsQuit = true;
                                        break;

                                    case "USEHISTORY":
                                        //lets move to the right parameter
                                        ParameterEnum = Parameters.GetEnumerator();
                                        ParameterEnum.MoveNext();
                                        ParameterEnum.MoveNext();

                                        switch (ParameterEnum.Current.Key)
                                        {
                                            case "default":
                                                LoadStandardHistory = true;

                                                if (!HistoryFileName.Length.Equals(0))
                                                    SaveHistory(HistoryFileName, SthMountedList);

                                                break;

                                            default:
                                                LoadStandardHistory = false;

                                                HistoryFileName = ParameterEnum.Current.Key;

                                                LoadHistoryFrom(HistoryFileName);

                                                break;

                                        }

                                        break;

                                    case "SAVEHISTORY":
                                        //lets move to the right parameter
                                        ParameterEnum = Parameters.GetEnumerator();
                                        ParameterEnum.MoveNext();
                                        ParameterEnum.MoveNext();

                                        if (LoadStandardHistory)
                                            SaveHistory(ParameterEnum.Current.Key, NothingMountedList);
                                        else
                                            SaveHistory(ParameterEnum.Current.Key, SthMountedList);

                                        break;

                                }

                                #endregion

                            //}

                        }

                        else
                            WriteLine("Nothing mounted...");

                        #endregion
                        //}//CommandArray.Length > 0 ?

                        sw.Stop();

                        if (Parameters.Count > 0 && Commands[CurrentCommand].CLI_Output != CLI_Output.Short)
                        {
                            WriteLine("Command took {0}ms, {1:0.0} MB RAM, {2:0.0}% CPU", sw.ElapsedMilliseconds, _RAMCounter.NextValue() / 1024 / 1024, _CPUCounter.NextValue());
                        }
                    //}
                    //catch (Exception e)
                    //{
                    //    WriteLine("Uuups... " + e.Message);
                    //    WriteLine("StackTrace... " + e.StackTrace);
                    //}

                    Reset();

                    #endregion

                }

            }

                

        }
コード例 #2
0
ファイル: GraphCLI.cs プロジェクト: TheByte/sones
        private List<ParserReturn> GetPossibleTokensViaIrony(String Input)
        {
            List<ParserReturn> tempCompletionList = new List<ParserReturn>();

            #region set up of autocompletion environment

            _Scanner = GraphCLICompiler.Scanner;

            _CompilerContext = new CompilerContext(GraphCLICompiler);

            #endregion

            #region get possible tokens

            _SourceFile = new SourceFile(Input, "Source");

            _Scanner.Prepare(_CompilerContext, _SourceFile);

            _CompilerContext.Tokens.Clear();

            _TokenStream = _Scanner.BeginNonDetermisticScan();

            tempCompletionList = GraphCLICompiler.Parser.GetPossibleTokens(_CompilerContext, _TokenStream, Input);

            #endregion

            return tempCompletionList;
        }