readChar() приватный Метод

private readChar ( ) : void
Результат void
Пример #1
0
 private static void matchSymbol(Scanner s)
 {
     if (!s.isInitial())
     {
         return;
     }
     s.readChar();
     while (s.isSubsequent())
     {
         s.readChar();
     }
 }
Пример #2
0
 private static bool matchSymbol(Scanner s)
 {
     if (!s.isInitial())
     {
         return(false);
     }
     s.readChar();
     while (s.isSubsequent())
     {
         s.readChar();
     }
     return(true);
 }
Пример #3
0
 private static TokenType?remainingFloat(Scanner s)
 {
     s.readChar(); // Skip the '.'
     while (s.isDigit() || s.isExponent())
     {
         if (s.isExponent())
         {
             return(readExponent(s));
         }
         s.readChar();
     }
     return(TokenType.Double);
 }
Пример #4
0
        // This code is pretty hairy - the problem is
        // distinguishing between:
        // 1. a floating point number, which may be
        // in scientific notification, and might simply begin
        // with "."
        // 2. A symbol with a dot in it
        // 3. Just a lone "." used for separating lists

        // It's doubtful that it's entirely correct - but if you find a bug,
        // add it as a test to ScannerTest and amend this logic.
        private static TokenType?matchNumber(Scanner s)
        {
            if (s.peek() == '.')
            {
                return(leadingFloat(s));
            }

            if (s.isOneOf("+-"))
            {
                s.readChar();
                if (s.peek() == '.')
                {
                    return(leadingFloat(s));
                }
                var num = unsignedNumber(s);
                if (num != null)
                {
                    return(num);
                }

                matchSymbol(s);
                return(TokenType.Symbol);
            }
            return(unsignedNumber(s));
        }
Пример #5
0
 // TODO:
 // WE should implement actual reader macros for this part of things.
 private static TokenType?matchHash(Scanner s)
 {
     if (s.peek() != '#')
     {
         return(null);
     }
     s.readChar();
     if (s.peek() == '(')
     {
         s.readChar();
         return(TokenType.VectorOpen);
     }
     if (s.isOneOf("tfTF"))
     {
         s.readChar();
         return(TokenType.Boolean);
     }
     throw s.fail("Unrecognized token");
 }
Пример #6
0
 // .Net method support.
 // Check if we received a "." or a ".symbol".
 // Given them different tokens so that the parser
 // can expand appropriately.
 private static TokenType?matchDot(Scanner s)
 {
     if (s.peek() != '.')
     {
         return(null);
     }
     s.readChar();
     matchSymbol(s);
     return(s.sb.Length > 1 ? TokenType.Symbol : TokenType.Dot);
 }
Пример #7
0
        private static TokenType?readExponent(Scanner s)
        {
            s.readChar(); // Skip exponent market
            var read = false;

            if (s.isOneOf("+-"))
            {
                s.readChar();
                read = true;
            }
            while (s.isDigit())
            {
                read = true;
                s.readChar();
            }
            if (read)
            {
                return(TokenType.Double);
            }
            // It's not a floating point number in exponent format.
            // Read it as a symbol instead.
            matchSymbol(s);
            return(TokenType.Symbol);
        }
Пример #8
0
 private static TokenType?unsignedNumber(Scanner s)
 {
     if (!s.isDigit())
     {
         return(null);
     }
     while (s.isDigit())
     {
         s.readChar();
     }
     if (s.isExponent())
     {
         return(readExponent(s));
     }
     if (s.peek() != '.')
     {
         return(TokenType.Integer);
     }
     return(remainingFloat(s));
 }
Пример #9
0
 // .Net method support.
 // Check if we received a "." or a ".symbol".
 // Given them different tokens so that the parser
 // can expand appropriately.
 private static TokenType? matchDot(Scanner s)
 {
     if (s.peek() != '.')
         return null;
     s.readChar();
     matchSymbol(s);
     return s.sb.Length > 1 ? TokenType.Symbol : TokenType.Dot;
 }
Пример #10
0
 private static bool matchSymbol(Scanner s)
 {
     if (!s.isInitial())
         return false;
     s.readChar();
     while (s.isSubsequent())
         s.readChar();
     return true;
 }
Пример #11
0
 // TODO:
 // WE should implement actual reader macros for this part of things.
 private static TokenType? matchHash(Scanner s)
 {
     if (s.peek() != '#')
         return null;
     s.readChar();
     if(s.peek() == '(')
     {
         s.readChar();
         return TokenType.VectorOpen;
     }
     if(s.isOneOf("tfTF"))
     {
         s.readChar();
         return TokenType.Boolean;
     }
     throw s.fail("Unrecognized token");
 }
Пример #12
0
        // This code is pretty hairy - the problem is
        // distinguishing between:
        // 1. a floating point number, which may be
        // in scientific notification, and might simply begin
        // with "."
        // 2. A symbol with a dot in it
        // 3. Just a lone "." used for separating lists

        // It's doubtful that it's entirely correct - but if you find a bug,
        // add it as a test to ScannerTest and amend this logic.
        private static TokenType? matchNumber(Scanner s)
        {
            if(s.peek() == '.')
                return leadingFloat(s);

            if(s.isOneOf("+-"))
            {
                s.readChar();
                if(s.peek() == '.')
                    return leadingFloat(s);
                var num = unsignedNumber(s);
                if (num != null)
                    return num;

                matchSymbol(s);
                return TokenType.Symbol;
            }
            return unsignedNumber(s);
        }
Пример #13
0
 private static TokenType? unsignedNumber(Scanner s)
 {
     if (!s.isDigit())
         return null;
     while (s.isDigit())
         s.readChar();
     if (s.isExponent())
         return readExponent(s);
     if (s.peek() != '.')
         return TokenType.Integer;
     return remainingFloat(s);
 }
Пример #14
0
 private static TokenType? remainingFloat(Scanner s)
 {
     s.readChar(); // Skip the '.'
     while (s.isDigit() || s.isExponent())
     {
         if (s.isExponent())
             return readExponent(s);
         s.readChar();
     }
     return TokenType.Double;
 }
Пример #15
0
 private static TokenType? readExponent(Scanner s)
 {
     s.readChar(); // Skip exponent market
     var read = false;
     if (s.isOneOf("+-"))
     {
         s.readChar();
         read = true;
     }
     while (s.isDigit())
     {
         read = true;
         s.readChar();
     }
     if(read)
         return TokenType.Double;
     // It's not a floating point number in exponent format.
     // Read it as a symbol instead.
     matchSymbol(s);
     return TokenType.Symbol;
 }
Пример #16
0
 private static void matchSymbol(Scanner s)
 {
     if (!s.isInitial())
         return;
     s.readChar();
     while (s.isSubsequent())
         s.readChar();
 }