저자: Piotr Olaszewski (piotroo89@gmail.com)
예제 #1
0
 /**
  * @param string $string
  * @return array
  * @throws Exception
  */
 public function lex($string)
 {
     $tokens = array();
     $offset = 0;
     while (isset($string[$offset])) {
         foreach (self::$tokenMap as $regex => $token) {
             if (preg_match($regex, $string, $matches, null, $offset)) {
                 $tokens[] = TokenObject::create($token, trim($matches[0]));
                 $offset += strlen($matches[0]);
                 continue 2;
             }
         }
         throw new Exception(sprintf('Unexpected character: >%s< offset >%d<', $string[$offset], $offset));
     }
     $tokens[] = TokenObject::create(Token::EOF, 'eof');
     return $tokens;
 }
예제 #2
0
 private function checkObjectHasOpenBracket(TokenObject $token)
 {
     $tokenObject = $this->lookAt($this->position - 2);
     if ($tokenObject && Strings::equalsIgnoreCase($tokenObject->getValue(), self::OBJECT_TYPE) && $token->getName() != Token::OPEN_OBJECT) {
         throw new ParserException('Missing open object');
     }
 }