Skip to content

Commit

Permalink
re-add antlr and sparql parser (see OntoWiki issue #123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolland Brunec authored and seebi committed Sep 17, 2012
1 parent 7a658a8 commit c99c327
Show file tree
Hide file tree
Showing 49 changed files with 43,355 additions and 0 deletions.
41 changes: 41 additions & 0 deletions library/Erfurt/Sparql/Parser/ErfurtParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is part of the {@link http://aksw.org/Projects/Erfurt Erfurt} project.
*
* @copyright Copyright (c) 2009, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

/**
* @category Erfurt
* @package Sparql_Parser_Sparql
* @author Rolland Brunec <rollxx@gmail.com>
* @copyright Copyright (c) 2010 {@link http://aksw.org aksw}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

require_once 'Erfurt/Sparql/Parser.php';

class Erfurt_Sparql_Parser_ErfurtParser implements Erfurt_Sparql_Parser_Interface
{

function __construct($parserOptions=array())
{
// TODO pass options?
}

public static function initFromString($queryString, $parserOptions = array()){
require_once 'Erfurt/Sparql/ParserException.php';
$retval=null;
$errors=null;
$parser = new Erfurt_Sparql_Parser($queryString);
try {
$retval = $parser->parse();
} catch (Erfurt_Sparql_ParserException $e) {
$errors = $e->__toString();
}
return array('retval' =>$retval, 'errors'=>$errors);
}

}
28 changes: 28 additions & 0 deletions library/Erfurt/Sparql/Parser/Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* This file is part of the {@link http://aksw.org/Projects/Erfurt Erfurt} project.
*
* @copyright Copyright (c) 2010, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

/**
* @category Erfurt
* @package Sparql_Parser
* @author Rolland Brunec <rollxx@gmail.com>
* @copyright Copyright (c) 2010 {@link http://aksw.org aksw}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
interface Erfurt_Sparql_Parser_Interface
{

/**
* @param string $queryString
* @param array $parserOptions
* @throws Parser Exception, if there was a poblem parsing the query
* @return Returns Erfurt_Sparql_Query2 object
*/
public static function initFromString($queryString, $parserOptions = array());

}
40 changes: 40 additions & 0 deletions library/Erfurt/Sparql/Parser/Rasqal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* This file is part of the {@link http://aksw.org/Projects/Erfurt Erfurt} project.
*
* @copyright Copyright (c) 2010, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

/**
* @category Erfurt
* @package Sparql_Parser_Sparql
* @author Rolland Brunec <rollxx@gmail.com>
* @copyright Copyright (c) 2010 {@link http://aksw.org aksw}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

class Erfurt_Sparql_Parser_Rasqal_Rasqal implements Erfurt_Sparql_Parser_Interface
{
/**
*
*/
protected $_fallback = 'sparql10';

protected $_toString = 'toString';

private $_parserName = null;

private $_lexerName = null;

function __construct($parserOptions=array())
{
}

public function initFromString($queryString, $parserOptions = array()){
}
}


}
43 changes: 43 additions & 0 deletions library/Erfurt/Sparql/Parser/Sparql10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* This file is part of the {@link http://aksw.org/Projects/Erfurt Erfurt} project.
*
* @copyright Copyright (c) 2009, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

/**
* @category Erfurt
* @package Sparql_Parser_Sparql
* @author Rolland Brunec <rollxx@gmail.com>
* @copyright Copyright (c) 2010 {@link http://aksw.org aksw}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/

require_once 'antlr/Php/antlr.php';

class Erfurt_Sparql_Parser_Sparql10 implements Erfurt_Sparql_Parser_Interface
{
public static function initFromString($queryString, $parsePartial = null){
$retval=null;
$input = new Erfurt_Sparql_Parser_Util_CaseInsensitiveStream($queryString);
$lexer = new Erfurt_Sparql_Parser_Sparql10_Sparql10Lexer($input);
// if (!count($lexer->getErrors())) {
$tokens = new CommonTokenStream($lexer);
$parser = new Erfurt_Sparql_Parser_Sparql10_Sparql10Parser($tokens);
if($parsePartial != null && is_string($parsePartial) && method_exists($parser, $parsePartial)){
$retval = call_user_func( array( $parser, $parsePartial ) );
} else {
$retval = $parser->parse();
}
// }
return array('retval' =>$retval, 'errors'=>
//array_merge($lexer->getErrors(),
//$parser?
$parser->getErrors()
//:array())
);
}

}
Loading

0 comments on commit c99c327

Please sign in to comment.