Exemple #1
0
        public static FieldNode Parse(TokenString tStr, ref int index)
        {
            var accessors = AccessibleNode.GetAccessors(tStr, ref index);

            if (!tStr.Match(index, TokenType.typeSpecifier, TokenType.identifier, TokenType.lineEnd))
            {
                return(null);
            }

            string type = tStr[index].Value;

            index++;
            string name = tStr[index].Value;

            index++;

            FieldNode node = new FieldNode(type, name, accessors);

            return(node);
        }
Exemple #2
0
        public static MethodNode Parse(TokenString tStr, ref int index)
        {
            int startIndex = index;

            var accessors = AccessibleNode.GetAccessors(tStr, ref index);

            if (!tStr.Match(index, TokenType.typeSpecifier, TokenType.identifier, TokenType.rBraceOpen))
            {
                return(null);
            }

            string type = tStr[index].Value;

            index++;
            string name = tStr[index].Value;

            index++;

            var args = new List <ArgumentNode>();

            var argTokens = tStr.GetRangeInBrackets(ref index).Split(false, TokenType.comma);

            foreach (var argTs in argTokens)
            {
                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);
            }

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

            return(node);
        }
Exemple #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);
        }