public function testIsOperator() { foreach ($this->ops as $c) { $this->assertTrue(ScannerHelper::isOperator($c), $c); } foreach ($this->nums as $c) { $this->assertFalse(ScannerHelper::isOperator($c), $c); } foreach ($this->lowAlpha as $c) { $this->assertFalse(ScannerHelper::isOperator($c), $c); } foreach ($this->upAlpha as $c) { $this->assertFalse(ScannerHelper::isOperator($c), $c); } foreach ($this->ws as $c) { $this->assertFalse(ScannerHelper::isOperator($c), $c); } }
/** * 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++; }