|
| 1 | +\NeedsTeXFormat{LaTeX2e} |
| 2 | +\ProvidesPackage{eclistings}[2026/04/07 EasyCrypt listings] |
| 3 | + |
| 4 | +\RequirePackage{listings} |
| 5 | +\RequirePackage{xcolor} |
| 6 | +\RequirePackage{xparse} |
| 7 | + |
| 8 | +% EasyCrypt % |
| 9 | +% Language |
| 10 | +\lstdefinelanguage{easycrypt}{% |
| 11 | + sensitive=true, % Case sensitive keywords |
| 12 | + % Keywords: Meta/Specification language |
| 13 | + morekeywords=[1]% |
| 14 | + { |
| 15 | + abbrev, abstract, as, assert, async, axiom, axiomatized, class, clone, |
| 16 | + const, debug, declare, eager, ehoare, elif, else, end, equiv, exists, exit, |
| 17 | + export, fail, for, forall, from, fun, glob, global, goal, hint, hoare, if, |
| 18 | + import, in, include, inductive, instance, islossless, lemma, let, local, locate, |
| 19 | + match, module, nosmt, notation, of, op, phoare, pragma, Pr, pred, print, proc, |
| 20 | + proof, prover, qed, quantum, realize, remove, rename, require, res, return, |
| 21 | + search, section, Self, subtype, then, theory, time, timeout, Top, type, |
| 22 | + undo, var, while, why3, with |
| 23 | + }, |
| 24 | + % Keywords: Regular (i.e., non-closing) tactics |
| 25 | + morekeywords=[2]% |
| 26 | + { |
| 27 | + algebra, alias, apply, async, auto, beta, |
| 28 | + byequiv, byphoare, bypr, call, case, cbv, cfold, |
| 29 | + change, clear, congr, conseq, cut, delta, dump, |
| 30 | + ecall, elim, eta, exfalso, exlim, fel, field, fieldeq, fission, |
| 31 | + fusion, gen, have, hoare, idtac, inline, interleave, iota, kill, left, logic, |
| 32 | + modpath, move, outline, pose, pr_bounded, progress, rcondf, |
| 33 | + rcondt, replace, rewrite, right, ring, ringeq, rnd, rndsem, rwnormal, |
| 34 | + seq, sim, simplify, skip, sp, split, splitwhile, subst, |
| 35 | + suff, swap, symmetry, transitivity, trivial, unroll, weakmem, wlog, |
| 36 | + wp, zeta |
| 37 | + }, |
| 38 | + % Keywords: Closing tactics/tacticals |
| 39 | + morekeywords=[3]% |
| 40 | + { |
| 41 | + abort, admit, admitted, assumption, by, check, done, |
| 42 | + edit, exact, fix, reflexivity, smt, solve |
| 43 | + }, |
| 44 | + % Keywords: Tacticals |
| 45 | + morekeywords=[4]% |
| 46 | + { |
| 47 | + do, expect, first, last, strict, try |
| 48 | + }, |
| 49 | + comment=[n]{(*}{*)}, % Multi-line, nested comments delimited by (* and *) |
| 50 | + string=[d]{"}, % Strings delimited by " and ", non-escapable |
| 51 | +} |
| 52 | + |
| 53 | +% Style (base/default) |
| 54 | +\lstdefinestyle{easycrypt-base}{% |
| 55 | + % Frame |
| 56 | + captionpos=t, % Position caption at top (mirroring what's typical for algorithms) |
| 57 | + frame=tb, % Top and bottom rules |
| 58 | + framesep=\smallskipamount, % Small skip between frame and listing content |
| 59 | + % Float placement |
| 60 | + floatplacement=tbhp, |
| 61 | + % Character printing and placement |
| 62 | + upquote=true, % Print backtick and single quote as is |
| 63 | + columns=[c]fixed, % Monospace characters, centered in their box |
| 64 | + keepspaces=true, % Don't drop spaces for column alignment |
| 65 | + tabsize=2, % Tabstops every 2 spaces |
| 66 | + mathescape=false, % Don't allow escaping to LaTeX with $ |
| 67 | + showstringspaces=false, % Don't print characters for spaces |
| 68 | + % Line numbers |
| 69 | + numbers=none, % No line numbers |
| 70 | + % Basic style |
| 71 | + basicstyle={\normalsize\ttfamily}, |
| 72 | + % Style for (non-keyword) identifiers |
| 73 | + identifierstyle={}, |
| 74 | +} |
| 75 | + |
| 76 | +% Define default colors based on availability of colorblind colors |
| 77 | +\makeatletter |
| 78 | +\@ifpackageloaded{colorblind}{ |
| 79 | + \lstdefinestyle{easycrypt-default}{% |
| 80 | + style=easycrypt-base, |
| 81 | + % Styles for different keyword classes |
| 82 | + keywordstyle=[1]{\color{T-Q-B6}},% |
| 83 | + keywordstyle=[2]{\color{T-Q-B1}},% |
| 84 | + keywordstyle=[3]{\color{T-Q-B5}},% |
| 85 | + keywordstyle=[4]{\color{T-Q-B4}},% |
| 86 | + % Styles for comments and strings |
| 87 | + commentstyle={\itshape\color{T-Q-B0}},% |
| 88 | + stringstyle={\color{T-Q-B3}}, |
| 89 | + % Style of line numbers (in case numbers is overwritten to true) |
| 90 | + numberstyle={\small\color{T-Q-B0}}, |
| 91 | + } |
| 92 | +}{% |
| 93 | + \lstdefinestyle{easycrypt-default}{% |
| 94 | + style=easycrypt-base, |
| 95 | + % Styles for different keyword classes |
| 96 | + keywordstyle=[1]{\color{violet}},% |
| 97 | + keywordstyle=[2]{\color{blue}},% |
| 98 | + keywordstyle=[3]{\color{red}},% |
| 99 | + keywordstyle=[4]{\color{olive}},% |
| 100 | + % Styles for comments and strings |
| 101 | + commentstyle={\itshape\color{gray}},% |
| 102 | + stringstyle={\color{green}}, |
| 103 | + % Style of line numbers (in case numbers is overwritten to true) |
| 104 | + numberstyle={\small\color{gray}}, |
| 105 | + } |
| 106 | +} |
| 107 | +\makeatother |
| 108 | + |
| 109 | +% Style for drafting/debugging (explicit spaces/tabs) |
| 110 | +\lstdefinestyle{easycrypt-draft}{% |
| 111 | + style=easycrypt-default, |
| 112 | + showspaces=true, |
| 113 | + showtabs=true, |
| 114 | + showstringspaces=true, |
| 115 | +} |
| 116 | + |
| 117 | +% Style without top/bottom frame rules |
| 118 | +\lstdefinestyle{easycrypt-plain}{% |
| 119 | + style=easycrypt-default, |
| 120 | + frame=none, |
| 121 | + framesep=0pt, |
| 122 | +} |
| 123 | + |
| 124 | +% Environments |
| 125 | +%% Default, non-floating environment |
| 126 | +%% Meant to be used inside other (potentially floating) environment |
| 127 | +%% that takes care of the caption and surrounding spacing |
| 128 | +\lstnewenvironment{eclst}[1][]{% |
| 129 | + \lstset{% |
| 130 | + language=easycrypt,% |
| 131 | + style=easycrypt-default,% |
| 132 | + aboveskip=\smallskipamount,% Equal to framesep of style if top rule, else 0pt |
| 133 | + belowskip=\smallskipamount,% Equal to framesep of style if bottom rule, else 0pt |
| 134 | + abovecaptionskip=0pt,% |
| 135 | + belowcaptionskip=0pt,% |
| 136 | + #1% |
| 137 | + }% |
| 138 | +}{} |
| 139 | + |
| 140 | +% Inline |
| 141 | +\NewDocumentCommand{\ecinl}{O{easycrypt-default} m O{}}{% |
| 142 | + \lstinline[% |
| 143 | + language=easycrypt,% |
| 144 | + style=#1,% |
| 145 | + breaklines,% |
| 146 | + breakindent=0pt,% |
| 147 | + columns=fullflexible,% |
| 148 | + #3% |
| 149 | + ]{#2}% |
| 150 | +} |
| 151 | + |
| 152 | +\NewDocumentCommand{\ecinlfoot}{O{easycrypt-default} m O{}}{% |
| 153 | + \ecinl[#1]{#2}[basicstyle={\footnotesize\ttfamily},#3]% |
| 154 | +} |
| 155 | + |
| 156 | +\endinput |
0 commit comments