Exemplo n.º 1
0
        public static ListOrValue parseRoot(TokenPos[] tokens)
        {
            //ListOrValue retVal = new ListOrValue();
            if (tokens == null || tokens.Length < 1)
            {
                return(new ListOrValue());
            }

            var tok = new TokenPos(
                tokens[0].getSource(),
                TokenType.document,
                0,
                tokens[0].sourceLength()
                //retVal.tokenSectionLength()
                //retVal.m_value.m_source.Length
                );

            ListOrValue retVal = new ListOrValue(new List <ListOrValue>(), tok);
            //retVal.m_value.m_type = TokenType.document;
            //retVal.m_value.m_start = 0;
            //retVal.m_value.m_source = tokens[0].m_source;
            //retVal.m_value.m_end = retVal.m_value.m_source.Length;
            //retVal.m_list = new List<ListOrValue>();

            var tokensLength = tokens.Length;
            int idx          = 0;

            while (idx < tokensLength)
            {
                var item = parseToken(tokens, idx, out idx);
                if (item.isDefault())
                {
                    continue;
                }
                retVal.add(item);
            }
            if (retVal.count() < 1)
            {
                return(new ListOrValue());
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public static ListOrValue parseToken(TokenPos[] tokens, int curIdx, out int nextIdx)
        {
            nextIdx = curIdx + 1;
            //ListOrValue curListOrVal = new ListOrValue();
            var curTok       = tokens[curIdx];
            var tokensLength = tokens.Length;

            if (curTok.getType() == TokenType.neutral)
            {
                return(new ListOrValue());
            }

            //ListOrValue curListOrVal = new ListOrValue(null, curTok);
            //curListOrVal.m_value = curTok;
            if (curTok.getType() != TokenType.list)
            {
                return(new ListOrValue(null, curTok));
            }

            // is list
            ListOrValue curListOrVal = new ListOrValue(new List <ListOrValue>(), curTok);

            //curListOrVal.m_list = new List<ListOrValue>();
            while (nextIdx < tokensLength)
            {
                if (tokens[nextIdx].getStart() >= curTok.getEnd())
                {
                    break;
                }
                var item = parseToken(tokens, nextIdx, out nextIdx);
                if (item.isDefault())
                {
                    continue;
                }
                curListOrVal.add(item);
            }
            return(curListOrVal);
        }