示例#1
0
 public function testIsWhiteSpace()
 {
     foreach ($this->ws as $c) {
         $this->assertTrue(ScannerHelper::isWhiteSpace($c), $c);
     }
     foreach ($this->ops as $c) {
         $this->assertFalse(ScannerHelper::isWhiteSpace($c), $c);
     }
     foreach ($this->nums as $c) {
         $this->assertFalse(ScannerHelper::isWhiteSpace($c), $c);
     }
     foreach ($this->lowAlpha as $c) {
         $this->assertFalse(ScannerHelper::isWhiteSpace($c), $c);
     }
     foreach ($this->upAlpha as $c) {
         $this->assertFalse(ScannerHelper::isWhiteSpace($c), $c);
     }
 }
示例#2
0
文件: Scanner.php 项目: bgarrels/ebnf
 /**
  * Start the scanning of the next token.
  *
  * This method should be called until {hasNextToken()} returns false.
  *
  * @return void
  */
 public function nextToken()
 {
     if ($this->currentToken > -1 && $this->currentToken < count($this->tokens) - 1) {
         // recover backtracked tokens.
         $this->currentToken++;
         return;
     }
     while ($this->hasNextCharacter()) {
         $this->nextCharacter();
         if (ScannerHelper::isAlpha($this->currentCharacter())) {
             $this->tokens[] = $this->scannIdentifier();
             $this->currentToken++;
             return;
         } else {
             if (ScannerHelper::isQuote($this->currentCharacter())) {
                 $this->tokens[] = $this->scanLiteral();
                 $this->currentToken++;
                 return;
             } else {
                 if (ScannerHelper::isOperator($this->currentCharacter())) {
                     if ("(" === $this->currentCharacter() && "*" === $this->peekCharacter()) {
                         $this->tokens[] = $this->scanComment();
                         $this->currentToken++;
                     } else {
                         $this->tokens[] = $this->scanOperator();
                         $this->currentToken++;
                     }
                     return;
                     // @codingStandardsIgnoreStart
                 } else {
                     if (ScannerHelper::isWhiteSpace($this->currentCharacter())) {
                         // ignore white spaces
                     } else {
                         // @codingStandardsIgnoreEnd
                         $this->raiseError("Invalid character");
                     }
                 }
             }
         }
         $this->checkNewline();
     }
     $this->tokens[] = new Token(Token::EOF, "", $this->createPosition());
     $this->currentToken++;
 }