Debian Codegraph @

texmf-dist/tex/optex/base/hisyntax-lua.opm

raw
1 %% This is part of the OpTeX project, see http://petr.olsak.net/optex
2
3 \_codedecl \_hisyntaxlua {Syntax highlighting for Lua sources <2025-12-02>}
4
5 \_newtoks \_hisyntaxlua \_newtoks \_hicolorslua
6
7 \_global\_hicolorslua={% colors for the Lua language
8 \_hicolor K \Red % Keywords
9 \_hicolor S \Magenta % Strings
10 \_hicolor C \Green % Comments
11 \_hicolor N \Cyan % Numbers
12 \_hicolor P \Blue % Preprocessor
13 \_hicolor O \Blue % Other tokens
14 }
15 \_global\_hisyntaxlua={%
16 \_the\_hicolorslua
17 \_let\c=\_relax \_let\e=\_relax \_let\o=\_relax
18 % multiline comments and strings are supported only for levels 0,1,2,3.
19 \_replfromto {--[[}{]]} {\x C{--[[#1]]}}% multi line comment --[[...]]
20 \_replfromto {--[=[}{]=]} {\x C{--[=[#1]=]}}% multi line comment --[=[...]=]
21 \_replfromto {--[==[}{]==]} {\x C{--[==[#1]==]}}% multi line comment --[==[...]==]
22 \_replfromto {--[===[}{]===]} {\x C{--[===[#1]===]}}% multi line comment --[===[...]===]
23 \_replthis {\_string\"} {{\_string\"}}% \" protected inside strings
24 \_replthis {\_string\'} {{\_string\'}}% \' protected inside strings
25 \_replfromto {[[}{]]} {\x S{[[#1]]}}% strings [[...]]
26 \_replfromto {[=[}{]=]} {\x S{[=[#1]=]}}% strings [=[...]=]
27 \_replfromto {[==[}{]==]} {\x S{[==[#1]==]}}% strings [==[...]==]
28 \_replfromto {[===[}{]===]} {\x S{[===[#1]===]}}% strings [===[...]===]
29 \_replfromto {"}{"} {\x S{"#1"}}% "..."
30 \_replfromto {'}{'} {\x S{'#1'}}% "..."
31 \_replfromto {--}{^^J} {\z C{--#1}^^J}% single line comment --...
32 \_edef\_tmpa {{<<}{>>}{//}{==}{\_string~=}{<=}{>=}{::}{...}{..}%
33 +-*/\_pcent^\_csstring\#\_string&\_string~|%
34 <>=()]\_string{\_string}[];:,.}% other tokens
35 \_ea \_foreach \_tmpa
36 \_do {\_replthis{#1}{\n\o{#1}\n}}%
37 \_foreach % keywords
38 {and}{break}{do}{else}{elseif}{end}{false}{for}{function}{goto}%
39 {if}{in}{local}{nil}{not}{or}{repeat}{return}{then}{true}{until}{while}%
40 \_do {\_replthis{\n#1\n}{\z K{#1}}}%
41 \_replthis{.}{\n.\n} % numbers
42 \_foreach 0123456789
43 \_do {\_replfromto{\n#1}{\n}{\c#1##1\e}}%
44 \_replthis{\e.\c}{.}%
45 \_replthis{\e.\n}{.\e}%
46 \_replthis{\n.\c}{\c.}%
47 \_replthis{e\e\o+\c}{e+}\_replthis{e\e\o-\c}{e-}%
48 \_replthis{E\e\o+\c}{E+}\_replthis{E\e\o-\c}{E-}%
49 \_def\o#1{\z O{#1}}%
50 \_def\c#1\e{\z N{#1}}%
51 }
52
53 \_endcode %------------------------------------------------
54
55 The list of keywords and special symbols comes from the Lua 5.3 Reference
56 Manual\fnote{\url{https://www.lua.org/manual/5.3/manual.html\#3}}, otherwise
57 this is mostly a port of `hisyntax-c.opm`.
58
59
60 \begtt \hisyntax{lua}
61 and break do else elseif end
62 false for function goto if in
63 local nil not or repeat return
64 then true until while
65
66 + - * / % ^ #
67 & ~ | << >> //
68 == ~= <= >= < > =
69 ( ) { } [ ] ::
70 ; : , . .. ...
71
72 a = 'alo\n123"'
73 a = "alo\n123\""
74 a = '\97lo\10\04923"'
75 a = [[alo
76 123"]]
77 a = [==[
78 alo
79 123"]==]
80
81 3 345 0xff 0xBEBADA
82
83 3.0 3.1416 314.16e-2 0.31416E1 34e1
84 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
85
86 1+1 2+a
87
88
89 --[[ multi line
90 comment
91 ]]
92 print(1+1)
93 \endtt
94
95
96 2025-12-02 comments and strings with [=[, [==[, [===[ supported
97 2025-11-28 multi line comment fixed
98 2021-06-29 released