rust-lang / rust-lang/fls

Lexical analysis of identifiers

Open
#595 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
reStructuredText
Stars
497
Forks
41
Avg merge
3h 52m
Merged PRs (30d)
4

Description

The main part of the syntax rules for identifiers in §2.3 (fls_21vnag69kbwe) is as follows:

PureIdentifier ::=
    XID_Start XID_Continue*
  | _ XID_Continue+

NonKeywordIdentifier ::=
    PureIdentifier
  | WeakKeyword

RawIdentifier ::=
    r# (PureIdentifier | RawIdentifierKeyword)

Identifier ::=
    NonKeywordIdentifier
  | RawIdentifier
Defining "pure identifier"

This seems to have been garbled somewhere.

NonKeywordIdentifier is defined as PureIdentifier | WeakKeyword, but PureIdentifier doesn't do anything to exclude keywords, so PureIdentifier and NonKeywordIdentifier have identical meaning and include all keywords.

The definition of "pure identifier" in the text is different, and excludes weak keywords but not strict or reserved keywords.

§2.3:3 (fls_xsdmun5uqy4c)

An identifier is a lexical element that refers to a name.

§2.3:4 (fls_ktnf6zkrdy45)

A pure identifier is an identifier that does not include weak keywords.

The upshot is that the FLS says Identifier includes at least strict and reserved keywords, and so Name does too, which is certainly wrong.

I think the intent must have been that both "pure identifier" and PureIdentifer would exclude all keywords.

Lone underscore

In the FLS's model identifier is evidently intended to exclude lone underscore (which is treated as punctuation).

The syntax rules do say that, but the description of the Unicode profile in §2.3:5 (fls_jpecw46eh061) allows lone underscore.

The fix for the parallel problem in the Reference was rust-lang/reference#1129.

Zero width characters

§2.3:9 (fls_cs6cbw625np1) reads

Characters 0x200C (zero width non-joiner) and 0x200D (zero width joiner) shall not appear in a pure identifier.

This paragraph isn't saying anything new: those characters aren't included in XID_Start or XID_Continue so they wouldn't be allowed anyway.

There is a similar paragraph in the Reference.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the FLS source for §2.3 and the anchors fls_21vnag69kbwe, fls_xsdmun5uqy4c, fls_ktnf6zkrdy45, fls_jpecw46eh061, and fls_cs6cbw625np1. Check the grammar, Unicode profile, lone-underscore handling, and zero-width character text against the issue and Reference issue #1129. Done means the syntax rules and prose consistently exclude keywords and lone underscore as intended, without redundant zero-width-character claims.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.