Repository navigation
[DOCS] Assorted comments on the grammar productions #387
Description
Activity
Fixes
alt-name:
The proposal uses identifiers here. Template arguments don't make sense here.//G alt-name: -//G unqualified-id : +//G identifier :
Although some declarations can be without an initializer, the grammar doesn't permit the ending
;. A statement is currently required.+//G declaration-initializer: +//G '=' statement +//G ';' +//G //G unnamed-declaration: -//G ':' meta-functions-list? template-parameter-declaration-list? function-type requires-clause? '=' statement -//G ':' meta-functions-list? template-parameter-declaration-list? type-id? requires-clause? '=' statement +//G ':' meta-functions-list? template-parameter-declaration-list? function-type requires-clause? declaration-initializer +//G ':' meta-functions-list? template-parameter-declaration-list? type-id? requires-clause? declaration-initializer //G ':' meta-functions-list? template-parameter-declaration-list? type-id -//G ':' meta-functions-list? template-parameter-declaration-list? 'final'? 'type' requires-clause? '=' statement +//G ':' meta-functions-list? template-parameter-declaration-list? 'final'? 'type' requires-clause? declaration-initializer //G ':' 'namespace' '=' statement
Resolved
by commit 9585ecc.
According to https://eel.is/c++draft/syntax#2.4, this shouldn't be a -list, but a -seq.
According to https://eel.is/c++draft/syntax#2.4, this shouldn't be a -list.
Resolved
by commit f441e43.
Commit 785c44d changed the syntax:
//G return-list: - //G expression-statement + //G expression ';'? //G '->' return-direction? type-id //G '->' parameter-declaration-list
Resolved
by #726.
Return-by move and forward:
//G return-list: -//G '->' type-id +//G '->' parameter-direction? type-id
#251 didn't add
$for interpolated raw string literals.It also added encoding-prefixes with 'R'.
These should be removed, as the 'R' is in the pertaining production of string-literal and can't apply to the other.//G encoding-prefix: one of -//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R' +//G 'u8' 'u' 'U' 'L' //G string-literal: //G encoding-prefix? '"' s-char-seq? '"' -//G encoding-prefix? 'R"' d-char-seq? '(' s-char-seq? ')' d-char-seq? '"' +//G encoding-prefix? '$'? 'R"' d-char-seq? '(' s-char-seq? ')' d-char-seq? '"'
template-argument-list:
The single argument alternative is missing.//G template-argument-list: //G template-argument-list ',' template-argument +//G template-argumentNeed fixing
The *-name-specifier of qualified-id lack recursion.
N::M::A<int, int>::B<42>::f<int, 43>
(fromregression-tests/pure2-types-order-independence-and-nesting.cpp2)
is not a qualified-id.//G qualified-id: //G nested-name-specifier unqualified-id //G member-name-specifier unqualified-id //G //G nested-name-specifier: //G '::' //G unqualified-id '::' //G //G member-name-specifier: //G unqualified-id '.'
The suffixes need to be factored out into their own production, like Cpp1.
zandZ(C++23) are missing.
Alternatively, the ud-suffixes of literal could be generalized to a literal-suffix.//G integer-literal: //G binary-literal //G hexadecimal-literal //G decimal-literal //G //G binary-literal: //G '0b' binary-digit //G '0B' binary-digit //G binary-literal binary-digit //G binary-literal ''' binary-digit //G //G hexadecimal-literal: //G '0x' hexadecimal-digit //G '0X' hexadecimal-digit //G hexadecimal-literal hexadecimal-digit //G hexadecimal-literal ''' hexadecimal-digit //G //G //G decimal-literal: //G digit [uU][lL][lL] //G decimal-literal digit [uU][lL][lL] //G decimal-literal ''' digit [uU][lL][lL]
Commit e38838e didn't add grammar.
Seems like a string-literal can't end in an interpolation.
//G string-literal: //G encoding-prefix? '"' s-char-seq? '"' //G encoding-prefix? 'R"' d-char-seq? '(' s-char-seq? ')' d-char-seq? '"' //G //G s-char-seq: //G interpolation? s-char //G interpolation? s-char-seq s-char
Simplifications
id-expression can be used to simplify type-id.
//G type-id: -//G type-qualifier-seq? qualified-id -//G type-qualifier-seq? unqualified-id +//G type-qualifier-seq? id-expression //G id-expression //G qualified-id //G unqualified-id
See also parameter-declaration-list.
It's possible to factor out an is-as-expression-target production.
+//G is-as-expression-target: +//G is-type-constraint +//G is-value-constraint +//G as-type-cast //G is-as-expression: //G prefix-expression -//G is-as-expression is-type-constraint -//G is-as-expression is-value-constraint -//G is-as-expression as-type-cast +//G is-as-expression is-as-expression-target //GTODO type-id is-type-constraint //G alternative: -//G alt-name? is-type-constraint '=' statement -//G alt-name? is-value-constraint '=' statement -//G alt-name? as-type-cast '=' statement +//G alt-name? is-as-expression-target '=' statement //G //G alt-name: //G unqualified-id : //G //G inspect-expression: //G 'inspect' 'constexpr'? expression '{' alternative-seq? '}' //G 'inspect' 'constexpr'? expression '->' type-id '{' alternative-seq? '}' //G //G alternative-seq: //G alternative //G alternative-seq alternative
Proposals
Resolved
by #1183.
//G return-list: //G '->' type-id //G '->' parameter_declaration_list
The
'->' parameter_declaration_listis target of #343.#343 can be fixed by
making the function-type a type-id and
allowing to omit a parameter's identifier.The order of parameter-declaration's productions means that:
- The
copyin(copy: T)is a parameter-direction. - A by-
inparameter named after a parameter-direction
needs theinexplicitly spelled out.
Visualized
See also parameter-declaration, type-id, inspect.
See also #387 (comment), #387 (comment), #397 (comment).
See also alternatives designs #456 (comment), #456 (comment), #305 (comment) (also provides a short summary of each alternative).//G type-id: -//G type-qualifier-seq? qualified-id -//G type-qualifier-seq? unqualified-id +//G type-qualifier-seq? id-expression +//G type-qualifier-seq? function-type //G parameter-declaration: +//G parameter-direction? unnamed-declaration //G this-specifier? parameter-direction? declaration +//G this-specifier? parameter-direction? identifier //G return-list: //G '->' type-id -//G '->' parameter_declaration_list
Resolved
by #1183.
inspectshould be able to result in a pointer to a function type.
Maybe it's just out of date.//G inspect-expression: -//G 'inspect' 'constexpr'? expression '{' alternative-seq? '}' -//G 'inspect' 'constexpr'? expression '->' type-id '{' alternative-seq? '}' +//G 'inspect' 'constexpr'? expression return-list? '{' alternative-seq? '}'
See also parameter-declaration-list.
Others
Commit 928186e didn't add grammar nor updated
for's.
My guess://G iteration-statement: //G label? 'while' logical-or-expression next-clause? compound-statement //G label? 'do' compound-statement 'while' logical-or-expression next-clause? ';' -//G label? 'for' expression next-clause? 'do' unnamed-declaration +//G label? 'for' expression next-clause? 'do' parameterized-statement +//G parameterized-statement: +//G parameter-declaration-list statement //G statement: //G selection-statement //G inspect-expression //G return-statement //G jump-statement //G iteration-statement //G compound-statement //G declaration +//G parameterized-statement //G expression-statement //G contract //GTODO try-block
Resolved
by commit ebdcd85.
Although the Cpp2 grammar doesn't seem to treat
true,false, andnullptrspecially,
writing a highlighter that does, and follows the order of productions, results in those not being highlighted.


