Where can I get the full list of Swift keywords?

If you're writing a custom highlighter, one thing you probably care about is that a subset of those keywords are contextual and should only be highlighted as keywords in certain positions, and some of the rules around them are tricky to get right; sometimes even line breaks are significant.

For example, copy is only treated as a keyword if it's immediately followed by another identifier on the same line:

let x = copy y    // copy is a keyword

let x = copy (y)  // copy is an identifier being called with y passed to it

let x = copy      // copy is an identifier
  y               // this is a separate statement

As you can see, the syntax highlighter on Discourse is already getting this wrong in the last two cases.

6 Likes