Verified Commit b8062717 authored by Camil Staps's avatar Camil Staps 🚀

Use new single-page HTML documentation

parent 4ac02c92
Pipeline #42121 passed with stages
in 10 minutes
...@@ -3,7 +3,7 @@ definition module Builtin.Predef ...@@ -3,7 +3,7 @@ definition module Builtin.Predef
from Cloogle.DB import :: FunctionEntry, :: ClassEntry, :: TypeDefEntry, from Cloogle.DB import :: FunctionEntry, :: ClassEntry, :: TypeDefEntry,
:: CleanLangReportLocation :: CleanLangReportLocation
CLR :: Int String String -> CleanLangReportLocation CLR :: !String -> CleanLangReportLocation
builtin_functions :: [FunctionEntry] builtin_functions :: [FunctionEntry]
builtin_classes :: [ClassEntry] builtin_classes :: [ClassEntry]
......
...@@ -20,30 +20,27 @@ import Clean.Types ...@@ -20,30 +20,27 @@ import Clean.Types
import Cloogle.API import Cloogle.API
import Cloogle.DB import Cloogle.DB
CLR :: Int String String -> CleanLangReportLocation CLR :: !String -> CleanLangReportLocation
CLR f sec h = CLR sec =
{ clr_version = v { clr_version = "3.0"
, clr_file = "CleanRep." + v + "_" <+ f <+ ".htm"
, clr_section = sec , clr_section = sec
, clr_heading = h
} }
where v = "2.2"
builtin_functions :: [FunctionEntry] builtin_functions :: [FunctionEntry]
builtin_functions = builtin_functions =
[ { zero [ { zero
& fe_loc=Builtin "if" [CLR 5 "3.4.2" "_Toc311798001"] & fe_loc=Builtin "if" [CLR "3.4.2"]
, fe_type=Just $ Func [Type "Bool" [], Var "a", Var "a"] (Var "a") (TypeContext []) , fe_type=Just $ Func [Type "Bool" [], Var "a", Var "a"] (Var "a") (TypeContext [])
} }
, { zero , { zero
& fe_loc=Builtin "dynamic" [CLR 10 "8.1" "_Toc311798076"] & fe_loc=Builtin "dynamic" [CLR "8.1"]
, fe_type=Just $ Func [Var "a"] (Type "Dynamic" []) (TypeContext [Instance "TC" [Var "a"]]) , fe_type=Just $ Func [Var "a"] (Type "Dynamic" []) (TypeContext [Instance "TC" [Var "a"]])
} }
] ]
builtin_classes :: [ClassEntry] builtin_classes :: [ClassEntry]
builtin_classes = builtin_classes =
[ { ce_loc=Builtin "TC" [CLR 10 "8.1.4" "_Toc311798080"] [ { ce_loc=Builtin "TC" [CLR "8.1.4"]
, ce_vars=["v"] , ce_vars=["v"]
, ce_is_meta=False , ce_is_meta=False
, ce_context=TypeContext [] , ce_context=TypeContext []
...@@ -58,24 +55,24 @@ builtin_classes = ...@@ -58,24 +55,24 @@ builtin_classes =
builtin_types :: [TypeDefEntry] builtin_types :: [TypeDefEntry]
builtin_types = builtin_types =
[ { deft [ { deft
& tde_loc=Builtin "Bool" [CLR 6 "4.1" "_Toc311798017"] & tde_loc=Builtin "Bool" [CLR "4.1"]
, tde_typedef.td_name = "Bool" , tde_typedef.td_name = "Bool"
, tde_typedef.td_rhs = TDRCons False , tde_typedef.td_rhs = TDRCons False
[ { defc & cons_name="False" } [ { defc & cons_name="False" }
, { defc & cons_name="True" } , { defc & cons_name="True" }
] ]
} }
, { deft & tde_loc=Builtin "Int" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Int"} , { deft & tde_loc=Builtin "Int" [CLR "4.1"], tde_typedef.td_name = "Int"}
, { deft & tde_loc=Builtin "Real" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Real"} , { deft & tde_loc=Builtin "Real" [CLR "4.1"], tde_typedef.td_name = "Real"}
, { deft & tde_loc=Builtin "Char" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Char"} , { deft & tde_loc=Builtin "Char" [CLR "4.1"], tde_typedef.td_name = "Char"}
, { deft & tde_loc=Builtin "Dynamic" [CLR 10 "8" "_Toc311798077"], tde_typedef.td_name = "Dynamic"} , { deft & tde_loc=Builtin "Dynamic" [CLR "8"], tde_typedef.td_name = "Dynamic"}
, { deft & tde_loc=Builtin "File" [CLR 6 "4.7" "_Toc311798037"], tde_typedef.td_name = "File"} , { deft & tde_loc=Builtin "File" [CLR "4.7"], tde_typedef.td_name = "File"}
, { deft , { deft
& tde_loc=Builtin "String" [CLR 6 "4.7" "_Toc311798037"] & tde_loc=Builtin "String" [CLR "4.7"]
, tde_typedef.td_name = "String" , tde_typedef.td_name = "String"
, tde_typedef.td_rhs = TDRSynonym (Type "_#Array" [Type "Char" []]) } , tde_typedef.td_rhs = TDRSynonym (Type "_#Array" [Type "Char" []]) }
, { deft , { deft
& tde_loc=Builtin "World" [CLR 6 "4.7" "_Toc311798037"], tde_typedef.td_name = "World" & tde_loc=Builtin "World" [CLR "4.7"], tde_typedef.td_name = "World"
, tde_typedef.td_uniq = True , tde_typedef.td_uniq = True
, tde_doc = Just , tde_doc = Just
{ TypeDoc | gDefault{|*|} { TypeDoc | gDefault{|*|}
...@@ -83,7 +80,7 @@ builtin_types = ...@@ -83,7 +80,7 @@ builtin_types =
} }
} }
, { deft , { deft
& tde_loc=Builtin "->" [CLR 6 "4.6" "_Toc311798036"] & tde_loc=Builtin "->" [CLR "4.6"]
, tde_typedef.td_name = "(->)" , tde_typedef.td_name = "(->)"
, tde_typedef.td_args = [Var "a", Var "b"] , tde_typedef.td_args = [Var "a", Var "b"]
, tde_doc = Just , tde_doc = Just
...@@ -132,7 +129,7 @@ where ...@@ -132,7 +129,7 @@ where
make_list :: [Char] [Char] -> TypeDefEntry make_list :: [Char] [Char] -> TypeDefEntry
make_list k s = make_list k s =
{ deft { deft
& tde_loc = Builtin higherorder [CLR 6 "4.2" "_Toc311798019"] & tde_loc = Builtin higherorder [CLR "4.2"]
, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s) , tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)
, tde_typedef.td_args = [Var "a"] , tde_typedef.td_args = [Var "a"]
, tde_doc = Just , tde_doc = Just
...@@ -172,7 +169,7 @@ where ...@@ -172,7 +169,7 @@ where
make_array :: [Char] -> TypeDefEntry make_array :: [Char] -> TypeDefEntry
make_array k = make_array k =
{ deft { deft
& tde_loc = Builtin typec [CLR 6 "4.4" "_Toc311798029"] & tde_loc = Builtin typec [CLR "4.4"]
, tde_typedef.td_name = toString (['_':k] ++ ['Array']) , tde_typedef.td_name = toString (['_':k] ++ ['Array'])
, tde_typedef.td_args = [Var "a"] , tde_typedef.td_args = [Var "a"]
, tde_doc = Just , tde_doc = Just
...@@ -194,7 +191,7 @@ where ...@@ -194,7 +191,7 @@ where
make_tuple :: Int -> TypeDefEntry make_tuple :: Int -> TypeDefEntry
make_tuple n = make_tuple n =
{ deft { deft
& tde_loc = Builtin typec [CLR 6 "4.3" "_Toc311798026"] & tde_loc = Builtin typec [CLR "4.3"]
, tde_typedef.td_name = "_Tuple" <+ n , tde_typedef.td_name = "_Tuple" <+ n
, tde_typedef.td_args = [Var $ toString [v:repeatn (n / 26) '`'] \\ v <- cycle ['a'..'z'] & n <- [0..n-1]] , tde_typedef.td_args = [Var $ toString [v:repeatn (n / 26) '`'] \\ v <- cycle ['a'..'z'] & n <- [0..n-1]]
, tde_doc = Just , tde_doc = Just
......
This diff is collapsed.
Subproject commit bf824ab422841292c9952035588435cf994e6dd0 Subproject commit 399f0baf1f02d0cc89a3f52b5b037e2194aa55f8
...@@ -460,7 +460,7 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag ...@@ -460,7 +460,7 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag
if (i != 0) if (i != 0)
doc += '; '; doc += '; ';
doc += '<a target="_blank" ' + doc += '<a target="_blank" ' +
'href="/doc/#' + loc.clr_file + ';jump=' + loc.clr_heading + '">' + 'href="/doc/#_' + loc.clr_section + '">' +
loc.clr_section + '</a>'; loc.clr_section + '</a>';
} }
doc += '.'; doc += '.';
......
...@@ -26,10 +26,6 @@ curl -Ls https://ftp.cs.ru.nl/Clean/builds/linux-x64/clean-base-linux-x64-latest ...@@ -26,10 +26,6 @@ curl -Ls https://ftp.cs.ru.nl/Clean/builds/linux-x64/clean-base-linux-x64-latest
ln -s ../libs.json ln -s ../libs.json
../util/fetch_libs.sh /opt/clean/lib ../util/fetch_libs.sh /opt/clean/lib
# Temporary fix for /doc
cd /opt/clean/doc
git clone https://gitlab.science.ru.nl/clean-compiler-and-rts/language-report.git CleanLangRep
# Build common problems index # Build common problems index
apt-get install -qq python3 ca-certificates git apt-get install -qq python3 ca-certificates git
git clone https://gitlab.science.ru.nl/cloogle/common-problems /tmp/common-problems git clone https://gitlab.science.ru.nl/cloogle/common-problems /tmp/common-problems
......
@font-face {
/* For the language report on /doc */
font-family: 'courier';
src:
url('fonts/courier.woff2') format('woff2'),
url('fonts/courier.woff') format('woff'),
url('fonts/courier.otf') format('opentype');
font-display: auto;
font-style: normal;
font-weight: 400;
}
body { body {
color: #222; color: #222;
font-family: sans-serif; font-family: sans-serif;
...@@ -143,11 +155,12 @@ a.more-info { ...@@ -143,11 +155,12 @@ a.more-info {
padding-left: .5em; padding-left: .5em;
} }
#sidebar br:last-child, #viewer br:last-child { #sidebar > p:last-child, #viewer > p:last-child {
margin-top: 8em; margin-top: 8em;
} }
#viewer { #viewer {
box-sizing: border-box;
height: 100%; height: 100%;
overflow: auto; overflow: auto;
} }
......
<?php <?php
define('CLEANHOME', '/opt/clean'); define('CLEANHOME', '/opt/clean');
error_reporting(0);
$dom = new DOMDocument;
$dom->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/CleanRep.2.2_1.htm'); $f=fopen (CLEANHOME.'/doc/CleanLanguageReport.html','r');
if (!$f)
function readContentsLevel($dom, $level) { die ('Failed to open language report.');
} $found_table=false;
while (($line=fgets ($f))!==false){
function isToc($class) { if ($found_table){
return preg_match('/^MsoToc\d$/', $class) === 1; echo $line;
} if (substr ($line,0,8)=='</table>')
break;
function cleanToc($name) { } else if (substr ($line,0,6)=='<table'){
$name = preg_replace(['/[\r\x80-\xff]+/', '/\n/'], ['', ' '], $name); echo $line;
$matches = []; $found_table=true;
if (preg_match_all('/^([\d\.]+)?\s*(.+?)\s+[iv\d]+$/', $name, $matches) === 1)
return [
'index' => $matches[1][0],
'title' => preg_replace('/Chapter \d+\s+/', '', $matches[2][0]),
];
else
return null;
}
$toc = [];
foreach ($dom->getElementsByTagName('p') as $p) {
if (isToc($p->getAttribute('class'))) {
$elem = cleanToc($p->textContent);
if ($elem != null) {
$elem['level'] = (int) str_replace('MsoToc', '', $p->getAttribute('class'));
$elem['link'] = str_replace('#', ';jump=', $p->getElementsByTagName('a')[0]->getAttribute('href'));
$toc[] = $elem;
}
}
}
class Toc {
protected $title = '';
protected $link = '';
protected $ref = null;
protected $children = [];
public static function factory($level, $elems) {
$toc = new Toc;
while (count($elems) > 0) {
$elem = array_shift($elems);
if ($elem['level'] <= $level) {
$deeper = [];
while ($elems[0]['level'] > $level)
$deeper[] = array_shift($elems);
$child = Toc::factory($level + 1, $deeper);
$child->title = $elem['title'];
$child->link = $elem['link'];
$toc->children[] = $child;
}
}
return $toc;
}
public function printTree() {
echo '<div class="browser togglee">';
foreach ($this->children as $child) {
if ($child->isLeaf()) {
echo '<div class="browser-item module" id="doc-' . $child->link .
'" data-name="' . $child->link . '">' .
$child->title . '</div>';
} else {
echo '<div class="browser-item directory toggle-container" id="doc-' . $child->link . '">' .
'<span class="toggler">' .
'<span class="toggle-icon">&#x229e;</span>' .
'<span class="title">' . $child->title . '</span></span>';
$child->printTree();
echo '</div>';
}
}
echo '</div>';
}
public function isLeaf() {
return count($this->children) == 0;
} }
} }
$toc = Toc::factory(1, $toc); fclose ($f);
$toc->printTree();
window.onload = function() {
var viewer = document.getElementById('viewer');
var browser = document.getElementsByClassName('browser')[0].browser({
newPath: function (path) {
path = path[0].split(';');
this.state.loc = path[0];
this.state.jump = null;
for (var i = 1; i < path.length; i++)
if (path[i].substring(0,5) == 'jump=')
this.state.jump = path[i].substring(5);
this.newState();
},
newHash: function (hash) {
var hashelems = hash.split(';');
this.state.loc = hashelems[0];
this.state.jump = null;
for (var i = 1; i < hashelems.length; i++)
if (hashelems[i].substring(0,5) == 'jump=')
this.state.jump = hashelems[i].substring(5);
this.newState();
browser.openTo(document.getElementById('doc-' + hash));
},
newState: function () {
var hash = this.state.loc;
if (this.state.jump != null)
hash += ';jump=' + this.state.jump;
document.location.hash = '#' + hash;
},
getUrl: function () {
return 'src.php?loc=' + encodeURIComponent(this.state.loc);
},
viewer: viewer,
onLoad: function(state) {
viewer.innerHTML += '<br/>';
if (state.jump != null) {
browser.scrollTo(document.getElementsByName(state.jump)[0]);
}
},
state: {
jump: false
}
});
browser.open();
browser.triggerChange();
var sidebar = document.getElementById('sidebar');
var viewer = document.getElementById('viewer');
if (window.innerWidth > 800) {
var height = window.innerHeight - 20;
sidebar.style.height = height + 'px';
viewer.style.height = height + 'px';
}
window.onhashchange = function () {
browser.open();
browser.triggerChange();
};
};
...@@ -6,17 +6,14 @@ ...@@ -6,17 +6,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content="Cloogle is a search engine for the Clean programming language"/> <meta name="description" content="Cloogle is a search engine for the Clean programming language"/>
<meta name="keywords" content="Clean,Clean language,Concurrent Clean,search,functions,search engine,programming language,clean platform,iTasks,cloogle,hoogle"/> <meta name="keywords" content="Clean,Clean language,Concurrent Clean,search,functions,search engine,programming language,clean platform,iTasks,cloogle,hoogle"/>
<script src="../common.js" defer="defer"></script>
<script src="../browser.js" defer="defer"></script>
<script src="doc.js" defer="defer"></script>
<link rel="stylesheet" href="../common.css" type="text/css"/> <link rel="stylesheet" href="../common.css" type="text/css"/>
<style> <style>
#viewer { td, th {
padding: 10px; padding-right: unset;
} }
#viewer p { a:visited {
position: relative; /* For images, e.g. in 3.5.2 */ color: blue !important;
} }
#sidebar { #sidebar {
...@@ -33,12 +30,16 @@ ...@@ -33,12 +30,16 @@
margin-left: 0; margin-left: 0;
} }
.Heading1Chapter img, .Newchapter img { #sidebar td {
display: none; white-space: nowrap;
} }
a:visited { #viewer {
color: blue !important; padding: 10px;
}
#viewer > div:first-child {
position: relative;
} }
</style> </style>
</head> </head>
...@@ -49,13 +50,11 @@ ...@@ -49,13 +50,11 @@
<hr/> <hr/>
<?php include_once('contents.php'); ?> <?php include_once('contents.php'); ?>
<hr/> <hr/>
The content of the language report is copyright &copy; 1987-2001, Hilt B.V., The Netherlands. An up to date PDF version of the language report can be found in your <a style="padding-left:0;" href="https://clean.cs.ru.nl/Download_Clean" target="_blank">Clean distribution</a>.
See the <a style="padding-left:0;" href="#CleanRep.2.2_2.htm;jump=_Toc311797972">copyright notice</a>. <p>&nbsp;</p>
<hr/>
Download the language report as a <a style="padding-left:0;" href="http://clean.cs.ru.nl/download/doc/CleanLangRep.2.2.pdf">PDF</a>.
<br/>
</div><div id="viewer"> </div><div id="viewer">
<?php include_once('src.php'); ?> <?php include_once('src.php'); ?>
<p>&nbsp;</p>
</div> </div>
</body> </body>
</html> </html>
...@@ -2,32 +2,22 @@ ...@@ -2,32 +2,22 @@
define('CLEANHOME', '/opt/clean'); define('CLEANHOME', '/opt/clean');
error_reporting(0); error_reporting(0);
$loc = $_REQUEST['loc'] ?: 'CleanRep.2.2_1.htm;jump=_Toc311797959'; $f=fopen (CLEANHOME.'/doc/CleanLanguageReport.html','r');
$loc = preg_replace('/\.\.+/', '.', $loc); if (!$f)
$loc = preg_replace('/[^\w\d.;=]+/', '', $loc); die ('Failed to open language report.');
$match = []; $found_body=false;
$file = preg_match('/(.+);jump=(.+)/', $loc, $match) > 0 ? $file = $match[1] : $loc; while (($line=fgets ($f))!==false){
if ($found_body){
$doc = new DOMDocument; if (substr ($line,0,7)=='</body>'){
$doc->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/' . $file); echo '</div>';
break;
function transformLink($orgfile, $a) { }
$href = $a->getAttribute('href'); echo $line;
if (substr($href, 0, 4) == 'http') { } else if (substr ($line,0,5)=='<body'){
$a->setAttribute('target', '_blank'); echo '<div'.substr ($line,5);
} else { $found_body=true;
$match = [];
if (preg_match('/^(.*)#(.*)$/', $href, $match) == 0)
$a->setAttribute('href', '#' . $href);
$file = $match[1] != '' ? $match[1] : $orgfile;
$hash = $match[2];
$a->setAttribute('href', '#' . $file . ';jump=' . $hash);
} }
} }
foreach ($doc->getElementsByTagName('a') as $a) { fclose ($f);
transformLink($file, $a);
}
echo $doc->saveHtml($doc);
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