Example #1
0
 /**
  * Scans a literal (any character inside single or double quotes.
  *
  * @return Token
  */
 private function scanLiteral()
 {
     $pos = $this->createPosition();
     $start = $this->currentCharacter();
     $str = $start;
     while ($this->hasNextCharacter()) {
         $this->nextCharacter();
         $str .= $this->currentCharacter();
         // Ensure that a lieral opened with " is not temrinated by ' and vice versa.
         if (ScannerHelper::isQuote($this->currentCharacter()) && $this->currentCharacter() === $start) {
             break;
         }
     }
     return new Token(Token::LITERAL, $str, $pos);
 }
Example #2
0
 public function testIsEquals()
 {
     $this->assertTrue(ScannerHelper::isEquals("-", array("-", "_")));
     $this->assertTrue(ScannerHelper::isEquals("_", array("-", "_")));
     $this->assertFalse(ScannerHelper::isEquals("a", array("-", "_")));
 }
Example #3
0
 /**
  * Checks if a passes string is encapsulated in quotes and removes them.
  * Also unescape inside quotes.
  *
  * @param string $str The string to unquote.
  *
  * @return string
  */
 public static function unquoteString($str)
 {
     $start = 0;
     $length = strlen($str) - 1;
     if (ScannerHelper::isQuote($str[$start])) {
         $start++;
     }
     if (ScannerHelper::isQuote($str[$length])) {
         $length--;
     }
     $str = substr($str, $start, $length);
     return stripcslashes($str);
 }