|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!DOCTYPE language [ |
| 3 | + <!ENTITY float "(\.?[0-9]+|[0-9]+\.[0-9]*)"> |
| 4 | + |
| 5 | + <!ENTITY ident0 "[a-zA-Z_]"> |
| 6 | + <!ENTITY identn "[a-zA-Z0-9_\-]"> |
| 7 | + <!ENTITY ident "&ident0;&identn;*"> |
| 8 | + <!ENTITY boundl "(?<!&ident0;)"> |
| 9 | + <!ENTITY boundr "(?!&identn;)"> |
| 10 | + <!ENTITY fmtbdl "(?<=\W|^)"> |
| 11 | + <!ENTITY fmtbdr "(?=\W|$)"> |
| 12 | +]> |
| 13 | + |
| 14 | +<!-- |
| 15 | + SPDX-FileCopyrightText: 2024 Marco Rebhan <[email protected]> |
| 16 | +
|
| 17 | + SPDX-License-Identifier: MIT |
| 18 | +--> |
| 19 | + |
| 20 | +<language |
| 21 | + name="Typst" |
| 22 | + version="1" |
| 23 | + kateversion="5.79" |
| 24 | + section="Markup" |
| 25 | + extensions="*.typ" |
| 26 | + casesensitive="1" |
| 27 | + author= "Marco Rebhan <[email protected]>" |
| 28 | + license="MIT" |
| 29 | + priority="1" |
| 30 | +> |
| 31 | + <highlighting> |
| 32 | + <list name="bool"> |
| 33 | + <item>true</item> |
| 34 | + <item>false</item> |
| 35 | + </list> |
| 36 | + <contexts> |
| 37 | + <context name="Markup" attribute="Normal Text" lineEndContext="#stay"> |
| 38 | + <IncludeRules context="Comment Rules" /> |
| 39 | + <RegExpr String="&fmtbdl;\*" attribute="Strong" context="Strong" /> |
| 40 | + <RegExpr String="&fmtbdl;_" attribute="Emphasis" context="Emphasis" /> |
| 41 | + <RegExpr String="```(`*)" attribute="Raw Text" context="Big Raw Text" /> |
| 42 | + <DetectChar char="`" attribute="Raw Text" context="Raw Text" /> |
| 43 | + <RegExpr String="^\s*=+.*" column="0" attribute="Heading" /> |
| 44 | + <RegExpr String="^\s*[-+]" column="0" attribute="List" /> |
| 45 | + <RegExpr String="\\(u\{[0-9A-Za-z]+\}|.?)" attribute="Special Char" /> |
| 46 | + <RegExpr String="https?://[0-9A-Za-z-._~:/?#\[\]@!\$&'\(\)\*\+,;%=]+" attribute="URL Literal" /> |
| 47 | + <DetectChar char="$" attribute="Math" context="Math" beginRegion="Math" /> |
| 48 | + <DetectChar char="#" attribute="Code Keyword" context="Code" /> |
| 49 | + <RegExpr String="<&ident;>" attribute="Label" /> |
| 50 | + <RegExpr String="@&ident;" attribute="Label Reference" /> |
| 51 | + <!-- |
| 52 | + Keep track of nested [] so we don't prematurely pop: |
| 53 | +
|
| 54 | + #[ text containing [] ] |
| 55 | + --> |
| 56 | + <DetectChar char="[" context="Markup Inner []" /> |
| 57 | + </context> |
| 58 | + <context name="Strong" attribute="Strong"> |
| 59 | + <RegExpr String="\*&fmtbdr;" attribute="Strong" context="#pop" /> |
| 60 | + <IncludeRules context="Markup" /> |
| 61 | + </context> |
| 62 | + <context name="Emphasis" attribute="Emphasis"> |
| 63 | + <RegExpr String="_&fmtbdr;" attribute="Emphasis" context="#pop" /> |
| 64 | + <IncludeRules context="Markup" /> |
| 65 | + </context> |
| 66 | + <context name="Raw Text" attribute="Raw Text"> |
| 67 | + <DetectChar char="`" attribute="Raw Text" context="#pop" /> |
| 68 | + </context> |
| 69 | + <context name="Big Raw Text" attribute="Raw Text"> |
| 70 | + <StringDetect String="```%1" dynamic="true" attribute="Raw Text" context="#pop" /> |
| 71 | + </context> |
| 72 | + |
| 73 | + <context name="Markup Block" attribute="Normal Text"> |
| 74 | + <DetectChar char="]" attribute="Operator" context="#pop" endRegion="Markup Block" /> |
| 75 | + <IncludeRules context="Markup" /> |
| 76 | + </context> |
| 77 | + <context name="Markup Inner []" attribute="Normal Text"> |
| 78 | + <DetectChar char="]" context="#pop" /> |
| 79 | + <IncludeRules context="Markup" /> |
| 80 | + </context> |
| 81 | + <context name="Markup Block Call" attribute="Normal Text"> |
| 82 | + <DetectChar char="]" attribute="Operator" context="#pop!Continued Expression" endRegion="Markup Block" /> |
| 83 | + <IncludeRules context="Markup Block" /> |
| 84 | + </context> |
| 85 | + |
| 86 | + <context name="Code" attribute="Code" lineEndContext="#pop!Line Error" fallthroughContext="#pop!Line Error"> |
| 87 | + <!-- |
| 88 | + Start of #-expression inside of a markup context. Needs |
| 89 | + special handling because we need to automatically return to |
| 90 | + the markup context at the end of the expression. |
| 91 | + --> |
| 92 | + <!-- Keep this synced with Nested Code below! --> |
| 93 | + <DetectSpaces /> |
| 94 | + <IncludeRules context="Comment Rules" /> |
| 95 | + <WordDetect String="none" attribute="Builtin" context="#pop!Continued Expression" /> |
| 96 | + <WordDetect String="auto" attribute="Builtin" context="#pop!Continued Expression" /> |
| 97 | + <keyword String="bool" attribute="Builtin" context="#pop!Continued Expression" /> |
| 98 | + <RegExpr String="&float;(fr|em|pt|mm|cm|in|%)" attribute="Float" context="#pop!Continued Expression" /> |
| 99 | + <Float attribute="Float" context="#pop!Continued Expression" /> |
| 100 | + <Int attribute="Int" context="#pop!Continued Expression" /> |
| 101 | + <DetectChar char=""" attribute="String" context="#pop!String" /> |
| 102 | + <RegExpr String="```(`*)" attribute="Raw Text" context="#pop!Big Raw Text" /> |
| 103 | + <DetectChar char="`" attribute="Raw Text" context="#pop!Raw Text" /> |
| 104 | + <DetectChar char="$" attribute="Math" context="#pop!Math" beginRegion="Math" /> |
| 105 | + <RegExpr String="<&ident;>" attribute="Label" context="Continued Expression" /> |
| 106 | + <DetectChar char="(" attribute="Operator" context="#pop!Parentheses" beginRegion="Parentheses" /> |
| 107 | + <DetectChar char="[" attribute="Operator" context="#pop!Markup Block" beginRegion="Markup Block" /> |
| 108 | + <DetectChar char="{" attribute="Operator" context="#pop!Code Block" beginRegion="Code Block" /> |
| 109 | + <Detect2Chars char="!" char1="=" attribute="Operator" /> |
| 110 | + <Detect2Chars char=">" char1="=" attribute="Operator" /> |
| 111 | + <Detect2Chars char="<" char1="=" attribute="Operator" /> |
| 112 | + <Detect2Chars char="+" char1="=" attribute="Operator" /> |
| 113 | + <Detect2Chars char="-" char1="=" attribute="Operator" /> |
| 114 | + <Detect2Chars char="=" char1="=" attribute="Operator" /> |
| 115 | + <AnyChar String="!><+-=" attribute="Operator" /> |
| 116 | + <WordDetect String="in" attribute="Operator" /> |
| 117 | + <WordDetect String="import" attribute="Import" context="#pop!Import" /> |
| 118 | + <WordDetect String="show" attribute="Code Keyword" context="#pop!Show" /> |
| 119 | + <WordDetect String="set" attribute="Code Keyword" context="#pop!Set" /> |
| 120 | + <WordDetect String="let" attribute="Code Keyword" context="#pop!Let" /> |
| 121 | + <WordDetect String="if" attribute="Control Flow" context="#pop!If" /> |
| 122 | + <WordDetect String="else" attribute="Control Flow" /> |
| 123 | + <WordDetect String="while" attribute="Control Flow" context="#pop!While" /> |
| 124 | + <WordDetect String="for" attribute="Control Flow" context="#pop!For" /> |
| 125 | + <WordDetect String="break" attribute="Control Flow" /> |
| 126 | + <WordDetect String="continue" attribute="Control Flow" /> |
| 127 | + <WordDetect String="return" attribute="Control Flow" /> |
| 128 | + <RegExpr String="&boundl;&ident;&boundr;" context="#pop!Continued Expression" /> |
| 129 | + </context> |
| 130 | + <context name="Nested Code" attribute="Code"> |
| 131 | + <!-- Keep this synced with Code above! --> |
| 132 | + <DetectSpaces /> |
| 133 | + <IncludeRules context="Comment Rules" /> |
| 134 | + <WordDetect String="none" attribute="Builtin" context="Continued Expression" /> |
| 135 | + <WordDetect String="auto" attribute="Builtin" context="Continued Expression" /> |
| 136 | + <keyword String="bool" attribute="Builtin" context="Continued Expression" /> |
| 137 | + <RegExpr String="&float;(fr|em|pt|mm|cm|in|%)" attribute="Float" context="Continued Expression" /> |
| 138 | + <Float attribute="Float" context="Continued Expression" /> |
| 139 | + <Int attribute="Int" context="Continued Expression" /> |
| 140 | + <DetectChar char=""" attribute="String" context="String" /> |
| 141 | + <RegExpr String="```(`*)" attribute="Raw Text" context="Big Raw Text" /> |
| 142 | + <DetectChar char="`" attribute="Raw Text" context="Raw Text" /> |
| 143 | + <DetectChar char="$" attribute="Math" context="Math" beginRegion="Math" /> |
| 144 | + <RegExpr String="<&ident;>" attribute="Label" context="Continued Expression" /> |
| 145 | + <DetectChar char="(" attribute="Operator" context="Parentheses" beginRegion="Parentheses" /> |
| 146 | + <DetectChar char="[" attribute="Operator" context="Markup Block" beginRegion="Markup Block" /> |
| 147 | + <DetectChar char="{" attribute="Operator" context="Code Block" beginRegion="Code Block" /> |
| 148 | + <Detect2Chars char="!" char1="=" attribute="Operator" /> |
| 149 | + <Detect2Chars char=">" char1="=" attribute="Operator" /> |
| 150 | + <Detect2Chars char="<" char1="=" attribute="Operator" /> |
| 151 | + <Detect2Chars char="+" char1="=" attribute="Operator" /> |
| 152 | + <Detect2Chars char="-" char1="=" attribute="Operator" /> |
| 153 | + <Detect2Chars char="=" char1="=" attribute="Operator" /> |
| 154 | + <AnyChar String="!><+-=" attribute="Operator" /> |
| 155 | + <WordDetect String="in" attribute="Operator" /> |
| 156 | + <WordDetect String="import" attribute="Import" context="Import" /> |
| 157 | + <WordDetect String="show" attribute="Code Keyword" context="Show" /> |
| 158 | + <WordDetect String="set" attribute="Code Keyword" context="Set" /> |
| 159 | + <WordDetect String="let" attribute="Code Keyword" context="Let" /> |
| 160 | + <WordDetect String="if" attribute="Control Flow" context="If" /> |
| 161 | + <WordDetect String="else" attribute="Control Flow" /> |
| 162 | + <WordDetect String="while" attribute="Control Flow" context="While" /> |
| 163 | + <WordDetect String="for" attribute="Control Flow" context="For" /> |
| 164 | + <WordDetect String="break" attribute="Control Flow" /> |
| 165 | + <WordDetect String="continue" attribute="Control Flow" /> |
| 166 | + <WordDetect String="return" attribute="Control Flow" /> |
| 167 | + <RegExpr String="&boundl;&ident;&boundr;" context="Continued Expression" /> |
| 168 | + </context> |
| 169 | + |
| 170 | + <context name="Code Block" attribute="Code"> |
| 171 | + <DetectChar char="}" attribute="Operator" context="#pop" endRegion="Code Block" /> |
| 172 | + <IncludeRules context="Nested Code" /> |
| 173 | + </context> |
| 174 | + |
| 175 | + <context name="Continued Expression" attribute="Code" lineEndContext="#pop" fallthroughContext="#pop"> |
| 176 | + <DetectChar char="(" attribute="Operator" context="#pop!Function Call" /> |
| 177 | + <DetectChar char="[" attribute="Operator" context="#pop!Markup Block Call" beginRegion="Markup Block" /> |
| 178 | + <DetectChar char="." attribute="Operator" context="Value Access" /> |
| 179 | + </context> |
| 180 | + |
| 181 | + <context name="Value Access" attribute="Code" lineEndContext="#pop" fallthroughContext="#pop!Line Error"> |
| 182 | + <RegExpr String="&boundl;&ident;&boundr;" context="#pop!Continued Expression" /> |
| 183 | + </context> |
| 184 | + |
| 185 | + <context name="Parentheses" attribute="Code"> |
| 186 | + <DetectChar char=")" attribute="Operator" context="#pop!Continued Expression" endRegion="Parentheses" /> |
| 187 | + <DetectChar char="," attribute="Operator" /> |
| 188 | + <IncludeRules context="Nested Code" /> |
| 189 | + </context> |
| 190 | + <context name="Function Call" attribute="Code"> |
| 191 | + <DetectChar char=":" attribute="Operator" context="Function Call - Parameter" /> |
| 192 | + <IncludeRules context="Parentheses" /> |
| 193 | + </context> |
| 194 | + <context name="Function Call - Parameter" attribute="Code"> |
| 195 | + <DetectChar char="," attribute="Operator" context="#pop" /> |
| 196 | + <IncludeRules context="Code" /> |
| 197 | + </context> |
| 198 | + |
| 199 | + <context name="Import" attribute="Code" lineEndContext="#pop" fallthroughContext="#pop"> |
| 200 | + <DetectChar char=":" attribute="Operator" context="#pop!Import 1" /> |
| 201 | + <IncludeRules context="Nested Code" /> |
| 202 | + </context> |
| 203 | + <context name="Import 1" attribute="Code" fallthroughContext="#pop!Line Error"> |
| 204 | + <DetectSpaces /> |
| 205 | + <DetectChar char="*" attribute="Operator" context="#pop" /> |
| 206 | + <RegExpr String="&boundl;&ident;&boundr;" context="#pop!Import 2" /> |
| 207 | + </context> |
| 208 | + <context name="Import 2" attribute="Code" lineEndContext="#pop" fallthroughContext="#pop"> |
| 209 | + <DetectSpaces /> |
| 210 | + <DetectChar char="," attribute="Operator" context="#pop!Import 1" /> |
| 211 | + </context> |
| 212 | + |
| 213 | + <context name="Show" attribute="Code"> |
| 214 | + <DetectSpaces /> |
| 215 | + <DetectChar char=":" attribute="Operator" context="#pop!Code" /> |
| 216 | + <IncludeRules context="Nested Code" /> |
| 217 | + </context> |
| 218 | + |
| 219 | + <context name="Set" attribute="Code" lineEndContext="#pop!Line Error" fallthroughContext="#pop!Line Error"> |
| 220 | + <DetectSpaces /> |
| 221 | + <RegExpr String="&boundl;&ident;&boundr;" attribute="Element" context="#pop!Set 1" /> |
| 222 | + </context> |
| 223 | + <context name="Set 1" attribute="Code"> |
| 224 | + <DetectSpaces /> |
| 225 | + <DetectChar char="(" attribute="Operator" context="#pop!Function Call" /> |
| 226 | + </context> |
| 227 | + |
| 228 | + <context name="Let" attribute="Code" fallthroughContext="#pop!Line Error"> |
| 229 | + <DetectSpaces /> |
| 230 | + <RegExpr String="&boundl;&ident;&boundr;" attribute="Element" context="#pop!Let 1" /> |
| 231 | + </context> |
| 232 | + <context name="Let 1" attribute="Code"> |
| 233 | + <DetectChar char="(" attribute="Operator" context="#pop!Let 2" /> |
| 234 | + <IncludeRules context="Let 3" /> |
| 235 | + </context> |
| 236 | + <context name="Let 2" attribute="Code"> |
| 237 | + <DetectChar char=")" attribute="Operator" context="#pop!Let 3" /> |
| 238 | + <IncludeRules context="Function Call" /> |
| 239 | + </context> |
| 240 | + <context name="Let 3" attribute="Code"> |
| 241 | + <DetectSpaces /> |
| 242 | + <DetectChar char="=" attribute="Operator" context="#pop!Code" /> |
| 243 | + </context> |
| 244 | + |
| 245 | + <context name="If" attribute="Code"> |
| 246 | + <DetectChar char="{" attribute="Operator" context="#pop!Code Block" beginRegion="Code Block" /> |
| 247 | + <DetectChar char="[" attribute="Operator" context="#pop!Markup Block" beginRegion="Markup Block" /> |
| 248 | + <IncludeRules context="Nested Code" /> |
| 249 | + </context> |
| 250 | + |
| 251 | + <context name="While" attribute="Code"> |
| 252 | + <DetectChar char="{" attribute="Operator" context="#pop!Code Block" beginRegion="Code Block" /> |
| 253 | + <DetectChar char="[" attribute="Operator" context="#pop!Markup Block" beginRegion="Markup Block" /> |
| 254 | + <IncludeRules context="Nested Code" /> |
| 255 | + </context> |
| 256 | + |
| 257 | + <context name="For" attribute="Code"> |
| 258 | + <DetectChar char="{" attribute="Operator" context="#pop!Code Block" beginRegion="Code Block" /> |
| 259 | + <DetectChar char="[" attribute="Operator" context="#pop!Markup Block" beginRegion="Markup Block" /> |
| 260 | + <WordDetect String="in" attribute="Control Flow" /> |
| 261 | + <IncludeRules context="Nested Code" /> |
| 262 | + </context> |
| 263 | + |
| 264 | + <context name="String" attribute="String"> |
| 265 | + <RegExpr String="\\." attribute="Special Char" /> |
| 266 | + <DetectChar char=""" attribute="String" context="#pop!Continued Expression" /> |
| 267 | + </context> |
| 268 | + |
| 269 | + |
| 270 | + <context name="Math" attribute="Math"> |
| 271 | + <DetectChar char="$" attribute="Math" context="#pop" endRegion="Math" /> |
| 272 | + <DetectChar char="#" attribute="Code Keyword" context="Code" /> |
| 273 | + </context> |
| 274 | + |
| 275 | + |
| 276 | + <context name="Line Error" attribute="Error" lineEndContext="#pop" /> |
| 277 | + |
| 278 | + |
| 279 | + <context name="Comment Rules" attribute="Normal Text" lineEndContext="#stay"> |
| 280 | + <Detect2Chars char="/" char1="/" attribute="Comment" context="Comment" /> |
| 281 | + <Detect2Chars char="/" char1="*" attribute="Comment" context="Multi-Line Comment" beginRegion="Comment" /> |
| 282 | + </context> |
| 283 | + <context name="Comment" attribute="Comment" lineEndContext="#pop"> |
| 284 | + <DetectSpaces attribute="Comment"/> |
| 285 | + <IncludeRules context="##Comments"/> |
| 286 | + <DetectIdentifier attribute="Comment" context="#stay" /> |
| 287 | + </context> |
| 288 | + <context name="Multi-Line Comment" attribute="Comment" lineEndContext="#stay"> |
| 289 | + <Detect2Chars char="*" char1="/" attribute="Comment" context="#pop" endRegion="Comment" /> |
| 290 | + <IncludeRules context="Comment" /> |
| 291 | + </context> |
| 292 | + </contexts> |
| 293 | + <itemDatas> |
| 294 | + <itemData name="Comment" defStyleNum="dsComment" /> |
| 295 | + <itemData name="Error" defStyleNum="dsError" /> |
| 296 | + |
| 297 | + <itemData name="Normal Text" defStyleNum="dsNormal" /> |
| 298 | + <itemData name="Heading" defStyleNum="dsFunction" bold="true" /> |
| 299 | + <itemData name="List" defStyleNum="dsNormal" bold="true" /> |
| 300 | + <itemData name="Strong" defStyleNum="dsNormal" bold="true" /> |
| 301 | + <itemData name="Emphasis" defStyleNum="dsNormal" italic="true" /> |
| 302 | + <itemData name="Raw Text" defStyleNum="dsSpecialString" /> |
| 303 | + <itemData name="URL Literal" defStyleNum="dsSpecialString" /> |
| 304 | + |
| 305 | + <itemData name="Code" defStyleNum="dsNormal" /> |
| 306 | + <itemData name="Code Keyword" defStyleNum="dsKeyword" /> |
| 307 | + <itemData name="Builtin" defStyleNum="dsBuiltIn" /> |
| 308 | + <itemData name="Int" defStyleNum="dsDecVal" /> |
| 309 | + <itemData name="Float" defStyleNum="dsFloat" /> |
| 310 | + <itemData name="String" defStyleNum="dsString" /> |
| 311 | + <itemData name="Special Char" defStyleNum="dsSpecialChar" /> |
| 312 | + <itemData name="Label" defStyleNum="dsVariable" /> |
| 313 | + <itemData name="Label Reference" defStyleNum="dsVariable" /> |
| 314 | + <itemData name="Operator" defStyleNum="dsOperator" /> |
| 315 | + <itemData name="Element" defStyleNum="dsVariable" /> |
| 316 | + <itemData name="Control Flow" defStyleNum="dsControlFlow" /> |
| 317 | + <itemData name="Import" defStyleNum="dsImport" /> |
| 318 | + |
| 319 | + <itemData name="Math" defStyleNum="dsSpecialString" /> |
| 320 | + </itemDatas> |
| 321 | + </highlighting> |
| 322 | + <general> |
| 323 | + <comments> |
| 324 | + <comment name="singleLine" start="//" /> |
| 325 | + <comment name="multiLine" start="/*" end="*/" region="Comment" /> |
| 326 | + </comments> |
| 327 | + <keywords casesensitive="1" weakDeliminator="-" additionalDeliminator="#" /> |
| 328 | + </general> |
| 329 | +</language> |
0 commit comments