diff options
Diffstat (limited to 'macros/luatex/optex/base/hi-syntax.opm')
-rw-r--r-- | macros/luatex/optex/base/hi-syntax.opm | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/macros/luatex/optex/base/hi-syntax.opm b/macros/luatex/optex/base/hi-syntax.opm index 540c618242..eb6d747914 100644 --- a/macros/luatex/optex/base/hi-syntax.opm +++ b/macros/luatex/optex/base/hi-syntax.opm @@ -1,24 +1,24 @@ -%% This is part of OpTeX project, see http://petr.olsak.net/optex +%% This is part of the OpTeX project, see http://petr.olsak.net/optex \_codedecl \hisyntax {Syntax highlithing of verbatim listings <2020-04-04>} % preloaded in format \_doc ----------------------------- - The following macros `\replfromto` and `\replthis` manipulate with the + The following macros `\replfromto` and `\replthis` manipulate with the verbatim text which has been read already and stored in the `\_tmpb` macro. - + The \`\replfromto` `{<from>}{<to>}{<what>}` finds first `<from>` then the - first `<to>` following by `<from>` pattern and the + first `<to>` following by `<from>` pattern and the `<text>` between them is packed to `#1`. Then `<from><text><to>` is replaced by `<what>`. The `<what>` parameter can use `#1` which is replaced by the `<text>`. The `\replfromto` continues by finding next `<from>`, then, next `<to>` - repeatedly over the whole verbatim text. If the verbatim text is ended by - opened `<from>` but not closing by `<to>` then `<to>` is appended to the - verbatim text automatically and the last part of verbatim text is replaced too. + repeatedly over the whole verbatim text. If the verbatim text is ended by + opened `<from>` but not closing by `<to>` then `<to>` is appended to the + verbatim text automatically and the last part of the verbatim text is replaced too. First two parameters are expanded before usage of `\replfromto`. You can - use `\csstring\%` or something else here. + use `\csstring\%` or something else here. \_cod ----------------------------- \_def\_replfromto #1#2{\_edef\_tmpa{{#1}{#2}}\_ea\_replfromtoE\_tmpa} @@ -26,10 +26,10 @@ \_def\_replfrom##1#1##2{\_addto\_tmpb{##1}% \_ifx\_end##2\_ea\_replstop \_else \_afterfi{\_replto##2}\_fi}% \_def\_replto##1#2##2{% - \_ifx\_end##2\_afterfi{\_replfin##1}\_else + \_ifx\_end##2\_afterfi{\_replfin##1}\_else \_addto\_tmpb{#3}% \_afterfi{\_replfrom##2}\_fi}% - \_def\_replfin##1#1\_end{\_addto\_tmpb{#3}\_replstop}% + \_def\_replfin##1#1\_end{\_addto\_tmpb{#3}\_replstop}% \_edef\_tmpb{\_ea}\_ea\_replfrom\_tmpb#1\_end#2\_end\_end\_relax } \_def\_replstop#1\_end\_relax{} @@ -55,7 +55,7 @@ The \`\_xscan` macro does replacing `\x` by `\z` in the post-processing phase. The `\x <letter>{<text>}` expands to `\_xscan {<letter>}<text>^^J^`. - If `#3` is `\_end` then it signals that something wrong happens, the + If `#3` is `\_end` then it signals that something wrong happens, the `<from>` was not terminated by legal `<to>` when `\replfromto` did work. We must to fix it by the \`\_xscanR` macro. \_cod ----------------------------- @@ -67,7 +67,7 @@ \_doc ----------------------------- The \`\hicolor` `<letter> <color>` defines `\_z<letter>{<text>}` - as `{<color><text>}`. It should be used in the context of + as `{<color><text>}`. It should be used in the context of `\x <letter>{<text>}` macros. \_cod ----------------------------- @@ -76,9 +76,9 @@ \_doc ----------------------------- The \`\hisyntax``{<name>}` re-defines default \^`\_prepareverbdata``<macro><verbtext>` in order to it does more things: - It saves `<verbtext>` to `\_tmpb`, appends `\n` around spaces and - `^^J` characters in pre-processing phase, it opens `hisyntax-<name>.opm` - file if `\_hisyntax<name>` is not defined. Then `\_the\_isyntax<name>` + It saves `<verbtext>` to `\_tmpb`, appends `\n` around spaces and + `^^J` characters in pre-processing phase, it opens `hisyntax-<name>.opm` + file if `\_hisyntax<name>` is not defined. Then `\_the\_isyntax<name>` is processed. Finally, the post-processing phase is realized by setting appropriate values to `\x` and `\y` macros and doing `\_edef\_tmpb{\_tmpb}`. @@ -138,12 +138,12 @@ The user can write \endtt and the code is colorized by C syntax. The user can write `\everytt={\hisyntax{C}}` and all verbatim listings are -colorized. +colorized. The \^`\hisyntax``{<name>}` reads the file `hisyntax-<name>.opm` where the colorization is declared. The parameter `<name>` is case insensitive and the -file name must include it in lowercase letters. For example the file -`hisyntax-c.opm` looks like: +file name must include it in lowercase letters. For example, the file +`hisyntax-c.opm` looks like this: \printdoc hisyntax-c.opm @@ -153,8 +153,8 @@ You can take inspiration from these files and declare more languages. User can re-declare colors by `\hicolors={...}` This value has precedence before `\_hicolors<name>` values declared in the `hicolors-<name>.opm` file. What exactly to do: copy `\_hicolors<name>={...}` -from `hicolors-<name>.opm` to your document, -rename it as `\hicolors={...}` and do you own colors modifications. +from `hicolors-<name>.opm` to your document, +rename it as `\hicolors={...}` and do you own colors modifications. Another way to set non-default colors is to declare `\newtoks\hicolors<name>` (without the `_` prefix) and set the colors palette here. @@ -162,15 +162,13 @@ It has precedence before `\_hicolors<name>` (with the `_` prefix) declared in the `hicolors-<name>.opm` file. This is useful when there are more hi-syntax languages used in one document. -\medskip -\noindent{\bf Notes for hi-syntax macro writers} - -The file `hisyntax-<name>.opm` is read only once in the \TeX/ group. -If there are definitions then they must be declared as global. +\secl4 Notes for hi-syntax macro writers +The file `hisyntax-<name>.opm` is read only once in the \TeX/ group. +If there are definitions then they must be declared as global. The `hisyntax-<name>.opm` file must (globally) declare `\_hisyntax<name>` tokens string where the action over verbatim text is declared typically by `\replfromto` or -`\replthis` macros. +`\replthis` macros. The verbatim text is prepared by {\em pre-processing phase}, then the `\_hisyntax<name>` is applied and then {\em post-processing phase} does final @@ -183,12 +181,12 @@ The pre-processing phase does: finding whole words (no subwords). The `\n` control sequence is removed in the post-processing phase. * Each end of line is represented by `\n^^J\n`. -* The `\_start` control sequence is added before the verbatim text and `\_end` control +* The `\_start` control sequence is added before the verbatim text and the `\_end` control sequence is appended to the end of the verbatim text. These control - sequences are removed in post-processing phase. -\enditems + sequences are removed in the post-processing phase. +\enditems -There are special macros working only in a group when processing the verbatim +Special macros are working only in a group when processing the verbatim text. @@ -209,12 +207,12 @@ text. by `\x C{<text>}` and they are replaced to `\z C{<text>}` without any change. But: \begtt \catcode`\<=13 - \x C{<text1>^^J<text3>^^J<text3>} + \x C{<text1>^^J<text3>^^J<text3>} is replaced by \z C{<text1>}^^J\z C{<text2>}^^J\z C{<text3>} \endtt The `\z <letter>{<text>}` is expanded to `\_z:<letter>{<text>}` and if - `\hicolor <letter> <color>` is declared then + `\hicolor <letter> <color>` is declared then `\_z:<letter>{<text>}` expands to `{<color><text>}`. So, required color is activated at all lines (separately) where C comment spans. * `\y {<text>}` is replaced by `\<text>` in the post processing phase. It should |