|
From: <cw...@us...> - 2007-08-12 18:10:09
|
Revision: 494
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=494&view=rev
Author: cweiske
Date: 2007-08-12 11:10:08 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Indent nicely so that you can actually see what the code is meant to be
If anyone of the original authors reads that: Thank you for giving me
so many hours of fun that I needed to indent the code so that
I could begin to understand what it was supposed to do.
Modified Paths:
--------------
trunk/rdfapi-php/api/syntax/N3Parser.php
Modified: trunk/rdfapi-php/api/syntax/N3Parser.php
===================================================================
--- trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 17:43:07 UTC (rev 493)
+++ trunk/rdfapi-php/api/syntax/N3Parser.php 2007-08-12 18:10:08 UTC (rev 494)
@@ -77,6 +77,7 @@
$Univar = '\?'.$Name;
$QName = '(?:[A-Za-z][A-Za-z0-9_@\.]*)?:'.$Name;
$Literal = '"(\\\"|[^"])*"'; # '"(?:\\"|[^"])*"'
+ $Number = '[0-9]+(:?[\\.e][0-9]+)?';
// $Literal = '"[^"\\\\]*(?:\\.\\[^"\\]*)*"'; # '"(?:\\"|[^"])*"'
$LangTag = '@[A-Za-z\-]*[^ \^\.\;\,]';
$Datatype = '(\^\^)[^ ,\.;)]+';
@@ -94,7 +95,7 @@
// $t = array( $LLiteral, $URI); //, $Literal, $PrefixDecl, $QName, $bNode, $Prefix,
// $Univar, 'a', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment);
- $t = array( $Datatype_URI,$Datatype,$LLiteral, $URI, $Literal, $PrefixDecl, $QName, $bNode, $Prefix, $Univar, 'a','=', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment,$LangTag);
+ $t = array( $Datatype_URI,$Datatype,$LLiteral, $URI, $Literal, $PrefixDecl, $QName, $Number, $bNode, $Prefix, $Univar, 'a','=', '{', '}', '\(', '\)', '\[', '\]', ',', ';', '\.', $WS, $Comment,$LangTag);
$this->Tokens = "/(".join($t,"|").")/m";
$this->bNode = 0;
@@ -443,7 +444,7 @@
$res=array();
preg_match_all($this->Tokens, $s, $newres);
$res=$this->array_concat($res, array_map('trim', $newres[0]));
-
+//var_dump($newres[0]);
return $res;
}
@@ -530,88 +531,87 @@
if ($l=='this') $l='<urn:urn-n:this>';
}
- /**
- * Applies stuff :)
- * Expands namespace prefixes etc.
- * @param array $prefixes
- * @param array $list
- * @returns $list
- * @access private
- **/
- function applyStuff($prefixes, $list) {
+ /**
+ * Applies stuff :)
+ * Expands namespace prefixes etc.
+ * @param array $prefixes
+ * @param array $list
+ * @returns $list
+ * @access private
+ **/
+ function applyStuff($prefixes, $list)
+ {
+ array_walk($list, array($this, 'replace_a_type'));
+ array_walk($list, array($this, 'replace_equal'));
+ array_walk($list, array($this, 'replace_this'));
- array_walk($list, array($this, 'replace_a_type'));
- array_walk($list, array($this, 'replace_equal'));
- array_walk($list, array($this, 'replace_this'));
+ for ($i=0; $i<count($list); $i++) {
+ if ($list[$i]=='<>') {
+ if (!isset($path)) {
+ if (!isset($_SERVER['SERVER_ADDR'])) {
+ $_SERVER['SERVER_ADDR'] = 'localhost';
+ }
+ if (!isset($_SERVER['REQUEST_URI'])) {
+ $_SERVER['REQUEST_URI'] = '/rdfapi-php';
+ }
+ $list[$i] = '<http://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'].'#generate_timestamp_'.time().'>';
+ } else {
+ $list[$i] = '<'.$path.'>';
+ };
+ };
- for ($i=0;$i<count($list);$i++) {
- // for i in range(len(list)) {
-// if (!strstr('<_"?.;,{}[]()',$list[$i]{0})) {
+ if ((!strstr('<_"?.;,{}[]()@',$list[$i]{0}))
+ && (substr($list[$i],0,3)!='^^<')
+ ) {
+ $_r = explode(":",$list[$i]);
+ $ns = $_r[0].':';
+ $name = $_r[1];
-// if a <> resource occours, change it to the parsed filename or local URI + timestamp
+ if (isset($prefixes[$ns])) {
+ $list[$i] = '<'.$prefixes[$ns].$name.'>';
+ } else if (isset($prefixes[substr($ns,2)])) {
+ $list[$i] = '^^'.$prefixes[substr($ns,2)].$name.'';
+ } else {
+ #die('Prefix not declared:'.$ns);
+ $this->parseError=true;
+ trigger_error('Prefix not declared: '.$ns, E_USER_ERROR);
+ break;
+ }
- if ($list[$i]=='<>') {
- if (!isset($path)) {
- if (!isset($_SERVER['SERVER_ADDR'])) $_SERVER['SERVER_ADDR']='localhost';
- if (!isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI']='/rdfapi-php';
- $list[$i]='<http://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'].'#generate_timestamp_'.time().'>';
+ } else {
+ if ($list[$i]{0} == '"') { // Congratulations - it's a literal!
+ if (substr($list[$i],0,3) == '"""') {
+ if (substr($list[$i],-3,3) == '"""') { // A big literal...
+ $lit = substr($list[$i],3,-3);
+ // print "++$lit++";
+ $lit=str_replace('\n', '\\n',$lit);
- }else {$list[$i]='<'.$path.'>';};
- };
+ $lit=ereg_replace("[^\\]\"", "\\\"", $lit);
+ $list[$i] = '"'.$lit.'"';
+ } else {
+ die ('Incorrect string formatting: '.substr($list[$i],-3,3));
+ }
+ } else {
+ if (strstr($list[$i],"\n")) {
+ die('Newline in literal: '+$list[$i]);
+ }
+ }
+ }
+ }
- if ((!strstr('<_"?.;,{}[]()@',$list[$i]{0}))AND (substr($list[$i],0,3)!='^^<')) {
- $_r= explode(":",$list[$i]);
+ if (substr($list[$i],0,2)=='^^') {
+ if ($list[$i][2]!='<'){$list[$i]='^^<'.substr($list[$i],2).'>';};
+ };
+ }//foreach list item
+ return $list;
+ }//function applyStuff($prefixes, $list)
- $ns=$_r[0].':';
- $name=$_r[1];
-
- if (isset($prefixes[$ns])) $list[$i] = '<'.$prefixes[$ns].$name.'>';
- else if (isset($prefixes[substr($ns,2)])) $list[$i] = '^^'.$prefixes[substr($ns,2)].$name.'';
- else {
- #die('Prefix not declared:'.$ns);
- $this->parseError=true;
- trigger_error('Prefix not declared: '.$ns, E_USER_ERROR);
- break;
-
-
- }
-
- } else {
- if ($list[$i]{0} == '"') { // Congratulations - it's a literal!
- if (substr($list[$i],0,3) == '"""') {
- if (substr($list[$i],-3,3) == '"""') { // A big literal...
- $lit = substr($list[$i],3,-3);
- // print "++$lit++";
- $lit=str_replace('\n', '\\n',$lit);
-
- $lit=ereg_replace("[^\\]\"", "\\\"", $lit);
-
- $list[$i] = '"'.$lit.'"';
- }
- else { die ('Incorrect string formatting: '.substr($list[$i],-3,3)); }
- } else {
- if (strstr($list[$i],"\n")) die('Newline in literal: '+$list[$i]);
- }
- }
- }
-
- if (substr($list[$i],0,2)=='^^') {
- if ($list[$i][2]!='<'){$list[$i]='^^<'.substr($list[$i],2).'>';};
- };
-
-
- }
-
-
- return $list;
- }
-
/**
* Returns an array of triples extracted from the list of n3 tokens
* @param array $list
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|