// Just before public void autoCastArguments() { ProseObject[] pattern = AssociatedPattern; for (int i = 0; i < pattern.Length; i++) { PNode componentStart, componentEnd; componentStart = getArgumentBounds(i, out componentEnd); // Check for auto-formatting of text expression into string // Auto-cast a text expression into a string by evaluating it. if (pattern[i] == runtime.@string && Matching[i].value == runtime.Quadquote) { PNode textStart = componentStart; PNode textEnd = componentEnd; // Create a StringLiteralObject to substitute string textAsString = runtime.parseTextExpressionIntoString(textStart, textEnd); PNode literal = new PNode(new StringLiteralObject(textAsString)); // Splice in this literal literal.prev = textStart.prev; if (textStart.prev != null) { textStart.prev.next = literal; } literal.next = textEnd; if (textEnd != null) { textEnd.prev = literal; } // Correct the match list. Matching[i] = literal; continue; } // Auto-cast a prose expression by unwrapping {} if (pattern[i] == runtime.@prose && componentStart.value == runtime.LeftCurlyBracket && componentEnd.prev.value == runtime.RightCurlyBracket) { PNode leftCurly = componentStart; PNode rightCurly = componentEnd.prev; // Correct the match list Matching[i] = leftCurly.next; // Eliminate the curly brackets leftCurly.removeSelf(); rightCurly.removeSelf(); continue; } } }
// Start on the left side of the sentence and perform actions. Eliminate ; along the way if // it's sandwhiched between actions. // NOTE: EXPECTS INITIAL PUNCTUATION private PNode doActionsOnLeftOfSentence(PNode sourcePtr, out bool didSomeActions, out bool sentenceHasBeenExecuted) { didSomeActions = false; sentenceHasBeenExecuted = false; PNode reduced = sourcePtr.next; // Skip initial punctuation while (reduced != null) { if (reduced.value is ProseAction) { // Callback Before if (BeforePerformingAction != null) { BeforePerformingAction(this, reduced); } // DO THE ACTION! // try { ((ProseAction)reduced.value).performAction(this); // } // catch (Exception e) // { // this.read ("language function exception: \"" + e.Message + "\"", GlobalClient); // } // Callback After if (AfterPerformingAction != null) { AfterPerformingAction(this, reduced); } didSomeActions = true; reduced.removeSelf(); reduced = reduced.next; } else if (reduced.value == Semicolon || reduced.value == Comma) { // Check to see if we should leave this semicolon in (as punctuation for the remaining // prose to match) or remove it because it's surrounded in actions. if (reduced.next != null) { // Skip over the semicolon and move on to the next action we found reduced = reduced.next; } else { // We've run into a the end, so leave the symbol there. break; } } else if (reduced.value == Period) { // We've run into the end of the whole sentence, so skip the period. sentenceHasBeenExecuted = true; return(reduced.next); } else { break; } } if (didSomeActions) { return(reduced); } else { return(sourcePtr); } }