Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lex] Better specify whitespace characters #7359

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlisdairM
Copy link
Contributor

This commit defines a grammar term for whitespace-character and uses it consistently where the plain text term whitespace character is used. A whitespace character is defined as one of the five characters that are mentioned in the text closest to provifing a defifinition. The unicode character name is (mostly) consistently used to name these characters, and for consistency, similar changes were made to name unicode characters rather than render specified characters in code font throughout [lex]. The one exception is backslash, which is retained as-is to avoid making more issues for P2348. Note that this commit is not a replacement for P2348, merely a clearer statement of the existing specification without any normative changes.

Copy link
Member

@jensmaurer jensmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2348r3.pdf

has a paper touching the same area. It seems the paper was abandoned by its author.

source/lex.tex Outdated Show resolved Hide resolved
source/lex.tex Outdated Show resolved Hide resolved
@AlisdairM AlisdairM force-pushed the define_whitespace_character branch 2 times, most recently from 7abebf8 to bbc7afd Compare October 28, 2024 23:03
@AlisdairM
Copy link
Contributor Author

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2348r3.pdf

has a paper touching the same area. It seems the paper was abandoned by its author.

I refer to this paper in my commit message, and how I leave room for it by deliberately not replacing textual "new-line" with U+000A LINE FEED, in order to leave room for that paper's specific treatment of new-lines and line-breaks.

This PR is entirely editorial, or there is an error in the PR. I believe P2348 intends to make small but normative changes in our handling of whitespace. P2348 should be a much simpler paper to update if this PR lands.

Paging @cor3ntin for further comments.

Copy link
Member

@jensmaurer jensmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'm ready to add a grammar non-terminal editorially. This needs a nod from CWG.

Comment on lines +474 to +488
\begin{bnf}
\nontermdef{whitespace-character}\br
\unicode{0009}{character tabulation}\br
\textnormal{new-line}\br
\unicode{000b}{line tabulation}\br
\unicode{000c}{form feed}\br
\unicode{0020}{space}\br
\end{bnf}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move that to the very top of [lex.pptoken]. While the grammar is used here first, whitespace-characters are much more relevant for separating pptokens than for comments. Yes, we'll have a forward reference then. Hm. Not good, either.

Alternatively, a new subclause under [lex.char] would be appropriate: It's a kind of character (set), after all.
But having a section that contains just grammar is not good. Can we add some more meat? Maybe not editorially.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first draft (not submitted) did indeed add the grammar to the top of [lex.pptoken], but it felt even more wrong there.

I think a real solution, leaning more in the direction of P2348 but remaining editorial, would be to add a new level above [lex.comment] for "Whitespace" the covers both whitespace characters, comprising the existing [lex.comment], and a new subclause with the grammar and some text describing whitespace characters. This would be a sibling to [lex.char] and [lex.pptoken], similar to when we introduced [lex.char] for character sets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed a more substantial update that creates a new Whitespace clause for both whitespace tokens and comments. With appropriate cross-references this feels like a better approach, and closer to P2348. The main difference with that paper is that it defines a full grammar for whitespace, whereas my PR is limited to whitespace-character. The full whitespace grammar in P2348 is more detailed, and has a special treatment for line-breaks that my PR deliberately leaves room for.

I believe my changes remain purely editorial with no semantic/technical changes, although Jens correctly points out that introducing a new grammar term should be seen in Core. And while I would like to make this change for C++26, introducing the new Whitespace clause after our main clause re-org might make this C++29 material.

I have also retained my original branch that this replaces, should we wish to revert to the earlier approach.

@jensmaurer jensmaurer added the cwg Issue must be reviewed by CWG. label Oct 29, 2024
source/lex.tex Outdated
Comment on lines 683 to 706
The appearance of either of the characters \unicode{0027}{apostrophe} or \unicode{005c}{reverse solidus} or of
either of the character sequences \tcode{/*} or \tcode{//} in a
\grammarterm{q-char-sequence} or an \grammarterm{h-char-sequence}
is conditionally-supported with \impldef{meaning of \tcode{'}, \tcode{\textbackslash},
\tcode{/*}, or \tcode{//} in a \grammarterm{q-char-sequence} or an
\grammarterm{h-char-sequence}} semantics, as is the appearance of the character
\tcode{"} in an \grammarterm{h-char-sequence}.
\unicode{0022}{quotation mark} in an \grammarterm{h-char-sequence}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to use unicode notation for printable basic characters (that introduces inconsistencies even within that paragraph)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur regarding this paragraph. Please revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted and force-pushed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change seems to be an accidental repetition of the same change in #7336 which is marked as approved. Should we revisit that PR too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand, having lone special characters such as ' appear in text as (just) the glyph is a bit non-obvious, so the \unicode stuff helps for that; on the other hand, we don't make an attempt to present anything but glyphs for // or /*, which feels totally fine to me in isolation.

I'm not really sure which way we should go. @tkoeppe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have reverted that chance in this branch, and it is a duplicate of #7336, I suggest we have that conversation over there and keep the simplified PR here.

Alternatively, I could split #7336 in two so that this question has a PR all of its own.

@AlisdairM AlisdairM force-pushed the define_whitespace_character branch 2 times, most recently from 00f3471 to 9b755df Compare October 29, 2024 17:35
This commit defines a grammar term for _whitespace-character_ and
uses it consistently where the plain text term whitespace character
is used.  A whitespace character is defined as one of the five
characters that are mentioned in the text closest to provifing a
defifinition.  The unicode character name is (mostly) consistently
used to name these characters, and for consistency, similar changes
were made to name unicode characters rather than render specified
characters in code font throughout [lex].  The one exception is
backslash, which is retained as-is to avoid making more issues for
P2348.  Note that this commit is not a replacement for P2348,
merely a clearer statement of the existing specification without
any normative changes.
AlisdairM added a commit to AlisdairM/draft that referenced this pull request Nov 23, 2024
This commit does not touch the new-line character as paper
P2348.  It resricts itself to consistent use of the unicode
character name for space, horizontal tab, and vertical tab.
Compared to PR cplusplus#7359 it deliberately does not touch the
grammar that would necessitate a review by core review.
The intent is to rebase that PR if this one lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants