예제 #1
0
파일: Parser.php 프로젝트: phpml/phpml
 public function __construct(Scanner $scanner)
 {
     $this->scanner = $scanner;
     $this->stack = new \SplStack();
     $this->componentBuilder = new ComponentBuilder($scanner->getFile());
     $this->tree = new Tree();
 }
예제 #2
0
파일: CloseParser.php 프로젝트: phpml/phpml
 public static function parse(Scanner $scanner)
 {
     $file = $scanner->getFile();
     // Must be /
     $char = $file->nextChar();
     // Unexpected char
     if ($char != '/') {
         // 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);
         }
     }
     // Must be >
     $char = $file->nextChar();
     // We have a problem here
     if ($char != '>') {
         // Illegal space
         if ($scanner->isSpace($char)) {
             throw ExceptionFactory::createIllegalSpace(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine());
             // Unexpected EOF
         } elseif ($char === false) {
             throw ExceptionFactory::createUnexpectedEOF(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine());
             // Unexpected char
         } else {
             throw ExceptionFactory::createUnexpectedChar(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine(), $char);
         }
     }
     // Next lookAhead
     $scanner->setLookAhead(Token::T_OPEN_TAG | Token::T_CLOSE_TAG | Token::T_TEXT);
     // T_CLOSE token found
     return new Token(Token::T_CLOSE);
 }
예제 #3
0
파일: EndParser.php 프로젝트: phpml/phpml
 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);
 }
예제 #4
0
파일: ScannerTest.php 프로젝트: phpml/phpml
 public function testNextCharSpaces()
 {
     $scanner = new Scanner(new File(FILES_DIR . 'spaces_file'));
     $this->assertEquals('t', $scanner->nextChar());
     $this->assertEquals('h', $scanner->nextChar());
     $this->assertFalse($scanner->getFile()->isEOF());
     $this->assertFalse($scanner->nextChar());
     $this->assertTrue($scanner->getFile()->isEOF());
     $this->assertFalse($scanner->nextChar());
     $this->assertTrue($scanner->getFile()->isEOF());
 }
예제 #5
0
파일: ValueParser.php 프로젝트: phpml/phpml
 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);
 }
예제 #6
0
 public static function parse(Scanner $scanner)
 {
     $file = $scanner->getFile();
     $char = $file->nextChar();
     $state = 0;
     $value = '';
     while (true) {
         switch ($state) {
             case 0:
                 // T_ATTRIBUTE begins with [a-zA-Z] or _
                 if ($scanner->isLetter($char) || $char == '_') {
                     $state = 1;
                     $value .= $char;
                     $char = $file->nextChar();
                     // 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:
                 // The second char can be [a-zA-Z0-9] or _
                 if ($scanner->isAlpha($char) || $char == '_') {
                     $state = 1;
                     $value .= $char;
                     $char = $file->nextChar();
                     // Space indicates the end of the T_ATTRIBUTE
                     // But we have to eat the next = char
                 } elseif ($scanner->isSpace($char)) {
                     $state = 2;
                     $char = $scanner->nextChar();
                     // If the next char is =, we're done
                 } elseif ($char == '=') {
                     break 2;
                     // 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 2:
                 // If the next char is =, we're done
                 if ($char == '=') {
                     break 2;
                     // 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;
         }
     }
     // Next lookAhead
     $scanner->setLookAhead(Token::T_VALUE);
     // T_ATTRIBUTE token found
     return new SimpleToken(Token::T_ATTRIBUTE, $value);
 }
예제 #7
0
 public static function parse(Scanner $scanner)
 {
     $file = $scanner->getFile();
     $char = $file->nextChar();
     $state = 0;
     $ns = '';
     $name = '';
     while (true) {
         switch ($state) {
             case 0:
                 // Must start with <
                 if ($char == '<') {
                     $state = 1;
                     $char = $file->nextChar();
                     // 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:
                 // The first char after < can be [a-zA-Z] or _
                 if ($scanner->isLetter($char) || $char == '_') {
                     $state = 2;
                     $ns .= $char;
                     $char = $file->nextChar();
                     // 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 2:
                 // From the second char after < onwards can be [a-zA-Z0-9] or _
                 if ($scanner->isAlpha($char) || $char == '_') {
                     $state = 2;
                     $ns .= $char;
                     $char = $file->nextChar();
                     // If the next char is :, we already have the namespace
                 } elseif ($char == ':') {
                     $state = 3;
                     $char = $file->nextChar();
                     // 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 3:
                 // The first char after : can be [a-zA-Z] or _
                 if ($scanner->isLetter($char) || $char == '_') {
                     $state = 4;
                     $name .= $char;
                     $char = $file->nextChar();
                     // Exception
                 } else {
                     // Unexpected EOF
                     if ($char == false) {
                         throw ExceptionFactory::createUnexpectedEOF(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine());
                         // Illegal space after :
                     } elseif ($scanner->isSpace($char)) {
                         throw ExceptionFactory::createIllegalSpace(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine());
                         // Unexpected Char
                     } else {
                         throw ExceptionFactory::createUnexpectedChar(__FILE__, __LINE__, $file->getFileName(), $file->getCurrentLine(), $char);
                     }
                 }
                 break;
             case 4:
                 // From the second char after : onwards can be [a-zA-Z0-9] or _
                 if ($scanner->isAlpha($char) || $char == '_') {
                     $state = 4;
                     $name .= $char;
                     $char = $file->nextChar();
                     // If the next char is \s, we got the name
                 } elseif ($scanner->isSpace($char)) {
                     break 2;
                     // If the next char is >, we got the T_END
                 } elseif ($char == '>') {
                     $file->goBack();
                     break 2;
                     // 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;
         }
     }
     // Next lookAhead
     $scanner->setLookAhead(Token::T_ATTRIBUTE | Token::T_END | Token::T_CLOSE);
     // T_REGISTER
     if ($ns == 'php' && $name == 'Register') {
         return new TagToken(Token::T_REGISTER, $ns, $name);
     }
     // T_OPEN_TAG token found
     return new TagToken(Token::T_OPEN_TAG, $ns, $name);
 }