<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language [
  <!ENTITY hex "[0-9a-fA-F]">
  <!ENTITY int "(?:[0-9](?:_?[0-9]++)*+)">
  <!ENTITY hex_int "(?:[0-9A-Fa-f](?:_?[0-9A-Fa-f]++)*+)">
  <!ENTITY exp_float "(?:[eE][+-]?&int;)">
  <!ENTITY exp_hexfloat "(?:[pP][-+]?&int;)">
]>

<!--
This file is part of KDE's Kate project

GO.XML supports syntax highlighting for the Go programming language
under Kate. Go is a compiled, garbage-collected, concurrent programming
language developed by Google Inc.

Copyright (C) 2010, Miquel Sabaté <mikisabate@gmail.com>

This program, including associated files, is free software.  You may
distribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either Version 2 of
the license, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-->

<language name="Go" version="10" kateversion="5.79" section="Sources" indenter="cstyle" extensions="*.go" author="Miquel Sabaté (mikisabate@gmail.com)" license="GPLv2+">
  <!-- https://go.dev/ref/spec -->
  <highlighting>

    <!-- https://go.dev/ref/spec#Keywords -->
    <list name="keywords">
      <item>chan</item>
      <item>const</item>
      <item>func</item>
      <item>import</item>
      <item>interface</item>
      <item>map</item>
      <item>package</item>
      <item>range</item>
      <item>struct</item>
      <item>type</item>
      <item>var</item>
    </list>
    <list name="controlflow">
      <item>break</item>
      <item>case</item>
      <item>continue</item>
      <item>default</item>
      <item>defer</item>
      <item>else</item>
      <item>fallthrough</item>
      <item>for</item>
      <item>go</item>
      <item>goto</item>
      <item>if</item>
      <item>return</item>
      <item>select</item>
      <item>switch</item>
    </list>

    <!-- https://go.dev/ref/spec#Types -->
    <list name="types">
      <item>bool</item>
      <item>byte</item>
      <item>complex64</item>
      <item>complex128</item>
      <item>error</item>
      <item>float32</item>
      <item>float64</item>
      <item>int</item>
      <item>int8</item>
      <item>int16</item>
      <item>int32</item>
      <item>int64</item>
      <item>rune</item>
      <item>string</item>
      <item>uint</item>
      <item>uintptr</item>
      <item>uint8</item>
      <item>uint16</item>
      <item>uint32</item>
      <item>uint64</item>
      <!-- Go 1.18 -->
      <item>any</item>
      <item>comparable</item>
    </list>

    <list name="builtin">
      <item>append</item>
      <item>cap</item>
      <item>close</item>
      <item>complex</item>
      <item>copy</item>
      <item>delete</item>
      <item>imag</item>
      <item>len</item>
      <item>make</item>
      <item>new</item>
      <item>panic</item>
      <item>print</item>
      <item>println</item>
      <item>real</item>
      <item>recover</item>
    </list>

    <list name="predeclared">
      <item>false</item>
      <item>nil</item>
      <item>true</item>
      <item>iota</item>
    </list>

    <contexts>
      <context name="normal" attribute="Normal Text" lineEndContext="#stay">
        <DetectSpaces />
        <keyword attribute="Keyword" context="#stay" String="keywords" />
        <keyword attribute="Control Flow" context="#stay" String="controlflow" />
        <keyword attribute="Predeclared Identifier" context="#stay" String="predeclared" />
        <keyword attribute="Data Type" context="#stay" String="types" />
        <keyword attribute="Builtin Function" context="#stay" String="builtin" />
        <DetectIdentifier />
        <DetectChar attribute="Symbol" context="#stay" char="{" beginRegion="Brace1" />
        <DetectChar attribute="Symbol" context="#stay" char="}" endRegion="Brace1"   />
        <Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"   />
        <Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment" />
        <RegExpr context="Number" String="\.?[0-9]" lookAhead="true" />
        <AnyChar attribute="Symbol" context="#stay" String=":!%&amp;()+,-/.*&lt;=&gt;?[]|~^;"/>
        <DetectChar attribute="String" context="String" char="&quot;" />
        <DetectChar attribute="Char" context="Char" char="'" />
        <DetectChar attribute="String" context="Multiline String" char="`"/>
      </context>

      <context attribute="Comment" lineEndContext="#pop" name="Commentar 1">
        <DetectSpaces />
        <IncludeRules context="##Comments" />
        <DetectIdentifier />
      </context>

      <context attribute="Comment" lineEndContext="#stay" name="Commentar 2">
        <DetectSpaces />
        <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment"/>
        <IncludeRules context="##Comments" />
        <DetectIdentifier />
      </context>

      <!-- https://go.dev/ref/spec#Integer_literals -->
      <!-- https://go.dev/ref/spec#Floating-point_literals -->
      <context attribute="Normal Text" lineEndContext="#pop" name="Number">
        <WordDetect attribute="Decimal" context="NumberSuffix" String="0" weakDeliminator="."/>
        <RegExpr attribute="Float" context="NumberSuffix" String="\.&int;&exp_float;?|0[xX](?:\.&hex_int;&exp_hexfloat;?|_?&hex_int;(?:&exp_hexfloat;|\.&hex_int;?&exp_hexfloat;?))|&int;(?:&exp_float;|\.&int;?&exp_float;?)" />
        <DetectChar context="#pop!IntStartsWith0" char="0" lookAhead="1"/>
        <RegExpr attribute="Decimal" context="NumberSuffix" String="&int;" />
      </context>
      <context name="IntStartsWith0" attribute="Normal Text" lineEndContext="#pop">
        <RegExpr attribute="Hex" context="NumberSuffix" String="0[xX](?:_?[0-9A-Fa-f]++)*+" />
        <RegExpr attribute="Binary" context="NumberSuffix" String="0[Bb](?:_?[01]++)*+" />
        <RegExpr attribute="Octal" context="NumberSuffix" String="0[Oo]?(?:_?[0-7]++)*+" />
        <DetectChar attribute="Decimal" context="NumberSuffix" char="0"/>
      </context>

      <context name="NumberSuffix" attribute="Error" lineEndContext="#pop#pop" fallthroughContext="NumericSuffixError">
        <DetectChar attribute="Suffix" context="NumericSuffixError" char="i" />
        <DetectChar attribute="Error" context="#stay" char="_" />
      </context>
      <context name="NumericSuffixError" attribute="Error" lineEndContext="#pop#pop#pop" fallthroughContext="#pop#pop#pop">
        <RegExpr attribute="Error" context="#pop#pop#pop" String="[._0-9A-Za-z]+" />
      </context>

      <!-- https://go.dev/ref/spec#String_literals -->
      <context attribute="String" lineEndContext="#pop" name="String">
        <DetectChar attribute="String" context="#pop" char="&quot;" />
        <IncludeRules context="FindEscape" />
      </context>

      <context attribute="String" lineEndContext="#pop" name="FindEscape">
        <DetectChar context="EscapedChar" char="\" lookAhead="1"/>
      </context>
      <context attribute="String" lineEndContext="#pop" name="EscapedChar">
        <RegExpr attribute="String Char" context="#pop" String="\\[abfnrtv\\'&quot;]|\\x&hex;{2}|\\u&hex;{4}|\\U&hex;{8}|\\[0-3][0-7]{2}" />
        <RegExpr attribute="Error" context="#pop" String="\\[xuU]&hex;*|\\[0-7]{1,3}|\\" />
      </context>

      <context attribute="String" lineEndContext="#stay" name="Multiline String">
        <DetectChar attribute="String" context="#pop" char="`"/>
      </context>

      <context attribute="Char" lineEndContext="#pop" name="Char">
        <DetectChar attribute="Char" context="#pop" char="'" />
        <IncludeRules context="FindEscape" />
      </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text"  defStyleNum="dsNormal"   spellChecking="false"/>
      <itemData name="Keyword"      defStyleNum="dsKeyword"  spellChecking="false"/>
      <itemData name="Control Flow" defStyleNum="dsControlFlow" spellChecking="false"/>
      <itemData name="Predeclared Identifier" defStyleNum="dsOthers"  spellChecking="false" />
      <itemData name="Builtin Function"       defStyleNum="dsBuiltIn" spellChecking="false" />
      <itemData name="Data Type"    defStyleNum="dsDataType" spellChecking="false"/>
      <itemData name="String Char"  defStyleNum="dsChar"     spellChecking="false"/>
      <itemData name="String"       defStyleNum="dsString"  />
      <itemData name="Comment"      defStyleNum="dsComment" />
      <itemData name="Decimal"      defStyleNum="dsDecVal"   spellChecking="false"/>
      <itemData name="Binary"       defStyleNum="dsBaseN"    spellChecking="false"/>
      <itemData name="Octal"        defStyleNum="dsBaseN"    spellChecking="false"/>
      <itemData name="Hex"          defStyleNum="dsBaseN"    spellChecking="false"/>
      <itemData name="Float"        defStyleNum="dsFloat"    spellChecking="false"/>
      <itemData name="Suffix"       defStyleNum="dsBuiltIn"  spellChecking="false"/>
      <itemData name="Char"         defStyleNum="dsChar"     spellChecking="false"/>
      <itemData name="Symbol"       defStyleNum="dsOperator" spellChecking="false"/>
      <itemData name="Error"        defStyleNum="dsError"    spellChecking="false"/>
    </itemDatas>
    </highlighting>
  <general>
    <comments>
      <comment name="singleLine" start="//" position="afterwhitespace" />
      <comment name="multiLine" start="/*" end="*/" region="Comment"/>
    </comments>
    <keywords casesensitive="1" additionalDeliminator="'&quot;" />
  </general>
</language>
<!-- kate: replace-tabs on; tab-width 2; indent-width 2; -->
