<lexer>
  <config>
    <name>Devicetree</name>
    <alias>devicetree</alias>
    <alias>dts</alias>
    <filename>*.dts</filename>
    <filename>*.dtsi</filename>
    <mime_type>text/x-devicetree</mime_type>
  </config>
  <rules>
    <state name="whitespace">
      <rule pattern="\n">
        <token type="TextWhitespace" />
      </rule>
      <rule pattern="\s+">
        <token type="TextWhitespace" />
      </rule>
      <rule pattern="\\\n">
        <token type="Text" />
      </rule>
      <rule pattern="//(\n|[\w\W]*?[^\\]\n)">
        <token type="CommentSingle" />
      </rule>
      <rule pattern="/(\\\n)?[*][\w\W]*?[*](\\\n)?/">
        <token type="CommentMultiline" />
      </rule>
    </state>

    <state name="macro">
      <rule pattern="(#include)(\s*(?:/[*][^*/]*?[*]/\s*)*)([^\n]+)">
        <bygroups>
          <token type="CommentPreproc" />
          <token type="CommentMultiline" />
          <token type="CommentPreprocFile" />
        </bygroups>
      </rule>
      <rule pattern="(#define)(\s*(?:/[*][^*/]*?[*]/\s*)*)([^\n]+)">
        <bygroups>
          <token type="CommentPreproc" />
          <token type="CommentMultiline" />
          <token type="CommentPreproc" />
        </bygroups>
      </rule>
      <rule pattern="/dts-v1/">
        <token type="CommentPreproc" />
      </rule>
      <rule pattern="/memreserve/">
        <token type="CommentPreproc" />
      </rule>
      <rule pattern="/delete-node/">
        <token type="CommentPreproc" />
      </rule>
      <rule pattern="/delete-property/">
        <token type="CommentPreproc" />
      </rule>
      <rule pattern="(/include/)(\s*(?:/[*][^*/]*?[*]/\s*)*)(&quot;[^\n]+&quot;)">
        <bygroups>
          <token type="CommentPreproc" />
          <token type="CommentMultiline" />
          <token type="CommentPreprocFile" />
        </bygroups>
      </rule>
    </state>

    <state name="basic_statements">
      <rule pattern="&amp;[a-zA-Z0-9_]+">
        <token type="NameLabel" />
      </rule>

      <rule pattern="[a-zA-Z0-9_]+:">
        <token type="NameLabel" />
      </rule>

      <rule pattern="(L?)(&quot;)">
        <bygroups>
          <token type="LiteralStringAffix" />
          <token type="LiteralString" />
        </bygroups>
        <push state="string" />
      </rule>
      <rule pattern="0x[0-9a-fA-F]+">
        <token type="LiteralNumberHex" />
      </rule>
      <rule pattern="\d+">
        <token type="LiteralNumberInteger" />
      </rule>

      <rule pattern="status\b">
        <token type="KeywordReserved" />
        <push state="status_property" />
      </rule>

      <rule pattern="([~!%^&amp;*+=|?:&lt;&gt;/#-])">
        <token type="Operator" />
      </rule>
      <rule pattern="[()\[\]{},.]">
        <token type="Punctuation" />
      </rule>

      <rule
        pattern="[a-zA-Z_][\w-]*(?=(?:\s*,\s*[a-zA-Z_][\w-]*|(?:\s*(?:/[*][^*/]*?[*]/\s*)*))*\s*[=;])">
        <token type="NameAttribute" />
      </rule>
      <rule pattern="[a-zA-Z_][\w-]*">
        <token type="Name" />
      </rule>
    </state>

    <state name="status_property">
      <rule>
        <include state="whitespace" />
      </rule>
      <rule pattern="=">
        <token type="Operator" />
      </rule>

      <rule pattern="&quot;okay&quot;">
        <token type="LiteralString" />
        <pop depth="1" />
      </rule>
      <rule pattern="&quot;disabled&quot;">
        <token type="KeywordType" />
        <pop depth="1" />
      </rule>
      <rule pattern="&quot;reserved&quot;">
        <token type="NameDecorator" />
        <pop depth="1" />
      </rule>
      <rule pattern="&quot;fail&quot;">
        <token type="GenericError" />
        <pop depth="1" />
      </rule>
      <rule pattern="&quot;fail-[^\&quot;]+&quot;">
        <token type="GenericTraceback" />
        <pop depth="1" />
      </rule>
      <rule pattern="&quot;">
        <token type="LiteralString" />
        <push state="string" />
      </rule>

      <rule pattern=";">
        <pop depth="1" />
      </rule>
    </state>

    <state name="root">
      <rule>
        <include state="whitespace" />
      </rule>
      <rule>
        <include state="macro" />
      </rule>

      <rule pattern="([^/*@\s&amp;]+|/)(@?)((?:0x)?[0-9a-fA-F,]*)(\s*(?:/[*][^*/]*?[*]/\s*)*)(\{)">
        <bygroups>
          <token type="NameFunction" />
          <token type="Operator" />
          <token type="LiteralNumberInteger" />
          <token type="CommentMultiline" />
          <token type="Punctuation" />
        </bygroups>
        <push state="node" />
      </rule>

      <rule>
        <push state="statement" />
      </rule>
    </state>

    <state name="node">
      <rule>
        <include state="whitespace" />
      </rule>
      <rule>
        <include state="macro" />
      </rule>

      <rule pattern="([^/*@\s&amp;]+|/)(@?)((?:0x)?[0-9a-fA-F,]*)(\s*(?:/[*][^*/]*?[*]/\s*)*)(\{)">
        <bygroups>
          <token type="NameFunction" />
          <token type="Operator" />
          <token type="LiteralNumberInteger" />
          <token type="CommentMultiline" />
          <token type="Punctuation" />
        </bygroups>
        <push />
      </rule>

      <rule pattern="([a-zA-Z0-9_]+)(\s*)(:)">
        <bygroups>
          <token type="NameLabel" />
          <token type="Text" />
          <token type="Punctuation" />
        </bygroups>
      </rule>

      <rule pattern="\}">
        <token type="Punctuation" />
        <pop depth="1" />
      </rule>
      <rule>
        <include state="basic_statements" />
      </rule>
      <rule pattern=";">
        <token type="Punctuation" />
      </rule>
    </state>

    <state name="statement">
      <rule>
        <include state="whitespace" />
      </rule>
      <rule pattern="([a-zA-Z0-9_]+)(\s*)(:)">
        <bygroups>
          <token type="NameLabel" />
          <token type="Text" />
          <token type="Punctuation" />
        </bygroups>
        <pop depth="1" />
      </rule>
      <rule>
        <include state="basic_statements" />
      </rule>
      <rule pattern=";">
        <token type="Punctuation" />
        <pop depth="1" />
      </rule>
    </state>

    <state name="string">
      <rule pattern="&quot;">
        <token type="LiteralString" />
        <pop depth="1" />
      </rule>
      <rule
        pattern="\\([\\abfnrtv&quot;\&#x27;]|x[a-fA-F0-9]{2,4}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})">
        <token type="LiteralStringEscape" />
      </rule>
      <rule pattern="[^\\&quot;\n]+">
        <token type="LiteralString" />
      </rule>
      <rule pattern="\\\n">
        <token type="LiteralString" />
      </rule>
      <rule pattern="\\">
        <token type="LiteralString" />
      </rule>
    </state>
  </rules>
</lexer>