diff options
Diffstat (limited to 'macros/latex/contrib/listings/lstdrvrs.dtx')
-rw-r--r-- | macros/latex/contrib/listings/lstdrvrs.dtx | 190 |
1 files changed, 118 insertions, 72 deletions
diff --git a/macros/latex/contrib/listings/lstdrvrs.dtx b/macros/latex/contrib/listings/lstdrvrs.dtx index 56c2a92642..25c197c9d5 100644 --- a/macros/latex/contrib/listings/lstdrvrs.dtx +++ b/macros/latex/contrib/listings/lstdrvrs.dtx @@ -1,6 +1,6 @@ % \iffalse % -% Time-stamp: <2024-03-12 09:33:03 ax006ho> +% Time-stamp: <2024-05-25 06:23:16 ax006ho> % %<*driver> \documentclass{ltxdoc} @@ -33,7 +33,7 @@ % \title{Language, Style and Format drivers\\ for \textsf{Listings}\\ % {\large by Carsten Heinz and individual authors:}} % \author{\InputIfFileExists{lstdrvrs.tmp}{}{}} -% \date{2024/03/11\enspace\enspace Version 1.10a\ \box\abstractbox} +% \date{2024/09/23\enspace\enspace Version 1.10c\ \box\abstractbox} % % \ifhyper % \hypersetup{pdftitle={Language, Style and Format drivers for the @@ -138,7 +138,7 @@ % \endgroup % We mainly define default dialects. % \begin{macrocode} -\ProvidesFile{listings.cfg}[2024/03/11 1.10a listings configuration] +\ProvidesFile{listings.cfg}[2024/09/23 1.10c listings configuration] \def\lstlanguagefiles {lstlang0.sty,lstlang1.sty,lstlang2.sty,lstlang3.sty} \lstset{defaultdialect=[R/3 6.10]ABAP, @@ -154,6 +154,7 @@ defaultdialect=[11.0]Mathematica, defaultdialect=[OMG]OCL, defaultdialect=[Standard]Pascal, + defaultdialect=[2]Python, defaultdialect=[67]Simula, defaultdialect=[plain]TeX, defaultdialect=[97]VRML} @@ -186,7 +187,7 @@ %<+lua-prf>\ProvidesFile{listings-lua.prf} %<+python-prf>\ProvidesFile{listings-python.prf} %<+rexx-prf>\ProvidesFile{listings-rexx.prf} -%<-config> [2024/03/11 1.10a listings language file] +%<-config> [2024/09/23 1.10c listings language file] % \end{macrocode} % % @@ -7819,7 +7820,8 @@ morecomment=[l]!% % % In August 2013 % \lstthanks{Alexis~Dimitriadis}{A.Dimitriadis@uu.nl}{2013/08/15} reworked -% the definition by supplying the builtins. +% the definition by supplying the builtins. The current version is based on +% \url{https://docs.python.org/2/reference/lexical_analysis.html#identifiers}. % \begingroup % \begin{macrocode} %<*lang1> @@ -7828,17 +7830,22 @@ morecomment=[l]!% %% %% Python definition (c) 1998 Michael Weber %% Additional definitions (2013) Alexis Dimitriadis +%% small corrections based on +%% https://docs.python.org/2/reference/lexical_analysis.html#identifiers %% -\lst@definelanguage{Python}{% - morekeywords={access, and, break, class, continue, def, del, elif, else,% - except, exec, finally, for, from, global, if, import, in, is, lambda,% - not, or, pass, print, raise, return, try, while},% +\lst@definelanguage[2]{Python}{% + morekeywords={and, as, assert, break, class, continue, def, del, elif,% + else, except, exec, finally, for, from, global, if, import, in, is,% + lambda, not, or, pass, print, raise, return, try, while, with, yield},% % \end{macrocode} -% Python has a long list of builtin-in functions +% Python has a long list of builtin-in functions (altogether 76 entries +% plus 5 special ones) % (\url{http://docs.python.org/2/library/functions.html}) and it is a good -% idea to make them visible in printed code +% idea to make them visible in printed code. % \begin{macrocode} - % Built-ins + % Built-ins according to + % http://docs.python.org/2/library/functions.html, + % the last five entries are known as advanced or not essential morekeywords=[2]{abs, all, any, basestring, bin, bool, bytearray,% callable, chr, classmethod, cmp, compile, complex, delattr, dict, dir,% divmod, enumerate, eval, execfile, file, filter, float, format,% @@ -7847,43 +7854,96 @@ morecomment=[l]!% memoryview, min, next, object, oct, open, ord, pow, property, range,% raw_input, reduce, reload, repr, reversed, round, set, setattr, slice,% sorted, staticmethod, str, sum, super, tuple, type, unichr, unicode,% - vars, xrange, zip, apply, buffer, coerce, intern},% + vars, xrange, zip, __import__, apply, buffer, coerce, intern},% sensitive=true,% morecomment=[l]\#,% + morestring=[s]{'''}{'''},% used for documentation text + % (multiline strings) + morestring=[s]{"""}{"""},% added by Philipp Matthias Hahn morestring=[b]',% - morestring=[b]",% -% \end{macrocode} -% According to PEP (Python Enhancement Proposals) comment should be -% distinguished from documentation strings, so we define -% \begin{macrocode} - morecomment=[s]{'''}{'''},% used for documentation text - % (mulitiline strings) - morecomment=[s]{"""}{"""},% added by Philipp Matthias Hahn -% \end{macrocode} -% \lsthelper{J\"urgen Dietel}{j.dietel@rz.rwth-aachen}{2015/05/05}{} provided -% an example with a wrong representation of documentation strings, so the -% two lines above got changed from |morestring| $\rightarrow$ |morecomment|. -% -% Python now supports so called \emph{raw strings} and also Unicode -% strings. Here is the definition of these strings: -% \begin{macrocode} - morestring=[s]{r'}{'},% `raw' strings - morestring=[s]{r"}{"},% - morestring=[s]{r'''}{'''},% - morestring=[s]{r"""}{"""},% - morestring=[s]{u'}{'},% unicode strings - morestring=[s]{u"}{"},% - morestring=[s]{u'''}{'''},% - morestring=[s]{u"""}{"""}% -}% + morestring=[b]"% +} % \end{macrocode} % \lsthelper{Philipp Matthias Hahn}{pmhahn@titan.lahn.de}{2002/04/18}{} -% added the third comment. \lsthelper{eRreuR}{rogspr@newdeal.ch}{2002/05/28} -% {probl\`eme avec "listings" et le langage Python} found a bug using Python -% and \lsthelper{Nicolas Markey}{markey@lsv.ens-cachan.fr}{2002/05/29} +% added the third comment above. +% \lsthelper{eRreuR}{rogspr@newdeal.ch}{2002/05/28} {probl\`eme avec +% "listings" et le langage Python} found a bug using Python and +% \lsthelper{Nicolas Markey}{markey@lsv.ens-cachan.fr}{2002/05/29} % {listings and Python} informed me about the corresponding thread on % \texttt{fr.comp.text.tex} and provided the fix---adding \texttt{[b]} to % both \texttt{morestring} declarations. +% +% \lsthelper{J\"urgen Dietel}{j.dietel@rz.rwth-aachen}{2015/05/05}{} +% provided an example with a wrong representation of documentation strings, +% so the two lines added by Philipp Matthias Hahn got changed from +% |morestring| $\rightarrow$ |morecomment|.\footnote{According to PEP +% (Python Enhancement Proposals---\url{https://peps.python.org/pep-0257/}) +% comment should be distinguished from documentation strings.} +% +% Python 3.0 was released in December 2008 and brought with it a number of +% new features. \lsthelper{Naoki Sean +% Pross}{npross@student.ethz.ch}{2024/05/25}{Python 3 syntax support for +% the listings LaTeX package} provided the lists of new keywords and +% built-in functions as well as the support for special strings. +% \begin{macrocode} +\lst@definelanguage[3]{Python}[2]{Python}{% + % keywords + deletekeywords={exec, print}, + morekeywords={False, None, True, async, await, nonlocal, +% \end{macrocode} +% Python knows so called soft keywords: +% \begin{macrocode} + match, case}, +% \end{macrocode} +% The list of built-in functions has changed considerably (only 71 entries, +% no special ones): +% \begin{macrocode} + % built-in functions + deletekeywords=[2]{apply, basestring, buffer, cmp, coerce, execfile, % + file, intern, long, raw_input, reduce, reload, unichr, unicode, xrange}, + morekeywords=[2]{aiter, anext, ascii, breakpoint, bytes, exec}, +% \end{macrocode} +% Python now supports special strings like \emph{raw strings}, Unicode +% strings, and some more. Here is the definition of these strings: +% \begin{macrocode} + % `raw' strings + morestring=[s]{r'}{'}, + morestring=[s]{r"}{"}, + morestring=[s]{r'''}{'''}, + morestring=[s]{r"""}{"""}, + morestring=[s]{R'}{'}, + morestring=[s]{R"}{"}, + morestring=[s]{R'''}{'''}, + morestring=[s]{R"""}{"""}, + % Unicode strings + morestring=[s]{u'}{'}, + morestring=[s]{u"}{"}, + morestring=[s]{u'''}{'''}, + morestring=[s]{u"""}{"""}, + morestring=[s]{U'}{'}, + morestring=[s]{U"}{"}, + morestring=[s]{U'''}{'''}, + morestring=[s]{U"""}{"""}, + % Format strings + morestring=[s]{f'}{'}, + morestring=[s]{f"}{"}, + morestring=[s]{f'''}{'''}, + morestring=[s]{f"""}{"""}, + morestring=[s]{F'}{'}, + morestring=[s]{F"}{"}, + morestring=[s]{F'''}{'''}, + morestring=[s]{F"""}{"""}, + % Byte literals + morestring=[s]{b'}{'}, + morestring=[s]{b"}{"}, + morestring=[s]{b'''}{'''}, + morestring=[s]{b"""}{"""}, + morestring=[s]{B'}{'}, + morestring=[s]{B"}{"}, + morestring=[s]{B'''}{'''}, + morestring=[s]{B"""}{"""}, +}% +% \end{macrocode} % \begin{macrocode} %</lang1> % \end{macrocode} @@ -7903,6 +7963,8 @@ morecomment=[l]!% %% Actual colors from idlelib/config-highlight.def %% --> corrected to ``web-safe'' +%% Unimplemented IDLE syntax: function/class names being +%% defined should be blue %% strings = #00aa00 / 0,170,0 (a darker green) %% builtins = #900090 / 144,0,144 (purple-ish) %% keywords = #FF7700 / 255,119,0 (quite close to plain `orange') @@ -7958,6 +8020,7 @@ morecomment=[l]!% procedure,pull,push,queue,return,say,select,signal,then,% to,trace,when},% sensitive=false,% + morecomment=[l]{--},% morecomment=[n]{/*}{*/},% morestring=[d]{'},% morestring=[d]{"},% @@ -7999,7 +8062,6 @@ morecomment=[l]!% sensitive=false,% morestring=[d]",% morestring=[d]',% - morecomment=[s]{/*}{*/},% }[keywords,comments,strings] % \end{macrocode} % \begin{macrocode} @@ -8026,7 +8088,7 @@ morecomment=[l]!% ::options, ::requires, ::resource, ::routine,% forward, guard, local, loop, raise, strict,% },% - alsoletter={:},% + alsoletter={:} }[keywords,comments,strings] % \end{macrocode} % \begin{macrocode} @@ -8042,38 +8104,22 @@ morecomment=[l]!% %<*rexx-prf> % \end{macrocode} % \begin{macrocode} -\usepackage{xcolor} -\usepackage{textcomp} - -%% Actual colors from idlelib/config-highlight.def -%% --> corrected to ``web-safe'' -%% strings = #00aa00 / 0,170,0 (a darker green) -%% builtins = #900090 / 144,0,144 (purple-ish) -%% keywords = #FF7700 / 255,119,0 (quite close to plain `orange') -%\definecolor{IDLEorange}{RGB}{255,119,0} % pretty close to real orange -%\definecolor{IDLEpurple}{RGB}{144,0,144} -%\definecolor{IDLEgreen}{RGB}{0,170,0} -%\definecolor{IDLEred}{RGB}{221,0,0} -%% Corrected to ``web-safe'' -%\definecolor{orange2}{RGB}{255,102,0} -\definecolor{purple2}{RGB}{153,0,153} % there's actually no standard purple -\definecolor{green2}{RGB}{0,153,0} % a darker green -%\definecolor{red2}{RGB}{221,0,0} +\usepackage{xcolor} % needed for colors like yellow!10 +\usepackage{textcomp} % needed for upquote -% Except for green and purple, the other colors are pretty good in standard -% hue -\lstdefinestyle{python-idle-code}{% - language=Python, % the language - basicstyle=\normalsize\ttfamily, % size of the fonts for the code - % Color settings to match IDLE style - keywordstyle=\color{orange}, % core keywords - keywordstyle={[2]\color{purple2}}, % built-ins - stringstyle=\color{green2},% - commentstyle=\color{red},% +\lstdefinestyle{rexx-colored}{% + language=oorexx, % the language + backgroundcolor=\color{yellow!10}, + basicstyle=\normalsize\ttfamily, % size of the fonts for + % the code + % Color settings to match JHf's preferred style + keywordstyle=\color{blue}, % core keywords + keywordstyle={[2]\color{cyan}}, % built-ins + keywordstyle={[3]\color{olive}}, % special keywords + stringstyle=\color{teal},% + commentstyle=\color{orange},% upquote=true, % requires textcomp } -% Unimplemented IDLE syntax: function/class names being defined should be -% blue % \end{macrocode} % This code is provided in the file |listings-rexx.prf|, see section % 2.4.1 (Preferences) of the \packagename{listings} documentation. |