<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
    <!ENTITY hex "[0-9a-f]++h?">
    <!ENTITY oct_hex "[0-7]++(?:&hex;|[hoq]?)|&hex;">
    <!ENTITY bin_oct_hex "[01]++(?:&oct_hex;|[hoqb]?)|&oct_hex;">
]>
<!-- kate: space-indent on; indent-width 2; -->

<!-- Microchip PIC assembler syntaxfile for gpasm/mpasm assembler by
  * Original author: Alain GIBAUD (alain.gibaud@univ-valenciennes.fr)
  * Small modifications for the new DTD: Joseph Wenninger <jowenn@kde.org>
  * Updated for 16-bit devices, etc.: Laurence Withers <lwithers@users.sf.net>
-->

<language name="PicAsm" version="6" kateversion="5.62" section="Assembler" extensions="*.src;*.SRC;*.asm;*.ASM;*.pic;*.PIC" mimetype="text/x-PicSrc;text/x-PicHdr" author="Alain GIBAUD (alain.gibaud@univ-valenciennes.fr)" license="LGPL">
  
  <highlighting>
    <list name="directives">
      <item>__BADRAM</item>
      <item>__CONFIG</item>
      <item>__IDLOCS</item>
      <item>__MAXRAM</item>
      
      <item>cblock</item>
      <item>constant</item>
      <item>da</item>
      <item>data</item>
      <item>db</item>
      <item>de</item>
      <item>dt</item>
      <item>dw</item>
      <item>endc</item>
      <item>endm</item>
      <item>equ</item>
      <item>error</item>
      <item>errorlevel</item>
      <item>exitm</item>
      <item>fill</item>
      <item>list</item>
      <item>local</item>
      <item>macro</item>
      <item>messg</item>
      <item>noexpand</item>
      <item>nolist</item>
      <item>org</item>
      <item>page</item>
      <item>processor</item>
      <item>radix</item>
      <item>res</item>
      <item>set</item>
      <item>space</item>
      <item>subtitle</item>
      <item>title</item>
      <item>variable</item>
      <item>end</item>
    </list>
    
    <list name="conditional">
      <item>if</item>
      <item>else</item>
      <item>idef</item>
      <item>ifndef</item>
      <item>endif</item>
      <item>while</item>
      <item>include</item>
      <item>endw</item>
    </list>
    
    <list name="gpasm_macro">
      <item>addcf</item>
      <item>b</item>
      <item>clrc</item>
      <item>clrz</item>
      <item>setc</item>
      <item>setz</item>
      <item>movfw</item>
      <item>skpc</item>
      <item>skpz</item>
      <item>skpnc</item>
      <item>skpnz</item>
      <item>subcf</item>
      <item>tstf</item>
    </list>

    <list name="branch instructions">
      <item>bra</item>
      <item>brw</item>
      <item>bc</item>
      <item>bz</item>
      <item>bnc</item>
      <item>bnz</item>
      <item>call</item>
      <item>goto</item>
    </list>
    
    <list name="instructions">
      <item>addlw</item>
      <item>addwf</item>
      <item>addwfc</item>
      <item>andlw</item>
      <item>andwf</item>
      <item>bcf</item>
      <item>bn</item>
      <item>bnov</item>
      <item>bov</item>
      <item>bsf</item>
      <item>btg</item>
      <item>btfsc</item>
      <item>btfss</item>
      <item>clrf</item>
      <item>clrw</item>
      <item>clrwdt</item>
      <item>comf</item>
      <item>cpfseq</item>
      <item>cpfslt</item>
      <item>cpfsgt</item>
      <item>daw</item>
      <item>decf</item>
      <item>dcfsnz</item>
      <item>decfsz</item>
      <item>incf</item>
      <item>incfsz</item>
      <item>infsnz</item>
      <item>iorlw</item>
      <item>iorwf</item>
      <item>lfsr</item>
      <item>movf</item>
      <item>movff</item>
      <item>movlb</item>
      <item>movlw</item>
      <item>movwf</item>
      <item>mullw</item>
      <item>mulwf</item>
      <item>negf</item>
      <item>nop</item>
      <item>option</item>
      <item>pop</item>
      <item>push</item>
      <item>rcall</item>
      <item>reset</item>
      <item>retfie</item>
      <item>retlw</item>
      <item>return</item>
      <item>rlcf</item>
      <item>rlf</item>
      <item>rlncf</item>
      <item>rrcf</item>
      <item>rrf</item>
      <item>rrncf</item>
      <item>setf</item>
      <item>sleep</item>
      <item>subfwb</item>
      <item>sublw</item>
      <item>subwf</item>
      <item>subwfb</item>
      <item>swapf</item>
      <item>tblrd</item>
      <item>tblwt</item>
      <item>tstfsz</item>
      <item>xorlw</item>
      <item>xorwf</item>
    </list>

    <list name="instruction_attr">
      <item>A</item>
      <item>ACCESS</item>
      <item>BANKED</item>
      <item>W</item>
      <item>F</item>
    </list>

    <list name="preprocessor">
      <item>define</item>
      <item>undefine</item>
      <item>v</item>
    </list>
    
    <list name="comment instructions">
      <item>INPUT</item>
      <item>OUTPUT</item>
      <item>PARAMETERS</item>
      <item>AUTHOR</item>
      <item>EMAIL</item>
    </list>
    
    <contexts>
      
      <!-- The main ('normal') context -->
      
      <context name="normal" attribute="Normal Text" lineEndContext="#stay">
        <DetectSpaces attribute="Normal Text" context="#stay"/>

        <keyword attribute="Directives" context="Operands" String="directives" insensitive="1"/>
        <keyword attribute="Preprocessor" context="Operands" String="conditional"/>
        <DetectIdentifier attribute="Label" context="EndLabel" column="0"/>
        <keyword attribute="Instructions" context="Operands" String="instructions" insensitive="1"/>
        <keyword attribute="Branch Instructions" context="Operands" String="branch instructions" insensitive="1"/>
        <keyword attribute="InstructionAttr" context="Operands" String="instruction_attr" insensitive="1"/>
        <keyword attribute="GPASM-macros" context="Operands" String="gpasm_macro" insensitive="1"/>

        <DetectIdentifier attribute="Unknown Instructions" context="Operands"/>

        <DetectChar attribute="Comment" context="#pop!comment" char=";" />
        <DetectChar attribute="Preprocessor" context="preprocessor1" char="#"/>
      </context>

      <context name="Operands" attribute="Normal Text" lineEndContext="#pop">
        <DetectSpaces attribute="Normal Text"/>

        <DetectChar attribute="Unbased Numbers" context="Number16or10" char="0" lookAhead="1"/>
        <Int attribute="Unbased Numbers" context="CheckNumberSuffix"/>
        <DetectChar attribute="Based Numbers" context="Number10" char="."/>

        <HlCChar attribute="Char" context="#stay"/>
        <Detect2Chars attribute="Char" context="ASCIIChar" char="A" char1="'" />
        <Detect2Chars attribute="Char" context="ASCIIChar" char="a" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="binaryDigits"  char="B" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="binaryDigits"  char="b" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="hexDigits"  char="H" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="hexDigits"  char="h" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="octDigits"  char="O" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="octDigits"  char="o" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="decimalDigits"  char="D" char1="'" />
        <Detect2Chars attribute="Based Numbers" context="decimalDigits"  char="d" char1="'" />
        <DetectChar attribute="String" context="string" char="&quot;" />
        <DetectChar attribute="Comment" context="#pop!comment" char=";" />
        <DetectChar attribute="Preprocessor" context="preprocessor2" char="#"/>
        <AnyChar attribute="Symbol" context="#stay" String=",-/*%+=&gt;&lt;&amp;|^!~()" />

        <DetectIdentifier attribute="Normal Text"/>
      </context>
      
      
      
      <!-- Additional contexts -->
      
      <context name="EndLabel" attribute="Label" lineEndContext="#pop" fallthroughContext="#pop">
        <Detect2Chars attribute="Char" context="#pop!LabelReplaceMacro" char="#" char1="v" />
        <DetectChar attribute="Symbol" context="#pop" char=":"/>
      </context>
      <context name="LabelReplaceMacro" attribute="Label" lineEndContext="#pop" fallthroughContext="#pop">
        <DetectChar attribute="Symbol" context="#pop!ReplaceMacro" char="("/>
      </context>
      <context name="ReplaceMacro" attribute="Label" lineEndContext="#pop">
        <DetectChar attribute="Symbol" context="ReplaceMacro2" char="("/>
        <DetectChar attribute="Symbol" context="#pop!ContinueLabel" char=")"/>
        <IncludeRules context="Operands"/>
      </context>
      <context name="ReplaceMacro2" attribute="Label" lineEndContext="#pop">
        <DetectChar attribute="Symbol" context="ReplaceMacro" char="("/>
        <DetectChar attribute="Symbol" context="#pop" char=")"/>
        <IncludeRules context="Operands"/>
      </context>
      <context name="ContinueLabel" attribute="Label" lineEndContext="#pop" fallthroughContext="#pop">
        <DetectIdentifier attribute="Label" context="#pop!EndLabel"/>
        <DetectChar attribute="Symbol" context="#pop" char=":"/>
      </context>

      <context name="string" attribute="String" lineEndContext="#pop">
        <LineContinue attribute="String" context="#stay"/>
        <HlCStringChar attribute="Char" context="#stay"/>
        <DetectChar attribute="String" context="#pop" char="&quot;"/>
      </context>

      <context name="comment" attribute="Comment" lineEndContext="#pop">
        <DetectSpaces attribute="Comment"/>
        <IncludeRules context="##Alerts" />
        <IncludeRules context="##Modelines" />
        <keyword attribute="Instructions" context="#stay" String="comment instructions" insensitive="0"/>
        <DetectIdentifier attribute="Comment"/>
      </context>
      
      <context name="preprocessor1" attribute="Preprocessor" lineEndContext="#pop" fallthroughContext="#pop!Operands">
        <keyword attribute="Preprocessor" context="#pop!Operands" String="preprocessor" insensitive="1"/>
        <DetectIdentifier attribute="Error" context="#pop!Operands"/>
      </context>
      <context name="preprocessor2" attribute="Preprocessor" lineEndContext="#pop" fallthroughContext="#pop">
        <keyword attribute="Preprocessor" context="#pop" String="preprocessor" insensitive="1"/>
        <DetectIdentifier attribute="Error" context="#pop"/>
      </context>
      
      
      
      <!-- Number -->

      <context name="Number10" attribute="Based Numbers" lineEndContext="#pop" fallthroughContext="#pop">
        <Int attribute="Unbased Numbers" context="#pop!CheckNumberSuffix"/>
      </context>

      <context name="Number16or10" attribute="Based Numbers" lineEndContext="#pop" fallthroughContext="#pop">
        <Detect2Chars attribute="Based Numbers" context="#pop!Number16" char="0" char1="x"/>
        <Detect2Chars attribute="Based Numbers" context="#pop!Number16" char="0" char1="X"/>
        <Int attribute="Unbased Numbers" context="#pop!CheckNumberSuffix"/>
      </context>

      <context name="Number16" attribute="Hex" lineEndContext="#pop" fallthroughContext="#pop">
        <RegExpr attribute="Hex" context="#pop!CheckNumberSuffix" String="[0-9A-Fa-f]+"/>
      </context>

      <context name="CheckNumberSuffix" attribute="Based Numbers" lineEndContext="#pop" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text" context="#pop"/>
        <AnyChar attribute="Symbol" context="#pop" String=",-/*%+=&gt;&lt;&amp;|^!~"/>
        <RegExpr attribute="Error" context="#pop" String="[\d\w]+"/>
      </context>



      <!-- Quoted numbers -->
      
      <context name="decimalDigits" attribute="Unbased Numbers" lineEndContext="#pop" fallthroughContext="QuotedNumEnd">
        <RegExpr attribute="Unbased Numbers" context="QuotedNumEnd" String="\d+"/>
      </context>
      
      <context name="binaryDigits" attribute="Binary" lineEndContext="#pop" fallthroughContext="QuotedNumEnd">
        <RegExpr attribute="Binary" context="QuotedNumEnd" String="[01]+"/>
      </context>
      
      <context name="hexDigits" attribute="Hex" lineEndContext="#pop" fallthroughContext="QuotedNumEnd">
        <RegExpr attribute="Hex" context="QuotedNumEnd" String="[0-9A-Fa-f]+"/>
      </context>
      
      <context name="octDigits" attribute="Octal" lineEndContext="#pop" fallthroughContext="QuotedNumEnd">
        <RegExpr attribute="Octal" context="QuotedNumEnd" String="[0-7]+" />
      </context>

      <context name="QuotedNumEnd" attribute="Error" lineEndContext="#pop#pop">
        <DetectChar attribute="Based Numbers" context="#pop#pop" char="'"/>
        <RegExpr attribute="Error" context="#pop#pop" String="."/>
      </context>



      <!-- Quoted char -->
      
      <context name="ASCIIChar" attribute="Char" lineEndContext="#pop">
        <RegExpr attribute="Char" context="QuotedASCIICharEnd" String="." />
      </context>

      <context name="QuotedASCIICharEnd" attribute="Error" lineEndContext="#pop#pop" fallthroughContext="#pop#pop">
        <DetectChar attribute="Char" context="#pop#pop" char="'"/>
        <RegExpr attribute="Error" context="#pop#pop" String="."/>
      </context>
      
    </contexts>
    
    
    <itemDatas>
      <itemData name="Normal Text"      defStyleNum="dsNormal"/>
      <itemData name="Label"            defStyleNum="dsFunction"/>
      <itemData name="Directives"       defStyleNum="dsOthers"/>
      <itemData name="Preprocessor"     defStyleNum="dsPreprocessor"/>
      <itemData name="Instructions"     defStyleNum="dsKeyword"/>
      <itemData name="Unknown Instructions" defStyleNum="dsNormal"/>
      <itemData name="Branch Instructions" defStyleNum="dsControlFlow"/>
      <itemData name="InstructionAttr"  defStyleNum="dsNormal" color="#000080" selColor="#000080" bold="0" italic="1"/>
      <itemData name="Unbased Numbers"  defStyleNum="dsDecVal"/>
      <itemData name="Based Numbers"    defStyleNum="dsBaseN" />
      <itemData name="Hex"              defStyleNum="dsBaseN" />
      <itemData name="Octal"            defStyleNum="dsBaseN" />
      <itemData name="Binary"           defStyleNum="dsBaseN" />
      <itemData name="Char"             defStyleNum="dsChar"/>
      <itemData name="String"           defStyleNum="dsString"/>
      <itemData name="Comment"          defStyleNum="dsComment" />
      <itemData name="Symbol"           defStyleNum="dsOperator"/>
      <itemData name="GPASM-macros"     defStyleNum="dsNormal" color="#000000" selColor="#000000" bold="1" italic="1"/>
      <itemData name="Error"            defStyleNum="dsError" />
    </itemDatas>
    
  </highlighting>
  
  
  <general>
    <comments>
      <comment name="singleLine" start=";" />
    </comments>
    <keywords casesensitive="1" additionalDeliminator="#"/>
  </general>
  
</language>
