Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
ttc.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2023-03-29 17:09:58 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
56e4e59a9a30d2b6aaf39a68768b8c1064b991a7
56e4e59a
1 parent
8c26f7fc
improved doc generation
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
16 deletions
ttc/_help.py
www/edit.css
www/help.md
ttc/_help.py
View file @
56e4e59
import
io
,
inspect
import
io
,
inspect
,
sys
,
pathlib
,
inspect
,
subprocess
,
re
from
.cpuinfo
import
description
,
parameters
,
extra
,
numdescription
,
regdoc
,
regname
from
.asm
import
stdlib
,
Preprocessor
...
...
@@ -85,11 +85,84 @@ def _prepro () :
if
not
doc
:
continue
usage
,
desc
=
doc
.
split
(
"
\n
"
,
1
)
out
.
write
(
f
"##
%
{usage}
\n\n
{desc}
\n\n
"
)
out
.
write
(
f
"##
`
%
{usage}`
\n\n
{desc}
\n\n
"
)
return
out
.
getvalue
()
.
strip
()
def
_clean_line
(
tex
)
:
for
old
,
new
in
[(
r"\textquotesingle{}"
,
'""'
),
#(r"\#", "#"),
#(r"\%", "%"),
(
r"\ "
,
" "
),
(
"{[}"
,
"["
),
(
"{]}"
,
"]"
),
#(r"\$", "$"),
(
r"\textless\textless{}"
,
r"\texttt{<<}"
),
(
r"\textgreater\textgreater{}"
,
r"\texttt{>>}"
),
(
"
\u27a1\ufe0f
"
,
r"$\mapsto$"
),
(
"
\u25b6\ufe0f
"
,
r"$\rightarrow$"
),
(
r"\texttt"
,
r"\ttcsrc"
),
#("{verbatim}", "{ttcsource}"),
(
r"\section"
,
r"\ttcsection"
),
(
r"\subsection"
,
r"\ttcsubsection"
),
]
:
tex
=
tex
.
replace
(
old
,
new
)
tex
=
re
.
sub
(
r"\\texorpdfstring\{\\ttcsrc\{([^\{\}]*)\}\}\{\1\}"
,
r"\\ttcsrc{\1}"
,
tex
)
return
tex
def
_clean_lines
(
tex
)
:
trim
=
False
for
line
in
tex
.
splitlines
()
:
if
line
.
startswith
(
r"\hypertarget"
)
:
trim
=
True
elif
trim
:
trim
=
False
yield
line
.
split
(
r"\label"
)[
0
]
elif
line
==
r"\tightlist"
:
pass
else
:
yield
line
def
clean_tex
(
tex
)
:
tex
=
"
\n
"
.
join
(
map
(
_clean_line
,
_clean_lines
(
tex
)))
return
tex
if
__name__
==
"__main__"
:
print
(
help
.
format
(
regdoc
=
_regdoc
(),
import
argparse
parser
=
argparse
.
ArgumentParser
(
prog
=
"ttc._help"
,
description
=
"TTC help generator"
)
parser
.
add_argument
(
"-o"
,
dest
=
"output"
,
metavar
=
"PATH"
,
default
=
None
,
type
=
str
,
help
=
"output help to PATH (default: stdout)"
)
parser
.
add_argument
(
"-f"
,
dest
=
"format"
,
metavar
=
"FMT"
,
default
=
None
,
type
=
lambda
s
:
str
(
s
)
.
lower
(),
help
=
"generate doc as FMT (default: 'md')"
)
args
=
parser
.
parse_args
()
if
args
.
format
is
None
:
if
args
.
output
in
(
"-"
,
None
)
:
args
.
format
=
"md"
else
:
args
.
format
=
pathlib
.
Path
(
args
.
output
)
.
suffix
.
lstrip
(
"."
)
.
lower
()
doc
=
help
.
format
(
regdoc
=
_regdoc
(),
instrdoc
=
_instrdoc
(),
stdlib
=
_stdlib
(),
prepro
=
_prepro
())
.
strip
())
prepro
=
_prepro
())
.
strip
()
+
"
\n
"
if
args
.
format
==
"md"
:
pass
elif
args
.
format
==
"tex"
:
doc
=
subprocess
.
check_output
([
"pandoc"
,
"-t"
,
"latex"
],
input
=
doc
,
encoding
=
"utf-8"
)
doc
=
clean_tex
(
doc
)
elif
args
.
format
==
"html"
:
doc
=
subprocess
.
check_output
([
"pandoc"
,
"-t"
,
"html"
],
input
=
doc
,
encoding
=
"utf-8"
)
else
:
parser
.
exit
(
1
,
inspect
.
cleandoc
(
"""unsupported format {args.format!r}
use one of
- md: Markdown
- tex: LaTeX
- html: HTML
"""
)
+
"
\n
"
)
if
args
.
output
in
(
"-"
,
None
)
:
out
=
sys
.
stdout
else
:
out
=
open
(
args
.
output
,
"w"
,
encoding
=
"utf-8"
)
out
.
write
(
doc
)
...
...
www/edit.css
View file @
56e4e59
...
...
@@ -162,6 +162,12 @@ html, body {
margin-top
:
5px
;
}
.help
h2
code
{
background-color
:
#fff
;
border
:
0px
;
padding
:
0px
;
}
.help
ul
{
margin
:
0px
;
padding-left
:
20px
;
...
...
www/help.md
View file @
56e4e59
...
...
@@ -146,11 +146,11 @@
# Preprocessor
##
%alias NAME REPL
##
`%alias NAME REPL`
define
`$NAME`
to be replaced by
`REPL`
for op/macros arguments
##
%def NAME ARG...
##
`%def NAME ARG...`
define a macro
`NAME`
```
...
...
@@ -161,7 +161,7 @@ if necessary
%end
```
##
%ifalias NAME
##
`%ifalias NAME`
insert text if an alias
`NAME`
is defined
```
...
...
@@ -173,7 +173,7 @@ this part is optional
%endif
```
##
%ifdef NAME
##
`%ifdef NAME`
insert text if an op/macro
`NAME`
is defined
```
...
...
@@ -185,7 +185,7 @@ this part is optional
%endif
```
##
%ifnalias NAME
##
`%ifnalias NAME`
insert text if an alias
`NAME`
is not defined
```
...
...
@@ -197,7 +197,7 @@ this part is optional
%endif
```
##
%ifndef NAME
##
`%ifndef NAME`
insert text if an op/macro
`NAME`
is not defined
```
...
...
@@ -209,7 +209,7 @@ this part is optional
%endif
```
##
%ifnnum VALUE
##
`%ifnnum VALUE`
insert text if
`VALUE`
is not a number (or label value)
```
...
...
@@ -221,7 +221,7 @@ this part is optional
%endif
```
##
%ifnreg VALUE
##
`%ifnreg VALUE`
insert text if
`VALUE`
is not a register
```
...
...
@@ -233,7 +233,7 @@ this part is optional
%endif
```
##
%ifnum VALUE
##
`%ifnum VALUE`
insert text if
`VALUE`
is a number (or label value)
```
...
...
@@ -245,7 +245,7 @@ this part is optional
%endif
```
##
%ifreg VALUE
##
`%ifreg VALUE`
insert text if
`VALUE`
is a register
```
...
...
@@ -257,10 +257,10 @@ this part is optional
%endif
```
##
%unalias NAME
##
`%unalias NAME`
undefine previously defined
`$NAME`
##
%undef NAME
##
`%undef NAME`
undefine a macro
`NAME`
...
...
Please
register
or
login
to post a comment