示例#1
0
        private string ConsumeSubQuery()
        {
            StringBuilder sq = new StringBuilder();

            while (!_tq.IsEmpty)
            {
                if (_tq.Matches("("))
                {
                    sq.Append("(").Append(_tq.ChompBalanced('(', ')')).Append(")");
                }
                else if (_tq.Matches("["))
                {
                    sq.Append("[").Append(_tq.ChompBalanced('[', ']')).Append("]");
                }
                else if (_tq.MatchesAny(combinators))
                {
                    break;
                }
                else
                {
                    sq.Append(_tq.Consume());
                }
            }
            return(sq.ToString());
        }
        public void chompBalancedMatchesAsMuchAsPossible()
        {
            TokenQueue tq = new TokenQueue("unbalanced(something(or another");

            tq.ConsumeTo("(");
            string match = tq.ChompBalanced('(', ')');

            Assert.AreEqual("something(or another", match);
        }
        public void chompBalanced()
        {
            TokenQueue tq        = new TokenQueue(":contains(one (two) three) four");
            string     pre       = tq.ConsumeTo("(");
            string     guts      = tq.ChompBalanced('(', ')');
            string     remainder = tq.Remainder();

            Assert.AreEqual(":contains", pre);
            Assert.AreEqual("one (two) three", guts);
            Assert.AreEqual(" four", remainder);
        }