% \usepackage{xcolor}
% \usepackage{listings}
% \usepackage{booktabs}
% \usepackage{array}
% \newcolumntype{?}{!{\vrule width 1pt}} % thick vertical line


% like Mac Classic or iPlastic
% \definecolor{basicCol}{HTML}{000000}
% \definecolor{commentCol}{HTML}{0066FF}
% \definecolor{stringCol}{HTML}{036A07}
% \definecolor{keywordCol}{HTML}{0000FF}
% \definecolor{identifierCol}{HTML}{318495}

% like Visual Studio 2010
% \definecolor{basicCol}{HTML}{000000}
% \definecolor{commentCol}{HTML}{006400}
% \definecolor{stringCol}{HTML}{A31515}
% \definecolor{keywordCol}{HTML}{0000FF}
% \definecolor{identifierCol}{HTML}{000000}

\definecolor{basicCol}{HTML}{000000}
\definecolor{commentCol}{HTML}{000000}
\definecolor{stringCol}{HTML}{000000}
\definecolor{keywordCol}{HTML}{000000}
\definecolor{identifierCol}{HTML}{000000}

% from https://gist.github.com/nikolajquorning/92bbbeef32e1dd80105c9bf2daceb89a
\lstdefinelanguage{sml} {
  morekeywords= {
    EQUAL, GREATER, LESS, NONE, SOME, abstraction, abstype, and, andalso, array, as, before, bool, case, char, datatype, do, else, end, eqtype, exception, exn, false, fn, fun, functor, handle, if, in, include, infix, infixr, int, let, list, local, nil, nonfix, not, o, of, op, open, option, orelse, overload, print, raise, real, rec, ref, sharing, sig, signature, string, struct, structure, substring, then, true, type, unit, val, vector, where, while, with, withtype, word
  },
  morestring=[b]",
  morecomment=[s]{(*}{*)},
}

