コード例 #1
0
ファイル: CtorNode.cs プロジェクト: pBactusp/Shpoon
        public static CtorNode Parse(string className, TokenString tStr, ref int index)
        {
            int startIndex = index;

            var accessors = new List <string>();

            while (tStr[index].Type == TokenType.accessor)
            {
                accessors.Add(tStr[index].Value);
                index++;
            }

            if (!(tStr.Match(index, TokenType.identifier, TokenType.rBraceOpen) && tStr[index].Value == className))
            {
                index = startIndex;
                return(null);
            }

            string type = tStr[index].Value;
            string name = "ctor";

            index++;

            var args = new List <ArgumentNode>();

            var argTokens = tStr.GetRangeInBrackets(ref index);

            if (argTokens != null && argTokens.Count > 0)
            {
                var argTokensSep = argTokens.Split(false, TokenType.comma);

                foreach (var argTs in argTokensSep)
                {
                    args.Add(new ArgumentNode(argTs[0].Value, argTs[1].Value));
                }
            }

            index = tStr.FindNextIndex(index, TokenType.cBraceOpen);

            var sta = CompoundStaNode.Parse(tStr, ref index);

            if (sta == null)
            {
                index = startIndex;
                return(null);
            }

            CtorNode node = new CtorNode(type, name, accessors, args, sta);

            return(node);
        }
コード例 #2
0
 public void AddCtor(CtorNode ctor)
 {
     ctor.Class = this;
     ctors.Add(ctor);
 }
コード例 #3
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);
        }