protected function EasyRdf_Parser_Turtle::parseQNameOrBoolean

Parses qnames and boolean values, which have equivalent starting characters. @ignore

1 call to EasyRdf_Parser_Turtle::parseQNameOrBoolean()
EasyRdf_Parser_Turtle::parseValue in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parses an RDF value. This method parses uriref, qname, node ID, quoted literal, integer, double and boolean. @ignore

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php, line 820

Class

EasyRdf_Parser_Turtle
Class to parse Turtle with no external dependancies.

Code

protected function parseQNameOrBoolean() {

  // First character should be a ':' or a letter
  $c = $this
    ->read();
  if ($c == -1) {
    throw new EasyRdf_Exception("Turtle Parse Error: unexpected end of file while readying value");
  }
  if ($c != ':' && !self::isPrefixStartChar($c)) {
    throw new EasyRdf_Exception("Turtle Parse Error: expected a ':' or a letter, found '{$c}'");
  }
  $namespace = null;
  if ($c == ':') {

    // qname using default namespace
    $namespace = $this->namespaces[""];
    if ($namespace == null) {
      throw new EasyRdf_Exception("Turtle Parse Error: default namespace used but not defined");
    }
  }
  else {

    // $c is the first letter of the prefix
    $prefix = $c;
    $c = $this
      ->read();
    while (self::isPrefixChar($c)) {
      $prefix .= $c;
      $c = $this
        ->read();
    }
    if ($c != ':') {

      // prefix may actually be a boolean value
      $value = $prefix;
      if ($value == "true" || $value == "false") {
        return array(
          'type' => 'literal',
          'value' => $value,
          'datatype' => EasyRdf_Namespace::get('xsd') . 'boolean',
        );
      }
    }
    $this
      ->verifyCharacter($c, ":");
    if (isset($this->namespaces[$prefix])) {
      $namespace = $this->namespaces[$prefix];
    }
    else {
      throw new EasyRdf_Exception("Turtle Parse Error: namespace prefix '{$prefix}' used but not defined");
    }
  }

  // $c == ':', read optional local name
  $localName = '';
  $c = $this
    ->read();
  if (self::isNameStartChar($c)) {
    $localName .= $c;
    $c = $this
      ->read();
    while (self::isNameChar($c)) {
      $localName .= $c;
      $c = $this
        ->read();
    }
  }

  // Unread last character
  $this
    ->unread($c);

  // Note: namespace has already been resolved
  return array(
    'type' => 'uri',
    'value' => $namespace . $localName,
  );
}