summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/optex/base/hisyntax-c.opm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/optex/base/hisyntax-c.opm')
-rw-r--r--Master/texmf-dist/tex/optex/base/hisyntax-c.opm66
1 files changed, 66 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/optex/base/hisyntax-c.opm b/Master/texmf-dist/tex/optex/base/hisyntax-c.opm
new file mode 100644
index 00000000000..3c1f228f88c
--- /dev/null
+++ b/Master/texmf-dist/tex/optex/base/hisyntax-c.opm
@@ -0,0 +1,66 @@
+%% This is part of the OpTeX project, see http://petr.olsak.net/optex
+
+\_codedecl \_hisyntaxc {Syntax highlighting for C sources <2020-04-03>}
+
+\_newtoks \_hisyntaxc \_newtoks \_hicolorsc
+
+\_global\_hicolorsc={% colors for C language
+ \_hicolor K \Red % Keywords
+ \_hicolor S \Magenta % Strings
+ \_hicolor C \Green % Comments
+ \_hicolor N \Cyan % Numbers
+ \_hicolor P \Blue % Preprocessor
+ \_hicolor O \Blue % Non-letters
+}
+\_global\_hisyntaxc={%
+ \_the\_hicolorsc
+ \_let\c=\_relax \_let\e=\_relax \_let\o=\_relax
+ \_replfromto {/*}{*/} {\x C{/*#1*/}}% /*...*/
+ \_replfromto {//}{^^J} {\z C{//#1}^^J}% //...
+ \_replfromto {\_string#}{^^J} {\z P{\##1}^^J}% #include ...
+ \_replthis {\_string\"} {{\_string\"}}% \" protected inside strings
+ \_replfromto {"}{"} {\x S{"#1"}}% "..."
+ %
+ \_edef\_tmpa {()\_string{\_string}+-*/=[]<>,:;\_pcent\_string&\_string^|!?}% non-letters
+ \_ea \_foreach \_tmpa
+ \_do {\_replthis{#1}{\n\o#1\n}}
+ \_foreach % keywords
+ {auto}{break}{case}{char}{continue}{default}{do}{double}%
+ {else}{entry}{enum}{extern}{float}{for}{goto}{if}{int}{long}{register}%
+ {return}{short}{sizeof}{static}{struct}{switch}{typedef}{union}%
+ {unsigned}{void}{while}
+ \_do {\_replthis{\n#1\n}{\z K{#1}}}
+ \_replthis{.}{\n.\n} % numbers
+ \_foreach 0123456789
+ \_do {\_replfromto{\n#1}{\n}{\c#1##1\e}}
+ \_replthis{\e.\c}{.}
+ \_replthis{\e.\n}{.\e}
+ \_replthis{\n.\c}{\c.}
+ \_replthis{e\e\o+\c}{e+}\_replthis{e\e\o-\c}{e-}
+ \_replthis{E\e\o+\c}{E+}\_replthis{E\e\o-\c}{E-}
+ \_def\o#1{\z O{#1}}
+ \_def\c#1\e{\z N{#1}}
+}
+
+\_endcode %------------------------------------------------
+
+
+Each `hisyntax-<name>.opm` file must declare the token list
+`\_hisyntax<name>` using `\newtoks` and must declare the syntax declaration
+in it. The second token list `\_hicolors<name>` is optional but recommended.
+User can re-declare his/her own colors by `\hicolors` which has precedence
+before `\_hicolors<name>`.
+
+The public variants can be declared if you want to give these token lists to
+the user namespace. But it is not explicitly needed.
+
+All settings must be global here because the file is typically read inside
+a group and we need not read it repeatedly before each code chunk
+again and again.
+
+Note that `\foreach` is used for each non-letters (expanded via \string
+because we needn't treat with active or special TeX characters). The
+keyword is applied in the `\foreach` loop too.
+
+See `hi-sytax.opm` for more information about `\hicolor`, `\replfromto` and
+`\replthis` macros.