//G primary-expression: //G inspect-expression -//G id-expression //G literal +//G id-expression //G '(' expression-list ')' //G '{' expression-list '}' //G unnamed-declaration
Reacted by Nick Treleaven- The
Beyond C++20
See also integer-suffix.
Resolved
by #483.
Maybecppfrontdoesn't handle this yet.//G postfix-expression: //G primary-expression //G postfix-expression postfix-operator [Note: without whitespace before the operator] -//G postfix-expression '[' expression-list ']' +//G postfix-expression '[' expression-list? ']' //G postfix-expression '(' expression-list? ')' //G postfix-expression '.' id-expression
Outdated
//GcommentsThe
Pinf: (P) = { }orf: <P> () = { }
is accepted as a parameter-declaration
but is not a declaration.//G parameter-declaration: //G this-specifier? parameter-direction? declaration +//G this-specifier? parameter-direction? identifier '...'?See also parameter-declaration-list.
Commit d8c1a50 didn't add
'@'.//G punctuator: one of //G '...' '.' //G '::' ':' -//G '{' '}' '(' ')' '[' ']' ';' ',' '?' '$' +//G '{' '}' '(' ')' '[' ']' ';' ',' '?' '$' '@'
The TODO is done by identifier's
'operator' operatorproduction.//G identifier: //G identifier-start //G identifier identifier-continue //G 'operator' operator //G unqualified-id: //G identifier //G template-id -//GTODO operator-function-idCommit ab3670a didn't add
'()' '[]'.
||=,&&=, and~=are not operators.//G operator: one of //G '/=' '/' //G '<<=' '<<' '<=>' '<=' '<' //G '>>=' '>>' '>=' '>' //G '++' '+=' '+' //G '--' '-=' '->' '-' -//G '||=' '||' '|=' '|' -//G '&&=' '&&' '&=' '&' +//G '||' '|=' '|' +//G '&&' '&=' '&' //G '*=' '*' //G '%=' '%' //G '^=' '^' -//G '~=' '~' +//G '~' //G '==' '=' //G '!=' '!' +//G '()' '[]'
#366 didn't update the grammar.
//G selection-statement: //G 'if' 'constexpr'? logical-or-expression compound-statement //G 'if' 'constexpr'? logical-or-expression compound-statement 'else' compound-statement +//G 'if' 'constexpr'? logical-or-expression compound-statement 'else' selection-statementDoubts
JohelEGP commented
on Apr 26, 2023 on Apr 26, 2023 · Hidden as outdatedAuthorshow commentMore actions- changed the title
[-]docs: assorted comments on the grammar productions[/-][+][DOCS] Assorted comments on the grammar productions[/+]on May 2, 2023 - added a commit that references this issue
on Sep 26, 2023 //G punctuator: one of //G '.' '..' '...' '..<' '..=' //G '::' ':' //G '{' '}' '(' ')' '[' ']' ';' ',' '?' '$'
What is
'?'for?What is
'?'for??is currently unused in Cpp2, like some of the keywords in thekeywordslist. They're in the grammar productions mostly because I started with cloning the relevant parts of the Cpp1 grammar.

Table of contents
//GcommentsSee also: #71, #392, #408.