Exemplo n.º 1
0
 static void afterPerformingAction(ProseRuntime runtime, PNode source)
 {
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Green;
     Console.Write("postaction>    ");
     writePrettyProseWithProgressMark(runtime, source, null, 1);
 }
Exemplo n.º 2
0
 static void afterReduction(ProseRuntime runtime, PNode source)
 {
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Gray;
     Console.Write("postreduction> ");
     writePrettyProseWithProgressMark(runtime, source, null, 0);
 }
Exemplo n.º 3
0
        public static void ReadProseAfterDelay(ProseRuntime runtime, List <ProseObject> args)
        {
            lock (lockObj) {
                if (args.Count < 2)
                {
                    throw new ArgumentException("ReadProseAfterDelay takes two arguments: @string[delay] @prose[script].");
                }

                //	Parse the args for the delay and the script
                double          seconds = Double.Parse(((StringLiteralObject)args[0]).literal);
                RuntimeRunnable script  = new ProseObjectListReader(args.GetRange(1, args.Count - 1));

                //	Configure the timer
                Timer timer = new Timer(seconds * 1000);
                timer.AutoReset = false;
                timer.Elapsed  += new ElapsedEventHandler(onTimeElapsed);

                timer.Enabled = true;

                //	Add the timer and the script to the list
                timerList.Add(timer);
                scriptList.Add(script);
                runtimeList.Add(runtime);
            }
        }
Exemplo n.º 4
0
 static void onParseSentence(ProseRuntime runtime, PNode source)
 {
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Gray;
     Console.Write("postparse>     ");
     writePrettyProseWithProgressMark(runtime, source, null, 0);
 }
Exemplo n.º 5
0
 public static void onMatch(ProseRuntime runtime, PatternMatcher match)
 {
     restoreConsoleColor();
     foreach (Phrase phrase in match.MatchedPhrases)
     {
         Console.WriteLine("match>          " + phrase.getReadableString());
     }
 }
Exemplo n.º 6
0
 static void writeStackDepthMarker(ProseRuntime runtime)
 {
     Console.BackgroundColor = ConsoleColor.Red;
     for (int i = 0; i < runtime.CallDepth - 1; i++)
     {
         Console.Write("   ");
     }
 }
Exemplo n.º 7
0
 static void onProgressReport(ProseRuntime runtime, PNode beginningOfFragment, PNode progressMark)
 {
     //debugOutput("- " + beginningOfFragment.getReadableStringWithProgressMark(progressMark));
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Blue;
     Console.Write("progress>      ");
     writePrettyProseWithProgressMark(runtime, beginningOfFragment, progressMark, 0);
 }
Exemplo n.º 8
0
        private static void PrivateWriteToShell(ProseRuntime runtime, string appName, string argString)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine();

            ProcessStartInfo startInfo = new ProcessStartInfo(appName, argString);

            Process.Start(startInfo);
        }
Exemplo n.º 9
0
        public static void onBreakPoint(ProseRuntime runtime, PNode source, BreakPointObject.RuntimeData rtdata, string script)
        {
            breakPointDepth++;

            runtime.read(script, runtime.GlobalClient);
            runtime.read("read file \"Libraries/REPL/onbreak.prose\"", runtime.GlobalClient);
            ProseREPLLoop();

            breakPointDepth--;
        }
Exemplo n.º 10
0
 static void onAmbiguity(ProseRuntime runtime, PNode source, List <PatternMatcher> matches)
 {
     Console.BackgroundColor = ConsoleColor.Yellow;
     Console.ForegroundColor = ConsoleColor.Black;
     Console.WriteLine("ambiguity> ");
     foreach (PatternMatcher match in matches)
     {
         foreach (Phrase phrase in match.MatchedPhrases)
         {
             Console.WriteLine(phrase.getReadableString());
         }
     }
 }
Exemplo n.º 11
0
        public static void OpenURL(ProseRuntime runtime, List <ProseObject> args)
        {
            string siteName = "http://";

            if (args.Count == 1 && args[0] is StringLiteralObject)
            {
                siteName += ((StringLiteralObject)args[0]).literal;
            }
            else
            {
                throw new ArgumentException("OpenURL expects a single string argument.");
            }

            PrivateWriteToShell(runtime, siteName, "");
        }
Exemplo n.º 12
0
        /*
         *      Expects all arguments to be strings.
         *
         *      @string[delay] @string[script]
         */
        public static void ReadStringAfterDelay(ProseRuntime runtime, List <ProseObject> args)
        {
            lock (lockObj) {
                if (args.Count != 2)
                {
                    throw new ArgumentException("ReadAfterDelay takes two string arguments: delay, script.");
                }
                foreach (ProseObject arg in args)
                {
                    if (!(arg is StringLiteralObject))
                    {
                        throw new ArgumentException("ReadAfterDelay takes only string arguments.");
                    }
                }

                //	Parse the args for the delay and the script
                double          seconds = Double.Parse(((StringLiteralObject)args[0]).literal);
                RuntimeRunnable script  = new ProseStringReader(((StringLiteralObject)args[1]).literal);

                //	Configure the timer
                Timer timer = new Timer(seconds * 1000);
                timer.AutoReset = false;
                timer.Elapsed  += new ElapsedEventHandler(onTimeElapsed);

//				timer.Elapsed += delegate(object sender, ElapsedEventArgs e)
//					{
//						lock(lockObj) {
//							//	Look up the timer fired
//							int idx = timerList.BinarySearch((Timer) sender);
//						Console.WriteLine(idx);
//							//	Run the script
//							//runtime.read(scriptList[idx], runtime.GlobalClient);
//							runtimeList[idx].read("write \"Hello Carly\"", runtimeList[idx].GlobalClient);
//						//	Remove the timer and the script from the lists
//							timerList.RemoveAt(idx);
//							scriptList.RemoveAt(idx);
//							runtimeList.RemoveAt(idx);
//						}
//					};
                timer.Enabled = true;

                //	Add the timer and the script to the list
                timerList.Add(timer);
                scriptList.Add(script);
                runtimeList.Add(runtime);
            }
        }
Exemplo n.º 13
0
        public static void onMatcherFailure(ProseRuntime runtime, PatternMatcher match)
        {
            restoreConsoleColor();
            StringBuilder str = new StringBuilder();

            ProseObject[] partialPattern = match.AssociatedPattern;
            foreach (ProseObject po in partialPattern)
            {
                str.Append(po.getReadableString());
                str.Append(" ");
            }
            if (str.Length != 0)
            {
                str.Remove(str.Length - 1, 1);
            }

            Console.WriteLine("match fail>     " + str.ToString());
        }
Exemplo n.º 14
0
        //	First argument = application file name
        //	Further arguments = command line arguments
        public static void WriteToShell(ProseRuntime runtime, List <ProseObject> args)
        {
            string appName;
            string argString;

            if (args.Count == 0)
            {
                throw new ArgumentException("Shell command missing executable file name.");
            }

            if (args[0] is StringLiteralObject)
            {
                appName = ((StringLiteralObject)args[0]).literal;
            }
            else
            {
                appName = args[0].getReadableString();
            }

            StringBuilder argBuilder = new StringBuilder();

            for (int i = 1; i < args.Count; i++)
            {
                if (args[i] is StringLiteralObject)
                {
                    argBuilder.Append(((StringLiteralObject)args[i]).literal);
                }
                else
                {
                    argBuilder.Append(args[i].getReadableString());
                }

                argBuilder.Append(" ");
            }
            argString = argBuilder.ToString();

            PrivateWriteToShell(runtime, appName, argString);
        }
Exemplo n.º 15
0
 //	Set which events are logged
 public static void SetShowEvent(ProseRuntime runtime, List <ProseObject> args)
 {
     setShowEvent(runtime, args);
 }
Exemplo n.º 16
0
 public static void ContinueFromBreakPoint(ProseRuntime runtime, List <ProseObject> args)
 {
     shouldContinue = true;
 }
Exemplo n.º 17
0
 public static void ErrorMethod(ProseRuntime runtime, List <ProseObject> args)
 {
     reportException(assembleArgumentsIntoString(args, "ErrorMethod takes only string arguments."));
 }
Exemplo n.º 18
0
 public static void WriteMethod(ProseRuntime runtime, List <ProseObject> args)
 {
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.Gray;
     Console.WriteLine(assembleArgumentsIntoString(args, "WriteMethod takes only string arguments."));
 }
