alx-0014 - Refactor syntax of preprocessing directives#8270
alx-0014 - Refactor syntax of preprocessing directives#8270alejandro-colomar wants to merge 7 commits into
Conversation
|
I wasn't able to build the draft PDF locally, so this is untested. |
|
I recommend reviewing these commits with git-show(1)'s Is it okay like this? Or do you prefer it squashed in one commit? (I wish github had this --color-moved in the WebUI. Actually, I wish I wasn't using github. :) ) |
|
Ping. :) |
|
As we are in the ballot resolution period for the C++26 standard, I would not be waiting too eagerly for a change of this scale to be reviewed in the next six months or so. I might happen, as we want to produce the highest quality standard that we can, but we also have significant work to resolve NB concerns and publish the completed standard that clearly have our undivided attention until then. |
Thanks! That's useful info to me. :) Cheers, |
|
Also, even though grammar productions are ultimately not observable, I'd hesitate to call such a change editorial, since the wording groups made a deliberate choice in the manner of presentation. I would prefer if such a proposed change were delivered as an (editorial) paper addressed at the relevant wording group (CWG in this case). |
Why do you claim "the wording groups" made a deliberate choice in the manner of presentation? This wording has been kept essentially intact since ANSI C89. The only choice that has been made ever since, was when adding modules; the only significant change to the directives since ANSI C89. Guess what? They added modules in the same manner I'm proposing now. If you notice, the only thing I haven't moved is the syntax for modules, precisely because it's organized exactly as I'm proposing for the rest of the directives. So, the only actual deliberate choice that has been ever made regarding this in the last 35 years has been in the same direction of my proposal. See the current syntax for
You have my proposal for wg14, which is written in a paper. With minor modifications, you can get it to apply to C++. In fact, you can just skip the "proposed wording", as you have here the actual diff, and read only the rationale, which applies entirely. I'll paste the rationale here (I'll paste the one from the updated paper I'll present soon): Here's the wg14 paper: |
A choice made four decades ago can still qualify as a deliberate choice, even if we prefer to phrase things differently now. |
But WG21 has already decided to not follow that anymore, when modules were added. That makes it an editorial change to align the rest of the directives with modules. I don't think this needs to waste much time from subgroups. 15.1 (Preprocessing directives :: Preamble) refers to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf#section.15.1 which is defined in 15.5 (Header unit importation) https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf#section.15.5 That's how the syntax for all directives should be defined. |
|
All the same, CWG is used to the current grammar, and I would not want to change it without their awareness. It seems that Jens has already said as much in #8249 (comment). But perhaps we can just get CWG to take a look at this pull request to get us started. @jensmaurer Could we slot this in somewhere? |
@jensmaurer , @tkoeppe Were you able to have a look at this? |
|
Approved in WG14. |
|
It seems it needs another rebase. @tkoeppe will you do that, or should I? |
|
Please do, probably easiest on your end. |
Ahh, sorry, I saw a message in this PR that you had force pushed, but now I see it talks about the main branch not this PR. I thought you had rebased this PR. Yes, I'll rebase this PR myself. |
5f136b8 to
e2ebd3b
Compare
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
e2ebd3b to
609580f
Compare
|
Done; I've rebased. An interesting thing is that the conflict was because p3868r3 had already applied some of the changes I was proposing, for line directives. |
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
609580f to
3a31df2
Compare
|
@jensmaurer: should CWG have a look here, so at least they're all on the same page? |
|
@tkoeppe Yes, this touches grammar, and preprocessor grammar is sometimes easy to anger, so this definitely needs CWG processing. |
While this "touches" grammar, it only moves grammar specification from one subsection to others, without any text changes (you can check that with |
| \indextext{preprocessing directive!embed a resource} | ||
| \indextext{\idxcode{\#embed}}% | ||
|
|
||
| \begin{bnf} |
There was a problem hiding this comment.
This gets us a "hanging paragraph" in ISO parlance (text directly in a subsection that also has further sub-subsections).
There was a problem hiding this comment.
I based the diff on related existing code. There's for example a recent commit that did the same thing, I believe:
commit 2c473cc8744fc5b2077349add2283826061ce881
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: 2025-11-09 20:46:24 +0100
P3868R1 Allow #line before module declarations
Fixes NB US 55-102 (C++26 CD).
Editorial note:
* Retained position of #line alternative within control-line.
diff --git a/source/preprocessor.tex b/source/preprocessor.tex
index 487c0360..e449e830 100644
--- a/source/preprocessor.tex
+++ b/source/preprocessor.tex
@@ -16,11 +16,11 @@
module-file
\end{bnf}
\begin{bnf}
\nontermdef{module-file}\br
- \opt{pp-global-module-fragment} pp-module \opt{group} \opt{pp-private-module-fragment}
+ \opt{line-directives} \opt{pp-global-module-fragment} pp-module \opt{group} \opt{pp-private-module-fragment}
\end{bnf}
\begin{bnf}
\nontermdef{pp-global-module-fragment}\br
\keyword{module} \terminal{;} new-line \opt{group}
@@ -53,17 +53,22 @@
\terminal{\# define } identifier replacement-list new-line\br
\terminal{\# define } identifier lparen \opt{identifier-list} \terminal{)} replacement-list new-line\br
\terminal{\# define } identifier lparen \terminal{... )} replacement-list new-line\br
\terminal{\# define } identifier lparen identifier-list \terminal{, ... )} replacement-list new-line\br
\terminal{\# undef \ } identifier new-line\br
- \terminal{\# line \ \ } pp-tokens new-line\br
+ line-directive\br
\terminal{\# error \ } \opt{pp-tokens} new-line\br
\terminal{\# warning} \opt{pp-tokens} new-line\br
\terminal{\# pragma } \opt{pp-tokens} new-line\br
\terminal{\# }new-line
\end{bnf}
+\begin{bnf}
+\nontermdef{line-directives}\br
+ line-directive \opt{line-directives}
+\end{bnf}
+
\begin{bnf}
\nontermdef{if-section}\br
if-group \opt{elif-groups} \opt{else-group} endif-line
\end{bnf}
@@ -2060,10 +2065,15 @@ a macro name.
\rSec1[cpp.line]{Line control}%
\indextext{preprocessing directive!line control}%
\indextext{\idxcode{\#line}|see{preprocessing directive, line control}}
+\begin{bnf}
+\nontermdef{line-directive}\br
+ \terminal{\# line} pp-tokens new-line
+\end{bnf}
+
\pnum
The \grammarterm{string-literal} of a
\tcode{\#line}
directive, if present,
shall be a character string literal.Am I missing something?
There was a problem hiding this comment.
Oh, now I see. Embed has subsections, while the others don't. What do you suggest? I don't know what should be done here. Is there any part of the standard that I could imitate for this?
Maybe put it in General (cpp.embed.gen)?
Closes: #8249
Cc: @jwakely , @jensmaurer
Revisions:
v1b
v1c
v1d
v1e