Exemplo n.º 1
0
 public function testForwarding()
 {
     $scanner = new Scanner(new File(FILES_DIR . 'not_empty_file'));
     $scanner->getFile()->nextChar();
     $this->assertEquals('ot', $scanner->forward(2));
     $scanner->getFile()->nextChar();
     $this->assertEquals('empty_file', $scanner->forward(20));
 }
Exemplo n.º 2
0
 public static function parse(Scanner $scanner)
 {
     $file = $scanner->getFile();
     $char = $file->nextChar();
     $state = 0;
     $value = '';
     $pos = 0;
     while (true) {
         switch ($state) {
             case 0:
                 // Ex: "value"
                 if ($char == '"') {
                     $state = 1;
                     $pos = $file->find('"');
                     // Ex: 'value'
                 } elseif ($char == "'") {
                     $state = 2;
                     $pos = $file->find("'");
                     // Exception
                 } else {
                     // Unexpected EOF
                     if ($char == false) {
                         throw ExceptionFactory::createUnexpectedEOF(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine());
                         // Unexpected Char
                     } else {
                         throw ExceptionFactory::createUnexpectedChar(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine(), $char);
                     }
                 }
                 break;
             case 1:
                 // Char " not found
                 if ($pos === false) {
                     throw ExceptionFactory::createCannotFindChar(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine(), '"');
                 }
                 // Get the value
                 $value .= $scanner->forward($pos);
                 // Bypass "
                 $scanner->forward(1);
                 break 2;
             case 2:
                 // Char ' not found
                 if ($pos === false) {
                     throw ExceptionFactory::createCannotFindChar(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine(), "'");
                 }
                 // Get the value
                 $value .= $scanner->forward($pos);
                 // Bypass '
                 $scanner->forward(1);
                 break 2;
         }
     }
     // Next lookAhead
     $scanner->setLookAhead(Token::T_ATTRIBUTE | Token::T_END | Token::T_CLOSE);
     // T_VALUE token found
     return new SimpleToken(Token::T_VALUE, $value);
 }
Exemplo n.º 3
0
 public static function parse(Scanner $scanner)
 {
     // We eat the character >
     $scanner->forward(1);
     // Next lookAhead
     $scanner->setLookAhead(Token::T_OPEN_TAG | Token::T_CLOSE_TAG | Token::T_TEXT);
     // T_END token found
     return new Token(Token::T_END);
 }