Exemplo n.º 19
0
        public static void setShowEvent(ProseRuntime runtime, List <ProseObject> args)
        {
            if (args.Count != 2)
            {
                throw new ArgumentException("SetShowEvent requires an event and a yes/no value.");
            }

            string eventWord = args[0].getReadableString();
            string yesNoWord = args[1].getReadableString();

            //	PROGRESS REPORTS
            if (eventWord == "progress")
            {
                if (yesNoWord == "yes")
                {
                    if (!showProgressReport)
                    {
                        runtime.OnProgressReport += onProgressReportDelegate;
                        showProgressReport        = true;
                    }
                }
                else
                {
                    runtime.OnProgressReport -= onProgressReportDelegate;
                    showProgressReport        = false;
                }
            }

            //	POSTPARSE REPORT
            if (eventWord == "postparse")
            {
                if (yesNoWord == "yes")
                {
                    if (!showParseSentenceReport)
                    {
                        runtime.OnParseSentence += onParseSentenceDelegate;
                        showParseSentenceReport  = true;
                    }
                }
                else
                {
                    runtime.OnParseSentence -= onParseSentenceDelegate;
                    showParseSentenceReport  = false;
                }
            }


            //	POSTACTION REPORTS
            if (eventWord == "postaction")
            {
                if (yesNoWord == "yes")
                {
                    if (!showAfterActionReport)
                    {
                        runtime.AfterPerformingAction += afterPerformingActionDelegate;
                        showAfterActionReport          = true;
                    }
                }
                else
                {
                    runtime.AfterPerformingAction -= afterPerformingActionDelegate;
                    showAfterActionReport          = false;
                }
            }


            //	PREACTION REPORTS
            if (eventWord == "preaction")
            {
                if (yesNoWord == "yes")
                {
                    if (!showBeforeActionReport)
                    {
                        runtime.BeforePerformingAction += beforePerformingActionDelegate;
                        showBeforeActionReport          = true;
                    }
                }
                else
                {
                    runtime.BeforePerformingAction -= beforePerformingActionDelegate;
                    showBeforeActionReport          = false;
                }
            }

            //	PREREDUCTION REPORTS
            if (eventWord == "prereduction")
            {
                if (yesNoWord == "yes")
                {
                    if (!showBeforeReductionReport)
                    {
                        runtime.BeforeReduction  += beforeReductionDelegate;
                        showBeforeReductionReport = true;
                    }
                }
                else
                {
                    runtime.BeforeReduction  -= beforeReductionDelegate;
                    showBeforeReductionReport = false;
                }
            }

            //	POSTREDUCTION REPORTS
            if (eventWord == "postreduction")
            {
                if (yesNoWord == "yes")
                {
                    if (!showAfterReductionReport)
                    {
                        runtime.AfterReduction  += afterReductionDelegate;
                        showAfterReductionReport = true;
                    }
                }
                else
                {
                    runtime.AfterReduction  -= afterReductionDelegate;
                    showAfterReductionReport = false;
                }
            }

            //	MATCH REPORTS
            if (eventWord == "matches")
            {
                if (yesNoWord == "yes")
                {
                    if (!showOnMatchReport)
                    {
                        runtime.OnMatch  += onMatchDelegate;
                        showOnMatchReport = true;
                    }
                }
                else
                {
                    runtime.OnMatch  -= onMatchDelegate;
                    showOnMatchReport = false;
                }
            }

            //	MATCHER FAILURE REPORTS
            if (eventWord == "matchfails")
            {
                if (yesNoWord == "yes")
                {
                    if (!showOnMatcherFailureReport)
                    {
                        runtime.OnMatcherFailure  += onMatcherFailureDelegate;
                        showOnMatcherFailureReport = true;
                    }
                }
                else
                {
                    runtime.OnMatcherFailure  -= onMatcherFailureDelegate;
                    showOnMatcherFailureReport = false;
                }
            }
        }
Exemplo n.º 20
0
 public void run(ProseRuntime runtime)
 {
     runtime.read(script, 0, script.Count, runtime.GlobalClient);
 }
