From 2e2bfac6d15f27db67b20c40ea73e4ebd9f0c4b4 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 28 Sep 2020 16:51:26 +0100 Subject: Re-generate latex tests --- test/latex/candperm.commands.tex.exp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/latex/candperm.commands.tex.exp b/test/latex/candperm.commands.tex.exp index 14153396..9c8ca6ff 100644 --- a/test/latex/candperm.commands.tex.exp +++ b/test/latex/candperm.commands.tex.exp @@ -1,19 +1,19 @@ \providecommand\saildoclabelled[2]{\phantomsection\label{#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 +22,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 +31,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 +39,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 +60,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 +72,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}}{}} -- cgit v1.2.3 From 1ed71fb2a5dbf1b1a44d25a8b9588c8e0f43144f Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 28 Sep 2020 16:51:54 +0100 Subject: LaTeX: provide default implementations of the other saildoc commands --- src/latex.ml | 7 ++++++- test/latex/candperm.commands.tex.exp | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/latex.ml b/src/latex.ml index be3e8748..96a74e06 100644 --- a/src/latex.ml +++ b/src/latex.ml @@ -440,7 +440,12 @@ let tdef_id = function let defs (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 diff --git a/test/latex/candperm.commands.tex.exp b/test/latex/candperm.commands.tex.exp index 9c8ca6ff..0ba8e659 100644 --- a/test/latex/candperm.commands.tex.exp +++ b/test/latex/candperm.commands.tex.exp @@ -1,4 +1,9 @@ \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{sailtypezast}{\saildoctype{}{\lstinputlisting[language=sail]{out/typezast6bb070d12e82e4887160cdfd016230c8.tex}}}} -- cgit v1.2.3 From bc73f660dc1a4b119670e66def7041fd328a715a Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 28 Sep 2020 16:53:37 +0100 Subject: LaTeX tests: check that the generated code builds --- test/latex/main.tex | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/latex/run_tests.sh | 17 ++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test/latex/main.tex diff --git a/test/latex/main.tex b/test/latex/main.tex new file mode 100644 index 00000000..154ad0c2 --- /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 +reftytpe: \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/run_tests.sh b/test/latex/run_tests.sh index 6ba3ce6f..8c317b98 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 -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 -- cgit v1.2.3 From 38341beb186e5ac871d0e3446e5a98a25a806667 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 28 Sep 2020 17:18:08 +0100 Subject: LaTeX: Underscore-escape values in the \ifstrequal code --- src/latex.ml | 4 +-- test/latex/main.tex | 4 +-- test/latex/reference-type.commands.tex.exp | 54 ++++++++++++++++++++++++++++++ test/latex/reference-type.sail | 27 +++++++++++++++ test/latex/run_tests.sh | 2 +- 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 test/latex/reference-type.commands.tex.exp create mode 100644 test/latex/reference-type.sail diff --git a/src/latex.ml b/src/latex.ml index 96a74e06..a4265686 100644 --- a/src/latex.ml +++ b/src/latex.ml @@ -241,7 +241,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, _) -> @@ -505,7 +505,7 @@ let defs (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/main.tex b/test/latex/main.tex index 154ad0c2..a0948482 100644 --- a/test/latex/main.tex +++ b/test/latex/main.tex @@ -24,10 +24,10 @@ \begin{document} \clearpage -type: \sailtype{cap_uperms_width} +type: \sailtype{cap\_uperms\_width} \clearpage -reftytpe: \sailreftype{cap\_uperms\_width}{ref to cap\_uperms\_width} +ref type: \sailreftype{cap\_uperms\_width}{ref to cap\_uperms\_width} \clearpage val: \sailval{main} 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 +$include + +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 8c317b98..17edb567 100755 --- a/test/latex/run_tests.sh +++ b/test/latex/run_tests.sh @@ -48,7 +48,7 @@ for testfile in *.sail; do # Check that the generated latex builds: if command -v latexmk > /dev/null; then cp -f "$DIR/main.tex" "$temp_dir" - if latexmk -pdf -cd -interaction=batchmode "$temp_dir/main.tex" > /dev/null 2>&1; then + 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" -- cgit v1.2.3