/// <summary> /// Removes the prefix according to the StartRemove and EndRemove values /// </summary> /// <param name="treeNode">The tree node to replace</param> /// <param name="referencedElement">The element that should be replaced</param> /// <returns>if the replacement has been done</returns> private bool ReplaceNonTerminal(InterpreterTreeNode treeNode, ModelElement referencedElement) { bool retVal; if (ReplaceAllReferences) { // Only do the repleacement for elements defined in a dictionary retVal = EnclosingFinder <Dictionary> .find(referencedElement) != null; } else { // Check that the reference corresponds to the specific reference for this visitor retVal = referencedElement == Ref; } if (retVal) { // Removes the prefix if (ShouldRemovePrefix) { ReplaceText("", StartRemove, EndRemove); ResetRemoveIndexes(); } string replacementValue = referencedElement.ReferenceName(User); ReplaceText(replacementValue, treeNode.Start, treeNode.End); } return(retVal); }
/// <summary> /// Provides the instance related to a character index in the textbox /// </summary> /// <param name="index"></param> /// <returns></returns> protected INamable GetInstance(int index) { INamable retVal = null; if (Model != null) { InterpreterTreeNode node = Parse(EditionTextBox.Text); if (node != null) { ContextGrabber grabber = new ContextGrabber(); retVal = grabber.GetContext(index, node); } if (retVal == null) { // Perform a fuzzy search by trying to find the corresponding expression text string text = GetExpressionText(EditionTextBox.Text, index); node = Parse(text); index = text.Length - 1; if (node != null) { ContextGrabber grabber = new ContextGrabber(); retVal = grabber.GetContext(index, node); } } } return(retVal); }
/// <summary> /// Provides an explanation of an interpreter tree node, if it is not null /// </summary> /// <param name="node"></param> /// <param name="explainSubElements"></param> public void Write(InterpreterTreeNode node, bool explainSubElements = true) { if (node != null) { node.GetExplain(this, explainSubElements); } else { Data.Append("<Unknown>"); } }
/// <summary> /// Parses the current statement or expression and returns the interpreter tree node /// </summary> /// <param name="text">The text to parse</param> /// <returns></returns> private InterpreterTreeNode Parse(string text) { InterpreterTreeNode retVal = null; if (!String.IsNullOrEmpty(text)) { Parser parser = new Parser(); retVal = parser.Statement(Instance as ModelElement, EditionTextBox.Text, true, true); if (retVal == null) { retVal = parser.Expression(Instance as ModelElement, text, AllMatches.INSTANCE, true, null, true, true); } } return(retVal); }
/// <summary> /// Removes the prefix according to the StartRemove and EndRemove values /// </summary> /// <param name="treeNode">The tree node to replace</param> /// <param name="referencedElement">The element that should be replaced</param> /// <returns>if the replacement has been done</returns> private bool ReplaceNonTerminal(InterpreterTreeNode treeNode, ModelElement referencedElement) { bool retVal; if (ReplaceAllReferences) { // Only do the repleacement for elements defined in a dictionary retVal = EnclosingFinder<Dictionary>.find(referencedElement) != null; } else { // Check that the reference corresponds to the specific reference for this visitor retVal = referencedElement == Ref; } if (retVal) { // Removes the prefix if (ShouldRemovePrefix) { ReplaceText("", StartRemove, EndRemove); ResetRemoveIndexes(); } string replacementValue = referencedElement.ReferenceName(User); ReplaceText(replacementValue, treeNode.Start, treeNode.End); } return retVal; }