rouge icon indicating copy to clipboard operation
rouge copied to clipboard

Swift lexer update for syntax highlight for macros and keywords

Open manojmahapatra opened this issue 5 months ago • 0 comments

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.

manojmahapatra avatar Jun 30 '25 20:06 manojmahapatra