protected function EasyRdf_Parser_Turtle::parseCollection

Parses a collection [16], e.g: ( item1 item2 item3 ) @ignore

2 calls to EasyRdf_Parser_Turtle::parseCollection()
EasyRdf_Parser_Turtle::parseObject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parse a object [12] @ignore
EasyRdf_Parser_Turtle::parseSubject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parse a subject [10] @ignore

File

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

Class

EasyRdf_Parser_Turtle
Class to parse Turtle with no external dependancies.

Code

protected function parseCollection() {
  $this
    ->verifyCharacter($this
    ->read(), "(");
  $c = $this
    ->skipWSC();
  if ($c == ')') {

    // Empty list
    $this
      ->read();
    return array(
      'type' => 'uri',
      'value' => EasyRdf_Namespace::get('rdf') . 'nil',
    );
  }
  else {
    $listRoot = array(
      'type' => 'bnode',
      'value' => $this->graph
        ->newBNodeId(),
    );

    // Remember current subject and predicate
    $oldSubject = $this->subject;
    $oldPredicate = $this->predicate;

    // generated bNode becomes subject, predicate becomes rdf:first
    $this->subject = $listRoot;
    $this->predicate = array(
      'type' => 'uri',
      'value' => EasyRdf_Namespace::get('rdf') . 'first',
    );
    $this
      ->parseObject();
    $bNode = $listRoot;
    while ($this
      ->skipWSC() != ')') {

      // Create another list node and link it to the previous
      $newNode = array(
        'type' => 'bnode',
        'value' => $this->graph
          ->newBNodeId(),
      );
      $this
        ->addTriple($bNode['value'], EasyRdf_Namespace::get('rdf') . 'rest', $newNode);

      // New node becomes the current
      $this->subject = $bNode = $newNode;
      $this
        ->parseObject();
    }

    // Skip ')'
    $this
      ->read();

    // Close the list
    $this
      ->addTriple($bNode['value'], EasyRdf_Namespace::get('rdf') . 'rest', array(
      'type' => 'uri',
      'value' => EasyRdf_Namespace::get('rdf') . 'nil',
    ));

    // Restore previous subject and predicate
    $this->subject = $oldSubject;
    $this->predicate = $oldPredicate;
    return $listRoot;
  }
}