Skip to content

Commit

Permalink
(swift) Improved highlighting for functions, initializers, and subscr…
Browse files Browse the repository at this point in the history
…ipts (#2930)

This PR improves highlighting for functions, initializers, and subscripts. This includes detailed highlighting for generic parameters as well as function parameters.

To differentiate between tuple elements and function params, I've also added a mode to match tuples, whose element names should not be highlighted as params.

- Fixes #2895
- Fixes #2857
  • Loading branch information
svanimpe committed Dec 28, 2020
1 parent 5a55ae2 commit 35cd463
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 109 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Language grammar improvements:
- Added support for quoted identifiers, implicit parameters, and property wrapper projections
- Support for more complex expressions in string interpolation
- enh(swift) Improved highlighting for types and generic arguments (#2920) [Steven Van Impe][]
- enh(swift) Improved highlighting for functions, initializers, and subscripts (#2930) [Steven Van Impe][]
- fix(http) avoid recursive sublanguage and tighten rules (#2893) [Josh Goebel][]
- fix(asciidoc): Handle section titles level 5 (#2868) [Vaibhav Chanana][]
- fix(asciidoc): Support unconstrained emphasis syntax (#2869) [Guillaume Grossetie][]
Expand Down
16 changes: 8 additions & 8 deletions src/languages/lib/kws_swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const keywords = [
'enum',
'extension',
'fallthrough',
'fileprivate(set)',
/fileprivate\(set\)/,
'fileprivate',
'final', // contextual
'for',
Expand All @@ -66,26 +66,26 @@ export const keywords = [
/init\?/,
/init!/,
'inout',
'internal(set)',
/internal\(set\)/,
'internal',
'in',
'is', // operator
'lazy', // contextual
'let',
'mutating', // contextual
'nonmutating', // contextual
'open(set)', // contextual
/open\(set\)/, // contextual
'open', // contextual
'operator',
'optional', // contextual
'override', // contextual
'postfix', // contextual
'precedencegroup',
'prefix', // contextual
'private(set)',
/private\(set\)/,
'private',
'protocol',
'public(set)',
/public\(set\)/,
'public',
'repeat',
'required', // contextual
Expand All @@ -104,8 +104,8 @@ export const keywords = [
/try!/, // operator
'try', // operator
'typealias',
'unowned(safe)', // contextual
'unowned(unsafe)', // contextual
/unowned\(safe\)/, // contextual
/unowned\(unsafe\)/, // contextual
'unowned', // contextual
'var',
'weak', // contextual
Expand Down Expand Up @@ -240,7 +240,7 @@ export const identifierHead = either(
/[\u2C00-\u2DFF\u2E80-\u2FFF]/,
/[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,
/[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,
/[\uFE47-\uFFFD]/
/[\uFE47-\uFEFE\uFF00-\uFFFD]/ // Should be /[\uFE47-\uFFFD]/, but we have to exclude FEFF.
// The following characters are also allowed, but the regexes aren't supported yet.
// /[\u{10000}-\u{1FFFD}\u{20000-\u{2FFFD}\u{30000}-\u{3FFFD}\u{40000}-\u{4FFFD}]/u,
// /[\u{50000}-\u{5FFFD}\u{60000-\u{6FFFD}\u{70000}-\u{7FFFD}\u{80000}-\u{8FFFD}]/u,
Expand Down

0 comments on commit 35cd463

Please sign in to comment.