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
from Cloogle.DB import :: FunctionEntry, :: ClassEntry, :: TypeDefEntry,
:: CleanLangReportLocation
CLR :: Int String String -> CleanLangReportLocation
CLR :: !String -> CleanLangReportLocation
builtin_functions :: [FunctionEntry]
builtin_classes :: [ClassEntry]
......
......@@ -20,30 +20,27 @@ import Clean.Types
import Cloogle.API
import Cloogle.DB
CLR :: Int String String -> CleanLangReportLocation
CLR f sec h =
{ clr_version = v
, clr_file = "CleanRep." + v + "_" <+ f <+ ".htm"
CLR :: !String -> CleanLangReportLocation
CLR sec =
{ clr_version = "3.0"
, clr_section = sec
, clr_heading = h
}
where v = "2.2"
builtin_functions :: [FunctionEntry]
builtin_functions =
[ { 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 [])
}
, { 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"]])
}
]
builtin_classes :: [ClassEntry]
builtin_classes =
[ { ce_loc=Builtin "TC" [CLR 10 "8.1.4" "_Toc311798080"]
[ { ce_loc=Builtin "TC" [CLR "8.1.4"]
, ce_vars=["v"]
, ce_is_meta=False
, ce_context=TypeContext []
......@@ -58,24 +55,24 @@ builtin_classes =
builtin_types :: [TypeDefEntry]
builtin_types =
[ { 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_rhs = TDRCons False
[ { defc & cons_name="False" }
, { defc & cons_name="True" }
]
}
, { deft & tde_loc=Builtin "Int" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Int"}
, { deft & tde_loc=Builtin "Real" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Real"}
, { deft & tde_loc=Builtin "Char" [CLR 6 "4.1" "_Toc311798017"], tde_typedef.td_name = "Char"}
, { deft & tde_loc=Builtin "Dynamic" [CLR 10 "8" "_Toc311798077"], tde_typedef.td_name = "Dynamic"}
, { deft & tde_loc=Builtin "File" [CLR 6 "4.7" "_Toc311798037"], tde_typedef.td_name = "File"}
, { deft & tde_loc=Builtin "Int" [CLR "4.1"], tde_typedef.td_name = "Int"}
, { deft & tde_loc=Builtin "Real" [CLR "4.1"], tde_typedef.td_name = "Real"}
, { deft & tde_loc=Builtin "Char" [CLR "4.1"], tde_typedef.td_name = "Char"}
, { deft & tde_loc=Builtin "Dynamic" [CLR "8"], tde_typedef.td_name = "Dynamic"}
, { deft & tde_loc=Builtin "File" [CLR "4.7"], tde_typedef.td_name = "File"}
, { 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_rhs = TDRSynonym (Type "_#Array" [Type "Char" []]) }
, { 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_doc = Just
{ TypeDoc | gDefault{|*|}
......@@ -83,7 +80,7 @@ builtin_types =
}
}
, { deft
& tde_loc=Builtin "->" [CLR 6 "4.6" "_Toc311798036"]
& tde_loc=Builtin "->" [CLR "4.6"]
, tde_typedef.td_name = "(->)"
, tde_typedef.td_args = [Var "a", Var "b"]
, tde_doc = Just
......@@ -132,7 +129,7 @@ where
make_list :: [Char] [Char] -> TypeDefEntry
make_list k s =
{ 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_args = [Var "a"]
, tde_doc = Just
......@@ -172,7 +169,7 @@ where
make_array :: [Char] -> TypeDefEntry
make_array k =
{ 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_args = [Var "a"]
, tde_doc = Just
......@@ -194,7 +191,7 @@ where
make_tuple :: Int -> TypeDefEntry
make_tuple n =
{ 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_args = [Var $ toString [v:repeatn (n / 26) '`'] \\ v <- cycle ['a'..'z'] & n <- [0..n-1]]
, 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
if (i != 0)
doc += '; ';
doc += '<a target="_blank" ' +
'href="/doc/#' + loc.clr_file + ';jump=' + loc.clr_heading + '">' +
'href="/doc/#_' + loc.clr_section + '">' +
loc.clr_section + '</a>';
}
doc += '.';
......
......@@ -26,10 +26,6 @@ curl -Ls https://ftp.cs.ru.nl/Clean/builds/linux-x64/clean-base-linux-x64-latest
ln -s ../libs.json
../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
apt-get install -qq python3 ca-certificates git
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 {
color: #222;
font-family: sans-serif;
......@@ -143,11 +155,12 @@ a.more-info {
padding-left: .5em;
}
#sidebar br:last-child, #viewer br:last-child {
#sidebar > p:last-child, #viewer > p:last-child {
margin-top: 8em;
}
#viewer {
box-sizing: border-box;
height: 100%;
overflow: auto;
}
......
<?php
define('CLEANHOME', '/opt/clean');
$dom = new DOMDocument;
$dom->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/CleanRep.2.2_1.htm');
function readContentsLevel($dom, $level) {
}
function isToc($class) {
return preg_match('/^MsoToc\d$/', $class) === 1;
}
function cleanToc($name) {
$name = preg_replace(['/[\r\x80-\xff]+/', '/\n/'], ['', ' '], $name);
$matches = [];
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;
error_reporting(0);
$f=fopen (CLEANHOME.'/doc/CleanLanguageReport.html','r');
if (!$f)
die ('Failed to open language report.');
$found_table=false;
while (($line=fgets ($f))!==false){
if ($found_table){
echo $line;
if (substr ($line,0,8)=='</table>')
break;
} else if (substr ($line,0,6)=='<table'){
echo $line;
$found_table=true;
}
}
$toc = Toc::factory(1, $toc);
$toc->printTree();
fclose ($f);
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 @@
<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="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"/>
<style>
#viewer {
padding: 10px;
td, th {
padding-right: unset;
}
#viewer p {
position: relative; /* For images, e.g. in 3.5.2 */
a:visited {
color: blue !important;
}
#sidebar {
......@@ -33,12 +30,16 @@
margin-left: 0;
}
.Heading1Chapter img, .Newchapter img {
display: none;
#sidebar td {
white-space: nowrap;
}
a:visited {
color: blue !important;
#viewer {
padding: 10px;
}
#viewer > div:first-child {
position: relative;
}
</style>
</head>
......@@ -49,13 +50,11 @@
<hr/>
<?php include_once('contents.php'); ?>
<hr/>
The content of the language report is copyright &copy; 1987-2001, Hilt B.V., The Netherlands.
See the <a style="padding-left:0;" href="#CleanRep.2.2_2.htm;jump=_Toc311797972">copyright notice</a>.
<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/>
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>.
<p>&nbsp;</p>
</div><div id="viewer">
<?php include_once('src.php'); ?>
<p>&nbsp;</p>
</div>
</body>
</html>
......@@ -2,32 +2,22 @@
define('CLEANHOME', '/opt/clean');
error_reporting(0);
$loc = $_REQUEST['loc'] ?: 'CleanRep.2.2_1.htm;jump=_Toc311797959';
$loc = preg_replace('/\.\.+/', '.', $loc);
$loc = preg_replace('/[^\w\d.;=]+/', '', $loc);
$f=fopen (CLEANHOME.'/doc/CleanLanguageReport.html','r');
if (!$f)
die ('Failed to open language report.');
$match = [];
$file = preg_match('/(.+);jump=(.+)/', $loc, $match) > 0 ? $file = $match[1] : $loc;
$doc = new DOMDocument;
$doc->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/' . $file);
function transformLink($orgfile, $a) {
$href = $a->getAttribute('href');
if (substr($href, 0, 4) == 'http') {
$a->setAttribute('target', '_blank');
} else {
$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);
$found_body=false;
while (($line=fgets ($f))!==false){
if ($found_body){
if (substr ($line,0,7)=='</body>'){
echo '</div>';
break;
}
echo $line;
} else if (substr ($line,0,5)=='<body'){
echo '<div'.substr ($line,5);
$found_body=true;
}
}
foreach ($doc->getElementsByTagName('a') as $a) {
transformLink($file, $a);
}
echo $doc->saveHtml($doc);
fclose ($f);
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