public InterfaceNode(TypeReferenceNode reference)
     : base(SyntaxTreeNodeType.InterfaceNode, reference.NodeName)
 {
     Nodes.Add(reference);
 }
 public InitializerNode(string keyword, TypeReferenceNode typeNode)
     : base(SyntaxTreeNodeType.InitializerSyntaxNode, keyword)
 {
 }
        public static bool TryParse(string instruction, out InitializerNode node)
        {
            node = null;

            var match = _regex.Match(instruction);
            if (!match.Success)
            {
                return false;
            }

            var refNode = new TypeReferenceNode(match.Groups["type"].Value);
            node = new InitializerNode(ReservedKeywords.New, refNode);

            CommentNode comment;
            if (CommentNode.TryParse(instruction, out comment))
            {
                node.Nodes.Add(comment);
            }

            return true;
        }
        private IEnumerable<ISyntaxTreeNode> ParseDeclarations(string[] content, ref int currentLine)
        {
            var result = new List<ISyntaxTreeNode>();

            var pattern = @"((?<keyword>Dim|Static|Public|Private|Friend|Global)\s)?(?<keyword>Dim|Static|Public|Private|Friend|Global|Const|Declare|Type|Enum)\s+(?<identifier>\w+)(?<arraySize>\(.*\))?(\s+As\s+?(((?<initializer>New)\s+)?)(?<type>\w+(\.\w+)?))?$";
            var regex = new Regex(pattern);

            var isDeclarationSection = true;
            while (isDeclarationSection)
            {
                if (content[currentLine].Trim().StartsWith("'"))
                {
                    // comment node
                    currentLine++;
                    continue;
                }

                var line = content[currentLine];
                isDeclarationSection =  !(
                                               line.Contains(ReservedKeywords.Property)
                                            || line.Contains(ReservedKeywords.Sub)
                                            || line.Contains(ReservedKeywords.Function)
                                         );
                if (isDeclarationSection)
                {
                    currentLine++;
                    var match = regex.Match(line);
                    ISyntaxTreeNode node = null;
                    if (match.Success && !line.StartsWith(ReservedKeywords.Implements))
                    {
                        if (match.Groups["keyword"].Captures.Count == 2)
                        {
                            node = new DeclarationNode(match.Groups["keyword"].Captures[0].Value,
                                                           match.Groups["keyword"].Captures[1].Value,
                                                           match.Groups["identifier"].Value,
                                                           match.Groups["arraySize"].Value,
                                                           match.Groups["initializer"].Value,
                                                           match.Groups["type"].Value);
                        }
                        else
                        {
                            node = new DeclarationNode(null, match.Groups["keyword"].Value,
                                                                 match.Groups["identifier"].Value,
                                                                 match.Groups["arraySize"].Value,
                                                                 match.Groups["initializer"].Value,
                                                                 match.Groups["type"].Value);
                        }
                    }
                    else if(line.StartsWith(ReservedKeywords.Implements))
                    {
                        var implements = Regex.Match(line, ReservedKeywords.Implements + @"\s(?<type>[a-zA-Z][_a-zA-Z0-9]*)$");
                        if (implements.Success)
                        {
                            var reference = new TypeReferenceNode(implements.Groups["type"].Value);
                            node = new InterfaceNode(reference);
                        }
                    }

                    if (node != null && node.NodeName == ReservedKeywords.Type)
                    {
                        while(content[currentLine].Trim() != string.Format("{0} {1}", ReservedKeywords.End, ReservedKeywords.Type))
                        {
                            var member = Regex.Match(content[currentLine].Trim(), @"(?<identifier>\w+)(?<arraySize>\(.*\))?(\s+As\s+?(((?<initializer>New)\s+)?)(?<type>\w+(\.\w+)?))$");
                            if (member.Success)
                            {
                                node.Nodes.Add(new DeclarationNode(null, member.Groups["identifier"].Value, member.Groups["identifier"].Value, member.Groups["arraySize"].Value, member.Groups["initializer"].Value, member.Groups["type"].Value));
                            }
                            currentLine++;
                        }
                    }
                    else if (node != null && node.NodeName == ReservedKeywords.Enum)
                    {
                        int currentValue = 0;
                        while (content[currentLine].Trim() != string.Format("{0} {1}", ReservedKeywords.End, ReservedKeywords.Enum))
                        {
                            var member = Regex.Match(content[currentLine].Trim(), @"(?<identifier>\w+)(\s\=\s(?<value>.*))?$");
                            if (member.Success)
                            {
                                var value = member.Groups["value"].Value;
                                if (string.IsNullOrEmpty(value))
                                {
                                    if (!int.TryParse(value, out currentValue))
                                    {
                                        currentValue++;
                                    }
                                }
                                node.Nodes.Add(new EnumMemberNode(member.Groups["identifier"].Value, currentValue));
                            }
                            currentLine++;
                        }
                    }

                    if (node != null)
                    {
                        result.Add(node);
                    }
                }
            }

            return result;
        }