<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!--
  Z80 assembly Kate SYNTAX HIGHLIGHTING RULES for SJASMPLUS assembler
  sjasmplus z00m's variant: https://github.com/z00m128/sjasmplus

  Created: Peter Helcmanovsky <ped@7gods.org>
  Version: 0.9.13 28/06/2026

  To install locally for your KDE5 desktop environment, copy the XML file into:
    ~/.local/share/org.kde.syntax-highlighting/syntax/
  (and restart the editors)

Changelog:
  // dd/mm/yyyy: version x.y (keep changelog in descending order)
  //   what was modified

  28/06/2026: version 0.9.13
    + new operator: pair, u16
    + new special: #line

  16/04/2026: version 0.9.12
    + new directive: sldopt
    + new operator: sizeof

  04/03/2026: version 0.9.11
    + labels identation by ">" character

  24/02/2026: version 0.9.10
    + new directive: hexout, hexend, savehex

  28/01/2026: version 0.9.9
    + new directive: dp, defp

  06/01/2026: version 0.9.8
    + new underscore digit separator

  20/08/2023: version 0.9.7
    + new device: amstradcpcplus
    + new directive: savecpr

  29/03/2022: version 0.9.6
    + new operator: exist
    + new devices: amstradcpc464, amstradcpc6128
    + new directives: save3dos, savecdt, savecpcsna
    + new label prefix combination: "@." (should work only inside macros, but works globally)
    + new temporary label syntax with underscored suffix ("123_b")

  21/01/2021: version 0.9.5
    + adding missing __DATE__/__TIME__ predefined defines

  08/12/2020: version 0.9.4
    + new directives: ELSEIF, WHILE, ENDW, [list of known DEVICEs]
    + new operator: abs
    + highlighting operators as "Normal Text" inside Arguments
    + new label prefix char "!"
    + DEFL/EQU expect only expression afterward (up to colon), instructions not possible

  18/08/2020: version 0.9.3
    + new directive TEXT added (STRUCT field)
    + adding support for EQU having comma delimited argument and closing curly braces

  27/07/2020: version 0.9.2
    + new directives added (RELOCATE_..., BPLIST, SETBP)
    + new predefined defines, new "norel" operator

  12/01/2020: version 0.9.1
    + fix after-label argument order of rules to work better with numeric constants

  11/01/2020: version 0.9
    + new directives added (MMU, CSPECTMAP, SAVEDEV)
    + new logic to deal with "label defl/=/equ expression" start of line (not perfect)
    + dot-repeater is now detected also after colon (second+ time on line)
    + dot-repeater is detected also after label=... expression
    + inlined Lua scripts gets now regular Lua syntax highlight (included from system)
    + fix: ".directive" (starting with dot) is highlighted as directive
    + fix: Error context ends with colon (`ret z : nop` was displaying `: nop` as error)

  28/05/2019: version 0.8.2
    + changes for new features after v1.13.0 (OPT, DEFARRAY+, ...)

  14/05/2019: version 0.8.1
    + adding backtick as word deliminator to cover new double-backtick multi-arg symbol
    + "repeater" directive ".expression" support (not doing correctly nested parentheses)

  13/04/2019: version 0.8
    + Numeric literals highlight rules extended with new C++ like rules

  12/04/2019: version 0.7
    Forked from my other asm-z80.xml syntax file, which is trying to support multiple
    Z80 assemblers at the same time. But I'm spending more time with sjasmplus lately.

  08/02/2019: version 0.6
    + fix: "out (c), 0" was not highlighted as unofficial instruction (space ahead 0)

  19/01/2019: version 0.5
    + "error" context added to report unexpected arguments on remaining line (only *FEW*
        cases are detected at the moment, it's nowhere near checking syntax properly)
    + Unofficial Z80 instructions highlighted as different category (dsExtension)
    + extra category for Z80N instructions (and Z80N control-flow instruction)
        (highlights as ordinary instructions by default, user can manually adjust colors)
    + string highlight separated for apostrophe and quotes (other will be part of string)
    + "hex" directive - improved check marking extra digit/non-digit as error
    + couple of instructions detection improved (adding "error" context for arguments,etc)

    This is probably one of last versions trying to stay "universal", as it works
    considerably well for me (after about one month of using it actively), future
    revisions will probably focus to narrow down syntax into more strict mode,
    preferring my desired code style, and particular assembler ("pasmoNext" probably).

  06/01/2019: version 0.2
    + instructions split into general group and control-flow group
    + comments now have TODO/FIXME/FIX ME highlighting support

  30/12/2018: version 0.1
    Initial version, released as part of ZXNextTests project (as "work in progress")

TODO missing things:
    - argument highlighting (symbols, operators, ...) and validation of expected number
        of arguments, etc... = of little importance to me personally, probably never
    - arguments-end turning back to instruction/error context
        This partially works, but doesn't try to fully validate expression, like
        parentheses nesting and operators having expected arguments (unary/binary/...)
        - needs rewrite from scratch to also parse label value expressions and do full analysis
    - macro/equ/label symbols differentiation = I would *love* these, but they are not
        possible with current Kate highlighting, as it would require extra input injected
        by editor through some new API, to provide list of various (type) symbols.
    - non-label identifiers (i.e. which are not valid labels (ignored by Label rules),
      but they are valid identifiers for DEFINE or macro argument names
    - Label identifiers rules into some xml macro (entities were in docs?).
    - when more finished, try to propose to upstream: https://github.com/KDE/syntax-highlighting/tree/master/data/syntax

-->
<language name="Z80 (sjasmplus)" section="Assembler" version="24" kateversion="5.0" extensions="*.asm;*.a80;*.s" mimetype="" author="Peter Helcmanovsky (ped@7gods.org)" license="MIT">
  <highlighting>
    <list name="registers">
      <!-- General purpose registers -->
      <item>a</item>
      <item>b</item>
      <item>c</item>
      <item>d</item>
      <item>e</item>
      <item>h</item>
      <item>l</item>
      <item>ixh</item>
      <item>ixl</item>
      <item>iyh</item>
      <item>iyl</item>
      <item>af</item>
      <item>bc</item>
      <item>de</item>
      <item>hl</item>
      <item>ix</item>
      <item>iy</item>
      <item>sp</item>
      <!-- Shadow registers (only af' can be used directly in instruction) -->
      <item>af'</item>
      <item>bc'</item>
      <item>de'</item>
      <item>hl'</item>
      <!-- Special registers -->
      <item>i</item>
      <item>r</item>
    </list>
    <list name="flow-instructions">
      <item>call</item>
      <item>djnz</item>
      <item>halt</item>
      <item>jp</item>
      <item>jr</item>
      <item>ret</item>
      <item>reti</item>
      <item>retn</item>
      <item>rst</item>
    </list>
    <list name="instructions">
      <item>adc</item>
      <item>add</item>
      <item>and</item>
      <item>bit</item>
      <item>ccf</item>
      <item>cp</item>
      <item>cpd</item>
      <item>cpdr</item>
      <item>cpi</item>
      <item>cpir</item>
      <item>cpl</item>
      <item>daa</item>
      <item>dec</item>
      <item>di</item>
      <item>ei</item>
      <item>ex</item>
      <item>exx</item>
      <item>im</item>
      <item>in</item>
      <item>inc</item>
      <item>ind</item>
      <item>indr</item>
      <item>ini</item>
      <item>inir</item>
      <item>ld</item>
      <item>ldd</item>
      <item>lddr</item>
      <item>ldi</item>
      <item>ldir</item>
      <item>neg</item>
      <item>nop</item>
      <item>or</item>
      <item>otdr</item>
      <item>otir</item>
      <item>out</item>
      <item>outd</item>
      <item>outi</item>
      <item>pop</item>
      <item>push</item>
      <item>res</item>
      <item>rl</item>
      <item>rla</item>
      <item>rlc</item>
      <item>rlca</item>
      <item>rld</item>
      <item>rr</item>
      <item>rra</item>
      <item>rrc</item>
      <item>rrca</item>
      <item>rrd</item>
      <item>sbc</item>
      <item>scf</item>
      <item>set</item>
      <item>sla</item>
      <item>sra</item>
      <item>srl</item>
      <item>sub</item>
      <item>xor</item>
    </list>
    <list name="instructions-unofficial">
      <!-- Unofficial instructions -->
      <item>sli</item>
    </list>
    <list name="instructions-z80n">
      <!-- ZX Spectrum Next (Z80N) extra instructions -->
      <item>brlc</item>
      <item>bsla</item>
      <item>bsra</item>
      <item>bsrf</item>
      <item>bsrl</item>
      <item>lddrx</item>
      <item>lddx</item>
      <item>ldirx</item>
      <item>ldix</item>
      <item>ldpirx</item>
      <item>ldws</item>
      <item>mirror</item>
      <item>mul</item>
      <item>nextreg</item>
      <item>outinb</item>
      <item>pixelad</item>
      <item>pixeldn</item>
      <item>setae</item>
      <item>swapnib</item>
      <item>test</item>
    </list>
    <list name="data">
      <!-- Initialized data -->
      <item>abyte</item>
      <item>abytec</item>
      <item>abytez</item>
      <item>block</item>
      <item>byte</item>
      <item>d24</item>
      <item>db</item>
      <item>dc</item>
      <item>dd</item>
      <item>defb</item>
      <item>defd</item>
      <item>defg</item>
      <item>defh</item>
      <item>defm</item>
      <item>defp</item>
      <item>defs</item>
      <item>defw</item>
      <item>dg</item>
      <item>dh</item>
      <item>dm</item>
      <item>dp</item>
      <item>ds</item>
      <item>dw</item>
      <item>dword</item>
      <item>dz</item>
      <item>hex</item>
      <item>text</item>
      <item>word</item>
      </list>
    <list name="directives">
      <item>align</item>
      <item>assert</item>
      <item>binary</item>
      <item>bplist</item>
      <item>cspectmap</item>
      <item>defarray</item>
      <item>defdevice</item>
      <item>define</item>
      <item>dephase</item>
      <item>device</item>
      <item>disp</item>
      <item>display</item>
      <item>dup</item>
      <item>edup</item>
      <item>else</item>
      <item>elseif</item>
      <item>emptytap</item>
      <item>emptytrd</item>
      <item>encoding</item>
      <item>end</item>
      <item>endif</item>
      <item>endm</item>
      <item>endmap</item>
      <item>endmod</item>
      <item>endmodule</item>
      <item>endr</item>
      <item>ends</item>
      <item>endt</item>
      <item>endw</item>
      <item>ent</item>
      <item>export</item>
      <item>field</item>
      <item>fpos</item>
      <item>hexout</item>
      <item>hexend</item>
      <item>if</item>
      <item>ifdef</item>
      <item>ifn</item>
      <item>ifndef</item>
      <item>ifnused</item>
      <item>ifused</item>
      <item>incbin</item>
      <item>inchob</item>
      <item>include</item>
      <item>includelua</item>
      <item>inctrd</item>
      <item>insert</item>
      <item>labelslist</item>
      <item>macro</item>
      <item>map</item>
      <item>memorymap</item>
      <item>mmu</item>
      <item>module</item>
      <item>opt</item>
      <item>org</item>
      <item>outend</item>
      <item>output</item>
      <item>page</item>
      <item>phase</item>
      <item>relocate_end</item>
      <item>relocate_start</item>
      <item>relocate_table</item>
      <item>rept</item>
      <item>save3dos</item>
      <item>saveamsdos</item>
      <item>savebin</item>
      <item>savecdt</item>
      <item>savecpcsna</item>
      <item>savecpr</item>
      <item>savedev</item>
      <item>savehex</item>
      <item>savehob</item>
      <item>savenex</item>
      <item>savesna</item>
      <item>savetap</item>
      <item>savetrd</item>
      <item>setbp</item>
      <item>setbreakpoint</item>
      <item>shellexec</item>
      <item>size</item>
      <item>sldopt</item>
      <item>slot</item>
      <item>struct</item>
      <item>tapend</item>
      <item>tapout</item>
      <item>textarea</item>
      <item>undefine</item>
      <item>unphase</item>
      <item>while</item>
    </list>
    <list name="operators"> <!-- TODO implement all of this -->
      <!-- Predefined values by assembler (not really an operator) -->
      <item>__SJASMPLUS__</item>
      <item>__VERSION__</item>
      <item>__PASS__</item>
      <item>__ERRORS__</item>
      <item>__WARNINGS__</item>
      <item>__INCLUDE_LEVEL__</item>
      <item>__BASE_FILE__</item>
      <item>__FILE__</item>
      <item>__LINE__</item>
      <item>__COUNTER__</item>
      <item>__DATE__</item>
      <item>__TIME__</item>
      <!-- Operators -->
      <item>abs</item>
      <item>and</item>
      <item>exist</item>
      <item>high</item>
      <item>low</item>
      <item>mod</item>
      <item>norel</item>
      <item>not</item>
      <item>or</item>
      <item>pair</item>
      <item>shl</item>
      <item>shr</item>
      <item>sizeof</item>
      <item>u16</item>
      <item>xor</item>
      <!-- other operators/symbols:
      $ $$ ! ~ + - * / % << >> >>> <? >? < > <= >= = == != & ^ | && || [ ] ( ) { }
      -->
      <!-- known devices names -->
      <item>AMSTRADCPC464</item>
      <item>AMSTRADCPC6128</item>
      <item>AMSTRADCPCPLUS</item>
      <item>NONE</item>
      <item>NOSLOT64K</item>
      <item>ZXSPECTRUM48</item>
      <item>ZXSPECTRUM128</item>
      <item>ZXSPECTRUM256</item>
      <item>ZXSPECTRUM512</item>
      <item>ZXSPECTRUM1024</item>
      <item>ZXSPECTRUM2048</item>
      <item>ZXSPECTRUM4096</item>
      <item>ZXSPECTRUM8192</item>
      <item>ZXSPECTRUMNEXT</item>
      </list>
    <contexts>
      <context name="LabelLine" attribute="Normal Text" lineEndContext="#stay" lineEmptyContext="#stay"
               fallthrough="true" fallthroughContext="Error">
        <!-- line can be indented by '>' -->
        <RegExpr attribute="Comment" context="#stay" String="^\s*>"/>
        <!-- Labels start at the beginning of the [indented] line, w/o label the "dotRepeat" context follows -->
        <RegExpr attribute="Label" context="#pop!afterLabel" String="(@\.|\.|@|\!|\!@|)[A-Za-z_][A-Za-z0-9_.?!#@]*(\+[0-9]|):?"/>
        <RegExpr attribute="Label" context="#pop!afterLabel" String="[0-9]+:?"/>
        <RegExpr attribute="Comment" context="#pop!Arguments" String="#\s*line\s+"/>
        <DetectSpaces attribute="Normal Text" context="#pop!dotRepeat"/>
        <DetectChar attribute="Comment" context="#pop!Normal" char=";" lookAhead="true"/>
        <Detect2Chars attribute="Comment" context="#pop!Normal" char="/" char1="/" lookAhead="true"/>
        <Detect2Chars attribute="Comment" context="#pop!Normal" char="/" char1="*" lookAhead="true"/>
        <DetectChar attribute="Normal Text" context="#pop!Normal" char="}"/>
      </context>

      <!-- Detect EQU/DEFL/= expressions, the argument now must end with colon (no instruction possible after expression since sjasmplus v1.18.0 -->
      <context name="afterLabel" attribute="Normal Text" lineEndContext="LabelLine" fallthrough="true" fallthroughContext="dotRepeat">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Directives" context="#pop!Arguments" char="=" />
        <WordDetect attribute="Directives" context="#pop!Arguments" String="DEFL"/>
        <WordDetect attribute="Directives" context="#pop!Arguments" String="defl"/>
        <WordDetect attribute="Directives" context="#pop!Arguments" String="EQU"/>
        <WordDetect attribute="Directives" context="#pop!Arguments" String="equ"/>
      </context>

      <context name="dotRepeat" attribute="Directives" lineEndContext="LabelLine" fallthrough="true" fallthroughContext="Normal">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <RegExpr attribute="Directives" context="#pop!Normal" String="\.(\d+|\(.*?\))\s"/>
      </context>
      <context name="Normal" attribute="Normal Text" lineEndContext="LabelLine"
               lineEmptyContext="LabelLine" fallthrough="true" fallthroughContext="Arguments">
        <!-- "normal" line, but without the label at beginning -->
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <IncludeRules context="BeginComment" />
        <WordDetect attribute="Data" context="Hexastring" insensitive="true" String="hex"/>
        <WordDetect attribute="Data" context="Hexastring" insensitive="true" String="dh"/>
        <WordDetect attribute="Data" context="Hexastring" insensitive="true" String="defh"/>
        <WordDetect attribute="Data" context="Bitstring" insensitive="true" String="dg"/>
        <WordDetect attribute="Data" context="Bitstring" insensitive="true" String="defg"/>
        <RegExpr attribute="Z80N Flow ins." context="Error" insensitive="true"
                 String="jp\s+\(c\)\s*"/>
        <RegExpr attribute="Control Flow ins." context="Arguments" insensitive="true"
                 String="(call|jp)\s+(nz|z|nc|c|po|pe|p|m|ns|s)\s*,"/>
        <RegExpr attribute="Control Flow ins." context="Arguments" insensitive="true"
                 String="jr\s+(nz|z|nc|c)\s*,"/>
        <RegExpr attribute="Control Flow ins." context="Error" insensitive="true"
                 String="ret\s+(nz|z|nc|c|po|pe|p|m|ns|s)\b\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="(in\s+(f,\s*|)\(c\)|out\s+\(c\),\s*0\b)\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="(rlc|rrc|rl|rr|sla|sll|sra|sli|sl1|srl)\s+\(\s*(ix|iy)\s*(\+|\-)[^;]*\),\s*[a-ehl]\b\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="(res|set)\s+[0-7],\s*\(\s*(ix|iy)\s*(\+|\-)[^;]*\),\s*[a-ehl]\b\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="(inc|dec|sub|and|or|xor|cp)\s+i[xy][lh]\b\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="(add|adc|sub|and|or|xor|cp)\s+a,\s*i[xy][lh]\b\s*"/>
        <RegExpr attribute="Unofficial ins." context="Arguments" insensitive="true"
                 String="ld\s+i[xy][lh],\s*"/>
        <RegExpr attribute="Unofficial ins." context="Error" insensitive="true"
                 String="ld\s+[a-e],\s*i[xy][lh]\b\s*"/>
        <keyword attribute="Control Flow ins." context="Arguments" String="flow-instructions"/>
        <keyword attribute="Unofficial ins." context="Arguments" String="instructions-unofficial"/>
        <keyword attribute="Z80N Instructions" context="Arguments" String="instructions-z80n"/>
        <keyword attribute="Instructions" context="Arguments" String="instructions"/>
        <keyword attribute="Data" context="Arguments" String="data"/>
        <!-- inlined LUA script block detection -->
        <RegExpr attribute="Directives" context="LuaInlinedScript_Enter"
                 String="\.?(lua|LUA)\b(\s+(PASS[123]|pass[123]|ALLPASS|allpass)|)\s*"/>
        <!-- directives detection is defined twice, to detect the directives starting with dot -->
        <DetectChar attribute="Directives" char=".">
            <WordDetect context="sourceEnd" String="end"/>
            <WordDetect context="sourceEnd" String="END"/>
            <WordDetect context="Arguments" String="defarray+"/>
            <WordDetect context="Arguments" String="DEFARRAY+"/>
            <keyword context="Arguments" String="directives"/>
        </DetectChar>
        <!-- end is defined twice (not "insensitive"), b/c "End" is label!, only all-up/all-low is -->
        <WordDetect attribute="Directives" context="sourceEnd" String="end"/>
        <WordDetect attribute="Directives" context="sourceEnd" String="END"/>
        <!-- defarray+ can't be found by keyword because of "+" being delimiter, when weak delimiter, then "(ix+1)" is not register :/ -->
        <WordDetect attribute="Directives" context="Arguments" String="defarray+"/>
        <WordDetect attribute="Directives" context="Arguments" String="DEFARRAY+"/>
        <keyword attribute="Directives" context="Arguments" String="directives"/>
      </context>

      <!-- After "END" directive show everything as comment -->
      <context name="sourceEnd" attribute="Comment" lineEndContext="#stay" />

      <context name="Error" attribute="Error" lineEndContext="#pop">
        <DetectChar attribute="Normal Text" context="#pop#pop!dotRepeat" char=":"/>
        <DetectChar attribute="Comment" context="Comment" char=";"/>
        <Detect2Chars attribute="Comment" context="Comment" char="/" char1="/"/>
      </context>

      <!-- "Hexastring" highlight for DEFH/DH/HEX directive -->
      <context name="Hexastring" attribute="Normal Text" lineEndContext="#pop"
               fallthrough="true" fallthroughContext="#pop!Error">
        <DetectChar attribute="Comment" context="HexastringQuoted" char="&quot;"/>
        <DetectChar attribute="Comment" context="HexastringQuoted" char="'"/>
        <DetectChar attribute="Comment" context="#stay" char=","/>
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <IncludeRules context="BeginComment" />
        <RegExpr attribute="BaseN" context="#stay" String="([0-9A-Fa-f]{2})+"/>
      </context>
      <context name="HexastringQuoted" attribute="Normal Text" lineEndContext="#pop"
               fallthrough="true" fallthroughContext="#pop#pop!Error">
        <DetectChar attribute="Comment" context="#pop" char="&quot;"/>
        <DetectChar attribute="Comment" context="#pop" char="'"/>
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <RegExpr attribute="BaseN" context="#stay" String="([0-9A-Fa-f]{2})+"/>
      </context>

      <!-- "Bitstring" highlight for DEFG/DG directive -->
      <context name="Bitstring" attribute="Data" lineEndContext="#pop"
               fallthrough="true" fallthroughContext="#pop!Error">
        <DetectSpaces attribute="Comment" context="#stay"/>
        <AnyChar String="&quot;'" attribute="Comment" context="#stay"/>
        <RegExpr attribute="Data" context="BitstringBits" lookAhead="true" String="(([^\s&quot;';][ \t]*){7}[^\s&quot;';])(.*)$"/>
      </context>
      <context name="BitstringBits" attribute="Data" lineEndContext="#pop#pop" dynamic="true">
        <RegExpr attribute="Data" context="#pop" String="%3$" lookAhead="true" dynamic="true" />
        <RegExpr String="[-._ \t]" attribute="Data" context="#stay" />
        <RegExpr String="." attribute="Number" context="#stay" />
      </context>

      <!-- "arguments" = generally anything what is not detected as instruction/directive or is comming after instruction -->
      <context name="Arguments" attribute="Normal Text" lineEndContext="#pop">
        <IncludeRules context="BeginComment" />
        <DetectChar attribute="Normal Text" context="#pop#pop!dotRepeat" char=":"/>
        <DetectChar attribute="String" context="StringApostrophe" char="'"/>
        <DetectChar attribute="String" context="String" char="&quot;"/>
        <keyword attribute="Registers" context="#stay" String="registers"/>
        <keyword attribute="Normal Text" context="#stay" String="operators"/>
        <RegExpr attribute="Label" context="#stay" String="(\.|@|)[A-Za-z_][A-Za-z0-9_.?!#@]*"/>
        <!-- temporary labels may be mistaken for binary number ("1b"), for 1-3 digits it's temporary label -->
        <RegExpr attribute="Label" context="#stay" String="\d{1,3}[bBfF]\b"/>
        <RegExpr attribute="Label" context="#stay" String="\d+_[bBfF]\b"/>  <!-- v1.19.0 temporary label syntax -->
        <!-- TODO but some DEFINE/macro-arg identifiers can avoid labels rules, like ".._" is valid! -->
        <!-- hexadecimal numbers -->
        <RegExpr attribute="BaseN" context="#stay" insensitive="true" String="((\$|0x|#)[a-f0-9]+(['_]?[a-f0-9]+)*|[0-9](['_]?[a-f0-9]+)*h)\b"/>
        <!-- octal numbers -->
        <RegExpr attribute="BaseN" context="#stay" insensitive="true" String="(0q[0-7](['_]?[0-7]+)*|[0-7](['_]?[0-7]+)*(q|o))\b"/>
        <!-- binary numbers -->
        <RegExpr attribute="BaseN" context="#stay" insensitive="true" String="((%|0b)[01](['_]?[01]+)*|[01](['_]?[01]+)*b)\b"/>
        <!-- decimal numbers -->
        <RegExpr attribute="Number" context="#stay" insensitive="true" String="\d(['_]?\d+)*d?\b"/>
        <Detect2Chars attribute="Number" context="#stay" char="$" char1="$"/>
        <DetectChar attribute="Number" context="#stay" char="$"/>
        <AnyChar String="!~+-*/%&lt;>?=&amp;^|[]()," attribute="Normal Text" context="#stay"/>
      </context>

      <!-- Comments, rules and contexts -->
      <context name="BeginComment" attribute="Comment" lineEndContext="#pop">
        <!-- this context just hold rules for starting comment, shouldn't be switched to -->
        <DetectChar attribute="Comment" context="Comment" char=";"/>
        <Detect2Chars attribute="Comment" context="Comment" char="/" char1="/"/>
        <Detect2Chars attribute="Comment" context="CommentB" char="/" char1="*" beginRegion="Comment"/>
        <Detect2Chars attribute="Error" context="Error" char="*" char1="/"/>
      </context>
      <context name="Comment" attribute="Comment" lineEndContext="#pop">
          <DetectSpaces />
          <RegExpr attribute="Alert" context="#stay" String="\b(TODO|FIX\s?ME|DEBUG)\b"/>
      </context>
      <context name="CommentB" attribute="Comment" lineEndContext="#stay">  <!-- block multiline comment /* */ -->
          <IncludeRules context="Comment" />
          <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment" />
          <!-- in sjasmplus the block comments actually can be nested! -->
          <Detect2Chars attribute="Comment" context="CommentB" char="/" char1="*" beginRegion="Comment"/>
      </context>

      <!-- Strings -->
      <context name="StringEscape" attribute="Char" fallthrough="true" fallthroughContext="#pop#pop!Error">
          <AnyChar String="\?'&quot;0AaBbDdEeFfNnRrTtVv" attribute="Char" context="#pop"/>
      </context>
      <context name="String" attribute="String" lineEndContext="#pop">
        <DetectChar attribute="Char" context="StringEscape" char="\"/>
        <DetectChar attribute="String" context="#pop" char="&quot;"/>
      </context>
      <context name="StringApostrophe" attribute="String" lineEndContext="#pop">
        <Detect2Chars attribute="Char" context="#stay" char="'" char1="'"/>
        <DetectChar attribute="String" context="#pop" char="'"/>
      </context>

        <context name="LuaInlinedScript_Enter" attribute="Error" lineEndContext="#pop!LuaInlinedScript">
            <DetectChar attribute="Comment" context="Comment" char=";"/>
            <Detect2Chars attribute="Comment" context="Comment" char="/" char1="/"/>
        </context>
        <context name="LuaInlinedScript" attribute="Normal Text" lineEndContext="#stay">
            <DetectChar attribute="Directives" char=".">
                <WordDetect context="#pop!Error" String="endlua"/>
                <WordDetect context="#pop!Error" String="ENDLUA"/>
            </DetectChar>
            <WordDetect attribute="Directives" context="#pop!Error" String="endlua"/>
            <WordDetect attribute="Directives" context="#pop!Error" String="ENDLUA"/>
            <IncludeRules context="Normal##Lua"/>
        </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text" defStyleNum="dsNormal"/>
      <itemData name="Error" defStyleNum="dsError"/>
      <itemData name="Registers" defStyleNum="dsVariable"/>
      <itemData name="Instructions" defStyleNum="dsKeyword"/>
      <itemData name="Unofficial ins." defStyleNum="dsExtension"/>
      <itemData name="Z80N Instructions" defStyleNum="dsKeyword"/>
      <itemData name="Z80N Flow ins." defStyleNum="dsControlFlow"/>
      <itemData name="Control Flow ins." defStyleNum="dsControlFlow"/>
      <itemData name="Directives" defStyleNum="dsPreprocessor"/>
      <itemData name="Comment" defStyleNum="dsComment"/>
      <itemData name="Alert" defStyleNum="dsAlert"/>
      <itemData name="Label" defStyleNum="dsFunction"/>
      <itemData name="Data" defStyleNum="dsDataType"/>
      <itemData name="BaseN" defStyleNum="dsBaseN"/>
      <itemData name="Float" defStyleNum="dsFloat"/>
      <itemData name="Number" defStyleNum="dsDecVal"/>
      <itemData name="Char" defStyleNum="dsChar"/>
      <itemData name="String" defStyleNum="dsString"/>
    </itemDatas>
  </highlighting>
  <general>
    <keywords casesensitive="0" additionalDeliminator="`"/>
    <comments>
      <comment name="singleLine" start=";" />
      <comment name="multiLine" start="/*" end="*/" />
    </comments>
  </general>
</language>
<!-- kate: space-indent on; indent-width 2; replace-tabs on; -->
