
<lexer>
  <config>
    <name>Typst</name>
    <alias>typst</alias>
    <filename>*.typ</filename>
    <mime_type>text/x-typst</mime_type>
  </config>
  <rules>
    <state name="root">
      <rule><include state="markup"/></rule>
    </state>
    <state name="into_code">
      <rule pattern="(\#let|\#set|\#show)\b"><token type="KeywordDeclaration"/><push state="inline_code"/></rule>
      <rule pattern="(\#import|\#include)\b"><token type="KeywordNamespace"/><push state="inline_code"/></rule>
      <rule pattern="(\#if|\#for|\#while|\#export)\b"><token type="KeywordReserved"/><push state="inline_code"/></rule>
      <rule pattern="#\{"><token type="Punctuation"/><push state="code"/></rule>
      <rule pattern="#\("><token type="Punctuation"/><push state="code"/></rule>
      <rule pattern="(#[a-zA-Z_][a-zA-Z0-9_-]*)(\[)"><bygroups><token type="NameFunction"/><token type="Punctuation"/></bygroups><push state="markup"/></rule>
      <rule pattern="(#[a-zA-Z_][a-zA-Z0-9_-]*)(\()"><bygroups><token type="NameFunction"/><token type="Punctuation"/></bygroups><push state="code"/></rule>
      <rule pattern="(\#true|\#false|\#none|\#auto)\b"><token type="KeywordConstant"/></rule>
      <rule pattern="#[a-zA-Z_][a-zA-Z0-9_]*"><token type="NameVariable"/></rule>
      <rule pattern="#0x[0-9a-fA-F]+"><token type="LiteralNumberHex"/></rule>
      <rule pattern="#0b[01]+"><token type="LiteralNumberBin"/></rule>
      <rule pattern="#0o[0-7]+"><token type="LiteralNumberOct"/></rule>
      <rule pattern="#[0-9]+[\.e][0-9]+"><token type="LiteralNumberFloat"/></rule>
      <rule pattern="#[0-9]+"><token type="LiteralNumberInteger"/></rule>
    </state>
    <state name="markup">
      <rule><include state="comment"/></rule>
      <rule pattern="^\s*=+.*$"><token type="GenericHeading"/></rule>
      <rule pattern="[*][^*]*[*]"><token type="GenericStrong"/></rule>
      <rule pattern="_[^_]*_"><token type="GenericEmph"/></rule>
      <rule pattern="\$"><token type="Punctuation"/><push state="math"/></rule>
      <rule pattern="`[^`]*`"><token type="LiteralStringBacktick"/></rule>
      <rule pattern="^(\s*)(-)(\s+)"><bygroups><token type="TextWhitespace"/><token type="Punctuation"/><token type="TextWhitespace"/></bygroups></rule>
      <rule pattern="^(\s*)(\+)(\s+)"><bygroups><token type="TextWhitespace"/><token type="Punctuation"/><token type="TextWhitespace"/></bygroups></rule>
      <rule pattern="^(\s*)([0-9]+\.)"><bygroups><token type="TextWhitespace"/><token type="Punctuation"/></bygroups></rule>
      <rule pattern="^(\s*)(/)(\s+)([^:]+)(:)"><bygroups><token type="TextWhitespace"/><token type="Punctuation"/><token type="TextWhitespace"/><token type="NameVariable"/><token type="Punctuation"/></bygroups></rule>
      <rule pattern="&lt;[a-zA-Z_][a-zA-Z0-9_-]*&gt;"><token type="NameLabel"/></rule>
      <rule pattern="@[a-zA-Z_][a-zA-Z0-9_-]*"><token type="NameLabel"/></rule>
      <rule pattern="\\#"><token type="Text"/></rule>
      <rule><include state="into_code"/></rule>
      <rule pattern="```(?:.|\n)*?```"><token type="LiteralStringBacktick"/></rule>
      <rule pattern="https?://[0-9a-zA-Z~/%#&amp;=\&#x27;,;.+?]*"><token type="GenericEmph"/></rule>
      <rule pattern="(\-\-\-|\\|\~|\-\-|\.\.\.)\B"><token type="Punctuation"/></rule>
      <rule pattern="\\\["><token type="Punctuation"/></rule>
      <rule pattern="\\\]"><token type="Punctuation"/></rule>
      <rule pattern="\["><token type="Punctuation"/><push/></rule>
      <rule pattern="\]"><token type="Punctuation"/><pop depth="1"/></rule>
      <rule pattern="[ \t]+\n?|\n"><token type="TextWhitespace"/></rule>
      <rule pattern="((?![*_$`&lt;@\\#\] ]|https?://).)+"><token type="Text"/></rule>
    </state>
    <state name="math">
      <rule><include state="comment"/></rule>
      <rule pattern="(\\_|\\\^|\\\&amp;)"><token type="Text"/></rule>
      <rule pattern="(_|\^|\&amp;|;)"><token type="Punctuation"/></rule>
      <rule pattern="(\+|/|=|\[\||\|\]|\|\||\*|:=|::=|\.\.\.|&#x27;|\-|=:|!=|&gt;&gt;|&gt;=|&gt;&gt;&gt;|&lt;&lt;|&lt;=|&lt;&lt;&lt;|\-&gt;|\|\-&gt;|=&gt;|\|=&gt;|==&gt;|\-\-&gt;|\~\~&gt;|\~&gt;|&gt;\-&gt;|\-&gt;&gt;|&lt;\-|&lt;==|&lt;\-\-|&lt;\~\~|&lt;\~|&lt;\-&lt;|&lt;&lt;\-|&lt;\-&gt;|&lt;=&gt;|&lt;==&gt;|&lt;\-\-&gt;|&gt;|&lt;|\~|:|\|)"><token type="Operator"/></rule>
      <rule pattern="\\"><token type="Punctuation"/></rule>
      <rule pattern="\\\$"><token type="Punctuation"/></rule>
      <rule pattern="\$"><token type="Punctuation"/><pop depth="1"/></rule>
      <rule><include state="into_code"/></rule>
      <rule pattern="([a-zA-Z][a-zA-Z0-9-]*)(\s*)(\()"><bygroups><token type="NameFunction"/><token type="TextWhitespace"/><token type="Punctuation"/></bygroups></rule>
      <rule pattern="([a-zA-Z][a-zA-Z0-9-]*)(:)"><bygroups><token type="NameVariable"/><token type="Punctuation"/></bygroups></rule>
      <rule pattern="([a-zA-Z][a-zA-Z0-9-]*)"><token type="NameVariable"/></rule>
      <rule pattern="[0-9]+(\.[0-9]+)?"><token type="LiteralNumber"/></rule>
      <rule pattern="\.{1,3}|\(|\)|,|\{|\}"><token type="Punctuation"/></rule>
      <rule pattern="&quot;[^&quot;]*&quot;"><token type="LiteralStringDouble"/></rule>
      <rule pattern="[ \t\n]+"><token type="TextWhitespace"/></rule>
    </state>
    <state name="comment">
      <rule pattern="//.*$"><token type="CommentSingle"/></rule>
      <rule pattern="/[*](.|\n)*?[*]/"><token type="CommentMultiline"/></rule>
    </state>
    <state name="code">
      <rule><include state="comment"/></rule>
      <rule pattern="\["><token type="Punctuation"/><push state="markup"/></rule>
      <rule pattern="\(|\{"><token type="Punctuation"/><push state="code"/></rule>
      <rule pattern="\)|\}"><token type="Punctuation"/><pop depth="1"/></rule>
      <rule pattern="&quot;[^&quot;]*&quot;"><token type="LiteralStringDouble"/></rule>
      <rule pattern=",|\.{1,2}"><token type="Punctuation"/></rule>
      <rule pattern="="><token type="Operator"/></rule>
      <rule pattern="(and|or|not)\b"><token type="OperatorWord"/></rule>
      <rule pattern="=&gt;|&lt;=|==|!=|&gt;|&lt;|-=|\+=|\*=|/=|\+|-|\\|\*"><token type="Operator"/></rule>
      <rule pattern="([a-zA-Z_][a-zA-Z0-9_-]*)(:)"><bygroups><token type="NameVariable"/><token type="Punctuation"/></bygroups></rule>
      <rule pattern="([a-zA-Z_][a-zA-Z0-9_-]*)(\()"><bygroups><token type="NameFunction"/><token type="Punctuation"/></bygroups><push state="code"/></rule>
      <rule pattern="(as|break|export|continue|else|for|if|in|return|while)\b"><token type="KeywordReserved"/></rule>
      <rule pattern="(import|include)\b"><token type="KeywordNamespace"/></rule>
      <rule pattern="(auto|none|true|false)\b"><token type="KeywordConstant"/></rule>
      <rule pattern="([0-9.]+)(mm|pt|cm|in|em|fr|%)"><bygroups><token type="LiteralNumber"/><token type="KeywordReserved"/></bygroups></rule>
      <rule pattern="0x[0-9a-fA-F]+"><token type="LiteralNumberHex"/></rule>
      <rule pattern="0b[01]+"><token type="LiteralNumberBin"/></rule>
      <rule pattern="0o[0-7]+"><token type="LiteralNumberOct"/></rule>
      <rule pattern="[0-9]+[\.e][0-9]+"><token type="LiteralNumberFloat"/></rule>
      <rule pattern="[0-9]+"><token type="LiteralNumberInteger"/></rule>
      <rule pattern="(let|set|show)\b"><token type="KeywordDeclaration"/></rule>
      <rule pattern="([a-zA-Z_][a-zA-Z0-9_-]*)"><token type="NameVariable"/></rule>
      <rule pattern="[ \t\n]+"><token type="TextWhitespace"/></rule>
      <rule pattern=":"><token type="Punctuation"/></rule>
    </state>
    <state name="inline_code">
      <rule pattern=";\b"><token type="Punctuation"/><pop depth="1"/></rule>
      <rule pattern="\n"><token type="TextWhitespace"/><pop depth="1"/></rule>
      <rule><include state="code"/></rule>
    </state>
  </rules>
</lexer>

