Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Identifiers

In Spade identifier tokens are lexed as defined by the following regular expression:

(r#)?(
[\p{XID_Start}_]
\p{XID_Continue}*
(\u{3F} | \u{21} | (\u{3F}\u{21}) | \u{2048})?
)

This loosely follows the definition of identifiers as defined by the Unicode Standard Annex #31, with differences described in the Differences from UAX #31 section.

Breaking this down further:

  • Identifiers may be prefixed with r#, the raw identifier syntax, which allows for identifiers sharing names with keywords
  • Identifiers must start with _ or any unicode character in the set XID_Start
  • Identifiers may contain any character present in the set XID_Continue
  • Identifiers may be followed by up to one the following character sequences: ?, !, ?!,

Examples

Here is a list of a few identifiers valid in Spade:

  • _spade
  • fish123?
  • r#if
  • _
  • 游泳

Here is a list of some identifiers invalid in Spade:

  • if (a keyword without the raw identifier syntax)
  • 123spade (begins with a non-XID_Start character)
  • test-ident (contains a non-XID_Continue character)

Differences from UAX 31

  • r# may be prefixed to denote a raw identifier
  • Underscore may be the first character in an identifier
  • Identifiers may end in one of the following: ?, !, ?!,