Beispiel #1
0
 /**
  * Parse a string, cleaning up whitespace when we're done
  * @param string $str
  * @param integer $loc
  * @return array A two-item array of the string location where parsing stopped, and the MC_Token instance that matches the grammar conditions
  */
 public function parsePart($str, $loc)
 {
     list($loc, $tok) = $this->_parse($str, $loc);
     $char = $str[$loc++];
     while ($char && MC_Parser::isWhitespace($char)) {
         $char = $str[$loc++];
     }
     --$loc;
     return array($loc, $tok);
 }
 public function _parse($str, $loc)
 {
     if (!$this->caseless) {
         $match = strpos($str, $this->search, $loc);
     } else {
         $match = stripos($str, $this->search, $loc);
     }
     if ($match !== $loc) {
         throw new MC_Parser_ParseError('Expected: ' . $this->search, $str, $loc);
     }
     $loc += strlen($this->search);
     if ($this->fullword && $loc < strlen($str) && !MC_Parser::isWhitespace($str[$loc])) {
         throw new MC_Parser_ParseError('Expected: ' . $this->search, $str, $loc);
     }
     return array($loc, $this->token($this->search));
 }