public void ParsePartialNVReferenceWithDollarIdentDotIdentLParen() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.LinkToRemote("); TemplateNode template = parser.ParseTemplate(); // Check errors Assert.AreEqual(2, parser.Errors.Count); AssertError("Expected expression, was 'Error'", new Position(1, 20, 1, 20), parser.Errors[0]); AssertError("Expected 'NVRParen' but was 'Error'", new Position(1, 20, 1, 20), parser.Errors[1]); // Check the TemplateNode Assert.AreEqual(1, template.Content.Count); NVReference nvReference = (NVReference)template.Content[0]; Assert.AreEqual("Ajax", nvReference.Designator.Name); Assert.AreEqual(1, nvReference.Designator.Selectors.Count); NVSelector selector = nvReference.Designator.Selectors[0]; Assert.AreEqual("LinkToRemote", selector.Name); Assert.AreEqual(0, selector.Actuals.Count); }
public void ParseReferenceWithMultipleActualParams() { Parser parser = GetNewParser("$first.second(100, 200, 300)"); TemplateNode templateNode = parser.ParseTemplate(); // NVReference with 1 selector and 1 actual param NVSelector nvSelector = ((NVReference)templateNode.Content[0]).Designator.Selectors[0]; Assert.AreEqual(3, nvSelector.Actuals.Count); Assert.AreEqual(100, ((NVNumExpression)nvSelector.Actuals[0]).Value); Assert.AreEqual(200, ((NVNumExpression)nvSelector.Actuals[1]).Value); Assert.AreEqual(300, ((NVNumExpression)nvSelector.Actuals[2]).Value); }
public void ReferenceFollowedByReference() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.InstallScripts()\n$Form."); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Designator NVSelector designator = (NVSelector)templateNode.GetNodeAt(2, 7); AssertPosition(new Position(2, 6, 2, 7), designator.Position); }
public void ParseReferenceWithOneActualParam() { Parser parser = GetNewParser("$first.second(100)"); TemplateNode templateNode = parser.ParseTemplate(); // NVReference with 1 selector and 1 actual param NVReference nvReference = (NVReference)templateNode.Content[0]; Assert.AreEqual(1, nvReference.Designator.Selectors.Count); NVSelector nvSelector = nvReference.Designator.Selectors[0]; Assert.AreEqual(1, nvSelector.Actuals.Count); Assert.AreEqual(typeof(NVNumExpression), nvSelector.Actuals[0].GetType()); NVNumExpression numExpr = (NVNumExpression)nvSelector.Actuals[0]; Assert.AreEqual(100, numExpr.Value); }
public void FirstDesignatorSelector() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax."); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Check template NVReference nvReference = (NVReference)templateNode.Content[0]; Assert.AreEqual("Ajax", nvReference.Designator.Name); NVSelector nvSelector = nvReference.Designator.Selectors[0]; Assert.AreEqual("", nvSelector.Name); // Get node at position AstNode astNode = templateNode.GetNodeAt(1, 7); Assert.AreEqual(typeof(NVSelector), astNode.GetType()); AssertPosition(new Position(1, 6, 1, 7), astNode.Position); }
private void AddNodesToTree(AstNode parentAstNode, TreeNode parentTreeNode) { if (parentAstNode is TemplateNode) { // Template Content foreach (AstNode node in ((TemplateNode)parentAstNode).Content) { AddNodesToTree(node, parentTreeNode); } } else if (parentAstNode is NVBinaryExpression) { NVBinaryExpression binExpr = (NVBinaryExpression)parentAstNode; TreeNode binExprTreeNode = new TreeNode(string.Format("NVBinaryExpression={{Op:\"{0}\"}}", binExpr.Op)); binExprTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(binExprTreeNode); AddNodesToTree(binExpr.Lhs, binExprTreeNode); AddNodesToTree(binExpr.Rhs, binExprTreeNode); } else if (parentAstNode is NVBoolExpression) { TreeNode boolTreeNode = new TreeNode(string.Format("NVBoolExpression={{Value:\"{0}\"}}", ((NVBoolExpression)parentAstNode).Value)); boolTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(boolTreeNode); } else if (parentAstNode is NVForeachDirective) { NVForeachDirective foreachDirective = (NVForeachDirective)parentAstNode; TreeNode foreachTreeNode = new TreeNode(string.Format("NVForeachDirective={{Iterator:\"{0}\"}}", foreachDirective.Iterator)); foreachTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(foreachTreeNode); // Content foreach (AstNode astNode in foreachDirective.Content) { AddNodesToTree(astNode, foreachTreeNode); } } else if (parentAstNode is NVDirective) { TreeNode directiveTreeNode = new TreeNode(string.Format("NVDirective={{Name:\"{0}\"}}", ((NVDirective)parentAstNode).Name)); directiveTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(directiveTreeNode); } else if (parentAstNode is NVNumExpression) { TreeNode numTreeNode = new TreeNode(string.Format("NVNumExpression={{Value:\"{0}\"}}", ((NVNumExpression)parentAstNode).Value)); numTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(numTreeNode); } else if (parentAstNode is NVReference) { TreeNode referenceTreeNode = new TreeNode(string.Format("NVReference={{Name:\"{0}\"}}", ((NVReference)parentAstNode).Designator.Name)); referenceTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(referenceTreeNode); foreach (NVSelector selector in ((NVReference)parentAstNode).Designator.Selectors) { AddNodesToTree(selector, referenceTreeNode); } } else if (parentAstNode is NVSelector) { NVSelector selector = (NVSelector)parentAstNode; TreeNode selectorTreeNode = new TreeNode(string.Format("NVSelector={{Name:\"{0}\", Type:\"{1}\"}}", selector.Name, selector.Type != null ? selector.Type.Name : "")); selectorTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(selectorTreeNode); if (selector.Actuals.Count > 0) { TreeNode actualsTreeNode = new TreeNode("Actuals:"); foreach (NVExpression actual in selector.Actuals) { AddNodesToTree(actual, actualsTreeNode); } selectorTreeNode.Nodes.Add(actualsTreeNode); } } else if (parentAstNode is NVStringExpression) { TreeNode stringTreeNode = new TreeNode(string.Format("NVStringExpression={{Value:\"{0}\"}}", ((NVStringExpression)parentAstNode).Value)); stringTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(stringTreeNode); } else if (parentAstNode is XmlAttribute) { TreeNode attributeTreeNode = new TreeNode(string.Format("XmlAttribute={{Name:\"{0}\"}}", ((XmlAttribute)parentAstNode).Name)); attributeTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(attributeTreeNode); // XML Attribute Content foreach (AstNode node in ((XmlAttribute)parentAstNode).Content) { AddNodesToTree(node, attributeTreeNode); } } else if (parentAstNode is XmlElement) { XmlElement xmlElement = (XmlElement)parentAstNode; TreeNode elementTreeNode = new TreeNode(string.Format("XmlElement={{Name:\"{0}\"}}", xmlElement.Name)); elementTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(elementTreeNode); // XML Element Attributes TreeNode attributesTreeNode = new TreeNode("Attributes:"); foreach (AstNode attribute in xmlElement.Attributes) { AddNodesToTree(attribute, attributesTreeNode); } elementTreeNode.Nodes.Add(attributesTreeNode); // XML Element Content TreeNode contentTreeNode = new TreeNode("Content:"); foreach (AstNode node in xmlElement.Content) { AddNodesToTree(node, contentTreeNode); } elementTreeNode.Nodes.Add(contentTreeNode); } else if (parentAstNode is XmlTextNode) { TreeNode textNodeTreeNode = new TreeNode(string.Format("XmlTextNode={{Text:\"{0}\"}}", ((XmlTextNode)parentAstNode).Text.Replace("\n", "\\n"))); textNodeTreeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(textNodeTreeNode); } else { if (parentAstNode != null) { TreeNode treeNode = new TreeNode("UNKNOWN===" + parentAstNode.GetType().Name); treeNode.Tag = parentAstNode; parentTreeNode.Nodes.Add(treeNode); } } }
private NVReference ParseNVDesignator(Position startPosition) { // NVDesignator -> nvIdentifer { "." nvIdentifier [ NVActualParams ] }. NVReference nvReference; if (CurrentTokenType == TokenType.NVIdentifier) { nvReference = new NVReference(new NVDesignator(_scanner.CurrentToken.Image)); nvReference.Position = new Position(startPosition, _scanner.CurrentPos); _scanner.GetToken(); } else { AddError("Expected reference identifier"); nvReference = new NVReference(new NVDesignator("")); nvReference.Position = new Position(startPosition, _scanner.CurrentPos); return(nvReference); } while (CurrentTokenType == TokenType.NVDot) { Position startSelectorPosition = new Position(_scanner.CurrentPos.Start); Position dotPosition = new Position(_scanner.CurrentPos); _scanner.GetToken(); if (CurrentTokenType == TokenType.NVIdentifier) { Position endSelectorPosition = new Position(_scanner.CurrentPos.End); NVSelector selector = new NVSelector(new NVMethodNode( _scanner.CurrentToken.Image), nvReference); _scanner.GetToken(); if (CurrentTokenType == TokenType.NVLParen) { selector.Actuals = ParseNVActualParams(); endSelectorPosition = new Position(_scanner.PreviousPos.Start); } selector.Position = new Position(startSelectorPosition, endSelectorPosition); nvReference.Designator.Selectors.Add(selector); nvReference.Position.End = new Position(endSelectorPosition); } else { AddError("Expected identifier"); NVSelector selector = new NVSelector(new NVMethodNode("", null), nvReference); selector.Position = new Position(dotPosition); nvReference.Designator.Selectors.Add(selector); nvReference.Position.End = new Position(selector.Position.End); return(nvReference); } } return(nvReference); }