-
Notifications
You must be signed in to change notification settings - Fork 793
Swift lexer update for syntax highlight for macros and keywords #2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,11 @@ class Swift < RegexLexer | |
| actor any associatedtype borrowing class consuming deinit distributed dynamic enum convenience extension fileprivate final func import indirect init internal lazy let macro nonisolated open optional package private protocol public required some static struct subscript typealias var | ||
| ) | ||
|
|
||
| # Swift Testing macros | ||
| testing_macros = Set.new %w( | ||
| expect require | ||
| ) | ||
|
|
||
| constants = Set.new %w( | ||
| true false nil | ||
| ) | ||
|
|
@@ -35,9 +40,13 @@ class Swift < RegexLexer | |
| @re_delim = "" # multi-line regex delimiter | ||
| end | ||
|
|
||
| # beginning of line | ||
| # beginning of line | ||
| state :bol do | ||
| rule %r/#(?![#"\/]).*/, Comment::Preproc | ||
| # Handle Swift compiler directives | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious what other directives there are that we should look for. For example #ifdef, #warning, #error.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've intentionally tokenized The rest like |
||
| rule %r/#if\b.*/, Comment::Preproc | ||
| rule %r/#elseif\b.*/, Comment::Preproc | ||
| rule %r/#else\b.*/, Comment::Preproc | ||
| rule %r/#endif\b.*/, Comment::Preproc | ||
|
|
||
| mixin :inline_whitespace | ||
|
|
||
|
|
@@ -86,7 +95,13 @@ class Swift < RegexLexer | |
| rule %r{[\d]+(?:_\d+)*}, Num::Integer | ||
|
|
||
| rule %r/@#{id}/, Keyword::Declaration | ||
| rule %r/##{id}/, Keyword | ||
| rule %r/#(#{id})/ do |m| | ||
| if testing_macros.include?(m[1]) | ||
| token Name::Builtin | ||
| else | ||
| token Keyword | ||
| end | ||
| end | ||
|
|
||
| rule %r/(private|internal)(\([ ]*)(\w+)([ ]*\))/ do |m| | ||
| if m[3] == 'set' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace added