コード例 #1
0
 /**
  * Assert the next token is of a specified type
  *
  * @param string $token
  * @param boolean $moveNext
  * @return $this
  */
 private function match($token, $moveNext = true)
 {
     $lookaheadType = $this->lexer->lookahead['type'];
     if ($lookaheadType !== $token) {
         $this->syntaxError($this->lexer->getLiteral($token));
     }
     if ($moveNext) {
         $this->lexer->moveNext();
     }
     return $this;
 }
コード例 #2
0
ファイル: LexerTest.php プロジェクト: jaapio/xml-reader
 public function testScannerTokenizesSimpleXPathCorrectly()
 {
     $xpath = '//bookstore/book';
     $lexer = new Lexer($xpath);
     $tokens = [['value' => '//', 'type' => Lexer::T_NODE_SEARCH_SEPARATOR, 'position' => 0], ['value' => 'bookstore', 'type' => Lexer::T_NODE_NAME, 'position' => 2], ['value' => '/', 'type' => Lexer::T_NODESEPARATOR, 'position' => 12], ['value' => 'book', 'type' => Lexer::T_NODE_NAME, 'position' => 13]];
     foreach ($tokens as $expected) {
         $lexer->moveNext();
         $actual = $lexer->lookahead;
         $this->assertEquals($expected['value'], $actual['value']);
         $this->assertEquals($expected['type'], $actual['type']);
         $this->assertEquals($expected['position'], $actual['position']);
     }
     $this->assertFalse($lexer->moveNext());
 }
コード例 #3
0
ファイル: Parser.php プロジェクト: manialib/formatting
 private function getLink()
 {
     $link = '';
     if (substr($this->lexer->lookahead['value'], 1, 1) == '[' && substr($this->lexer->lookahead['value'], -1, 1) == ']') {
         //We are looking for a link like $h[xxx]yyy$h
         $this->lexer->moveNext();
         $matches = array();
         if ($this->lexer->lookahead && preg_match('/^\\[([^\\]]*)\\]$/iu', $this->lexer->lookahead['value'], $matches)) {
             $link = $matches[1];
         }
     } else {
         //We are looking for a link like $hxxxx$h
         $endLinkTokens = array(Lexer::T_EXTERNAL_LINK, Lexer::T_INTERNAL_LINK, Lexer::T_RESET_ALL);
         do {
             $nextLookahead = $this->lexer->peek();
             if ($nextLookahead && ($nextLookahead['type'] == Lexer::T_NONE || $nextLookahead['type'] == Lexer::T_ESCAPED_CHAR)) {
                 $link .= $nextLookahead['value'];
                 if (substr($link, 0, 1) == '[') {
                     //It means that there is no closing square bracket $l[noclosingsquarebracket
                     array_push($this->lookaheadToSkip, $nextLookahead);
                 }
             }
         } while ($nextLookahead !== null && !in_array($nextLookahead['type'], $endLinkTokens));
         if (substr($link, 0, 1) == '[') {
             //It means that there is no closing square bracket $l[noclosingsquarebracket
             $link = '';
         }
     }
     return $link;
 }
コード例 #4
0
 /**
  * Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure,
  * partition, tablespace, and other object names are known as identifiers.
  *
  * @return \TYPO3\CMS\Core\Database\Schema\Parser\AST\Identifier
  * @throws \TYPO3\CMS\Core\Database\Schema\Exception\StatementException
  */
 protected function schemaObjectName()
 {
     $schemaObjectName = $this->lexer->lookahead['value'];
     $this->lexer->moveNext();
     return new AST\Identifier((string) $schemaObjectName);
 }