Skip to content

Conversation

@manojmahapatra
Copy link

@manojmahapatra manojmahapatra commented Jun 30, 2025

Hi,

I've reviewed the code of conduct. Here is a summary of the changes.

What is the issue?

  • The Rouge syntax highlighter for Swift didn't recognize #expect from Swift Testing framework, treating it as a generic preprocessor instead of a testing assertion. Basically, the rule catches ANY line starting with # (except for ##, #", or #/) and treats the entire line as a preprocessor comment.

Changes

  • Added a testing_macros set containing expect and require

  • Modified the rule for # prefixed identifiers to check if they're Swift Testing macros

  • Swift Testing macros (#expect, #require) are now highlighted as Name::Builtin

  • Other Swift macros (like #selector) continue to be highlighted as Keyword

  • Preprocessor directives (#if, #else, #endif) are properly handled in the :bol state

Testing

  • Ran the the tests locally, looks alright.

# beginning of line
state :bol do
rule %r/#(?![#"\/]).*/, Comment::Preproc
# Handle Swift compiler directives

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've intentionally tokenized #if and its relatives as preprocessor, but traditionally they're called as compiler directive in Swift land.

The rest like #warning, #error et al will be treated as Keyword as they'll not match to any rule.

end

# beginning of line
# beginning of line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants