Esempio n. 1
0
        public bool TryMatch(ParseContext context, out Token token)
        {
            if (context.Eof())
            {
                token = null;
                return(false);
            }
            bool nega = context.CurrentChar == 'n';

            ++context.Position;
            if (!char.IsDigit(context.CurrentChar))
            {
                --context.Position;
                token = null;
                return(false);
            }
            int number = 0;

            while (!context.Eof() && char.IsDigit(context.CurrentChar))
            {
                number = number * 10 + (context.CurrentChar - 0x30);
                ++context.Position;
            }
            if (nega)
            {
                number = -number;
            }
            token = new Token(Name, number);
            return(true);
        }
Esempio n. 2
0
 protected bool TryParse_Length(ParseContext context, out int length)
 {
     if (context.Eof() || !char.IsDigit(context.CurrentChar))
     {
         length = -1;
         return(false);
     }
     length = 0;
     while (!context.Eof() && char.IsDigit(context.CurrentChar))
     {
         length = length * 10 + (context.CurrentChar - 0x30);
         ++context.Position;
     }
     return(true);
 }