function parse($q, $src = '', $iso_fallback = 'ignore')
{
$this->setDefaultPrefixes();
$this->base = $src ? $this->calcBase($src) : ARC2::getRequestURI();
$this->r = array('base' => '', 'vars' => array(), 'prefixes' => array());
$this->unparsed_code = $q;
list($r, $v) = $this->xQuery($q);
if ($r) {
$this->r['query'] = $r;
$this->unparsed_code = trim($v);
} elseif (!$this->getErrors() && !$this->unparsed_code) {
$this->addError('Query not properly closed');
}
$this->r['prefixes'] = $this->prefixes;
$this->r['base'] = $this->base;
/* remove trailing comments */
while (preg_match('/^\\s*(\\#[^\\xd\\xa]*)(.*)$/si', $this->unparsed_code, $m)) {
$this->unparsed_code = $m[2];
}
if ($this->unparsed_code && !$this->getErrors()) {
$rest = preg_replace('/[\\x0a|\\x0d]/i', ' ', substr($this->unparsed_code, 0, 30));
$msg = trim($rest) ? 'Could not properly handle "' . $rest . '"' : 'Syntax error, probably an incomplete pattern';
$this->addError($msg);
}
}