{{ message }}
Repository navigation
Conversation
Since SE-0001 any keyword except inout, var and let can be an argument
label, e.g. devices(for: .audio) or func f(in x: Int). The lexer
highlighted those labels as keywords. A label after '(' or ',' that is
followed by ':' (call site) or by a parameter name and ':' (declaration)
is now lexed as a Name. true/false/nil are excluded so dictionary keys
such as [true: 1, false: 0] stay constants.
Fixes pygments#1079.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #1079.
Since SE-0001, Swift allows any keyword except
inout,varandletas an argument label, and Apple APIs use this a lot (devices(for:),contains(where:),index(of:in:)).SwiftLexerstill highlights those labels as keywords:Fix: a new rule in
root, placed before the keyword rules, lexes an identifier that follows(or,as aNamewhen it is a label::(f(for: x)):(func f(in x: Int))The lookahead leaves the rest of the parameter to the existing rules. Excluded from the rule:
inout,varandlet, which SE-0001 doesn't allow as labels. This keepsif let a = x, let b: Int = yand Swift 2 style(inout x: Int)as they are.true,falseandnil, so dictionary literals like[true: 1, false: 0]keep both keys asKeyword.Constant._, so#selector(foo(_:))andfunc f(_ x: Int)are unchanged.I also compared the output before and after for a ternary in an argument list,
case a, b:,default:, generic constraints (<T: P, U: Q>,where T: Equatable, U: Hashable) and multi-line calls. Only the keyword labels change.Tests: I added
tests/snippets/swift/test_keyword_argument_labels.txt, covering the call-site and declaration forms. It fails onmasterand passes with the fix. Thetests/examplefiles/swift/test.swiftgolden output is unchanged, and the full suite passes (pytest tests --ignore=tests/contrast: 5330 passed, 16 skipped). I skippedtests/contrastbecausewcag_contrast_ratioisn't installed in my environment.🤖 Generated with Claude Code