Esempio n. 1
0
        public static ClassNode Parse(TokenString tStr, ref int index)
        {
            var accessors = AccessibleNode.GetAccessors(tStr, ref index);

            if (!tStr.Match(index, TokenType.@class, TokenType.identifier, TokenType.cBraceOpen))
            {
                return(null);
            }

            int startIndex = index;

            index++;

            ClassNode node = new ClassNode(tStr[index].Value, accessors);

            index++;

            if (tStr[index].Type != TokenType.cBraceOpen)
            {
                index = startIndex;
                return(null);
            }

            // Get internals
            var internalRange = tStr.GetRangeInBrackets(ref index);
            int iRangeIndex   = 0;

            while (iRangeIndex < internalRange.Count)
            {
                Node tempNode;


                if ((tempNode = CtorNode.Parse(node.Name, internalRange, ref iRangeIndex)) != null)
                {
                    node.AddCtor(tempNode as CtorNode);
                }
                else if ((tempNode = MethodNode.Parse(internalRange, ref iRangeIndex)) != null)
                {
                    node.AddMethod(tempNode as MethodNode);
                }
                else if ((tempNode = FieldNode.Parse(internalRange, ref iRangeIndex)) != null)
                {
                    node.AddField(tempNode as FieldNode);
                }
                else
                {
                    iRangeIndex++;
                }

                //if (internalRange.Match(iRangeIndex, TokenType.typeSpecifier, TokenType.identifier))
                //{
                //    if (internalRange.Match(iRangeIndex + 2, TokenType.rBraceOpen))
                //        node.AddMethod(MethodNode.Parse(internalRange, ref iRangeIndex));
                //    else
                //        node.AddField(FieldNode.Parse(internalRange, ref iRangeIndex));
                //}
                //else
                //    iRangeIndex++;
            }

            //index += iRangeIndex;
            return(node);
        }
Esempio n. 2
0
 public void AddMethod(MethodNode method)
 {
     method.Class = this;
     methods.Add(method);
 }