\lstdefinelanguage{D}{
  % Keywords
  morekeywords=[1]{
    abstract, alias, align, auto, body, break, cast, catch, class, const,
    continue, debug, delegate, delete, deprecated, do, else, enum, export,
    false, final, finally, for, foreach, foreach_reverse, function, goto, if,
    immutable, import, in, inout, interface, invariant, is, lazy, macro, mixin,
    module, new, nothrow, null, out, override, package, pragma, private,
    protected, public, pure, ref, return, shared, static, struct, super,
    switch, synchronized, template, this, throw, true, try, typedef, typeid,
    typeof, union, unittest, volatile, while, with
  },
  % Special identifiers, common functions
  morekeywords=[2]{enforce},
  % Ugly identifiers
  morekeywords=[3]{
    __DATE__, __EOF__, __FILE__, __LINE__, __TIMESTAMP__, __TIME__, __VENDOR__,
    __VERSION__, __ctfe, __gshared, __monitor, __thread, __vptr, _argptr,
    _arguments, _ctor, _dtor
  },
  % Basic types
  morekeywords=[4]{
     byte, ubyte, short, ushort, int, uint, long, ulong, cent, ucent, void,
     bool, bit, float, double, real, ushort, int, uint, long, ulong, float,
     char, wchar, dchar, string, wstring, dstring, ireal, ifloat, idouble,
     creal, cfloat, cdouble, size_t, ptrdiff_t, sizediff_t, equals_t, hash_t
  },
  % Strings
  morestring=[b]{"},
  morestring=[b]{'},
  morestring=[b]{`},
  % Comments
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morecomment=[s][\color{blue}]{/**}{*/},
  morecomment=[n]{/+}{+/},
  morecomment=[n][\color{blue}]{/++}{+/},
  % Options
  sensitive=true
}

\lstdefinelanguage{rust}{
  % Keywords
  morekeywords=[1]{
    abstract, alignof, as, become, box,
    break, const, continue, crate, do,
    else, enum, extern, false, final,
    fn, for, if, impl, in,
    let, loop, macro, match, mod,
    move, mut, offsetof, override, priv,
    proc, pub, pure, ref, return,
    Self, self, sizeof, static, struct,
    super, trait, true,  type, typeof,
    unsafe, unsized, use, virtual, where,
    while, yield
  },
  % Strings
  morestring=[b]{"},
  % Comments
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  % Options
  sensitive=true
}

\newcommand{\KWC}{K-W C\xspace}

\renewcommand{\ttdefault}{pcr}

\newcommand{\basicstylesmall}{\scriptsize\ttfamily\color{basicCol}}

\lstdefinestyle{defaultStyle}{
  escapeinside={@@},
  basicstyle=\footnotesize\ttfamily\color{basicCol},
  keywordstyle=\bfseries\color{keywordCol},
  commentstyle=\itshape\color{commentCol},
  identifierstyle=\color{identifierCol},
  stringstyle=\color{stringCol},
  mathescape=true,
  columns=fixed,
  aboveskip=4pt,                                  % spacing above/below code block
  belowskip=3pt,
  keepspaces=true,
  frame=lines,
  literate=,
  showlines=true,                                 % show blank lines at end of code
  showspaces=false,
  showstringspaces=false,
  escapechar=\$,
  xleftmargin=\parindentlnth,                     % indent code to paragraph indentation
  moredelim=[is][\color{red}\bfseries]{**R**}{**R**},    % red highlighting
  % moredelim=* detects keywords, comments, strings, and other delimiters and applies their formatting
  % moredelim=** allows cumulative application
}
\lstset{
  language = CFA,
  style=defaultStyle
}
\lstMakeShortInline[basewidth=0.5em,breaklines=true,breakatwhitespace,basicstyle=\normalsize\ttfamily\color{basicCol}]@  % single-character for \lstinline

\lstnewenvironment{cfacode}[1][]{
  \lstset{
    language = CFA,
    style=defaultStyle,
    #1
    % belowcaptionskip=1\baselineskip,
    % breaklines=true,
    % frame=L,
  }
}{}

\lstnewenvironment{cppcode}[1][]{
  \lstset{
    language = c++,
    style=defaultStyle,
    #1
  }
}{}

\lstnewenvironment{javacode}[1][]{
  \lstset{
    language = java,
    style=defaultStyle,
    #1
  }
}{}

\lstnewenvironment{scalacode}[1][]{
  \lstset{
    language = scala,
    style=defaultStyle,
    #1
  }
}{}

\lstnewenvironment{smlcode}[1][]{
  \lstset{
    language = sml,
    style=defaultStyle,
    #1
  }
}{}

\lstnewenvironment{dcode}[1][]{
  \lstset{
    language = D,
    style=defaultStyle,
    #1
  }
}{}

\lstnewenvironment{rustcode}[1][]{
  \lstset{
    language = rust,
    style=defaultStyle,
    #1
  }
}{}

\newcommand{\zero}{\lstinline{zero_t}\xspace}
\newcommand{\one}{\lstinline{one_t}\xspace}
\newcommand{\ateq}{\lstinline{\@=}\xspace}

\newenvironment{newtext}{\color{red}}{\ignorespacesafterend}

% \lstset{ %
%   backgroundcolor=\color{white},
%   basicstyle=\footnotesize,
%   breakatwhitespace=false,
%   breaklines=true,
%   captionpos=b,
%   commentstyle=\color{mygreen},
%   escapeinside={\%*}{*)},
%   extendedchars=true,
%   frame=single,
%   keywordstyle=\color{blue},
%   language=Prolog,
%   numbers=left,
%   numbersep=5pt,
%   numberstyle=\tiny\color{mygray},
%   rulecolor=\color{black},
%   showspaces=false,
%   showstringspaces=false,
%   showtabs=false,
%   stepnumber=2,
%   stringstyle=\color{mymauve},
%   tabsize=2,
%   title=\lstname,
%   morekeywords={not,\},\{,preconditions,effects },
%   deletekeywords={time}
% }
