Commit 1c82d166 authored by Mart Lubbers's avatar Mart Lubbers

version 2.4 all libraries supported

parent 5d2fb42d
sync.sh
stdenv
ArgEnv
Directory
Dynamics
Generics
MersenneTwister
StdEnv
StdLib
TCPIP
......@@ -27,15 +27,17 @@ containing the following fields
- `data`
An array of search results. Every items contains the following fields:
`filename`, `module`, `func` and `distance` representing the filename, the
module name, the matched function signature and the levenshtein distance.
`library`, `filename`, `module`, `func` and `distance` representing the name
of the library, filename, the module name, the matched function signature and
the levenshtein distance.
### Todo
### Todo in order of importance
- Search in not only `StdEnv` but also in `clean-platform` and other libraries
- Search on type definitions
- Search for function signatures
- Maybe search for instances of classes?
- Also grab possible comments above the function signature
- Search also in `clean-platform`
- Search for instances of classes
### Licence
......
......@@ -92,6 +92,7 @@ sform.onsubmit = function(){
for(var i = 0; i<responsedata['data'].length; i++){
var c = responsedata['data'][i];
sresults.innerHTML += '<hr /><table>' +
'<tr><th>Library: </th><td>' + c['library'] + '</td></tr>' +
'<tr><th>Filename: </th><td>' + c['filename'] + '</td></tr>' +
'<tr><th>Module: </th><td>' + c['module'] + '</td>' +
'<td>' + c['distance'] + '</td></tr>' +
......
......@@ -2,38 +2,38 @@
error_reporting(E_ALL);
ini_set('display_errors', '1');
define('STDENV_PATH', './stdenv/');
define('PRE_IDENT', '[\w~@#$%^?!+\-*<>\/|&=:`]+');
define('PRE_MODULE',
"/\s*(?:definition\s*|system\s*|implementation\s*)module\s+(\S+)\s*[\n;]/");
define('PRE_FUNC',
'/^\s*(?:instance|class)?\s*\(?(' . PRE_IDENT . ')\)?\s*(?:infix[lr]?\s+\d\s*)?(?:\s+a\s+)?::.*$/mi');
function search_doc(&$r, $name){
$files = glob(STDENV_PATH . "*.dcl", GLOB_NOSORT | GLOB_MARK);
foreach($files as $filepath) {
if(mb_substr($filepath, -1) !== DIRECTORY_SEPARATOR){
$filename = explode(DIRECTORY_SEPARATOR, $filepath);
$filename = end($filename);
$contents = file_get_contents($filepath);
$module = preg_match(PRE_MODULE, $contents, $modules) == 1 ?
$modules[1] : NULL;
$namelen = strlen($name);
if(preg_match_all(PRE_FUNC, $contents, $funcs) !== false){
for($i=0; $i<count($funcs[1]); $i++){
$funcname = $funcs[1][$i];
$funcsig = $funcs[0][$i];
$score = levenshtein(strtolower($name), $funcname);
if($score < $namelen/2+1){
array_push($r, array(
"filename" => $filename,
"func" => str_replace("\n", "", $funcsig),
"module" => $module,
"distance" => $score));
function search_doc(&$r, $name, $libraries){
foreach($libraries as $library => $librarypath){
$files = glob($librarypath . "*.dcl", GLOB_NOSORT | GLOB_MARK);
foreach($files as $filepath) {
if(mb_substr($filepath, -1) !== DIRECTORY_SEPARATOR){
$filename = end(explode(DIRECTORY_SEPARATOR, $filepath));
$contents = file_get_contents($filepath);
$module = preg_match(PRE_MODULE, $contents, $modules) == 1 ?
$modules[1] : NULL;
if(preg_match_all(PRE_FUNC, $contents, $funcs) !== false){
for($i=0; $i<count($funcs[1]); $i++){
$funcname = $funcs[1][$i];
$funcsig = $funcs[0][$i];
$score = levenshtein(strtolower($name), $funcname);
if($score < strlen($funcname)/2){
array_push($r, array(
"library" => $library,
"filename" => $filename,
"func" => str_replace("\n", "", $funcsig),
"module" => $module,
"distance" => $score));
}
}
}
}
}
}
}
return "Success";
}
......@@ -53,8 +53,18 @@ if($_SERVER['REQUEST_METHOD'] !== 'GET'){
"data" => array(),
"msg" => "GET variable 'str' should be set"));
} else {
$libraries = array(
'ArgEnv' => './ArgEnv/',
'Directory' => './Directory/',
'Dynamics' => './Dynamics/',
'Generics' => './Generics/',
'MersenneTwister' => './MersenneTwister/',
'StdEnv' => './StdEnv/',
'StdLib' => './StdLib/',
'TCPIP' => './TCPIP/');
$res = array();
$msg = search_doc($res, $_GET['str']);
$msg = search_doc($res, $_GET['str'], $libraries);
sort_results($res);
if(!$res){
echo json_encode(array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment