// Start a pattern match at the beginning with one object. internal PatternMatcher(ProseRuntime runtime) { this.runtime = runtime; patternTrie = runtime.GlobalScope.PatternTree; state = MatcherState.MATCHING_OBJECT; currNode = patternTrie.Root; }
// 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); }
public override void performAction(ProseRuntime runtime) { // Create/fetc a possibly new word object representing the words. Word newWord = runtime.addWordFromRawWords(rawWordsToBindAsWord); // Bind the word using inheritence newWord.isa = new Word[] { parent }; }
public void performAction(ProseRuntime runtime) { // Look up the type. Type type = assemblyWord.AssemblyObject.GetType(typeName); TypeNameWord typeNameWord = new TypeNameWord(rawWords, runtime, type); runtime.addWord(typeNameWord); }
public void performAction(ProseRuntime runtime) { // Load the dll Assembly assembly = Assembly.LoadFrom(dllName); // Build an assembly word from it AssemblyNameWord asmName = new AssemblyNameWord(rawWords, runtime, assembly); runtime.addWord(asmName); }
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); }
public void performAction(ProseRuntime runtime) { // Look up the type. MethodInfo methodInfo = typeWord.TypeObject.GetMethod(methodName, BindingFlags.Public|BindingFlags.Static); ProseLanguage.ActionDelegate delegateMethod = (ProseLanguage.ActionDelegate) Delegate.CreateDelegate(typeof(ProseLanguage.ActionDelegate), methodInfo); MethodNameWord methodNameWord = new MethodNameWord(rawWords, runtime, delegateMethod); runtime.addWord(methodNameWord); }
public virtual void performAction(ProseRuntime runtime) { // Create/fetc a possibly new word object representing the words. Word newWord = runtime.addWordFromRawWords(rawWordsToBindAsWord); // Bind the word using inheritence Word[] newIsa = new Word[newWord.isa.Length + 1]; // Copy all the old inherited words. Array.Copy(newWord.isa, newIsa, newWord.isa.Length); newIsa[newWord.isa.Length] = parent; // Add this new one. newWord.isa = newIsa; }
public static void constructInitialInheritance(ProseRuntime runtime) { ProseScope scope = runtime.GlobalScope; //runtime.Period.addParent(runtime.Comma); runtime.Period.addParent (runtime.Semicolon); runtime.Semicolon.addParent(runtime.Comma); runtime.Word_phrase.addParent(runtime.Word_word); }
public void performAction(ProseRuntime runtime) { try { method(runtime, args); } catch (Exception e) { // If anything goes wrong we "throw an exception" on the side. runtime.read("foreign function exception: \"" + e.Message + "\"", runtime.GlobalClient); } }
public void performAction(ProseRuntime runtime) { try { method(runtime, args); } catch (Exception e) { // If anything goes wrong we "throw an exception" on the side. runtime.read ("foreign function exception: \"" + e.Message + "\"", runtime.GlobalClient); } }
virtual public void performAction(ProseRuntime runtime) { // Create/fetc a possibly new word object representing the words. Word newWord = runtime.addWordFromRawWords(rawWordsToBindAsWord); // Bind the word using inheritence Word[] newIsa = new Word[newWord.isa.Length + 1]; // Copy all the old inherited words. Array.Copy(newWord.isa, newIsa, newWord.isa.Length); newIsa[newWord.isa.Length] = parent; // Add this new one. newWord.isa = newIsa; }
static public void constructInitialInheritance(ProseRuntime runtime) { ProseScope scope = runtime.GlobalScope; //runtime.Period.addParent(runtime.Comma); runtime.Period.addParent(runtime.Semicolon); runtime.Semicolon.addParent(runtime.Comma); runtime.Word_phrase.addParent(runtime.Word_word); }
public void performAction(ProseRuntime runtime) { // Look up the type. MethodInfo methodInfo = typeWord.TypeObject.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static); ProseLanguage.ActionDelegate delegateMethod = (ProseLanguage.ActionDelegate)Delegate.CreateDelegate(typeof(ProseLanguage.ActionDelegate), methodInfo); MethodNameWord methodNameWord = new MethodNameWord(rawWords, runtime, delegateMethod); runtime.addWord(methodNameWord); }
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, ""); }
/* * 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); } }
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); } }
public void performAction(ProseRuntime runtime) { runtime.read(readMe, runtime.GlobalClient); }
public bool doBreakPoint(ProseRuntime runtime, PNode source, BreakPointObject.RuntimeData rtdata) { return(onBreak(runtime, source, rtdata)); }
static public void constructInitialPatternTrie(ProseRuntime runtime) { ProseScope scope = runtime.GlobalScope; Trie <ProseObject, List <Phrase> > patternTrie = scope.PatternTree; // // Pattern Creation Pattern // // The only pattern we need to "force" into the system is the pattern for making patterns: // word[phrase_class] : @pattern[pattern] -> @prose[value] . // Phrase phrasePhrase = new SimplePhrase(runtime.Word_phrase, // new ProseObject[] { runtime.Word_word, //patternTrie.putObjectString( #region Word binding phrases // , word : @raw , { ProseObject[] commaDelimitedBindWordsPattern = new ProseObject[] { runtime.Comma, runtime.Word_word, runtime.Colon, runtime.@raw, runtime.Comma }; WordBindingPhrase bindWords_commaDelimited = new WordBindingPhrase(runtime.Word_phrase, commaDelimitedBindWordsPattern); scope.addPhrase(bindWords_commaDelimited); } // , word +: @raw , { ProseObject[] commaDelimitedBindWordsPattern = new ProseObject[] { runtime.Comma, runtime.Word_word, runtime.PlusColon, runtime.@raw, runtime.Comma }; WordBindingPhrase bindWords_commaDelimited = new WordBindingPhrase(runtime.Word_phrase, commaDelimitedBindWordsPattern); scope.addPhrase(bindWords_commaDelimited); } // , word <- @raw , { ProseObject[] commaDelimitedBindWordsPattern = new ProseObject[] { runtime.Comma, runtime.Word_word, runtime.LeftArrow, runtime.@raw, runtime.Comma }; ExclusiveWordBindingPhrase exclusiveBindWords_commaDelimited = new ExclusiveWordBindingPhrase(runtime.Word_phrase, commaDelimitedBindWordsPattern); scope.addPhrase(exclusiveBindWords_commaDelimited); } #endregion #region Phrase creation phrases // Comma delimited exclusive phrase creation // , word[class]: @pattern -> @prose[value] , { ProseObject[] phrasePattern = new ProseObject[] { runtime.Comma, runtime.Word_word, runtime.Colon, runtime.@pattern, runtime.RightArrow, runtime.@prose, runtime.Comma }; ExclusivePhraseBindingPhrase phrasePhrase = new ExclusivePhraseBindingPhrase(runtime.Word_phrase, phrasePattern); scope.addPhrase(phrasePhrase); } // Semicolon delimited exclusive phrase creation // ; word[class]: @pattern -> @prose[value] ; { ProseObject[] phrasePattern = new ProseObject[] { runtime.Semicolon, runtime.Word_word, runtime.Colon, runtime.@pattern, runtime.RightArrow, runtime.@prose, runtime.Semicolon }; ExclusivePhraseBindingPhrase phrasePhrase = new ExclusivePhraseBindingPhrase(runtime.Word_phrase, phrasePattern); scope.addPhrase(phrasePhrase); } // Period delimited exclusive phrase creation // . word[class]: @pattern -> @prose[value] . { ProseObject[] phrasePattern = new ProseObject[] { runtime.Period, runtime.Word_word, runtime.Colon, runtime.@pattern, runtime.RightArrow, runtime.@prose, runtime.Period }; ExclusivePhraseBindingPhrase phrasePhrase = new ExclusivePhraseBindingPhrase(runtime.Word_phrase, phrasePattern); scope.addPhrase(phrasePhrase); } #endregion #region Reading // , read @string[x] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("read"), runtime.word("@string"), runtime.Comma }; Phrase readPhrase = new ReadPhrase(runtime.Word_phrase, p); scope.addPhrase(readPhrase); } // contents of text file @string[file_name] { ProseObject[] p = new ProseObject[] { runtime.word("contents"), runtime.word("of"), runtime.word("text"), runtime.word("file"), runtime.word("@string") }; Phrase readFilePhrase = new ContentsOfTextFilePhrase(runtime.Word_phrase, p); scope.addPhrase(readFilePhrase); } runtime.read("phrase: , read file @string[path] , -> , read contents of text file path ,", runtime.GlobalClient); #endregion #region Foreign Function Interface // Load an assembly and bind it to a name // , load assembly : @string[file_name] <- @raw[new_assembly_word] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("load"), runtime.word("assembly"), runtime.Colon, runtime.@string, runtime.LeftArrow, runtime.@raw, runtime.Comma }; BindAssemblyPhrase asmPhrase = new BindAssemblyPhrase(runtime.Word_phrase, p); scope.addPhrase(asmPhrase); } // Load a type and bind it to a name // , @assembly[asm_name] type : @string[type_name] <- @raw[new_type_word] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("@assembly"), runtime.word("type"), runtime.Colon, runtime.@string, runtime.LeftArrow, runtime.@raw, runtime.Comma }; BindTypePhrase typePhrase = new BindTypePhrase(runtime.Word_phrase, p); scope.addPhrase(typePhrase); } // Load a method and bind it to a name // , @type[type_name] method : @string[method_name] <- @raw[new_method_word] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("@type"), runtime.word("method"), runtime.Colon, runtime.@string, runtime.LeftArrow, runtime.@raw, runtime.Comma }; BindMethodPhrase methodPhrase = new BindMethodPhrase(runtime.Word_phrase, p); scope.addPhrase(methodPhrase); } // Apply a method to some arguments to produce an action // , @method[method_name] @prose[args] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("@method"), runtime.@prose, runtime.Comma }; Phrase applyMethodPhrase = new ApplyMethodPhrase(runtime.Word_phrase, p); scope.addPhrase(applyMethodPhrase); } // Apply a method with no arguments to produce an action // , @method[method_name] , { ProseObject[] p = new ProseObject[] { runtime.Comma, runtime.word("@method"), runtime.Comma }; Phrase applyMethodPhrase = new ApplyMethodPhrase(runtime.Word_phrase, p); scope.addPhrase(applyMethodPhrase); } #endregion // Add a breakpoint { ProseObject[] p = new ProseObject[] { runtime.@break }; Phrase addBreakpointPhrase = new BreakPointPhrase(runtime.Word_phrase, p); scope.addPhrase(addBreakpointPhrase); } #region Debugger #endregion #region Experimental // , -> @pattern -> , { ProseObject[] test = new ProseObject[] { runtime.Comma, runtime.RightArrow, runtime.@pattern, runtime.RightArrow, runtime.Comma }; DebugOutputPhrase dbg = new DebugOutputPhrase("Carlybou", runtime.Word_phrase, test); scope.addPhrase(dbg); } #endregion }
public bool doBreakPoint(ProseRuntime runtime, PNode source, BreakPointObject.RuntimeData rtdata) { return onBreak (runtime, source, rtdata); }
public static void ErrorMethod(ProseRuntime runtime, List<ProseObject> args) { reportException(assembleArgumentsIntoString(args, "ErrorMethod takes only string arguments.")); }
public static void ContinueFromBreakPoint(ProseRuntime runtime, List<ProseObject> args) { shouldContinue = true; }
public PNode parseTokensIntoPNodes(ProseRuntime runtime, ProseClient who, List <LexerToken> tokens) { // Save the parameters this.who = who; this.runtime = runtime; sourceTokenList = tokens; setupForParsing(); Trie <RawWord, Word> .Node currWordLookupNode, wordLookupRoot, lastGoodNode; wordLookupRoot = runtime.getWordLookupRoot(); currWordLookupNode = wordLookupRoot; lastGoodNode = null; int lastGoodNodeTokenIdx = -1; // Record whether or not we're in the process of building up a word. bool isBuildingWord = false; int lastProcessedTokenIdx = -1; while (tokenIdx < tokens.Count) { LexerToken token = tokens[tokenIdx]; // // Deal With Quadquotes. // if (token.rawWord == ProseLanguage.Raw.Quadquote) { // First clean up any word we may be building and write it to output. if (isBuildingWord) { if (lastGoodNode == null) { // // If we're inside a quadquote block then this is fine: even if we don't have // // a legitimate word we can still wrap rawwords. Otherwise it's an error. // if (insideQuadquoteExpression) { // If there is no last good match, then take the raw words we've passed // and dump them all into raw word objects. for (int i = lastProcessedTokenIdx + 1; i < tokenIdx; i++) { writePNode(new PNode(new RawWordObject(tokens[i].rawWord))); } // Update everything so we continue after this point lastGoodNodeTokenIdx = tokenIdx - 1; lastProcessedTokenIdx = lastGoodNodeTokenIdx; currWordLookupNode = wordLookupRoot; isBuildingWord = false; // Don't bother updating tokenIdx because we need to look at the word again. } // else { // throw new RuntimeLexerSourceException("Unrecognized word or symbol.", tokens[tokenIdx-1]); // } } else { writePNode(new PNode(lastGoodNode.Value)); // Reset everything so we're looking for a new word again. lastGoodNode = null; currWordLookupNode = wordLookupRoot; isBuildingWord = false; lastGoodNodeTokenIdx = tokenIdx; lastProcessedTokenIdx = lastGoodNodeTokenIdx; } } // Output a quadquote writePNode(new PNode(runtime.Quadquote)); // Toggle our quad-quote-state. insideQuadquoteExpression = !insideQuadquoteExpression; lastQuadquoteIdx = tokenIdx; lastProcessedTokenIdx = tokenIdx; // Continue tokenIdx++; continue; } if (insideQuadquoteExpression) { if (token.tokenType != LexerToken.TYPE.UNCLASSIFIED) { throw new RuntimeLexerFailure("Static Lexer Failed Token Classification."); } // // This code is essentially copied from the LexerToken.TYPE.UNCLASSIFIED block below. // The only major difference is that instead of throwing an exception we wrap unknown // text inside raw word objects. // isBuildingWord = true; // Try to continue the current word matching. Trie <RawWord, Word> .Node nodeForThisRawWord = currWordLookupNode.getChildNode(token.rawWord); // If we can't continue this way... if (nodeForThisRawWord == null) { //...then whatever our last good match was is the correct word. if (lastGoodNode == null) { // If there is no last good match, then take the raw words we've passed // and dump them all into raw word objects. for (int i = lastProcessedTokenIdx + 1; i < tokenIdx; i++) { writePNode(new PNode(new RawWordObject(tokens[i].rawWord))); } lastProcessedTokenIdx = tokenIdx - 1; // Update everything so we continue after this point // Don't bother updating tokenIdx because we need to look at the word again. // Do update currWordLookupNode currWordLookupNode = wordLookupRoot.getChildNode(token.rawWord); // If there's no node at all, we have to deal with it now if (currWordLookupNode == null) { writePNode(new PNode(new RawWordObject(token.rawWord))); lastGoodNodeTokenIdx = tokenIdx; isBuildingWord = false; currWordLookupNode = wordLookupRoot; lastProcessedTokenIdx = tokenIdx; tokenIdx++; } else { isBuildingWord = true; lastGoodNodeTokenIdx = tokenIdx - 1; tokenIdx++; } continue; } writePNode(new PNode(lastGoodNode.Value)); // Reset everything so we're looking for a new word again. lastGoodNode = null; currWordLookupNode = wordLookupRoot; isBuildingWord = false; lastProcessedTokenIdx = lastGoodNodeTokenIdx; // Move the head back to the spot after the last token in the word tokenIdx = lastGoodNodeTokenIdx + 1; continue; } // If adding this raw word makes a word, then record it as good if (nodeForThisRawWord.Value != null) { lastGoodNode = nodeForThisRawWord; lastGoodNodeTokenIdx = tokenIdx; } currWordLookupNode = nodeForThisRawWord; continue; } else { switch (token.tokenType) { case LexerToken.TYPE.UNCLASSIFIED: { isBuildingWord = true; // Try to continue the current word matching. Trie <RawWord, Word> .Node nodeForThisRawWord = currWordLookupNode.getChildNode(token.rawWord); // If we can't continue this way... if (nodeForThisRawWord == null) { //...then whatever our last good match was is the correct word. if (lastGoodNode == null) { //throw new RuntimeLexerSourceException("Unrecognized word or symbol.", token); // Dump everything into raw words. tokenIdx++; // Include this word for (int i = lastProcessedTokenIdx + 1; i < tokenIdx; i++) { writePNode(new PNode(new RawWordObject(tokens[i].rawWord))); } // Update everything so we continue after this point lastGoodNodeTokenIdx = tokenIdx - 1; lastProcessedTokenIdx = lastGoodNodeTokenIdx; currWordLookupNode = wordLookupRoot; isBuildingWord = false; continue; } writePNode(new PNode(lastGoodNode.Value)); // Reset everything so we're looking for a new word again. lastGoodNode = null; currWordLookupNode = wordLookupRoot; isBuildingWord = false; lastProcessedTokenIdx = lastGoodNodeTokenIdx; // Move the head back to the spot after the last token in the word tokenIdx = lastGoodNodeTokenIdx + 1; continue; } // If adding this raw word makes a word, then record it as good if (nodeForThisRawWord.Value != null) { lastGoodNode = nodeForThisRawWord; lastGoodNodeTokenIdx = tokenIdx; } currWordLookupNode = nodeForThisRawWord; continue; } break; case LexerToken.TYPE.STRING: { // First clean up any word we may be building and write it to output. if (isBuildingWord) { if (lastGoodNode == null || lastGoodNodeTokenIdx != tokenIdx - 1) { //throw new RuntimeLexerSourceException("Unrecognized word or symbol.", tokens[tokenIdx-1]); // Just take all the words up until now and dump them into raw words. for (int i = lastProcessedTokenIdx + 1; i < tokenIdx; i++) { writePNode(new PNode(new RawWordObject(tokens[i].rawWord))); } // Update everything so we continue after this point lastGoodNodeTokenIdx = tokenIdx - 1; lastProcessedTokenIdx = lastGoodNodeTokenIdx; currWordLookupNode = wordLookupRoot; isBuildingWord = false; } else { writePNode(new PNode(lastGoodNode.Value)); // Reset everything so we're looking for a new word again. lastGoodNode = null; currWordLookupNode = wordLookupRoot; isBuildingWord = false; lastProcessedTokenIdx = lastGoodNodeTokenIdx; } } // Now write the string literal object to output writePNode(new PNode(new StringLiteralObject(token.rawWord.AsString))); lastProcessedTokenIdx = tokenIdx; // Continue tokenIdx++; continue; } break; } } } finalCheckAfterParsing(); return(outputRoot); }
public void performAction(ProseRuntime runtime) { //runtime.StdOut.Write(writeMe); }
public void performAction(ProseRuntime runtime) { Console.WriteLine("debugAction(" + who + ", " + what + ")"); }
public AssemblyNameWord(RawWord[] words, ProseRuntime runtime, Assembly assembly) : base(words) { this.assembly = assembly; isa = new Word[] { runtime.word("@assembly") }; }
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); }
// Set which events are logged public static void SetShowEvent(ProseRuntime runtime, List<ProseObject> args) { setShowEvent(runtime, args); }
// 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(); }
public static void SwitchToNewRuntime(ProseRuntime runtime, List<ProseObject> args) { shouldGetNewREPLRuntime = true; }
static void writeStackDepthMarker(ProseRuntime runtime) { Console.BackgroundColor = ConsoleColor.Red; for (int i=0; i < runtime.CallDepth - 1; i++) { Console.Write(" "); } }
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.")); }
public static void ExitREPL(ProseRuntime runtime, List<ProseObject> args) { shouldContinue = true; }
static void beforePerformingAction(ProseRuntime runtime, PNode source) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.Write("preaction> "); writePrettyProseWithProgressMark(runtime, source, null, 1); }
// Overriding instructions: // Return true if you want the runtime to make the standard breakpoint callback. // Return false if you prefer to handle the event yourself in the body of onBreak() public bool onBreak(ProseRuntime runtime, PNode source, BreakPointObject.RuntimeData rtdata) { // Handle the breakpoint in a non-standard way if you want // by putting something in the body of this function. return true; }
static void beforeReduction(ProseRuntime runtime, PNode source) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("prereduction> "); writePrettyProseWithProgressMark(runtime, source, null, 0); }
public TypeNameWord(RawWord[] words, ProseRuntime runtime, Type type) : base(words) { this.type = type; isa = new Word[] { runtime.word("@type") }; }
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()); } } }
// Get a list of all words descending from this one. public List <ProseObject> getAllDescendents(ProseRuntime runtime) { return(internalGetAllDescendents(runtime.getNewTag())); }
static void onParseSentence(ProseRuntime runtime, PNode source) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("postparse> "); writePrettyProseWithProgressMark(runtime, source, null, 0); }
// Overriding instructions: // Return true if you want the runtime to make the standard breakpoint callback. // Return false if you prefer to handle the event yourself in the body of onBreak() public bool onBreak(ProseRuntime runtime, PNode source, BreakPointObject.RuntimeData rtdata) { // Handle the breakpoint in a non-standard way if you want // by putting something in the body of this function. return(true); }
public void performAction(ProseRuntime runtime) { runtime.addPhraseAndDeleteExistingPhrases(phrase); }
public override PNode evaluate(PNode evaluateMe, PatternMatcher successfulMatch) { PatternMatcher match = successfulMatch; // Create the phrase represented by the user's code // Extract the pattern from the match ProseObject[] pattern = match.CurrPatternObject.Pattern; ProseObject[] argNames = match.CurrPatternObject.elementNames.ToArray(); // Create a value[] array for the new phrase ProseObject[] pvalue = match.getArgumentAsProseAtIndex(5).ToArray(); // Go through and make substitutions for the arguments PatternObject po = match.CurrPatternObject; for (int i = 0; i < po.Length; i++) { ProseObject argName = po.elementNames[i]; if (argName == null) { continue; } // If we actually have an argument name, then scan through // the value array and replace instances of that variable name // with ArgRefObjects. for (int j = 0; j < pvalue.Length; j++) { if (pvalue[j] == argName) { // Replace this object with a reference to the pattern. pvalue[j] = new ArgRefObject(i); } } } // Follow rules regarding , ; . // 1. When matching these on the beginning or end of a pattern, they automatically // generate ArgRefObjects on the beginning/end of the corresponding value. This // means punctuation never gets downgraded. // 2. Shouldn't allow stronger punctuation on the inside than on the outside, but // this is a little tougher to check. ProseRuntime runtime = successfulMatch.Runtime; if (pattern[0] == runtime.Comma || pattern[0] == runtime.Semicolon) { // Add a ref to the beginning ProseObject[] newValue = new ProseObject[pvalue.Length + 1]; Array.Copy(pvalue, 0, newValue, 1, pvalue.Length); newValue[0] = new ArgRefObject(0); pvalue = newValue; } int patternEnd = pattern.Length - 1; if (pattern[patternEnd] == runtime.Comma || pattern[patternEnd] == runtime.Semicolon) { // Add a ref to the beginning ProseObject[] newValue = new ProseObject[pvalue.Length + 1]; Array.Copy(pvalue, 0, newValue, 0, pvalue.Length); newValue[pvalue.Length] = new ArgRefObject(patternEnd); pvalue = newValue; } // Create a simple phrase from these ingredients SimplePhrase newPhrase = new SimplePhrase(match.Matching[1].value, pattern, argNames, pvalue); // Extract the "arguments" from the PatternMatcher. List <PNode> M = successfulMatch.Matching; // The pattern -> prose index from the match value = new ProseObject[3]; value[0] = M[0].value; value[1] = new ExclusivePhraseBindingAction(newPhrase); value[2] = M[6].value; PNode ret = replaceWithValueAt(evaluateMe, successfulMatch); value = null; return(ret); }
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()); }
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; } } }
public MethodNameWord(RawWord[] words, ProseRuntime runtime, ProseLanguage.ActionDelegate delegateMethod) : base(words) { this.delegateMethod = delegateMethod; isa = new Word[] { runtime.word("@method") }; }