Example #1
0
 /**
  * This method return a tuple representing the token discovered.
  *
  * @access public
  * @param \Unicity\IO\Reader $reader                        the reader to be used
  * @return \Unicity\Lexer\Scanner\Tuple                     a tuple representing the token
  *                                                          discovered
  */
 public function process(IO\Reader $reader)
 {
     $index = $reader->position();
     $char = $reader->readChar($index, false);
     if ($char !== null && $char >= '0' && $char <= '9') {
         // "integer" token, "real" token, or "hexadecimal" token
         $type = null;
         $lookahead = $index;
         if ($char == '0') {
             $lookahead++;
             $next = $reader->readChar($lookahead, false);
             if ($next == 'x' or $next == 'X') {
                 do {
                     $lookahead++;
                     $next = $reader->readChar($lookahead, false);
                 } while ($next !== null && $next >= '0' && $next <= '9');
                 $type = Lexer\Scanner\TokenType::hexadecimal();
             } else {
                 if ($next == '.') {
                     do {
                         $lookahead++;
                         $next = $reader->readChar($lookahead, false);
                     } while ($next !== null && $next >= '0' && $next <= '9');
                     $type = Lexer\Scanner\TokenType::real();
                 } else {
                     $type = Lexer\Scanner\TokenType::integer();
                 }
             }
         } else {
             $next = null;
             do {
                 $lookahead++;
                 $next = $reader->readChar($lookahead, false);
             } while ($next !== null && $next >= '0' && $next <= '9');
             if ($next == '.') {
                 do {
                     $lookahead++;
                     $next = $reader->readChar($lookahead, false);
                 } while ($next !== null && $next >= '0' && $next <= '9');
                 $type = Lexer\Scanner\TokenType::real();
             } else {
                 $type = Lexer\Scanner\TokenType::integer();
             }
         }
         $token = $reader->readRange($index, $lookahead);
         $tuple = new Lexer\Scanner\Tuple($type, new Common\String($token));
         return $tuple;
     }
     return null;
 }