Skip to content

Instantly share code, notes, and snippets.

@mrousavy
Created August 21, 2017 10:25
Show Gist options
  • Save mrousavy/e938db008be18b7ac986b181344797c1 to your computer and use it in GitHub Desktop.
Save mrousavy/e938db008be18b7ac986b181344797c1 to your computer and use it in GitHub Desktop.
C# RegEx based (No AST) syntax highlighting
<SyntaxDefinition name="CSharp" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="CommentSingle" foreground="#0cad31" />
<Color name="CommentMulti" foreground="#068724" />
<Color name="String" foreground="Orange" />
<Color name="Char" foreground="DarkOrange" />
<Color name="Digits" foreground="DarkBlue"/>
<RuleSet>
<Span color="CommentSingle" begin="//" />
<Span color="CommentMulti" multiline="true"
begin="/\*" end="\*/" />
<Span color="String">
<Begin>"</Begin>
<End>"</End>
<RuleSet>
<!-- nested span for escape sequences -->
<Span begin="\\" end="." />
</RuleSet>
</Span>
<Span color="Char">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<!-- nested span for escape sequences -->
<Span begin="\\" end="." />
</RuleSet>
</Span>
<Keywords fontWeight="bold" foreground="LightBlue">
<Word>abstract</Word>
<Word>as</Word>
<Word>async</Word>
<Word>await</Word>
<Word>base</Word>
<Word>bool</Word>
<Word>break</Word>
<Word>byte</Word>
<Word>case</Word>
<Word>catch</Word>
<Word>char</Word>
<Word>checked</Word>
<Word>class</Word>
<Word>const</Word>
<Word>continue</Word>
<Word>decimal</Word>
<Word>default</Word>
<Word>delegate</Word>
<Word>do</Word>
<Word>double</Word>
<Word>else</Word>
<Word>enum</Word>
<Word>event</Word>
<Word>explicit</Word>
<Word>extern</Word>
<Word>false</Word>
<Word>finally</Word>
<Word>fixed</Word>
<Word>float</Word>
<Word>for</Word>
<Word>foreach</Word>
<Word>goto</Word>
<Word>if</Word>
<Word>implicit</Word>
<Word>in</Word>
<Word>int</Word>
<Word>interface</Word>
<Word>internal</Word>
<Word>is</Word>
<Word>lock</Word>
<Word>long</Word>
<Word>namespace</Word>
<Word>new</Word>
<Word>null</Word>
<Word>object</Word>
<Word>operator</Word>
<Word>out</Word>
<Word>override</Word>
<Word>params</Word>
<Word>private</Word>
<Word>protected</Word>
<Word>public</Word>
<Word>readonly</Word>
<Word>ref</Word>
<Word>return</Word>
<Word>sbyte</Word>
<Word>sealed</Word>
<Word>short</Word>
<Word>sizeof</Word>
<Word>stackalloc</Word>
<Word>static</Word>
<Word>string</Word>
<Word>struct</Word>
<Word>switch</Word>
<Word>this</Word>
<Word>throw</Word>
<Word>true</Word>
<Word>try</Word>
<Word>typeof</Word>
<Word>uint</Word>
<Word>ulong</Word>
<Word>unchecked</Word>
<Word>unsafe</Word>
<Word>ushort</Word>
<Word>using</Word>
<Word>var</Word>
<Word>virtual</Word>
<Word>void</Word>
<Word>volatile</Word>
<Word>while</Word>
<Word>?</Word>
<Word>,</Word>
<Word>.</Word>
<Word>;</Word>
<Word>:</Word>
<Word>)</Word>
<Word>(</Word>
<Word>[</Word>
<Word>]</Word>
<Word>{</Word>
<Word>}</Word>
<Word>+</Word>
<Word>-</Word>
<Word>/</Word>
<Word>%</Word>
<Word>*</Word>
<Word>&lt;</Word>
<Word>&gt;</Word>
<Word>^</Word>
<Word>=</Word>
<Word>~</Word>
<Word>!</Word>
<Word>|</Word>
<Word>&amp;</Word>
</Keywords>
<!-- Digits -->
<Rule foreground="#ecffc4">
\b0[xX][0-9a-fA-F]+ # hex number
| \b
( \d+(\.[0-9]+)? #number with optional floating point
| \.[0-9]+ #or just starting with floating point
)
([eE][+-]?[0-9]+)? # optional exponent
</Rule>
<!-- Types -->
<Rule foreground="#408E66">
(^|\s)[A-Z][a-zA-Z]*[0-9]*
</Rule>
</RuleSet>
</SyntaxDefinition>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment