Example #1
0
        private static bool TryTakeIdentifier(StringKeeper stringKeeper, out StringKeeper newStringKeeper, out ApplyIfToken token)
        {
            var work  = new StringKeeper(stringKeeper);
            var value = string.Empty;

            while (!IsTerminator(work))
            {
                value += work.Next;
                work   = work.Take();
            }

            if (!string.IsNullOrWhiteSpace(value))
            {
                newStringKeeper = work;
                token           = new ApplyIfToken(ApplyIfTokenType.Identifier, value);
                return(true);
            }

            newStringKeeper = stringKeeper;
            token           = null;
            return(false);
        }
Example #2
0
        private static bool TryTake(StringKeeper stringKeeper, Dictionary <string, ApplyIfToken> tokens, out StringKeeper newStringKeeper, out ApplyIfToken token)
        {
            var thisToken = tokens.FirstOrDefault(x => stringKeeper.IsNext(x.Key, false));

            if (thisToken.Key != null)
            {
                var work = stringKeeper.Take(thisToken.Key.Length);
                newStringKeeper = work;
                token           = thisToken.Value;
                return(true);
            }

            newStringKeeper = stringKeeper;
            token           = null;
            return(false);
        }