public IWebFormsNode CreateNode(Match match, NodeType type) { Func<Match, IWebFormsNode> builder; if (NodeBuilders.TryGetValue(type, out builder)) { return builder(match); } else { var genericNode = new WebFormsNode { Type = type }; attributesReader.ReadAttributes(match, genericNode.Attributes); return genericNode; } }
public IWebFormsNode CreateNode(Match match, NodeType type) { Func <Match, IWebFormsNode> builder; if (NodeBuilders.TryGetValue(type, out builder)) { return(builder(match)); } else { var genericNode = new WebFormsNode { Type = type }; attributesReader.ReadAttributes(match, genericNode.Attributes); return(genericNode); } }
public IDocument<IWebFormsNode> Parse(string input) { Match match; int startAt = 0; var root = new WebFormsNode { Type = NodeType.Document }; IWebFormsNode parentNode = root; do { if ((match = textRegex.Match(input, startAt)).Success) { AppendTextNode(parentNode, match); startAt = match.Index + match.Length; } if (startAt != input.Length) { if ((match = directiveRegex.Match(input, startAt)).Success) { var directiveNode = NodeFactory.CreateNode(match, NodeType.Directive); parentNode.Children.Add(directiveNode); } else if ((match = commentRegex.Match(input, startAt)).Success) { var commentNode = NodeFactory.CreateNode(match, NodeType.Comment); parentNode.Children.Add(commentNode); } else if ((match = runatServerTagRegex.Match(input, startAt)).Success) { var serverControlNode = NodeFactory.CreateNode(match, NodeType.ServerControl); parentNode.Children.Add(serverControlNode); if(!match.Value.EndsWith("/>")) { parentNode = serverControlNode; } } else if ((match = doctypeRegex.Match(input, startAt)).Success) { AppendTextNode(parentNode, match); } else if ((match = startTagOpeningBracketRegex.Match(input, startAt)).Success) { AppendTextNode(parentNode, match); } else if ((match = endTagRegex.Match(input, startAt)).Success) { var tagName = match.Groups["tagname"].Captures[0].Value; var serverControlParent = parentNode as IWebFormsServerControlNode; if (serverControlParent != null && tagName.ToLowerInvariant() == serverControlParent.TagName.ToLowerInvariant()) { parentNode = parentNode.Parent; } else { AppendTextNode(parentNode, match); } } else if ((match = aspExprRegex.Match(input, startAt)).Success || (match = aspEncodedExprRegex.Match(input, startAt)).Success) { var expressionBlockNode = NodeFactory.CreateNode(match, NodeType.ExpressionBlock); parentNode.Children.Add(expressionBlockNode); } else if ((match = aspCodeRegex.Match(input, startAt)).Success) { var codeBlockNode = NodeFactory.CreateNode(match, NodeType.CodeBlock); parentNode.Children.Add(codeBlockNode); } else if ((match = scriptRegex.Match(input, startAt)).Success) // Relocated to enable processing of <% %> tags within the script block. { AppendTextNode(parentNode, match); } else { throw new Exception( string.Format("Unrecognized page element: {0}...", input.Substring(startAt, 20))); } startAt = match.Index + match.Length; } } while (startAt != input.Length); ApplyPostprocessingFilters(root); return new Document<IWebFormsNode>(root); }