summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair Armstrong2020-09-30 13:15:21 +0100
committerGitHub2020-09-30 13:15:21 +0100
commit36cd0d8a7a146f8d51ef920212be768428680dac (patch)
tree7e5225b6f819d44de504c65fc91f046959e0ecea
parent1609552d3ff34bd887755c163eb27eb98b72837f (diff)
parent38341beb186e5ac871d0e3446e5a98a25a806667 (diff)
Merge pull request #100 from arichardson/add-more-latex-tests-and-fix-escaping
Add more latex tests and fix underscore escaping
-rw-r--r--src/latex.ml11
-rw-r--r--test/latex/candperm.commands.tex.exp27
-rw-r--r--test/latex/main.tex44
-rw-r--r--test/latex/reference-type.commands.tex.exp54
-rw-r--r--test/latex/reference-type.sail27
-rwxr-xr-xtest/latex/run_tests.sh17
6 files changed, 163 insertions, 17 deletions
diff --git a/src/latex.ml b/src/latex.ml
index c2c61078..9cb0b4d8 100644
--- a/src/latex.ml
+++ b/src/latex.ml
@@ -242,7 +242,7 @@ let latex_of_markdown str =
| Paragraph elems ->
let prepend = if state.noindent then (state.noindent <- false; "\\noindent ") else "" in
prepend ^ format elems ^ "\n\n"
- | Text str -> Str.global_replace (Str.regexp_string "_") "\\_" str
+ | Text str -> text_code str
| Emph elems -> sprintf "\\emph{%s}" (format elems)
| Bold elems -> sprintf "\\textbf{%s}" (format elems)
| Ref (r, "THIS", alt, _) ->
@@ -441,7 +441,12 @@ let tdef_id = function
let defs { defs; _ } =
reset_state state;
- let preamble = string "\\providecommand\\saildoclabelled[2]{\\phantomsection\\label{#1}#2}" ^^ twice hardline in
+ let preamble = string ("\\providecommand\\saildoclabelled[2]{\\phantomsection\\label{#1}#2}\n" ^
+ "\\providecommand\\saildocval[2]{#1 #2}\n" ^
+ "\\providecommand\\saildocfcl[2]{#1 #2}\n" ^
+ "\\providecommand\\saildoctype[2]{#1 #2}\n" ^
+ "\\providecommand\\saildocfn[2]{#1 #2}\n" ^
+ "\\providecommand\\saildocoverload[2]{#1 #2}\n\n") in
let overload_counter = ref 0 in
@@ -501,7 +506,7 @@ let defs { defs; _ } =
identifiers then outputs the correct mangled command. *)
let id_command cat ids =
sprintf "\\newcommand{\\%s%s}[1]{\n " !opt_prefix (category_name cat)
- ^ Util.string_of_list "%\n " (fun id -> sprintf "\\ifstrequal{#1}{%s}{\\%s}{}" (string_of_id id) (latex_cat_id cat id))
+ ^ Util.string_of_list "%\n " (fun id -> sprintf "\\ifstrequal{#1}{%s}{\\%s}{}" (text_code (string_of_id id)) (latex_cat_id cat id))
(IdSet.elements ids)
^ "}"
|> string
diff --git a/test/latex/candperm.commands.tex.exp b/test/latex/candperm.commands.tex.exp
index 14153396..0ba8e659 100644
--- a/test/latex/candperm.commands.tex.exp
+++ b/test/latex/candperm.commands.tex.exp
@@ -1,19 +1,24 @@
\providecommand\saildoclabelled[2]{\phantomsection\label{#1}#2}
+\providecommand\saildocval[2]{#1 #2}
+\providecommand\saildocfcl[2]{#1 #2}
+\providecommand\saildoctype[2]{#1 #2}
+\providecommand\saildocfn[2]{#1 #2}
+\providecommand\saildocoverload[2]{#1 #2}
-\newcommand{\sailtypeast}{\saildoclabelled{typezast}{\saildoctype{}{\lstinputlisting[language=sail]{out/typezast6bb070d12e82e4887160cdfd016230c8.tex}}}}
+\newcommand{\sailtypeast}{\saildoclabelled{sailtypezast}{\saildoctype{}{\lstinputlisting[language=sail]{out/typezast6bb070d12e82e4887160cdfd016230c8.tex}}}}
-\newcommand{\sailvalexecute}{\saildoclabelled{zexecute}{\saildocval{}{\lstinputlisting[language=sail]{out/valzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
+\newcommand{\sailvalexecute}{\saildoclabelled{sailzexecute}{\saildocval{}{\lstinputlisting[language=sail]{out/valzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
-\newcommand{\sailfclCAndPermBrokenexecute}{\saildoclabelled{fclCAndPermBrokenzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+\newcommand{\sailfclCAndPermBrokenexecute}{\saildoclabelled{sailfclCAndPermBrokenzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
its previous value and bits 0 .. 10 of integer register \emph{rs2}
and the \cuperms{} field set to the bitwise and of its previous value
-and bits \hyperref\hyperref[ztablezGpseudocodezDconstants]{\lstinline{table:pseudocode-constants}}{\emph{first\_uperm}} ..
-\hyperref\hyperref[ztablezGpseudocodezDconstants]{\lstinline{table:pseudocode-constants}}{\emph{last\_uperm}} of \emph{rd}.
+and bits \hyperref\hyperref[sailztablezGpseudocodezDconstants]{\lstinline{table:pseudocode-constants}}{\emph{first\_uperm}} ..
+\hyperref\hyperref[sailztablezGpseudocodezDconstants]{\lstinline{table:pseudocode-constants}}{\emph{last\_uperm}} of \emph{rd}.
}{\lstinputlisting[language=sail]{out/fclCAndPermBrokenzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
-\newcommand{\sailfclCAndPermEscapedexecute}{\saildoclabelled{fclCAndPermEscapedzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+\newcommand{\sailfclCAndPermEscapedexecute}{\saildoclabelled{sailfclCAndPermEscapedzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
its previous value and bits 0 .. 10 of integer register \emph{rs2}
and the \cuperms{} field set to the bitwise and of its previous value
@@ -22,7 +27,7 @@ and bits \hyperref[table:pseudocode-constants]{\emph{first\_uperm}} ..
}{\lstinputlisting[language=sail]{out/fclCAndPermEscapedzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
-\newcommand{\sailfclCAndPermMarkdownexecute}{\saildoclabelled{fclCAndPermMarkdownzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+\newcommand{\sailfclCAndPermMarkdownexecute}{\saildoclabelled{sailfclCAndPermMarkdownzexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
its previous value and bits 0 .. 10 of integer register \emph{rs2}
and the \cuperms{} field set to the bitwise and of its previous value
@@ -31,7 +36,7 @@ and bits \hyperref[table:pseudocode-constants]{*first_uperm*} ..
}{\lstinputlisting[language=sail]{out/fclCAndPermMarkdownzexecute33a689e3a631b9b905b85461d3814943.tex}}}}
-\newcommand{\sailfclCAndPermMarkdownWithRefMacroexecute}{\saildoclabelled{fclCAndPermMarkdownWithRefMacrozexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+\newcommand{\sailfclCAndPermMarkdownWithRefMacroexecute}{\saildoclabelled{sailfclCAndPermMarkdownWithRefMacrozexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
its previous value and bits 0 .. 10 of integer register \emph{rs2}
and the \cuperms{} field set to the bitwise and of its previous value
@@ -39,7 +44,7 @@ and bits \firstUPerm{} .. \lastUPerm{} of \emph{rd}.
}{\lstinputlisting[language=sail]{out/fclCAndPermMarkdownWithRefMacrozexecute33a689e3a631b9b905b85461d3814943.tex}}}}
-\newcommand{\sailfclCAndPermMarkdownWithExceptionsexecute}{\saildoclabelled{fclCAndPermMarkdownWithExceptionszexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
+\newcommand{\sailfclCAndPermMarkdownWithExceptionsexecute}{\saildoclabelled{sailfclCAndPermMarkdownWithExceptionszexecute}{\saildocfcl{Capability register \emph{cd} is replaced with the contents of capability
register \emph{cs1} with the \cperms{} field set to the bitwise-AND of
its previous value and bits 0 .. 10 of integer register \emph{rs2}
and the \cuperms{} field set to the bitwise and of its previous value
@@ -60,7 +65,7 @@ An exception is raised if:
\ifstrequal{#1}{execute}{\sailvalexecute}{}}
\newcommand{\sailrefval}[2]{
- \ifstrequal{#1}{execute}{\hyperref[zexecute]{#2}}{}}
+ \ifstrequal{#1}{execute}{\hyperref[sailzexecute]{#2}}{}}
\newcommand{\sailfn}[1]{
}
@@ -72,4 +77,4 @@ An exception is raised if:
\ifstrequal{#1}{ast}{\sailtypeast}{}}
\newcommand{\sailreftype}[2]{
- \ifstrequal{#1}{ast}{\hyperref[typezast]{#2}}{}}
+ \ifstrequal{#1}{ast}{\hyperref[sailtypezast]{#2}}{}}
diff --git a/test/latex/main.tex b/test/latex/main.tex
new file mode 100644
index 00000000..a0948482
--- /dev/null
+++ b/test/latex/main.tex
@@ -0,0 +1,44 @@
+\documentclass{article}
+\usepackage{etoolbox}
+\usepackage{hyperref}
+\usepackage{xcolor}
+\usepackage{listings}
+\lstdefinelanguage{sail}
+ { morekeywords={val,function,mapping,cast,type,forall,overload,operator,enum,union,undefined,exit,and,assert,sizeof,
+ scattered,register,inc,dec,if,then,else,effect,let,as,@,in,end,Type,Int,Order,match,clause,struct,
+ foreach,from,to,by,infix,infixl,infixr,bitfield,default,try,catch,throw,constraint},
+ keywordstyle={\bf\ttfamily\color{blue}},
+ morestring=[b]",
+ stringstyle={\ttfamily\color{red}},
+ morecomment=[l][\itshape\color{DarkGreen}]{//},
+ morecomment=[s][\itshape\color{DarkGreen}]{/*}{*/},
+ deletestring=[bd]{'},
+ escapechar=\#,
+ emphstyle={\it},
+ literate=
+ {\{|}{{$\{|$}}1
+ {|\}}{{$|\}$}}1
+ }
+
+\input{out/commands.tex}
+\begin{document}
+
+\clearpage
+type: \sailtype{cap\_uperms\_width}
+
+\clearpage
+ref type: \sailreftype{cap\_uperms\_width}{ref to cap\_uperms\_width}
+
+\clearpage
+val: \sailval{main}
+
+\clearpage
+refval: \sailrefval{main}{ref to main}
+
+\clearpage
+\sailfn{main}
+
+\clearpage
+reffn: \sailreffn{main}{ref to main}
+
+\end{document}
diff --git a/test/latex/reference-type.commands.tex.exp b/test/latex/reference-type.commands.tex.exp
new file mode 100644
index 00000000..3c8c80ab
--- /dev/null
+++ b/test/latex/reference-type.commands.tex.exp
@@ -0,0 +1,54 @@
+\providecommand\saildoclabelled[2]{\phantomsection\label{#1}#2}
+\providecommand\saildocval[2]{#1 #2}
+\providecommand\saildocfcl[2]{#1 #2}
+\providecommand\saildoctype[2]{#1 #2}
+\providecommand\saildocfn[2]{#1 #2}
+\providecommand\saildocoverload[2]{#1 #2}
+
+\newcommand{\sailtypecapUpermsWidth}{\saildoclabelled{sailtypezcapzyupermszywidth}{\saildoctype{}{\lstinputlisting[language=sail]{out/typezcap_uperms_widthf6dfed0942499b0c2d58b90971faca40.tex}}}}
+
+\newcommand{\sailvalmain}{\saildoclabelled{sailzmain}{\saildocval{}{\lstinputlisting[language=sail]{out/valzmaine3ee21bf8f1dbb3fd716a5a1803d7e24.tex}}}}
+
+\newcommand{\sailfnmain}{\saildoclabelled{sailfnzmain}{\saildocfn{\begin{itemize}
+\item Ref to \hyperref[sailzcapzyupermszywidth]{\lstinline{cap_uperms_width}}
+\item Ref to \hyperref[sailzcapzyupermszywidth]{description}
+\item Ref to \hyperref[sailztypez0capzyupermszywidth]{type description}
+\item Ref to % FIXME: this should be using type\_description \hyperref[sailztypezycapzyupermszywidth]{type_description}
+\item Ref to \sailreftype{cap\_uperms\_width}{uperms\_width}
+\item Ref to \sailreftype{cap\_uperms\_width}{uperms\_width}
+\end{itemize}
+}{\lstinputlisting[language=sail]{out/fnzmaine3ee21bf8f1dbb3fd716a5a1803d7e24.tex}}}}
+
+\newcommand{\sailvalfunctionWithUnderscores}{\saildoclabelled{sailzfunctionzywithzyunderscores}{\saildocval{}{\lstinputlisting[language=sail]{out/valzfunction_with_underscores6e195bff96b3fe3d60b356f28519989f.tex}}}}
+
+\newcommand{\sailfnfunctionWithUnderscores}{\saildoclabelled{sailfnzfunctionzywithzyunderscores}{\saildocfn{\begin{itemize}
+\item \hyperref[sailzfunction\_with\_underscores]{\lstinline{function\_with\_underscores}}
+\item \hyperref[sailzfunctionzywithzyunderscores]{\lstinline{function_with_underscores}}
+\item \hyperref[sailzNOTz0function\_with\_underscores]{function\_with\_underscores}
+\item \hyperref[sailzNOTz0\lstinline{function_with_underscores}]{\lstinline{function_with_underscores}}
+\item \hyperref[sailzfunction\_with\_underscores]{NOT function\_with\_underscores}
+\item \hyperref[sailzfunctionzywithzyunderscores]{NOT \lstinline{function_with_underscores}}
+\end{itemize}
+}{\lstinputlisting[language=sail]{out/fnzfunction_with_underscores6e195bff96b3fe3d60b356f28519989f.tex}}}}
+
+\newcommand{\sailval}[1]{
+ \ifstrequal{#1}{function\_with\_underscores}{\sailvalfunctionWithUnderscores}{}%
+ \ifstrequal{#1}{main}{\sailvalmain}{}}
+
+\newcommand{\sailrefval}[2]{
+ \ifstrequal{#1}{function_with_underscores}{\hyperref[sailzfunctionzywithzyunderscores]{#2}}{}%
+ \ifstrequal{#1}{main}{\hyperref[sailzmain]{#2}}{}}
+
+\newcommand{\sailfn}[1]{
+ \ifstrequal{#1}{function\_with\_underscores}{\sailfnfunctionWithUnderscores}{}%
+ \ifstrequal{#1}{main}{\sailfnmain}{}}
+
+\newcommand{\sailreffn}[2]{
+ \ifstrequal{#1}{function_with_underscores}{\hyperref[sailfnzfunctionzywithzyunderscores]{#2}}{}%
+ \ifstrequal{#1}{main}{\hyperref[sailfnzmain]{#2}}{}}
+
+\newcommand{\sailtype}[1]{
+ \ifstrequal{#1}{cap\_uperms\_width}{\sailtypecapUpermsWidth}{}}
+
+\newcommand{\sailreftype}[2]{
+ \ifstrequal{#1}{cap_uperms_width}{\hyperref[sailtypezcapzyupermszywidth]{#2}}{}}
diff --git a/test/latex/reference-type.sail b/test/latex/reference-type.sail
new file mode 100644
index 00000000..d41ae10f
--- /dev/null
+++ b/test/latex/reference-type.sail
@@ -0,0 +1,27 @@
+default Order dec
+
+$include <flow.sail>
+$include <vector_dec.sail>
+
+type cap_uperms_width : Int = 4
+let cap_uperms_width = sizeof(cap_uperms_width)
+
+/*!
+ * - Ref to [cap_uperms_width]
+ * - Ref to [description][cap_uperms_width]
+ * - Ref to [type description][type cap_uperms_width]
+ * - Ref to % FIXME: this should be using type\_description [type_description][type_cap_uperms_width]
+ * - Ref to \sailreftype{cap_uperms_width}{uperms\_width}
+ * - Ref to \sailreftype{cap\_uperms\_width}{uperms\_width}
+ */
+function main() -> unit = return(())
+
+/*!
+ * - [NAME]
+ * - [THIS]
+ * - [NAME][NOT NAME]
+ * - [THIS][NOT THIS]
+ * - [NOT NAME][NAME]
+ * - [NOT THIS][THIS]
+ */
+function function_with_underscores() -> unit = return(())
diff --git a/test/latex/run_tests.sh b/test/latex/run_tests.sh
index 6ba3ce6f..17edb567 100755
--- a/test/latex/run_tests.sh
+++ b/test/latex/run_tests.sh
@@ -26,7 +26,6 @@ for testfile in *.sail; do
exp_prefix=${testfile//.sail/}
errmsg="Missing .exp files for $testfile?"
for expected in "${exp_prefix}"*.exp; do
- echo "expected=$expected"
# remove prefix and suffix
exp_file_name=${expected//${exp_prefix}./}
generated_file="$temp_dir/out/${exp_file_name//.exp/}"
@@ -42,10 +41,22 @@ for testfile in *.sail; do
fi
done
if [ -z "$errmsg" ]; then
- green "LaTeX for $testfile" "ok"
+ green "Generating LaTeX for $testfile" "ok"
else
- yellow "LaTeX for $testfile" "$errmsg"
+ yellow "Generating LaTeX for $testfile" "$errmsg"
fi;
+ # Check that the generated latex builds:
+ if command -v latexmk > /dev/null; then
+ cp -f "$DIR/main.tex" "$temp_dir"
+ if latexmk -pdf -cd -file-line-error -interaction=batchmode "$temp_dir/main.tex" > /dev/null 2>&1; then
+ green "Building LaTeX for $testfile" "ok"
+ else
+ tail -n 50 "$temp_dir/main.log"
+ yellow "Building LaTeX for $testfile" "failed to build"
+ fi
+ else
+ red "Building LaTeX for $testfile" "latexmk not installed"
+ fi
else
red "failed to generate latex for $testfile" "fail"
fi