-
Notifications
You must be signed in to change notification settings - Fork 27
/
idrislang.sty
160 lines (148 loc) · 5.36 KB
/
idrislang.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%% --------------------------------------------------- [ Idris Styling Package ]
%%
%% A set of LaTeX macros and styling for working with Idris in LaTeX
%%
%% + Provides a listings bindings:
%% + idris :: default ascii
%% + literateidris :: convert ascii maths to math symbols.
%% + Defines a `numbers', `default', and `stdout' listings style.
%% + default :: Uses TT font for code and SF font for comments,
%% and indented by parident.
%% + numbers :: default but with numbers.
%% + beamer :: default minus parindent
%% + stdout :: for formatting stdout.
%% + Defines a `code' environment for typesetting idris.
%% + \begin{code}[...] ... \end{code}
%% + Defines an input command for externally defined idris files.
%% + \inputIdrisListing[...]{file.idr}
%% + Provides definitions (from Idris Compiler) for pretty-printing Idris
%% code using Fancy Verbatim and colour commands.
%% + Sets commandchars for latex commands.
%% + Defines commands typesetting the name Idris.
%% + \Idris{}
%% + \idris{}
%%
%% Options:
%% - literate :: turn on literate idris for code environments.
%%
%% ----------------------------------------------------------- [ Begin Package ]
\ProvidesPackage{idrislang}
\RequirePackage{ifthen}
\RequirePackage{xcolor}
\RequirePackage{fancyvrb}
\RequirePackage{listings}
\RequirePackage{xspace}
\RequirePackage{textcomp}
\RequirePackage{setspace}
%% ----------------------------------------------------------------- [ Options ]
\newboolean{literate}
\setboolean{literate}{false}
\DeclareOption{literate}{%
\setboolean{literate}{true}
}
\ProcessOptions\relax
%% ---------------------------------------------------------------- [ Commands ]
\newcommand{\Idris}{\textsc{Idris}\xspace}
\newcommand{\idris}{\textsc{Idris}\xspace}
\newcommand{\IdrisLineSpacing}{\singlespacing}
%% ---------------------------------------------------------- [ Color Commands ]
\newcommand{\IdrisData}[1]{\textcolor{red}{#1}}
\newcommand{\IdrisType}[1]{\textcolor{blue}{#1}}
\newcommand{\IdrisBound}[1]{\textcolor{magenta}{#1}}
\newcommand{\IdrisFunction}[1]{\textcolor{green}{#1}}
\newcommand{\IdrisKeyword}[1]{{\underline{#1}}}
\newcommand{\IdrisImplicit}[1]{{\itshape \IdrisBound{#1}}}
\fvset{commandchars=\\\{\}}
%% --------------------------------------------------- [ Define Idris Listings ]
\lstdefinelanguage{idris}{%
sensitive,%
%% ----------------------------------------------------------- [ Default Style ]
xleftmargin=1.5em,
tabsize=2,
upquote=true,
basicstyle=\ttfamily,
flexiblecolumns=false,
commentstyle=\footnotesize\itshape,
%% ---------------------------------------------------------------- [ Keywords ]
%% From Idris Parser and idris-mode and vimscript
keywords={%
abstract, attack, case, compute, do, dsl, else, exact, focus, if,
import, in, infix, infixl, infixr, instance, intros, module,
mutual, namespace, of, let, parameters, partial, pattern, prefix,
private, public, refine, rewrite, solve, syntax, term, then,
total, trivial, try, using, where, with
},
%% ------------------------------------------------------- [ Prelude Functions ]
morekeywords={%
class, data, instance, record, dsl, postulate, default,
lambda, variable, index_first, index_next
},
%% ---------------------------------------------------------------- [ Comments ]
morecomment=[l]--,%
morecomment=[n]{\{-}{-\}}
}[keywords,comments,strings]%
%% ---------------------------------------- [ Define Idris with Literate Stuff ]
\lstdefinelanguage{literateidris}[]{idris}{
literate= {+}{{$+$}}1
{/}{{$/$}}1
{*}{{$*$}}1
{=}{{$=$}}1
{>}{{$>$}}1
{<}{{$<$}}1
{\\}{{$\lambda$}}1
{\\\\}{{\char`\\\char`\\}}1
{->}{{$\rightarrow$}}2
{>=}{{$\geq$}}2
{<-}{{$\leftarrow$}}2
{<=}{{$\leq$}}2
{=>}{{$\Rightarrow$}}2
{==}{{$\equiv$}}2
{\ .}{{$\circ$}}2
{\ .\ }{{$\circ$}}2
{>>}{{>>}}2
{>>=}{{>>=}}2
{|}{{$\mid$}}1,
}
%% -------------------------------------------------- [ Default Listings Style ]
\lstdefinestyle{default}{%
basicstyle=\ttfamily\normalsize,
}
\lstdefinestyle{numbers}{%
numbers=left,
numbersep=10pt,
numberstyle=\footnotesize\sffamily,
frame=leftline
}
\lstdefinestyle{stdout}{%
xleftmargin=\parindent,
tabsize=2,
basicstyle=\ttfamily\normalsize,
showstringspaces=false,
escapechar=^
}
\lstdefinestyle{beamer}{%
basicstyle=\ttfamily\normalsize,
escapechar=^
}
%% ------------------------------------------------------ [ A Code Environment ]
%% Replicate the existence of literate haskell code environments,
%% option to make pretty with numbers.
\lstnewenvironment{code}[1][]
{\ifthenelse{\boolean{literate}}{%
\lstset{language=literateidris}}{%
\lstset{language=idris}}
\IdrisLineSpacing{}
}{}
%% ---------------------------------------------------------- [ Input Listings ]
%% Command to add externally defined Idris code to the document.
\newcommand{\inputIdrisListing}[2][]{%
\begingroup
\ifthenelse{\boolean{literate}}{%
\lstset{language=literateidris}}{%
\lstset{language=idris}}
\IdrisLineSpacing{}
\lstinputlisting[#1]{#2}
\endgroup
}
\endinput
%% --------------------------------------------------------------------- [ EOF ]