• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- lib/Parser/Fortran-parsers.cpp ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // Top-level grammar specification for Fortran.  These parsers drive
10 // the tokenization parsers in cooked-tokens.h to consume characters,
11 // recognize the productions of Fortran, and to construct a parse tree.
12 // See ParserCombinators.md for documentation on the parser combinator
13 // library used here to implement an LL recursive descent recognizer.
14 
15 // The productions that follow are derived from the draft Fortran 2018
16 // standard, with some necessary modifications to remove left recursion
17 // and some generalization in order to defer cases where parses depend
18 // on the definitions of symbols.  The "Rxxx" numbers that appear in
19 // comments refer to these numbered requirements in the Fortran standard.
20 
21 // The whole Fortran grammar originally constituted one header file,
22 // but that turned out to require more memory to compile with current
23 // C++ compilers than some people were willing to accept, so now the
24 // various per-type parsers are partitioned into several C++ source
25 // files.  This file contains parsers for constants, types, declarations,
26 // and misfits (mostly clauses 7, 8, & 9 of Fortran 2018).  The others:
27 //  executable-parsers.cpp  Executable statements
28 //  expr-parsers.cpp        Expressions
29 //  io-parsers.cpp          I/O statements and FORMAT
30 //  openmp-parsers.cpp      OpenMP directives
31 //  program-parsers.cpp     Program units
32 
33 #include "basic-parsers.h"
34 #include "expr-parsers.h"
35 #include "misc-parsers.h"
36 #include "stmt-parser.h"
37 #include "token-parsers.h"
38 #include "type-parser-implementation.h"
39 #include "flang/Parser/parse-tree.h"
40 #include "flang/Parser/user-state.h"
41 
42 namespace Fortran::parser {
43 
44 // R601 alphanumeric-character -> letter | digit | underscore
45 // R603 name -> letter [alphanumeric-character]...
46 constexpr auto nonDigitIdChar{letter || otherIdChar};
47 constexpr auto rawName{nonDigitIdChar >> many(nonDigitIdChar || digit)};
48 TYPE_PARSER(space >> sourced(rawName >> construct<Name>()))
49 
50 // R604 constant ->  literal-constant | named-constant
51 // Used only via R607 int-constant and R845 data-stmt-constant.
52 // The look-ahead check prevents occlusion of constant-subobject in
53 // data-stmt-constant.
54 TYPE_PARSER(construct<ConstantValue>(literalConstant) ||
55     construct<ConstantValue>(namedConstant / !"%"_tok / !"("_tok))
56 
57 // R608 intrinsic-operator ->
58 //        power-op | mult-op | add-op | concat-op | rel-op |
59 //        not-op | and-op | or-op | equiv-op
60 // R610 extended-intrinsic-op -> intrinsic-operator
61 // These parsers must be ordered carefully to avoid misrecognition.
62 constexpr auto namedIntrinsicOperator{
63     ".LT." >> pure(DefinedOperator::IntrinsicOperator::LT) ||
64     ".LE." >> pure(DefinedOperator::IntrinsicOperator::LE) ||
65     ".EQ." >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
66     ".NE." >> pure(DefinedOperator::IntrinsicOperator::NE) ||
67     ".GE." >> pure(DefinedOperator::IntrinsicOperator::GE) ||
68     ".GT." >> pure(DefinedOperator::IntrinsicOperator::GT) ||
69     ".NOT." >> pure(DefinedOperator::IntrinsicOperator::NOT) ||
70     ".AND." >> pure(DefinedOperator::IntrinsicOperator::AND) ||
71     ".OR." >> pure(DefinedOperator::IntrinsicOperator::OR) ||
72     ".EQV." >> pure(DefinedOperator::IntrinsicOperator::EQV) ||
73     ".NEQV." >> pure(DefinedOperator::IntrinsicOperator::NEQV) ||
74     extension<LanguageFeature::XOROperator>(
75         ".XOR." >> pure(DefinedOperator::IntrinsicOperator::NEQV)) ||
76     extension<LanguageFeature::LogicalAbbreviations>(
77         ".N." >> pure(DefinedOperator::IntrinsicOperator::NOT) ||
78         ".A." >> pure(DefinedOperator::IntrinsicOperator::AND) ||
79         ".O." >> pure(DefinedOperator::IntrinsicOperator::OR) ||
80         extension<LanguageFeature::XOROperator>(
81             ".X." >> pure(DefinedOperator::IntrinsicOperator::NEQV)))};
82 
83 constexpr auto intrinsicOperator{
84     "**" >> pure(DefinedOperator::IntrinsicOperator::Power) ||
85     "*" >> pure(DefinedOperator::IntrinsicOperator::Multiply) ||
86     "//" >> pure(DefinedOperator::IntrinsicOperator::Concat) ||
87     "/=" >> pure(DefinedOperator::IntrinsicOperator::NE) ||
88     "/" >> pure(DefinedOperator::IntrinsicOperator::Divide) ||
89     "+" >> pure(DefinedOperator::IntrinsicOperator::Add) ||
90     "-" >> pure(DefinedOperator::IntrinsicOperator::Subtract) ||
91     "<=" >> pure(DefinedOperator::IntrinsicOperator::LE) ||
92     extension<LanguageFeature::AlternativeNE>(
93         "<>" >> pure(DefinedOperator::IntrinsicOperator::NE)) ||
94     "<" >> pure(DefinedOperator::IntrinsicOperator::LT) ||
95     "==" >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
96     ">=" >> pure(DefinedOperator::IntrinsicOperator::GE) ||
97     ">" >> pure(DefinedOperator::IntrinsicOperator::GT) ||
98     namedIntrinsicOperator};
99 
100 // R609 defined-operator ->
101 //        defined-unary-op | defined-binary-op | extended-intrinsic-op
102 TYPE_PARSER(construct<DefinedOperator>(intrinsicOperator) ||
103     construct<DefinedOperator>(definedOpName))
104 
105 // R505 implicit-part -> [implicit-part-stmt]... implicit-stmt
106 // TODO: Can overshoot; any trailing PARAMETER, FORMAT, & ENTRY
107 // statements after the last IMPLICIT should be transferred to the
108 // list of declaration-constructs.
109 TYPE_CONTEXT_PARSER("implicit part"_en_US,
110     construct<ImplicitPart>(many(Parser<ImplicitPartStmt>{})))
111 
112 // R506 implicit-part-stmt ->
113 //         implicit-stmt | parameter-stmt | format-stmt | entry-stmt
TYPE_PARSER(first (construct<ImplicitPartStmt> (statement (indirect (Parser<ImplicitStmt>{}))),construct<ImplicitPartStmt> (statement (indirect (parameterStmt))),construct<ImplicitPartStmt> (statement (indirect (oldParameterStmt))),construct<ImplicitPartStmt> (statement (indirect (formatStmt))),construct<ImplicitPartStmt> (statement (indirect (entryStmt))),construct<ImplicitPartStmt> (indirect (compilerDirective))))114 TYPE_PARSER(first(
115     construct<ImplicitPartStmt>(statement(indirect(Parser<ImplicitStmt>{}))),
116     construct<ImplicitPartStmt>(statement(indirect(parameterStmt))),
117     construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
118     construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
119     construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
120     construct<ImplicitPartStmt>(indirect(compilerDirective))))
121 
122 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
123 // Internal subprograms are not program units, so their END statements
124 // can be followed by ';' and another statement on the same line.
125 TYPE_CONTEXT_PARSER("internal subprogram"_en_US,
126     (construct<InternalSubprogram>(indirect(functionSubprogram)) ||
127         construct<InternalSubprogram>(indirect(subroutineSubprogram))) /
128         forceEndOfStmt)
129 
130 // R511 internal-subprogram-part -> contains-stmt [internal-subprogram]...
131 TYPE_CONTEXT_PARSER("internal subprogram part"_en_US,
132     construct<InternalSubprogramPart>(statement(containsStmt),
133         many(StartNewSubprogram{} >> Parser<InternalSubprogram>{})))
134 
135 // R605 literal-constant ->
136 //        int-literal-constant | real-literal-constant |
137 //        complex-literal-constant | logical-literal-constant |
138 //        char-literal-constant | boz-literal-constant
139 TYPE_PARSER(
140     first(construct<LiteralConstant>(Parser<HollerithLiteralConstant>{}),
141         construct<LiteralConstant>(realLiteralConstant),
142         construct<LiteralConstant>(intLiteralConstant),
143         construct<LiteralConstant>(Parser<ComplexLiteralConstant>{}),
144         construct<LiteralConstant>(Parser<BOZLiteralConstant>{}),
145         construct<LiteralConstant>(charLiteralConstant),
146         construct<LiteralConstant>(Parser<LogicalLiteralConstant>{})))
147 
148 // R606 named-constant -> name
149 TYPE_PARSER(construct<NamedConstant>(name))
150 
151 // R701 type-param-value -> scalar-int-expr | * | :
152 TYPE_PARSER(construct<TypeParamValue>(scalarIntExpr) ||
153     construct<TypeParamValue>(star) ||
154     construct<TypeParamValue>(construct<TypeParamValue::Deferred>(":"_tok)))
155 
156 // R702 type-spec -> intrinsic-type-spec | derived-type-spec
157 // N.B. This type-spec production is one of two instances in the Fortran
158 // grammar where intrinsic types and bare derived type names can clash;
159 // the other is below in R703 declaration-type-spec.  Look-ahead is required
160 // to disambiguate the cases where a derived type name begins with the name
161 // of an intrinsic type, e.g., REALITY.
162 TYPE_CONTEXT_PARSER("type spec"_en_US,
163     construct<TypeSpec>(intrinsicTypeSpec / lookAhead("::"_tok || ")"_tok)) ||
164         construct<TypeSpec>(derivedTypeSpec))
165 
166 // R703 declaration-type-spec ->
167 //        intrinsic-type-spec | TYPE ( intrinsic-type-spec ) |
168 //        TYPE ( derived-type-spec ) | CLASS ( derived-type-spec ) |
169 //        CLASS ( * ) | TYPE ( * )
170 // N.B. It is critical to distribute "parenthesized()" over the alternatives
171 // for TYPE (...), rather than putting the alternatives within it, which
172 // would fail on "TYPE(real_derived)" with a misrecognition of "real" as an
173 // intrinsic-type-spec.
174 TYPE_CONTEXT_PARSER("declaration type spec"_en_US,
175     construct<DeclarationTypeSpec>(intrinsicTypeSpec) ||
176         "TYPE" >>
177             (parenthesized(construct<DeclarationTypeSpec>(intrinsicTypeSpec)) ||
178                 parenthesized(construct<DeclarationTypeSpec>(
179                     construct<DeclarationTypeSpec::Type>(derivedTypeSpec))) ||
180                 construct<DeclarationTypeSpec>(
181                     "( * )" >> construct<DeclarationTypeSpec::TypeStar>())) ||
182         "CLASS" >> parenthesized(construct<DeclarationTypeSpec>(
183                                      construct<DeclarationTypeSpec::Class>(
184                                          derivedTypeSpec)) ||
185                        construct<DeclarationTypeSpec>("*" >>
186                            construct<DeclarationTypeSpec::ClassStar>())) ||
187         extension<LanguageFeature::DECStructures>(
188             construct<DeclarationTypeSpec>(
189                 construct<DeclarationTypeSpec::Record>(
190                     "RECORD /" >> name / "/"))))
191 
192 // R704 intrinsic-type-spec ->
193 //        integer-type-spec | REAL [kind-selector] | DOUBLE PRECISION |
194 //        COMPLEX [kind-selector] | CHARACTER [char-selector] |
195 //        LOGICAL [kind-selector]
196 // Extensions: DOUBLE COMPLEX, BYTE
197 TYPE_CONTEXT_PARSER("intrinsic type spec"_en_US,
198     first(construct<IntrinsicTypeSpec>(integerTypeSpec),
199         construct<IntrinsicTypeSpec>(
200             construct<IntrinsicTypeSpec::Real>("REAL" >> maybe(kindSelector))),
201         construct<IntrinsicTypeSpec>("DOUBLE PRECISION" >>
202             construct<IntrinsicTypeSpec::DoublePrecision>()),
203         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Complex>(
204             "COMPLEX" >> maybe(kindSelector))),
205         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Character>(
206             "CHARACTER" >> maybe(Parser<CharSelector>{}))),
207         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Logical>(
208             "LOGICAL" >> maybe(kindSelector))),
209         construct<IntrinsicTypeSpec>("DOUBLE COMPLEX" >>
210             extension<LanguageFeature::DoubleComplex>(
211                 construct<IntrinsicTypeSpec::DoubleComplex>())),
212         extension<LanguageFeature::Byte>(
213             construct<IntrinsicTypeSpec>(construct<IntegerTypeSpec>(
214                 "BYTE" >> construct<std::optional<KindSelector>>(pure(1)))))))
215 
216 // R705 integer-type-spec -> INTEGER [kind-selector]
217 TYPE_PARSER(construct<IntegerTypeSpec>("INTEGER" >> maybe(kindSelector)))
218 
219 // R706 kind-selector -> ( [KIND =] scalar-int-constant-expr )
220 // Legacy extension: kind-selector -> * digit-string
221 TYPE_PARSER(construct<KindSelector>(
222                 parenthesized(maybe("KIND ="_tok) >> scalarIntConstantExpr)) ||
223     extension<LanguageFeature::StarKind>(construct<KindSelector>(
224         construct<KindSelector::StarSize>("*" >> digitString64 / spaceCheck))))
225 
226 // R707 signed-int-literal-constant -> [sign] int-literal-constant
227 TYPE_PARSER(sourced(construct<SignedIntLiteralConstant>(
228     SignedIntLiteralConstantWithoutKind{}, maybe(underscore >> kindParam))))
229 
230 // R708 int-literal-constant -> digit-string [_ kind-param]
231 // The negated look-ahead for a trailing underscore prevents misrecognition
232 // when the digit string is a numeric kind parameter of a character literal.
233 TYPE_PARSER(construct<IntLiteralConstant>(
234     space >> digitString, maybe(underscore >> kindParam) / !underscore))
235 
236 // R709 kind-param -> digit-string | scalar-int-constant-name
237 TYPE_PARSER(construct<KindParam>(digitString64) ||
238     construct<KindParam>(scalar(integer(constant(name)))))
239 
240 // R712 sign -> + | -
241 // N.B. A sign constitutes a whole token, so a space is allowed in free form
242 // after the sign and before a real-literal-constant or
243 // complex-literal-constant.  A sign is not a unary operator in these contexts.
244 constexpr auto sign{
245     "+"_tok >> pure(Sign::Positive) || "-"_tok >> pure(Sign::Negative)};
246 
247 // R713 signed-real-literal-constant -> [sign] real-literal-constant
248 constexpr auto signedRealLiteralConstant{
249     construct<SignedRealLiteralConstant>(maybe(sign), realLiteralConstant)};
250 
251 // R714 real-literal-constant ->
252 //        significand [exponent-letter exponent] [_ kind-param] |
253 //        digit-string exponent-letter exponent [_ kind-param]
254 // R715 significand -> digit-string . [digit-string] | . digit-string
255 // R716 exponent-letter -> E | D
256 // Extension: Q
257 // R717 exponent -> signed-digit-string
258 constexpr auto exponentPart{
259     ("ed"_ch || extension<LanguageFeature::QuadPrecision>("q"_ch)) >>
260     SignedDigitString{}};
261 
262 TYPE_CONTEXT_PARSER("REAL literal constant"_en_US,
263     space >>
264         construct<RealLiteralConstant>(
265             sourced((digitString >> "."_ch >>
266                             !(some(letter) >>
267                                 "."_ch /* don't misinterpret 1.AND. */) >>
268                             maybe(digitString) >> maybe(exponentPart) >> ok ||
269                         "."_ch >> digitString >> maybe(exponentPart) >> ok ||
270                         digitString >> exponentPart >> ok) >>
271                 construct<RealLiteralConstant::Real>()),
272             maybe(underscore >> kindParam)))
273 
274 // R718 complex-literal-constant -> ( real-part , imag-part )
275 TYPE_CONTEXT_PARSER("COMPLEX literal constant"_en_US,
276     parenthesized(construct<ComplexLiteralConstant>(
277         Parser<ComplexPart>{} / ",", Parser<ComplexPart>{})))
278 
279 // PGI/Intel extension: signed complex literal constant
TYPE_PARSER(construct<SignedComplexLiteralConstant> (sign,Parser<ComplexLiteralConstant>{}))280 TYPE_PARSER(construct<SignedComplexLiteralConstant>(
281     sign, Parser<ComplexLiteralConstant>{}))
282 
283 // R719 real-part ->
284 //        signed-int-literal-constant | signed-real-literal-constant |
285 //        named-constant
286 // R720 imag-part ->
287 //        signed-int-literal-constant | signed-real-literal-constant |
288 //        named-constant
289 TYPE_PARSER(construct<ComplexPart>(signedRealLiteralConstant) ||
290     construct<ComplexPart>(signedIntLiteralConstant) ||
291     construct<ComplexPart>(namedConstant))
292 
293 // R721 char-selector ->
294 //        length-selector |
295 //        ( LEN = type-param-value , KIND = scalar-int-constant-expr ) |
296 //        ( type-param-value , [KIND =] scalar-int-constant-expr ) |
297 //        ( KIND = scalar-int-constant-expr [, LEN = type-param-value] )
298 TYPE_PARSER(construct<CharSelector>(Parser<LengthSelector>{}) ||
299     parenthesized(construct<CharSelector>(
300         "LEN =" >> typeParamValue, ", KIND =" >> scalarIntConstantExpr)) ||
301     parenthesized(construct<CharSelector>(
302         typeParamValue / ",", maybe("KIND ="_tok) >> scalarIntConstantExpr)) ||
303     parenthesized(construct<CharSelector>(
304         "KIND =" >> scalarIntConstantExpr, maybe(", LEN =" >> typeParamValue))))
305 
306 // R722 length-selector -> ( [LEN =] type-param-value ) | * char-length [,]
307 // N.B. The trailing [,] in the production is permitted by the Standard
308 // only in the context of a type-declaration-stmt, but even with that
309 // limitation, it would seem to be unnecessary and buggy to consume the comma
310 // here.
311 TYPE_PARSER(construct<LengthSelector>(
312                 parenthesized(maybe("LEN ="_tok) >> typeParamValue)) ||
313     construct<LengthSelector>("*" >> charLength /* / maybe(","_tok) */))
314 
315 // R723 char-length -> ( type-param-value ) | digit-string
316 TYPE_PARSER(construct<CharLength>(parenthesized(typeParamValue)) ||
317     construct<CharLength>(space >> digitString64 / spaceCheck))
318 
319 // R724 char-literal-constant ->
320 //        [kind-param _] ' [rep-char]... ' |
321 //        [kind-param _] " [rep-char]... "
322 // "rep-char" is any non-control character.  Doubled interior quotes are
323 // combined.  Backslash escapes can be enabled.
324 // N.B. the parsing of "kind-param" takes care to not consume the '_'.
325 TYPE_CONTEXT_PARSER("CHARACTER literal constant"_en_US,
326     construct<CharLiteralConstant>(
327         kindParam / underscore, charLiteralConstantWithoutKind) ||
328         construct<CharLiteralConstant>(construct<std::optional<KindParam>>(),
329             space >> charLiteralConstantWithoutKind))
330 
331 TYPE_CONTEXT_PARSER(
332     "Hollerith"_en_US, construct<HollerithLiteralConstant>(rawHollerithLiteral))
333 
334 // R725 logical-literal-constant ->
335 //        .TRUE. [_ kind-param] | .FALSE. [_ kind-param]
336 // Also accept .T. and .F. as extensions.
337 TYPE_PARSER(construct<LogicalLiteralConstant>(
338                 logicalTRUE, maybe(underscore >> kindParam)) ||
339     construct<LogicalLiteralConstant>(
340         logicalFALSE, maybe(underscore >> kindParam)))
341 
342 // R726 derived-type-def ->
343 //        derived-type-stmt [type-param-def-stmt]...
344 //        [private-or-sequence]... [component-part]
345 //        [type-bound-procedure-part] end-type-stmt
346 // R735 component-part -> [component-def-stmt]...
347 TYPE_CONTEXT_PARSER("derived type definition"_en_US,
348     construct<DerivedTypeDef>(statement(Parser<DerivedTypeStmt>{}),
349         many(unambiguousStatement(Parser<TypeParamDefStmt>{})),
350         many(statement(Parser<PrivateOrSequence>{})),
351         many(inContext("component"_en_US,
352             unambiguousStatement(Parser<ComponentDefStmt>{}))),
353         maybe(Parser<TypeBoundProcedurePart>{}),
354         statement(Parser<EndTypeStmt>{})))
355 
356 // R727 derived-type-stmt ->
357 //        TYPE [[, type-attr-spec-list] ::] type-name [(
358 //        type-param-name-list )]
359 TYPE_CONTEXT_PARSER("TYPE statement"_en_US,
360     construct<DerivedTypeStmt>(
361         "TYPE" >> optionalListBeforeColons(Parser<TypeAttrSpec>{}), name,
362         defaulted(parenthesized(nonemptyList(name)))))
363 
364 // R728 type-attr-spec ->
365 //        ABSTRACT | access-spec | BIND(C) | EXTENDS ( parent-type-name )
366 TYPE_PARSER(construct<TypeAttrSpec>(construct<Abstract>("ABSTRACT"_tok)) ||
367     construct<TypeAttrSpec>(construct<TypeAttrSpec::BindC>("BIND ( C )"_tok)) ||
368     construct<TypeAttrSpec>(
369         construct<TypeAttrSpec::Extends>("EXTENDS" >> parenthesized(name))) ||
370     construct<TypeAttrSpec>(accessSpec))
371 
372 // R729 private-or-sequence -> private-components-stmt | sequence-stmt
373 TYPE_PARSER(construct<PrivateOrSequence>(Parser<PrivateStmt>{}) ||
374     construct<PrivateOrSequence>(Parser<SequenceStmt>{}))
375 
376 // R730 end-type-stmt -> END TYPE [type-name]
377 TYPE_PARSER(construct<EndTypeStmt>(
378     recovery("END TYPE" >> maybe(name), endStmtErrorRecovery)))
379 
380 // R731 sequence-stmt -> SEQUENCE
381 TYPE_PARSER(construct<SequenceStmt>("SEQUENCE"_tok))
382 
383 // R732 type-param-def-stmt ->
384 //        integer-type-spec , type-param-attr-spec :: type-param-decl-list
385 // R734 type-param-attr-spec -> KIND | LEN
386 constexpr auto kindOrLen{"KIND" >> pure(common::TypeParamAttr::Kind) ||
387     "LEN" >> pure(common::TypeParamAttr::Len)};
388 TYPE_PARSER(construct<TypeParamDefStmt>(integerTypeSpec / ",", kindOrLen,
389     "::" >> nonemptyList("expected type parameter declarations"_err_en_US,
390                 Parser<TypeParamDecl>{})))
391 
392 // R733 type-param-decl -> type-param-name [= scalar-int-constant-expr]
393 TYPE_PARSER(construct<TypeParamDecl>(name, maybe("=" >> scalarIntConstantExpr)))
394 
395 // R736 component-def-stmt -> data-component-def-stmt |
396 //        proc-component-def-stmt
397 // Accidental extension not enabled here: PGI accepts type-param-def-stmt in
398 // component-part of derived-type-def.
399 TYPE_PARSER(recovery(
400     withMessage("expected component definition"_err_en_US,
401         first(construct<ComponentDefStmt>(Parser<DataComponentDefStmt>{}),
402             construct<ComponentDefStmt>(Parser<ProcComponentDefStmt>{}))),
403     construct<ComponentDefStmt>(inStmtErrorRecovery)))
404 
405 // R737 data-component-def-stmt ->
406 //        declaration-type-spec [[, component-attr-spec-list] ::]
407 //        component-decl-list
408 // N.B. The standard requires double colons if there's an initializer.
409 TYPE_PARSER(construct<DataComponentDefStmt>(declarationTypeSpec,
410     optionalListBeforeColons(Parser<ComponentAttrSpec>{}),
411     nonemptyList(
412         "expected component declarations"_err_en_US, Parser<ComponentDecl>{})))
413 
414 // R738 component-attr-spec ->
415 //        access-spec | ALLOCATABLE |
416 //        CODIMENSION lbracket coarray-spec rbracket |
417 //        CONTIGUOUS | DIMENSION ( component-array-spec ) | POINTER
418 TYPE_PARSER(construct<ComponentAttrSpec>(accessSpec) ||
419     construct<ComponentAttrSpec>(allocatable) ||
420     construct<ComponentAttrSpec>("CODIMENSION" >> coarraySpec) ||
421     construct<ComponentAttrSpec>(contiguous) ||
422     construct<ComponentAttrSpec>("DIMENSION" >> Parser<ComponentArraySpec>{}) ||
423     construct<ComponentAttrSpec>(pointer) ||
424     construct<ComponentAttrSpec>(recovery(
425         fail<ErrorRecovery>(
426             "type parameter definitions must appear before component declarations"_err_en_US),
427         kindOrLen >> construct<ErrorRecovery>())))
428 
429 // R739 component-decl ->
430 //        component-name [( component-array-spec )]
431 //        [lbracket coarray-spec rbracket] [* char-length]
432 //        [component-initialization]
433 TYPE_CONTEXT_PARSER("component declaration"_en_US,
434     construct<ComponentDecl>(name, maybe(Parser<ComponentArraySpec>{}),
435         maybe(coarraySpec), maybe("*" >> charLength), maybe(initialization)))
436 
437 // R740 component-array-spec ->
438 //        explicit-shape-spec-list | deferred-shape-spec-list
439 // N.B. Parenthesized here rather than around references to this production.
440 TYPE_PARSER(construct<ComponentArraySpec>(parenthesized(
441                 nonemptyList("expected explicit shape specifications"_err_en_US,
442                     explicitShapeSpec))) ||
443     construct<ComponentArraySpec>(parenthesized(deferredShapeSpecList)))
444 
445 // R741 proc-component-def-stmt ->
446 //        PROCEDURE ( [proc-interface] ) , proc-component-attr-spec-list
447 //          :: proc-decl-list
448 TYPE_CONTEXT_PARSER("PROCEDURE component definition statement"_en_US,
449     construct<ProcComponentDefStmt>(
450         "PROCEDURE" >> parenthesized(maybe(procInterface)),
451         localRecovery("expected PROCEDURE component attributes"_err_en_US,
452             "," >> nonemptyList(Parser<ProcComponentAttrSpec>{}), ok),
453         localRecovery("expected PROCEDURE declarations"_err_en_US,
454             "::" >> nonemptyList(procDecl), SkipTo<'\n'>{})))
455 
456 // R742 proc-component-attr-spec ->
457 //        access-spec | NOPASS | PASS [(arg-name)] | POINTER
458 constexpr auto noPass{construct<NoPass>("NOPASS"_tok)};
459 constexpr auto pass{construct<Pass>("PASS" >> maybe(parenthesized(name)))};
460 TYPE_PARSER(construct<ProcComponentAttrSpec>(accessSpec) ||
461     construct<ProcComponentAttrSpec>(noPass) ||
462     construct<ProcComponentAttrSpec>(pass) ||
463     construct<ProcComponentAttrSpec>(pointer))
464 
465 // R744 initial-data-target -> designator
466 constexpr auto initialDataTarget{indirect(designator)};
467 
468 // R743 component-initialization ->
469 //        = constant-expr | => null-init | => initial-data-target
470 // R805 initialization ->
471 //        = constant-expr | => null-init | => initial-data-target
472 // Universal extension: initialization -> / data-stmt-value-list /
473 TYPE_PARSER(construct<Initialization>("=>" >> nullInit) ||
474     construct<Initialization>("=>" >> initialDataTarget) ||
475     construct<Initialization>("=" >> constantExpr) ||
476     extension<LanguageFeature::SlashInitialization>(construct<Initialization>(
477         "/" >> nonemptyList("expected values"_err_en_US,
478                    indirect(Parser<DataStmtValue>{})) /
479             "/")))
480 
481 // R745 private-components-stmt -> PRIVATE
482 // R747 binding-private-stmt -> PRIVATE
483 TYPE_PARSER(construct<PrivateStmt>("PRIVATE"_tok))
484 
485 // R746 type-bound-procedure-part ->
486 //        contains-stmt [binding-private-stmt] [type-bound-proc-binding]...
487 TYPE_CONTEXT_PARSER("type bound procedure part"_en_US,
488     construct<TypeBoundProcedurePart>(statement(containsStmt),
489         maybe(statement(Parser<PrivateStmt>{})),
490         many(statement(Parser<TypeBoundProcBinding>{}))))
491 
492 // R748 type-bound-proc-binding ->
493 //        type-bound-procedure-stmt | type-bound-generic-stmt |
494 //        final-procedure-stmt
495 TYPE_CONTEXT_PARSER("type bound procedure binding"_en_US,
496     recovery(
497         first(construct<TypeBoundProcBinding>(Parser<TypeBoundProcedureStmt>{}),
498             construct<TypeBoundProcBinding>(Parser<TypeBoundGenericStmt>{}),
499             construct<TypeBoundProcBinding>(Parser<FinalProcedureStmt>{})),
500         construct<TypeBoundProcBinding>(
501             !"END"_tok >> SkipTo<'\n'>{} >> construct<ErrorRecovery>())))
502 
503 // R749 type-bound-procedure-stmt ->
504 //        PROCEDURE [[, bind-attr-list] ::] type-bound-proc-decl-list |
505 //        PROCEDURE ( interface-name ) , bind-attr-list :: binding-name-list
506 TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
507     "PROCEDURE" >>
508         (construct<TypeBoundProcedureStmt>(
509              construct<TypeBoundProcedureStmt::WithInterface>(
510                  parenthesized(name),
511                  localRecovery("expected list of binding attributes"_err_en_US,
512                      "," >> nonemptyList(Parser<BindAttr>{}), ok),
513                  localRecovery("expected list of binding names"_err_en_US,
514                      "::" >> listOfNames, SkipTo<'\n'>{}))) ||
515             construct<TypeBoundProcedureStmt>(
516                 construct<TypeBoundProcedureStmt::WithoutInterface>(
517                     optionalListBeforeColons(Parser<BindAttr>{}),
518                     nonemptyList(
519                         "expected type bound procedure declarations"_err_en_US,
520                         Parser<TypeBoundProcDecl>{})))))
521 
522 // R750 type-bound-proc-decl -> binding-name [=> procedure-name]
523 TYPE_PARSER(construct<TypeBoundProcDecl>(name, maybe("=>" >> name)))
524 
525 // R751 type-bound-generic-stmt ->
526 //        GENERIC [, access-spec] :: generic-spec => binding-name-list
527 TYPE_CONTEXT_PARSER("type bound GENERIC statement"_en_US,
528     construct<TypeBoundGenericStmt>("GENERIC" >> maybe("," >> accessSpec),
529         "::" >> indirect(genericSpec), "=>" >> listOfNames))
530 
531 // R752 bind-attr ->
532 //        access-spec | DEFERRED | NON_OVERRIDABLE | NOPASS | PASS [(arg-name)]
533 TYPE_PARSER(construct<BindAttr>(accessSpec) ||
534     construct<BindAttr>(construct<BindAttr::Deferred>("DEFERRED"_tok)) ||
535     construct<BindAttr>(
536         construct<BindAttr::Non_Overridable>("NON_OVERRIDABLE"_tok)) ||
537     construct<BindAttr>(noPass) || construct<BindAttr>(pass))
538 
539 // R753 final-procedure-stmt -> FINAL [::] final-subroutine-name-list
540 TYPE_CONTEXT_PARSER("FINAL statement"_en_US,
541     construct<FinalProcedureStmt>("FINAL" >> maybe("::"_tok) >> listOfNames))
542 
543 // R754 derived-type-spec -> type-name [(type-param-spec-list)]
544 TYPE_PARSER(construct<DerivedTypeSpec>(name,
545     defaulted(parenthesized(nonemptyList(
546         "expected type parameters"_err_en_US, Parser<TypeParamSpec>{})))))
547 
548 // R755 type-param-spec -> [keyword =] type-param-value
549 TYPE_PARSER(construct<TypeParamSpec>(maybe(keyword / "="), typeParamValue))
550 
551 // R756 structure-constructor -> derived-type-spec ( [component-spec-list] )
552 TYPE_PARSER((construct<StructureConstructor>(derivedTypeSpec,
553                  parenthesized(optionalList(Parser<ComponentSpec>{}))) ||
554                 // This alternative corrects misrecognition of the
555                 // component-spec-list as the type-param-spec-list in
556                 // derived-type-spec.
557                 construct<StructureConstructor>(
558                     construct<DerivedTypeSpec>(
559                         name, construct<std::list<TypeParamSpec>>()),
560                     parenthesized(optionalList(Parser<ComponentSpec>{})))) /
561     !"("_tok)
562 
563 // R757 component-spec -> [keyword =] component-data-source
564 TYPE_PARSER(construct<ComponentSpec>(
565     maybe(keyword / "="), Parser<ComponentDataSource>{}))
566 
567 // R758 component-data-source -> expr | data-target | proc-target
TYPE_PARSER(construct<ComponentDataSource> (indirect (expr)))568 TYPE_PARSER(construct<ComponentDataSource>(indirect(expr)))
569 
570 // R759 enum-def ->
571 //        enum-def-stmt enumerator-def-stmt [enumerator-def-stmt]...
572 //        end-enum-stmt
573 TYPE_CONTEXT_PARSER("enum definition"_en_US,
574     construct<EnumDef>(statement(Parser<EnumDefStmt>{}),
575         some(unambiguousStatement(Parser<EnumeratorDefStmt>{})),
576         statement(Parser<EndEnumStmt>{})))
577 
578 // R760 enum-def-stmt -> ENUM, BIND(C)
579 TYPE_PARSER(construct<EnumDefStmt>("ENUM , BIND ( C )"_tok))
580 
581 // R761 enumerator-def-stmt -> ENUMERATOR [::] enumerator-list
582 TYPE_CONTEXT_PARSER("ENUMERATOR statement"_en_US,
583     construct<EnumeratorDefStmt>("ENUMERATOR" >> maybe("::"_tok) >>
584         nonemptyList("expected enumerators"_err_en_US, Parser<Enumerator>{})))
585 
586 // R762 enumerator -> named-constant [= scalar-int-constant-expr]
587 TYPE_PARSER(
588     construct<Enumerator>(namedConstant, maybe("=" >> scalarIntConstantExpr)))
589 
590 // R763 end-enum-stmt -> END ENUM
591 TYPE_PARSER(recovery("END ENUM"_tok, "END" >> SkipPast<'\n'>{}) >>
592     construct<EndEnumStmt>())
593 
594 // R801 type-declaration-stmt ->
595 //        declaration-type-spec [[, attr-spec]... ::] entity-decl-list
596 constexpr auto entityDeclWithoutEqInit{construct<EntityDecl>(name,
597     maybe(arraySpec), maybe(coarraySpec), maybe("*" >> charLength),
598     !"="_tok >> maybe(initialization))}; // old-style REAL A/0/ still works
599 TYPE_PARSER(
600     construct<TypeDeclarationStmt>(declarationTypeSpec,
601         defaulted("," >> nonemptyList(Parser<AttrSpec>{})) / "::",
602         nonemptyList("expected entity declarations"_err_en_US, entityDecl)) ||
603     // C806: no initializers allowed without colons ("REALA=1" is ambiguous)
604     construct<TypeDeclarationStmt>(declarationTypeSpec,
605         construct<std::list<AttrSpec>>(),
606         nonemptyList("expected entity declarations"_err_en_US,
607             entityDeclWithoutEqInit)) ||
608     // PGI-only extension: comma in place of doubled colons
609     extension<LanguageFeature::MissingColons>(construct<TypeDeclarationStmt>(
610         declarationTypeSpec, defaulted("," >> nonemptyList(Parser<AttrSpec>{})),
611         withMessage("expected entity declarations"_err_en_US,
612             "," >> nonemptyList(entityDecl)))))
613 
614 // R802 attr-spec ->
615 //        access-spec | ALLOCATABLE | ASYNCHRONOUS |
616 //        CODIMENSION lbracket coarray-spec rbracket | CONTIGUOUS |
617 //        DIMENSION ( array-spec ) | EXTERNAL | INTENT ( intent-spec ) |
618 //        INTRINSIC | language-binding-spec | OPTIONAL | PARAMETER | POINTER |
619 //        PROTECTED | SAVE | TARGET | VALUE | VOLATILE
620 TYPE_PARSER(construct<AttrSpec>(accessSpec) ||
621     construct<AttrSpec>(allocatable) ||
622     construct<AttrSpec>(construct<Asynchronous>("ASYNCHRONOUS"_tok)) ||
623     construct<AttrSpec>("CODIMENSION" >> coarraySpec) ||
624     construct<AttrSpec>(contiguous) ||
625     construct<AttrSpec>("DIMENSION" >> arraySpec) ||
626     construct<AttrSpec>(construct<External>("EXTERNAL"_tok)) ||
627     construct<AttrSpec>("INTENT" >> parenthesized(intentSpec)) ||
628     construct<AttrSpec>(construct<Intrinsic>("INTRINSIC"_tok)) ||
629     construct<AttrSpec>(languageBindingSpec) || construct<AttrSpec>(optional) ||
630     construct<AttrSpec>(construct<Parameter>("PARAMETER"_tok)) ||
631     construct<AttrSpec>(pointer) || construct<AttrSpec>(protectedAttr) ||
632     construct<AttrSpec>(save) ||
633     construct<AttrSpec>(construct<Target>("TARGET"_tok)) ||
634     construct<AttrSpec>(construct<Value>("VALUE"_tok)) ||
635     construct<AttrSpec>(construct<Volatile>("VOLATILE"_tok)))
636 
637 // R804 object-name -> name
638 constexpr auto objectName{name};
639 
640 // R803 entity-decl ->
641 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
642 //          [* char-length] [initialization] |
643 //        function-name [* char-length]
644 TYPE_PARSER(construct<EntityDecl>(objectName, maybe(arraySpec),
645     maybe(coarraySpec), maybe("*" >> charLength), maybe(initialization)))
646 
647 // R806 null-init -> function-reference   ... which must resolve to NULL()
648 TYPE_PARSER(lookAhead(name / "( )") >> construct<NullInit>(expr))
649 
650 // R807 access-spec -> PUBLIC | PRIVATE
651 TYPE_PARSER(construct<AccessSpec>("PUBLIC" >> pure(AccessSpec::Kind::Public)) ||
652     construct<AccessSpec>("PRIVATE" >> pure(AccessSpec::Kind::Private)))
653 
654 // R808 language-binding-spec ->
655 //        BIND ( C [, NAME = scalar-default-char-constant-expr] )
656 // R1528 proc-language-binding-spec -> language-binding-spec
657 TYPE_PARSER(construct<LanguageBindingSpec>(
658     "BIND ( C" >> maybe(", NAME =" >> scalarDefaultCharConstantExpr) / ")"))
659 
660 // R809 coarray-spec -> deferred-coshape-spec-list | explicit-coshape-spec
661 // N.B. Bracketed here rather than around references, for consistency with
662 // array-spec.
663 TYPE_PARSER(
664     construct<CoarraySpec>(bracketed(Parser<DeferredCoshapeSpecList>{})) ||
665     construct<CoarraySpec>(bracketed(Parser<ExplicitCoshapeSpec>{})))
666 
667 // R810 deferred-coshape-spec -> :
668 // deferred-coshape-spec-list - just a list of colons
listLength(std::list<Success> && xs)669 inline int listLength(std::list<Success> &&xs) { return xs.size(); }
670 
671 TYPE_PARSER(construct<DeferredCoshapeSpecList>(
672     applyFunction(listLength, nonemptyList(":"_tok))))
673 
674 // R811 explicit-coshape-spec ->
675 //        [[lower-cobound :] upper-cobound ,]... [lower-cobound :] *
676 // R812 lower-cobound -> specification-expr
677 // R813 upper-cobound -> specification-expr
678 TYPE_PARSER(construct<ExplicitCoshapeSpec>(
679     many(explicitShapeSpec / ","), maybe(specificationExpr / ":") / "*"))
680 
681 // R815 array-spec ->
682 //        explicit-shape-spec-list | assumed-shape-spec-list |
683 //        deferred-shape-spec-list | assumed-size-spec | implied-shape-spec |
684 //        implied-shape-or-assumed-size-spec | assumed-rank-spec
685 // N.B. Parenthesized here rather than around references to avoid
686 // a need for forced look-ahead.
687 // Shape specs that could be deferred-shape-spec or assumed-shape-spec
688 // (e.g. '(:,:)') are parsed as the former.
689 TYPE_PARSER(
690     construct<ArraySpec>(parenthesized(nonemptyList(explicitShapeSpec))) ||
691     construct<ArraySpec>(parenthesized(deferredShapeSpecList)) ||
692     construct<ArraySpec>(
693         parenthesized(nonemptyList(Parser<AssumedShapeSpec>{}))) ||
694     construct<ArraySpec>(parenthesized(Parser<AssumedSizeSpec>{})) ||
695     construct<ArraySpec>(parenthesized(Parser<ImpliedShapeSpec>{})) ||
696     construct<ArraySpec>(parenthesized(Parser<AssumedRankSpec>{})))
697 
698 // R816 explicit-shape-spec -> [lower-bound :] upper-bound
699 // R817 lower-bound -> specification-expr
700 // R818 upper-bound -> specification-expr
701 TYPE_PARSER(construct<ExplicitShapeSpec>(
702     maybe(specificationExpr / ":"), specificationExpr))
703 
704 // R819 assumed-shape-spec -> [lower-bound] :
705 TYPE_PARSER(construct<AssumedShapeSpec>(maybe(specificationExpr) / ":"))
706 
707 // R820 deferred-shape-spec -> :
708 // deferred-shape-spec-list - just a list of colons
709 TYPE_PARSER(construct<DeferredShapeSpecList>(
710     applyFunction(listLength, nonemptyList(":"_tok))))
711 
712 // R821 assumed-implied-spec -> [lower-bound :] *
713 TYPE_PARSER(construct<AssumedImpliedSpec>(maybe(specificationExpr / ":") / "*"))
714 
715 // R822 assumed-size-spec -> explicit-shape-spec-list , assumed-implied-spec
716 TYPE_PARSER(construct<AssumedSizeSpec>(
717     nonemptyList(explicitShapeSpec) / ",", assumedImpliedSpec))
718 
719 // R823 implied-shape-or-assumed-size-spec -> assumed-implied-spec
720 // R824 implied-shape-spec -> assumed-implied-spec , assumed-implied-spec-list
721 // I.e., when the assumed-implied-spec-list has a single item, it constitutes an
722 // implied-shape-or-assumed-size-spec; otherwise, an implied-shape-spec.
TYPE_PARSER(construct<ImpliedShapeSpec> (nonemptyList (assumedImpliedSpec)))723 TYPE_PARSER(construct<ImpliedShapeSpec>(nonemptyList(assumedImpliedSpec)))
724 
725 // R825 assumed-rank-spec -> ..
726 TYPE_PARSER(construct<AssumedRankSpec>(".."_tok))
727 
728 // R826 intent-spec -> IN | OUT | INOUT
729 TYPE_PARSER(construct<IntentSpec>("IN OUT" >> pure(IntentSpec::Intent::InOut) ||
730     "IN" >> pure(IntentSpec::Intent::In) ||
731     "OUT" >> pure(IntentSpec::Intent::Out)))
732 
733 // R827 access-stmt -> access-spec [[::] access-id-list]
734 TYPE_PARSER(construct<AccessStmt>(accessSpec,
735     defaulted(maybe("::"_tok) >>
736         nonemptyList("expected names and generic specifications"_err_en_US,
737             Parser<AccessId>{}))))
738 
739 // R828 access-id -> access-name | generic-spec
740 TYPE_PARSER(construct<AccessId>(indirect(genericSpec)) ||
741     construct<AccessId>(name)) // initially ambiguous with genericSpec
742 
743 // R829 allocatable-stmt -> ALLOCATABLE [::] allocatable-decl-list
744 TYPE_PARSER(construct<AllocatableStmt>("ALLOCATABLE" >> maybe("::"_tok) >>
745     nonemptyList(
746         "expected object declarations"_err_en_US, Parser<ObjectDecl>{})))
747 
748 // R830 allocatable-decl ->
749 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
750 // R860 target-decl ->
751 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
752 TYPE_PARSER(
753     construct<ObjectDecl>(objectName, maybe(arraySpec), maybe(coarraySpec)))
754 
755 // R831 asynchronous-stmt -> ASYNCHRONOUS [::] object-name-list
756 TYPE_PARSER(construct<AsynchronousStmt>("ASYNCHRONOUS" >> maybe("::"_tok) >>
757     nonemptyList("expected object names"_err_en_US, objectName)))
758 
759 // R832 bind-stmt -> language-binding-spec [::] bind-entity-list
760 TYPE_PARSER(construct<BindStmt>(languageBindingSpec / maybe("::"_tok),
761     nonemptyList("expected bind entities"_err_en_US, Parser<BindEntity>{})))
762 
763 // R833 bind-entity -> entity-name | / common-block-name /
764 TYPE_PARSER(construct<BindEntity>(pure(BindEntity::Kind::Object), name) ||
765     construct<BindEntity>("/" >> pure(BindEntity::Kind::Common), name / "/"))
766 
767 // R834 codimension-stmt -> CODIMENSION [::] codimension-decl-list
768 TYPE_PARSER(construct<CodimensionStmt>("CODIMENSION" >> maybe("::"_tok) >>
769     nonemptyList("expected codimension declarations"_err_en_US,
770         Parser<CodimensionDecl>{})))
771 
772 // R835 codimension-decl -> coarray-name lbracket coarray-spec rbracket
773 TYPE_PARSER(construct<CodimensionDecl>(name, coarraySpec))
774 
775 // R836 contiguous-stmt -> CONTIGUOUS [::] object-name-list
776 TYPE_PARSER(construct<ContiguousStmt>("CONTIGUOUS" >> maybe("::"_tok) >>
777     nonemptyList("expected object names"_err_en_US, objectName)))
778 
779 // R837 data-stmt -> DATA data-stmt-set [[,] data-stmt-set]...
780 TYPE_CONTEXT_PARSER("DATA statement"_en_US,
781     construct<DataStmt>(
782         "DATA" >> nonemptySeparated(Parser<DataStmtSet>{}, maybe(","_tok))))
783 
784 // R838 data-stmt-set -> data-stmt-object-list / data-stmt-value-list /
785 TYPE_PARSER(construct<DataStmtSet>(
786     nonemptyList(
787         "expected DATA statement objects"_err_en_US, Parser<DataStmtObject>{}),
788     withMessage("expected DATA statement value list"_err_en_US,
789         "/"_tok >> nonemptyList("expected DATA statement values"_err_en_US,
790                        Parser<DataStmtValue>{})) /
791         "/"))
792 
793 // R839 data-stmt-object -> variable | data-implied-do
794 TYPE_PARSER(construct<DataStmtObject>(indirect(variable)) ||
795     construct<DataStmtObject>(dataImpliedDo))
796 
797 // R840 data-implied-do ->
798 //        ( data-i-do-object-list , [integer-type-spec ::] data-i-do-variable
799 //        = scalar-int-constant-expr , scalar-int-constant-expr
800 //        [, scalar-int-constant-expr] )
801 // R842 data-i-do-variable -> do-variable
802 TYPE_PARSER(parenthesized(construct<DataImpliedDo>(
803     nonemptyList(Parser<DataIDoObject>{} / lookAhead(","_tok)) / ",",
804     maybe(integerTypeSpec / "::"), loopBounds(scalarIntConstantExpr))))
805 
806 // R841 data-i-do-object ->
807 //        array-element | scalar-structure-component | data-implied-do
808 TYPE_PARSER(construct<DataIDoObject>(scalar(indirect(designator))) ||
809     construct<DataIDoObject>(indirect(dataImpliedDo)))
810 
811 // R843 data-stmt-value -> [data-stmt-repeat *] data-stmt-constant
812 TYPE_PARSER(construct<DataStmtValue>(
813     maybe(Parser<DataStmtRepeat>{} / "*"), Parser<DataStmtConstant>{}))
814 
815 // R847 constant-subobject -> designator
816 // R846 int-constant-subobject -> constant-subobject
817 constexpr auto constantSubobject{constant(indirect(designator))};
818 
819 // R844 data-stmt-repeat -> scalar-int-constant | scalar-int-constant-subobject
820 // R607 int-constant -> constant
821 // Factored into: constant -> literal-constant -> int-literal-constant
822 // The named-constant alternative of constant is subsumed by constant-subobject
823 TYPE_PARSER(construct<DataStmtRepeat>(intLiteralConstant) ||
824     construct<DataStmtRepeat>(scalar(integer(constantSubobject))))
825 
826 // R845 data-stmt-constant ->
827 //        scalar-constant | scalar-constant-subobject |
828 //        signed-int-literal-constant | signed-real-literal-constant |
829 //        null-init | initial-data-target |
830 //        constant-structure-constructor
831 // null-init and a structure-constructor without parameters or components
832 // are syntactically ambiguous in DATA, so "x()" is misparsed into a
833 // null-init then fixed up later in expression semantics.
834 // TODO: Some structure constructors can be misrecognized as array
835 // references into constant subobjects.
836 TYPE_PARSER(sourced(first(
837     construct<DataStmtConstant>(scalar(Parser<ConstantValue>{})),
838     construct<DataStmtConstant>(nullInit),
839     construct<DataStmtConstant>(scalar(constantSubobject)) / !"("_tok,
840     construct<DataStmtConstant>(Parser<StructureConstructor>{}),
841     construct<DataStmtConstant>(signedRealLiteralConstant),
842     construct<DataStmtConstant>(signedIntLiteralConstant),
843     extension<LanguageFeature::SignedComplexLiteral>(
844         construct<DataStmtConstant>(Parser<SignedComplexLiteralConstant>{})),
845     construct<DataStmtConstant>(initialDataTarget))))
846 
847 // R848 dimension-stmt ->
848 //        DIMENSION [::] array-name ( array-spec )
849 //        [, array-name ( array-spec )]...
850 TYPE_CONTEXT_PARSER("DIMENSION statement"_en_US,
851     construct<DimensionStmt>("DIMENSION" >> maybe("::"_tok) >>
852         nonemptyList("expected array specifications"_err_en_US,
853             construct<DimensionStmt::Declaration>(name, arraySpec))))
854 
855 // R849 intent-stmt -> INTENT ( intent-spec ) [::] dummy-arg-name-list
856 TYPE_CONTEXT_PARSER("INTENT statement"_en_US,
857     construct<IntentStmt>(
858         "INTENT" >> parenthesized(intentSpec) / maybe("::"_tok), listOfNames))
859 
860 // R850 optional-stmt -> OPTIONAL [::] dummy-arg-name-list
861 TYPE_PARSER(
862     construct<OptionalStmt>("OPTIONAL" >> maybe("::"_tok) >> listOfNames))
863 
864 // R851 parameter-stmt -> PARAMETER ( named-constant-def-list )
865 // Legacy extension: omitted parentheses, no implicit typing from names
866 TYPE_CONTEXT_PARSER("PARAMETER statement"_en_US,
867     construct<ParameterStmt>(
868         "PARAMETER" >> parenthesized(nonemptyList(Parser<NamedConstantDef>{}))))
869 TYPE_CONTEXT_PARSER("old style PARAMETER statement"_en_US,
870     extension<LanguageFeature::OldStyleParameter>(construct<OldParameterStmt>(
871         "PARAMETER" >> nonemptyList(Parser<NamedConstantDef>{}))))
872 
873 // R852 named-constant-def -> named-constant = constant-expr
874 TYPE_PARSER(construct<NamedConstantDef>(namedConstant, "=" >> constantExpr))
875 
876 // R853 pointer-stmt -> POINTER [::] pointer-decl-list
877 TYPE_PARSER(construct<PointerStmt>("POINTER" >> maybe("::"_tok) >>
878     nonemptyList(
879         "expected pointer declarations"_err_en_US, Parser<PointerDecl>{})))
880 
881 // R854 pointer-decl ->
882 //        object-name [( deferred-shape-spec-list )] | proc-entity-name
TYPE_PARSER(construct<PointerDecl> (name,maybe (parenthesized (deferredShapeSpecList))))883 TYPE_PARSER(
884     construct<PointerDecl>(name, maybe(parenthesized(deferredShapeSpecList))))
885 
886 // R855 protected-stmt -> PROTECTED [::] entity-name-list
887 TYPE_PARSER(
888     construct<ProtectedStmt>("PROTECTED" >> maybe("::"_tok) >> listOfNames))
889 
890 // R856 save-stmt -> SAVE [[::] saved-entity-list]
891 TYPE_PARSER(construct<SaveStmt>(
892     "SAVE" >> defaulted(maybe("::"_tok) >>
893                   nonemptyList("expected SAVE entities"_err_en_US,
894                       Parser<SavedEntity>{}))))
895 
896 // R857 saved-entity -> object-name | proc-pointer-name | / common-block-name /
897 // R858 proc-pointer-name -> name
898 TYPE_PARSER(construct<SavedEntity>(pure(SavedEntity::Kind::Entity), name) ||
899     construct<SavedEntity>("/" >> pure(SavedEntity::Kind::Common), name / "/"))
900 
901 // R859 target-stmt -> TARGET [::] target-decl-list
902 TYPE_PARSER(construct<TargetStmt>("TARGET" >> maybe("::"_tok) >>
903     nonemptyList("expected objects"_err_en_US, Parser<ObjectDecl>{})))
904 
905 // R861 value-stmt -> VALUE [::] dummy-arg-name-list
906 TYPE_PARSER(construct<ValueStmt>("VALUE" >> maybe("::"_tok) >> listOfNames))
907 
908 // R862 volatile-stmt -> VOLATILE [::] object-name-list
909 TYPE_PARSER(construct<VolatileStmt>("VOLATILE" >> maybe("::"_tok) >>
910     nonemptyList("expected object names"_err_en_US, objectName)))
911 
912 // R866 implicit-name-spec -> EXTERNAL | TYPE
913 constexpr auto implicitNameSpec{
914     "EXTERNAL" >> pure(ImplicitStmt::ImplicitNoneNameSpec::External) ||
915     "TYPE" >> pure(ImplicitStmt::ImplicitNoneNameSpec::Type)};
916 
917 // R863 implicit-stmt ->
918 //        IMPLICIT implicit-spec-list |
919 //        IMPLICIT NONE [( [implicit-name-spec-list] )]
920 TYPE_CONTEXT_PARSER("IMPLICIT statement"_en_US,
921     construct<ImplicitStmt>(
922         "IMPLICIT" >> nonemptyList("expected IMPLICIT specifications"_err_en_US,
923                           Parser<ImplicitSpec>{})) ||
924         construct<ImplicitStmt>("IMPLICIT NONE"_sptok >>
925             defaulted(parenthesized(optionalList(implicitNameSpec)))))
926 
927 // R864 implicit-spec -> declaration-type-spec ( letter-spec-list )
928 // The variant form of declarationTypeSpec is meant to avoid misrecognition
929 // of a letter-spec as a simple parenthesized expression for kind or character
930 // length, e.g., PARAMETER(I=5,N=1); IMPLICIT REAL(I-N)(O-Z) vs.
931 // IMPLICIT REAL(I-N).  The variant form needs to attempt to reparse only
932 // types with optional parenthesized kind/length expressions, so derived
933 // type specs, DOUBLE PRECISION, and DOUBLE COMPLEX need not be considered.
934 constexpr auto noKindSelector{construct<std::optional<KindSelector>>()};
935 constexpr auto implicitSpecDeclarationTypeSpecRetry{
936     construct<DeclarationTypeSpec>(first(
937         construct<IntrinsicTypeSpec>(
938             construct<IntegerTypeSpec>("INTEGER" >> noKindSelector)),
939         construct<IntrinsicTypeSpec>(
940             construct<IntrinsicTypeSpec::Real>("REAL" >> noKindSelector)),
941         construct<IntrinsicTypeSpec>(
942             construct<IntrinsicTypeSpec::Complex>("COMPLEX" >> noKindSelector)),
943         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Character>(
944             "CHARACTER" >> construct<std::optional<CharSelector>>())),
945         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Logical>(
946             "LOGICAL" >> noKindSelector))))};
947 
948 TYPE_PARSER(construct<ImplicitSpec>(declarationTypeSpec,
949                 parenthesized(nonemptyList(Parser<LetterSpec>{}))) ||
950     construct<ImplicitSpec>(implicitSpecDeclarationTypeSpecRetry,
951         parenthesized(nonemptyList(Parser<LetterSpec>{}))))
952 
953 // R865 letter-spec -> letter [- letter]
954 TYPE_PARSER(space >> (construct<LetterSpec>(letter, maybe("-" >> letter)) ||
955                          construct<LetterSpec>(otherIdChar,
956                              construct<std::optional<const char *>>())))
957 
958 // R867 import-stmt ->
959 //        IMPORT [[::] import-name-list] |
960 //        IMPORT , ONLY : import-name-list | IMPORT , NONE | IMPORT , ALL
961 TYPE_CONTEXT_PARSER("IMPORT statement"_en_US,
962     construct<ImportStmt>(
963         "IMPORT , ONLY :" >> pure(common::ImportKind::Only), listOfNames) ||
964         construct<ImportStmt>(
965             "IMPORT , NONE" >> pure(common::ImportKind::None)) ||
966         construct<ImportStmt>(
967             "IMPORT , ALL" >> pure(common::ImportKind::All)) ||
968         construct<ImportStmt>(
969             "IMPORT" >> maybe("::"_tok) >> optionalList(name)))
970 
971 // R868 namelist-stmt ->
972 //        NAMELIST / namelist-group-name / namelist-group-object-list
973 //        [[,] / namelist-group-name / namelist-group-object-list]...
974 // R869 namelist-group-object -> variable-name
975 TYPE_PARSER(construct<NamelistStmt>("NAMELIST" >>
976     nonemptySeparated(
977         construct<NamelistStmt::Group>("/" >> name / "/", listOfNames),
978         maybe(","_tok))))
979 
980 // R870 equivalence-stmt -> EQUIVALENCE equivalence-set-list
981 // R871 equivalence-set -> ( equivalence-object , equivalence-object-list )
982 TYPE_PARSER(construct<EquivalenceStmt>("EQUIVALENCE" >>
983     nonemptyList(
984         parenthesized(nonemptyList("expected EQUIVALENCE objects"_err_en_US,
985             Parser<EquivalenceObject>{})))))
986 
987 // R872 equivalence-object -> variable-name | array-element | substring
TYPE_PARSER(construct<EquivalenceObject> (indirect (designator)))988 TYPE_PARSER(construct<EquivalenceObject>(indirect(designator)))
989 
990 // R873 common-stmt ->
991 //        COMMON [/ [common-block-name] /] common-block-object-list
992 //        [[,] / [common-block-name] / common-block-object-list]...
993 TYPE_PARSER(
994     construct<CommonStmt>("COMMON" >> defaulted("/" >> maybe(name) / "/"),
995         nonemptyList("expected COMMON block objects"_err_en_US,
996             Parser<CommonBlockObject>{}),
997         many(maybe(","_tok) >>
998             construct<CommonStmt::Block>("/" >> maybe(name) / "/",
999                 nonemptyList("expected COMMON block objects"_err_en_US,
1000                     Parser<CommonBlockObject>{})))))
1001 
1002 // R874 common-block-object -> variable-name [( array-spec )]
1003 TYPE_PARSER(construct<CommonBlockObject>(name, maybe(arraySpec)))
1004 
1005 // R901 designator -> object-name | array-element | array-section |
1006 //                    coindexed-named-object | complex-part-designator |
1007 //                    structure-component | substring
1008 // The Standard's productions for designator and its alternatives are
1009 // ambiguous without recourse to a symbol table.  Many of the alternatives
1010 // for designator (viz., array-element, coindexed-named-object,
1011 // and structure-component) are all syntactically just data-ref.
1012 // What designator boils down to is this:
1013 //  It starts with either a name or a character literal.
1014 //  If it starts with a character literal, it must be a substring.
1015 //  If it starts with a name, it's a sequence of %-separated parts;
1016 //  each part is a name, maybe a (section-subscript-list), and
1017 //  maybe an [image-selector].
1018 //  If it's a substring, it ends with (substring-range).
1019 TYPE_CONTEXT_PARSER("designator"_en_US,
1020     sourced(construct<Designator>(substring) || construct<Designator>(dataRef)))
1021 
1022 constexpr auto percentOrDot{"%"_tok ||
1023     // legacy VAX extension for RECORD field access
1024     extension<LanguageFeature::DECStructures>(
1025         "."_tok / lookAhead(OldStructureComponentName{}))};
1026 
1027 // R902 variable -> designator | function-reference
1028 // This production appears to be left-recursive in the grammar via
1029 //   function-reference ->  procedure-designator -> proc-component-ref ->
1030 //     scalar-variable
1031 // and would be so if we were to allow functions to be called via procedure
1032 // pointer components within derived type results of other function references
1033 // (a reasonable extension, esp. in the case of procedure pointer components
1034 // that are NOPASS).  However, Fortran constrains the use of a variable in a
1035 // proc-component-ref to be a data-ref without coindices (C1027).
1036 // Some array element references will be misrecognized as function references.
1037 constexpr auto noMoreAddressing{!"("_tok >> !"["_tok >> !percentOrDot};
1038 TYPE_CONTEXT_PARSER("variable"_en_US,
1039     construct<Variable>(indirect(functionReference / noMoreAddressing)) ||
1040         construct<Variable>(indirect(designator)))
1041 
1042 // R908 substring -> parent-string ( substring-range )
1043 // R909 parent-string ->
1044 //        scalar-variable-name | array-element | coindexed-named-object |
1045 //        scalar-structure-component | scalar-char-literal-constant |
1046 //        scalar-named-constant
TYPE_PARSER(construct<Substring> (dataRef,parenthesized (Parser<SubstringRange>{})))1047 TYPE_PARSER(
1048     construct<Substring>(dataRef, parenthesized(Parser<SubstringRange>{})))
1049 
1050 TYPE_PARSER(construct<CharLiteralConstantSubstring>(
1051     charLiteralConstant, parenthesized(Parser<SubstringRange>{})))
1052 
1053 // R910 substring-range -> [scalar-int-expr] : [scalar-int-expr]
1054 TYPE_PARSER(construct<SubstringRange>(
1055     maybe(scalarIntExpr), ":" >> maybe(scalarIntExpr)))
1056 
1057 // R911 data-ref -> part-ref [% part-ref]...
1058 // R914 coindexed-named-object -> data-ref
1059 // R917 array-element -> data-ref
1060 TYPE_PARSER(
1061     construct<DataRef>(nonemptySeparated(Parser<PartRef>{}, percentOrDot)))
1062 
1063 // R912 part-ref -> part-name [( section-subscript-list )] [image-selector]
1064 TYPE_PARSER(construct<PartRef>(name,
1065     defaulted(
1066         parenthesized(nonemptyList(Parser<SectionSubscript>{})) / !"=>"_tok),
1067     maybe(Parser<ImageSelector>{})))
1068 
1069 // R913 structure-component -> data-ref
1070 TYPE_PARSER(construct<StructureComponent>(
1071     construct<DataRef>(some(Parser<PartRef>{} / percentOrDot)), name))
1072 
1073 // R919 subscript -> scalar-int-expr
1074 constexpr auto subscript{scalarIntExpr};
1075 
1076 // R920 section-subscript -> subscript | subscript-triplet | vector-subscript
1077 // R923 vector-subscript -> int-expr
1078 // N.B. The distinction that needs to be made between "subscript" and
1079 // "vector-subscript" is deferred to semantic analysis.
1080 TYPE_PARSER(construct<SectionSubscript>(Parser<SubscriptTriplet>{}) ||
1081     construct<SectionSubscript>(intExpr))
1082 
1083 // R921 subscript-triplet -> [subscript] : [subscript] [: stride]
1084 TYPE_PARSER(construct<SubscriptTriplet>(
1085     maybe(subscript), ":" >> maybe(subscript), maybe(":" >> subscript)))
1086 
1087 // R925 cosubscript -> scalar-int-expr
1088 constexpr auto cosubscript{scalarIntExpr};
1089 
1090 // R924 image-selector ->
1091 //        lbracket cosubscript-list [, image-selector-spec-list] rbracket
1092 TYPE_CONTEXT_PARSER("image selector"_en_US,
1093     construct<ImageSelector>("[" >> nonemptyList(cosubscript / !"="_tok),
1094         defaulted("," >> nonemptyList(Parser<ImageSelectorSpec>{})) / "]"))
1095 
1096 // R926 image-selector-spec ->
1097 //        STAT = stat-variable | TEAM = team-value |
1098 //        TEAM_NUMBER = scalar-int-expr
1099 TYPE_PARSER(construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Stat>(
1100                 "STAT =" >> scalar(integer(indirect(variable))))) ||
1101     construct<ImageSelectorSpec>(construct<TeamValue>("TEAM =" >> teamValue)) ||
1102     construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Team_Number>(
1103         "TEAM_NUMBER =" >> scalarIntExpr)))
1104 
1105 // R927 allocate-stmt ->
1106 //        ALLOCATE ( [type-spec ::] allocation-list [, alloc-opt-list] )
1107 TYPE_CONTEXT_PARSER("ALLOCATE statement"_en_US,
1108     construct<AllocateStmt>("ALLOCATE (" >> maybe(typeSpec / "::"),
1109         nonemptyList(Parser<Allocation>{}),
1110         defaulted("," >> nonemptyList(Parser<AllocOpt>{})) / ")"))
1111 
1112 // R928 alloc-opt ->
1113 //        ERRMSG = errmsg-variable | MOLD = source-expr |
1114 //        SOURCE = source-expr | STAT = stat-variable
1115 // R931 source-expr -> expr
1116 TYPE_PARSER(construct<AllocOpt>(
1117                 construct<AllocOpt::Mold>("MOLD =" >> indirect(expr))) ||
1118     construct<AllocOpt>(
1119         construct<AllocOpt::Source>("SOURCE =" >> indirect(expr))) ||
1120     construct<AllocOpt>(statOrErrmsg))
1121 
1122 // R929 stat-variable -> scalar-int-variable
TYPE_PARSER(construct<StatVariable> (scalar (integer (variable))))1123 TYPE_PARSER(construct<StatVariable>(scalar(integer(variable))))
1124 
1125 // R932 allocation ->
1126 //        allocate-object [( allocate-shape-spec-list )]
1127 //        [lbracket allocate-coarray-spec rbracket]
1128 // TODO: allocate-shape-spec-list might be misrecognized as
1129 // the final list of subscripts in allocate-object.
1130 TYPE_PARSER(construct<Allocation>(Parser<AllocateObject>{},
1131     defaulted(parenthesized(nonemptyList(Parser<AllocateShapeSpec>{}))),
1132     maybe(bracketed(Parser<AllocateCoarraySpec>{}))))
1133 
1134 // R933 allocate-object -> variable-name | structure-component
1135 TYPE_PARSER(construct<AllocateObject>(structureComponent) ||
1136     construct<AllocateObject>(name / !"="_tok))
1137 
1138 // R934 allocate-shape-spec -> [lower-bound-expr :] upper-bound-expr
1139 // R938 allocate-coshape-spec -> [lower-bound-expr :] upper-bound-expr
1140 TYPE_PARSER(construct<AllocateShapeSpec>(maybe(boundExpr / ":"), boundExpr))
1141 
1142 // R937 allocate-coarray-spec ->
1143 //      [allocate-coshape-spec-list ,] [lower-bound-expr :] *
1144 TYPE_PARSER(construct<AllocateCoarraySpec>(
1145     defaulted(nonemptyList(Parser<AllocateShapeSpec>{}) / ","),
1146     maybe(boundExpr / ":") / "*"))
1147 
1148 // R939 nullify-stmt -> NULLIFY ( pointer-object-list )
1149 TYPE_CONTEXT_PARSER("NULLIFY statement"_en_US,
1150     "NULLIFY" >> parenthesized(construct<NullifyStmt>(
1151                      nonemptyList(Parser<PointerObject>{}))))
1152 
1153 // R940 pointer-object ->
1154 //        variable-name | structure-component | proc-pointer-name
1155 TYPE_PARSER(construct<PointerObject>(structureComponent) ||
1156     construct<PointerObject>(name))
1157 
1158 // R941 deallocate-stmt ->
1159 //        DEALLOCATE ( allocate-object-list [, dealloc-opt-list] )
1160 TYPE_CONTEXT_PARSER("DEALLOCATE statement"_en_US,
1161     construct<DeallocateStmt>(
1162         "DEALLOCATE (" >> nonemptyList(Parser<AllocateObject>{}),
1163         defaulted("," >> nonemptyList(statOrErrmsg)) / ")"))
1164 
1165 // R942 dealloc-opt -> STAT = stat-variable | ERRMSG = errmsg-variable
1166 // R1165 sync-stat -> STAT = stat-variable | ERRMSG = errmsg-variable
1167 TYPE_PARSER(construct<StatOrErrmsg>("STAT =" >> statVariable) ||
1168     construct<StatOrErrmsg>("ERRMSG =" >> msgVariable))
1169 
1170 // Directives, extensions, and deprecated statements
1171 // !DIR$ IGNORE_TKR [ [(tkr...)] name ]...
1172 // !DIR$ name...
1173 constexpr auto beginDirective{skipStuffBeforeStatement >> "!"_ch};
1174 constexpr auto endDirective{space >> endOfLine};
1175 constexpr auto ignore_tkr{
1176     "DIR$ IGNORE_TKR" >> optionalList(construct<CompilerDirective::IgnoreTKR>(
1177                              defaulted(parenthesized(some("tkr"_ch))), name))};
1178 TYPE_PARSER(beginDirective >>
1179     sourced(construct<CompilerDirective>(ignore_tkr) ||
1180         construct<CompilerDirective>(
1181             "DIR$" >> many(construct<CompilerDirective::NameValue>(name,
1182                           maybe(("="_tok || ":"_tok) >> digitString64))))) /
1183         endDirective)
1184 
1185 TYPE_PARSER(extension<LanguageFeature::CrayPointer>(construct<BasedPointerStmt>(
1186     "POINTER" >> nonemptyList("expected POINTER associations"_err_en_US,
1187                      construct<BasedPointer>("(" >> objectName / ",",
1188                          objectName, maybe(Parser<ArraySpec>{}) / ")")))))
1189 
1190 TYPE_PARSER(construct<StructureStmt>("STRUCTURE /" >> name / "/", pure(true),
1191                 optionalList(entityDecl)) ||
1192     construct<StructureStmt>(
1193         "STRUCTURE" >> name, pure(false), pure<std::list<EntityDecl>>()))
1194 
1195 TYPE_PARSER(construct<StructureField>(statement(StructureComponents{})) ||
1196     construct<StructureField>(indirect(Parser<Union>{})) ||
1197     construct<StructureField>(indirect(Parser<StructureDef>{})))
1198 
1199 TYPE_CONTEXT_PARSER("STRUCTURE definition"_en_US,
1200     extension<LanguageFeature::DECStructures>(construct<StructureDef>(
1201         statement(Parser<StructureStmt>{}), many(Parser<StructureField>{}),
1202         statement(
1203             construct<StructureDef::EndStructureStmt>("END STRUCTURE"_tok)))))
1204 
1205 TYPE_CONTEXT_PARSER("UNION definition"_en_US,
1206     construct<Union>(statement(construct<Union::UnionStmt>("UNION"_tok)),
1207         many(Parser<Map>{}),
1208         statement(construct<Union::EndUnionStmt>("END UNION"_tok))))
1209 
1210 TYPE_CONTEXT_PARSER("MAP definition"_en_US,
1211     construct<Map>(statement(construct<Map::MapStmt>("MAP"_tok)),
1212         many(Parser<StructureField>{}),
1213         statement(construct<Map::EndMapStmt>("END MAP"_tok))))
1214 
1215 TYPE_CONTEXT_PARSER("arithmetic IF statement"_en_US,
1216     deprecated<LanguageFeature::ArithmeticIF>(construct<ArithmeticIfStmt>(
1217         "IF" >> parenthesized(expr), label / ",", label / ",", label)))
1218 
1219 TYPE_CONTEXT_PARSER("ASSIGN statement"_en_US,
1220     deprecated<LanguageFeature::Assign>(
1221         construct<AssignStmt>("ASSIGN" >> label, "TO" >> name)))
1222 
1223 TYPE_CONTEXT_PARSER("assigned GOTO statement"_en_US,
1224     deprecated<LanguageFeature::AssignedGOTO>(construct<AssignedGotoStmt>(
1225         "GO TO" >> name,
1226         defaulted(maybe(","_tok) >>
1227             parenthesized(nonemptyList("expected labels"_err_en_US, label))))))
1228 
1229 TYPE_CONTEXT_PARSER("PAUSE statement"_en_US,
1230     deprecated<LanguageFeature::Pause>(
1231         construct<PauseStmt>("PAUSE" >> maybe(Parser<StopCode>{}))))
1232 
1233 // These requirement productions are defined by the Fortran standard but never
1234 // used directly by the grammar:
1235 //   R620 delimiter -> ( | ) | / | [ | ] | (/ | /)
1236 //   R1027 numeric-expr -> expr
1237 //   R1031 int-constant-expr -> int-expr
1238 //   R1221 dtv-type-spec -> TYPE ( derived-type-spec ) |
1239 //           CLASS ( derived-type-spec )
1240 //
1241 // These requirement productions are defined and used, but need not be
1242 // defined independently here in this file:
1243 //   R771 lbracket -> [
1244 //   R772 rbracket -> ]
1245 //
1246 // Further note that:
1247 //   R607 int-constant -> constant
1248 //     is used only once via R844 scalar-int-constant
1249 //   R904 logical-variable -> variable
1250 //     is used only via scalar-logical-variable
1251 //   R906 default-char-variable -> variable
1252 //     is used only via scalar-default-char-variable
1253 //   R907 int-variable -> variable
1254 //     is used only via scalar-int-variable
1255 //   R915 complex-part-designator -> designator % RE | designator % IM
1256 //     %RE and %IM are initially recognized as structure components
1257 //   R916 type-param-inquiry -> designator % type-param-name
1258 //     is occulted by structure component designators
1259 //   R918 array-section ->
1260 //        data-ref [( substring-range )] | complex-part-designator
1261 //     is not used because parsing is not sensitive to rank
1262 //   R1030 default-char-constant-expr -> default-char-expr
1263 //     is only used via scalar-default-char-constant-expr
1264 } // namespace Fortran::parser
1265