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

Consider introducing a new grammar pp-balanced-token-seq #5022

Open
tkoeppe opened this issue Oct 12, 2021 · 3 comments · May be fixed by #5065
Open

Consider introducing a new grammar pp-balanced-token-seq #5022

tkoeppe opened this issue Oct 12, 2021 · 3 comments · May be fixed by #5065
Assignees

Comments

@tkoeppe
Copy link
Contributor

tkoeppe commented Oct 12, 2021

Just a note from a discussion with Richard, for future consideration. We have a few places in which we spell out in prose how to form a balanced preprocessor token sequence. This could be simplified if we defined a new piece of grammar. The idea, as described by @zygoloid, might look like this:

pp-balanced-token:
    any preprocessor-token other than ( or )
    ( pp-balanced-token-seq[opt] )
pp-balanced-token-seq:
    pp-balanced-token
    pp-balanced-token-seq pp-balanced-token
va-opt-replacement:
    __VA_OPT__ ( pp-balanced-token-seq[opt] )

Then:

"""
delete [cpp.replace.general]p5 (it's misplaced anyway; this belongs in p12).
I
n p12, delete "Each subsequent [...rest of paragraph 12 and paragraph 13...]".

Add new paragraph after p12, combining parts of p5, p12, p13:

"Each instance of a function-like macro name followed by a ( as the next preprocessing token shall be a function-like macro invocation of the form:

identifier ( pp-balanced-token-seq[opt] )

Within the sequence of preprocessing tokens making up an invocation of a function-like macro, new-line is considered a normal whitespace character. The arguments of the macro invocation are the sequences of pp-balanced-tokens separated by comma preprocessing tokens. If the identifier-list in the macro definition does not end with an ellipsis, the number of arguments (including those arguments consisting of no pp-balanced-tokens) shall equal the number of parameters in the macro definition. Otherwise, there shall be at least as many arguments in the invocation as there are parameters in the macro definition (excluding the ...). If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives,[Footnote] the behavior is undefined."

Then include p15 ("If there is a ... immediately preceding the )").

Then a new paragraph defining the semantics:

"Each function-like macro invocation is replaced by the replacement list in the macro definition, after performing argument substitution as described in [cpp.subst]."

Then finally p14 (the example).

I might also want to split out an "object-like macro" and a "function-like macro" section from [cpp.replace.general]
"""

@jensmaurer
Copy link
Member

It seems a bit of a stretch to apply this editorially.

Also, this touches shared territory with C, so @ThePhD might want to offer an opinion as C project editor.

@jensmaurer jensmaurer self-assigned this Oct 22, 2021
@jensmaurer jensmaurer changed the title Consider introducing a new grammar pp-balanced-token-seq Consider introducing a new grammar _pp-balanced-token-seq_ Oct 23, 2021
@jensmaurer jensmaurer changed the title Consider introducing a new grammar _pp-balanced-token-seq_ Consider introducing a new grammar /pp-balanced-token-seq/ Oct 23, 2021
@jensmaurer jensmaurer changed the title Consider introducing a new grammar /pp-balanced-token-seq/ Consider introducing a new grammar pp-balanced-token-seq Oct 23, 2021
@ThePhD
Copy link

ThePhD commented Oct 23, 2021

Introducing this as a grammar token is likely to make life a lot easier and I would probably introduce this change in coordination with __VA_OPT__ getting into C23!

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Oct 23, 2021

@gustedt: I think you had some views on this matter? It might be useful to gather early feedback on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants