Exemple #1
0
        public bool VerifyNexts(ProgressiveList <T> nexts)
        {
            T    def   = default(T);
            bool ret   = true;
            int  state = GetState();
            T    item;

            while (!Equals(item = nexts.Next(), def))
            {
                var nitem = nexts.Next();
                if (Equals(nitem, def) || !Equals(item, nitem))
                {
                    ret = false;
                    break;
                }
            }
            RestoreState(state);
            return(ret);
        }
Exemple #2
0
        public override bool Match(ProgressiveList <Token> tokens)
        {
            Token token;
            bool  result;

            switch (condType)
            {
            case TokenConditional.Text:
                return(tokens.Next().text == text);

            case TokenConditional.Type:
                token  = tokens.Next();
                result = token.Type() == type;
                if (result && storeOn != null)
                {
                    Set(storeOn, token.value);
                }
                return(result);

            case TokenConditional.Value:
                token  = tokens.Next();
                result = Tokenizer.isValue(token.Type());
                if (result && storeOn != null)
                {
                    Set(storeOn, token.value);
                }
                return(result);

            case TokenConditional.Any:
                token  = tokens.Next();
                result = true;
                if (storeOn != null)
                {
                    Set(storeOn, token.value);
                }
                return(result);
            }
            return(false);
        }
Exemple #3
0
        public bool VerifyNexts(ProgressiveList <string> nexts, bool dontWorryAboutOrder = false,
                                Func <Token, Tokens, bool> checker = null)
        {
            bool ret   = true;
            int  state = GetState();
            bool begun = true;

            if (dontWorryAboutOrder)
            {
                begun = false;
            }
            Token token;

            while ((token = tokens.Next()) != null)
            {
                var ntoken = nexts.Next();
                if (ntoken == null)
                {
                    if (!begun)
                    {
                        return(false);
                    }
                    return(ret);
                }
                if (token.text != ntoken)
                {
                    if (!begun)
                    {
                        nexts.Back();
                        continue;
                    }
                    ret = false;
                    break;
                }
                else
                {
                    if (!begun)
                    {
                        if (checker == null)
                        {
                            begun = true;
                        }
                        else if (checker != null)
                        {
                            int prev = GetState();
                            if (!checker(token, this))
                            {
                                nexts.Back();
                            }
                            else
                            {
                                begun = true;
                                return(true);
                            }
                            RestoreState(prev);
                        }
                    }
                }
            }
            RestoreState(state);
            if (!begun)
            {
                ret = false;
            }
            return(ret);
        }
Exemple #4
0
 /// <summary>
 /// Return a token and advance the pointer
 /// </summary>
 /// <returns>The next.</returns>
 public Token Next()
 {
     return(tokens.Next());
 }