Example #1
0
 public function testCreateCannotFindCharException()
 {
     $parserException = new ParserException('source.php', 8, 'Cannot find char : in source.phpml on line 5');
     $exception = ExceptionFactory::createCannotFindChar('source.php', 8, 'source.phpml', 5, ':');
     $this->assertSame($parserException->getFile(), $exception->getFile());
     $this->assertSame($parserException->getLine(), $exception->getLine());
     $this->assertSame($parserException->getMessage(), $exception->getMessage());
     $this->assertInstanceOf('PHPML\\Exception\\ParserException', $exception);
 }
Example #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);
 }