Exemplo n.º 21
0
        //	Pass null to progress mark to eliminate
        static void writePrettyProseWithProgressMark(ProseRuntime runtime, PNode start, PNode progressMark, int maxNodesToProcess)
        {
            writeStackDepthMarker(runtime);

            //Stack<ProseObject> parenStack = new Stack<ProseObject>();
            int parenCount     = 0;
            int bracketCount   = 0;
            int quadQuoteCount = 0;
            int periodCount    = 0;
            int nodesProcessed = 0;

            PNode p = start;

            do
            {
                nodesProcessed++;

                while (p != null && p.value == null)
                {
                    p = p.next;
                }

                if (p.value == null)
                {
                    p = p.next;
                    continue;
                }
                p = runtime.filterIncomingPNode(p);
                if (p == null)
                {
                    break;
                }

                //	PROGRESS MARK
                if (p == progressMark)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Write(" ");
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.Write(" ");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Write(" ");
                }

                //	Write a leading space
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write(" ");


                //	OBJECTS
                if (p.value is ProseAction)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else if (p.value == runtime.Comma ||
                         p.value == runtime.Semicolon ||
                         p.value == runtime.Period)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Magenta;
                }
                else if (p.value is RawWordObject)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                //				else if (	p.value == runtime.LefetParenthesis
                //				         ||	p.value == runtime.LeftSquareBracket
                //				         ||	p.value == runtime.LeftCurlyBracket
                //				         || p.value == runtime.RightParenthesis
                //				         || p.value == r
                else if (p.value == runtime.Colon ||
                         p.value == runtime.LeftArrow ||
                         p.value == runtime.PlusColon ||
                         p.value == runtime.MinusColon ||
                         p.value == runtime.RightArrow ||
                         p.value == runtime.ColonPlus ||
                         p.value == runtime.ColonMinus ||
                         p.value == runtime.Quadquote)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Cyan;
                }
                else if (p.value is AssemblyNameWord ||
                         p.value is TypeNameWord ||
                         p.value is MethodNameWord)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }
                else
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

                //	Inside a text block everything is forced to white unless its in brackets
                //	Deal with different highighting inside of text expressions
                if (quadQuoteCount % 2 == 1)
                {
                    if (p.value == runtime.LeftSquareBracket)
                    {
                        bracketCount++;
                    }

                    //	Neutralize colors of words that behave as text
                    if (bracketCount == 0)
                    {
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.ForegroundColor = ConsoleColor.Cyan;
                    }

                    if (p.value == runtime.RightSquareBracket)
                    {
                        bracketCount--;
                    }
                }

                if (p.value == runtime.@break ||
                    p.value is BreakPointObject)
                {
                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Black;
                }


                //	Prewrite logic



                //	Write the output
                //

                Console.Write(p.value.getReadableString());
                //	Just so nothing too ugly can go wrong
                Console.BackgroundColor = ConsoleColor.Black;

                //	Postwrite logic

                if (p.value == runtime.RightArrow ||
                    p.value == runtime.ColonPlus ||
                    p.value == runtime.ColonMinus)
                {
                    if (Console.CursorLeft > 60 ||
                        Console.CursorLeft + 40 > Console.BufferWidth)
                    {
                        restoreConsoleColor();
                        Console.WriteLine();
                        Console.Write("               ");
                        writeStackDepthMarker(runtime);
                        restoreConsoleColor();
                        Console.Write("\t\t");
                    }
                }


                //
                //	Other exits
                //
                if (nodesProcessed == maxNodesToProcess)
                {
                    break;
                }

                //
                //	Keep track of parentheticals to know if we can quit
                //
                if (p.value == runtime.LeftParenthesis ||
                    p.value == runtime.LeftCurlyBracket ||
                    p.value == runtime.LeftSquareBracket)
                {
                    parenCount++;
                    //parenStack.Push(p.value);
                }
                else if (p.value == runtime.RightParenthesis ||
                         p.value == runtime.RightCurlyBracket ||
                         p.value == runtime.RightSquareBracket)
                {
                    parenCount--;
                }
                else if (p.value == runtime.Quadquote)
                {
                    quadQuoteCount++;
                }
                else if (p.value == runtime.Period &&
                         parenCount == 0 &&
                         quadQuoteCount % 2 == 0)
                {
                    periodCount++;
                    //	If parens and quadquotes are done and we have period then bail
                    if (periodCount == 2)
                    {
                        break;
                    }
                }



                //	Update
                p = p.next;
            } while (p != null);
            //outStr.Remove(outStr.Length - 1, 1);
            //return outStr.ToString();

            Console.WriteLine();
        }