You are here

protected function EasyRdf_Parser_Turtle::parseQuotedLiteral in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php \EasyRdf_Parser_Turtle::parseQuotedLiteral()

Parses a quoted string, optionally followed by a language tag or datatype. @ignore

1 call to EasyRdf_Parser_Turtle::parseQuotedLiteral()
EasyRdf_Parser_Turtle::parseValue in 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

vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php, line 557

Class

EasyRdf_Parser_Turtle
Class to parse Turtle with no external dependancies.

Code

protected function parseQuotedLiteral() {
  $label = $this
    ->parseQuotedString();

  // Check for presence of a language tag or datatype
  $c = $this
    ->peek();
  if ($c == '@') {
    $this
      ->read();

    // Read language
    $lang = '';
    $c = $this
      ->read();
    if ($c == -1) {
      throw new EasyRdf_Parser_Exception("Turtle Parse Error: unexpected end of file while reading language", $this->line, $this->column);
    }
    elseif (!self::isLanguageStartChar($c)) {
      throw new EasyRdf_Parser_Exception("Turtle Parse Error: expected a letter, found '{$c}'", $this->line, $this->column);
    }
    $lang .= $c;
    $c = $this
      ->read();
    while (!self::isWhitespace($c)) {
      if ($c == '.' || $c == ';' || $c == ',' || $c == ')' || $c == ']' || $c == -1) {
        break;
      }
      if (self::isLanguageChar($c)) {
        $lang .= $c;
      }
      else {
        throw new EasyRdf_Parser_Exception("Turtle Parse Error: illegal language tag char: '{$c}'", $this->line, $this->column);
      }
      $c = $this
        ->read();
    }
    $this
      ->unread($c);
    return array(
      'type' => 'literal',
      'value' => $label,
      'lang' => $lang,
    );
  }
  elseif ($c == '^') {
    $this
      ->read();

    // next character should be another '^'
    $this
      ->verifyCharacterOrFail($this
      ->read(), "^");

    // Read datatype
    $datatype = $this
      ->parseValue();
    if ($datatype['type'] == 'uri') {
      return array(
        'type' => 'literal',
        'value' => $label,
        'datatype' => $datatype['value'],
      );
    }
    else {
      throw new EasyRdf_Parser_Exception("Turtle Parse Error: illegal datatype type: " . $datatype['type'], $this->line, $this->column);
    }
  }
  else {
    return array(
      'type' => 'literal',
      'value' => $label,
    );
  }
}