@@ -18,7 +18,7 @@ class CSharp < RegexLexer
1818 # Contextual Keywords
1919 # LINQ Query Expressions
2020 def self . keywords
21- @keywords ||= %w(
21+ @keywords ||= Set . new %w(
2222 abstract add alias and as ascending async await base
2323 break by case catch checked const continue default delegate
2424 descending do else enum equals event explicit extern false
@@ -34,20 +34,22 @@ def self.keywords
3434 end
3535
3636 def self . keywords_type
37- @keywords_type ||= %w(
37+ @keywords_type ||= Set . new %w(
3838 bool byte char decimal double dynamic float int long nint nuint
3939 object sbyte short string uint ulong ushort var
4040 )
4141 end
4242
4343 def self . cpp_keywords
44- @cpp_keywords ||= %w(
44+ @cpp_keywords ||= Set . new %w(
4545 if endif else elif define undef line error warning region
4646 endregion pragma nullable
4747 )
4848 end
4949
5050 state :whitespace do
51+ rule %r/^[ \t ]*#/ , Comment ::Preproc , :preproc
52+
5153 rule %r/\s +/m , Text
5254 rule %r(//.*?$) , Comment ::Single
5355 rule %r(/[*].*?[*]/)m , Comment ::Multiline
@@ -96,13 +98,22 @@ def self.cpp_keywords
9698 )ix , Num
9799 rule %r/\b (?:class|record|struct|interface)\b / , Keyword , :class
98100 rule %r/\b (?:namespace|using)\b / , Keyword , :namespace
99- rule %r/^#[ \t ]*(#{ CSharp . cpp_keywords . join ( '|' ) } )\b .*?\n / , Comment ::Preproc
100- rule %r/\b (#{ CSharp . keywords . join ( '|' ) } )\b / , Keyword
101- rule %r/\b (#{ CSharp . keywords_type . join ( '|' ) } )\b / , Keyword ::Type
101+
102+ keywords %r/\w +/ do
103+ rule :keywords , Keyword
104+ rule :keywords_type , Keyword ::Type
105+ end
106+
102107 rule %r/#{ id } (?=\s *[(])/ , Name ::Function
103108 rule id , Name
104109 end
105110
111+ state :preproc do
112+ rule %r/[^\\ \n ]+/ , Comment ::Preproc
113+ rule %r/\\ .?/m , Comment ::Preproc
114+ rule %r/\n / , Comment ::Preproc , :pop!
115+ end
116+
106117 state :class do
107118 mixin :whitespace
108119 rule id , Name ::Class , :pop!
0 commit comments