typename std::decay<decltype(parser)>::type::resultType>);
result = parser.Parse(state);
if (!result.has_value()) {
- auto prevEnd = prevState.GetLocation();
- auto lastEnd = state.GetLocation();
+ auto prevEnd{prevState.GetLocation()};
+ auto lastEnd{state.GetLocation()};
if (prevEnd == lastEnd) {
prevState.messages().Incorporate(state.messages());
if (state.anyDeferredMessages()) {
}
// Both alternatives failed. Retain the state (and messages) from the
// alternative parse that went the furthest.
- auto paEnd = paState.GetLocation();
- auto pbEnd = state.GetLocation();
+ auto paEnd{paState.GetLocation()};
+ auto pbEnd{state.GetLocation()};
if (paEnd > pbEnd) {
messages.Annex(paState.messages());
state = std::move(paState);
constexpr ManyParser(const PA &parser) : parser_{parser} {}
std::optional<resultType> Parse(ParseState &state) const {
resultType result;
- auto at = state.GetLocation();
+ auto at{state.GetLocation()};
while (std::optional<paType> x{parser_.Parse(state)}) {
result.emplace_back(std::move(*x));
if (state.GetLocation() <= at) {
constexpr SomeParser(const SomeParser &) = default;
constexpr SomeParser(const PA &parser) : parser_{parser} {}
std::optional<resultType> Parse(ParseState &state) const {
- auto start = state.GetLocation();
+ auto start{state.GetLocation()};
if (std::optional<paType> first{parser_.Parse(state)}) {
resultType result;
result.emplace_back(std::move(*first));
constexpr SkipManyParser(const SkipManyParser &) = default;
constexpr SkipManyParser(const PA &parser) : parser_{parser} {}
std::optional<Success> Parse(ParseState &state) const {
- for (auto at = state.GetLocation();
+ for (auto at{state.GetLocation()};
parser_.Parse(state) && state.GetLocation() > at;
at = state.GetLocation()) {
}
constexpr explicit Construct1(const PA &parser) : parser_{parser} {}
constexpr Construct1(const Construct1 &) = default;
std::optional<T> Parse(ParseState &state) const {
- if (auto ax = parser_.Parse(state)) {
+ if (auto ax{parser_.Parse(state)}) {
return {T(std::move(*ax))};
}
return {};
constexpr Construct2(const PA &pa, const PB &pb) : pa_{pa}, pb_{pb} {}
constexpr Construct2(const Construct2 &) = default;
std::optional<T> Parse(ParseState &state) const {
- if (auto ax = pa_.Parse(state)) {
- if (auto bx = pb_.Parse(state)) {
+ if (auto ax{pa_.Parse(state)}) {
+ if (auto bx{pb_.Parse(state)}) {
return {T{std::move(*ax), std::move(*bx)}};
}
}
: pa_{pa}, pb_{pb}, pc_{pc} {}
constexpr Construct3(const Construct3 &) = default;
std::optional<resultType> Parse(ParseState &state) const {
- if (auto ax = pa_.Parse(state)) {
- if (auto bx = pb_.Parse(state)) {
- if (auto cx = pc_.Parse(state)) {
+ if (auto ax{pa_.Parse(state)}) {
+ if (auto bx{pb_.Parse(state)}) {
+ if (auto cx{pc_.Parse(state)}) {
return {T{std::move(*ax), std::move(*bx), std::move(*cx)}};
}
}
: pa_{pa}, pb_{pb}, pc_{pc}, pd_{pd} {}
constexpr Construct4(const Construct4 &) = default;
std::optional<resultType> Parse(ParseState &state) const {
- if (auto ax = pa_.Parse(state)) {
- if (auto bx = pb_.Parse(state)) {
- if (auto cx = pc_.Parse(state)) {
- if (auto dx = pd_.Parse(state)) {
+ if (auto ax{pa_.Parse(state)}) {
+ if (auto bx{pb_.Parse(state)}) {
+ if (auto cx{pc_.Parse(state)}) {
+ if (auto dx{pd_.Parse(state)}) {
return {T{std::move(*ax), std::move(*bx), std::move(*cx),
std::move(*dx)}};
}
: pa_{pa}, pb_{pb}, pc_{pc}, pd_{pd}, pe_{pe} {}
constexpr Construct5(const Construct5 &) = default;
std::optional<resultType> Parse(ParseState &state) const {
- if (auto ax = pa_.Parse(state)) {
- if (auto bx = pb_.Parse(state)) {
- if (auto cx = pc_.Parse(state)) {
- if (auto dx = pd_.Parse(state)) {
- if (auto ex = pe_.Parse(state)) {
+ if (auto ax{pa_.Parse(state)}) {
+ if (auto bx{pb_.Parse(state)}) {
+ if (auto cx{pc_.Parse(state)}) {
+ if (auto dx{pd_.Parse(state)}) {
+ if (auto ex{pe_.Parse(state)}) {
return {T{std::move(*ax), std::move(*bx), std::move(*cx),
std::move(*dx), std::move(*ex)}};
}
: pa_{pa}, pb_{pb}, pc_{pc}, pd_{pd}, pe_{pe}, pf_{pf} {}
constexpr Construct6(const Construct6 &) = default;
std::optional<resultType> Parse(ParseState &state) const {
- if (auto ax = pa_.Parse(state)) {
- if (auto bx = pb_.Parse(state)) {
- if (auto cx = pc_.Parse(state)) {
- if (auto dx = pd_.Parse(state)) {
- if (auto ex = pe_.Parse(state)) {
- if (auto fx = pf_.Parse(state)) {
+ if (auto ax{pa_.Parse(state)}) {
+ if (auto bx{pb_.Parse(state)}) {
+ if (auto cx{pc_.Parse(state)}) {
+ if (auto dx{pd_.Parse(state)}) {
+ if (auto ex{pe_.Parse(state)}) {
+ if (auto fx{pf_.Parse(state)}) {
return {T{std::move(*ax), std::move(*bx), std::move(*cx),
std::move(*dx), std::move(*ex), std::move(*fx)}};
}
if (state.strictConformance()) {
return {};
}
- auto at = state.GetLocation();
- auto result = parser_.Parse(state);
+ auto at{state.GetLocation()};
+ auto result{parser_.Parse(state)};
if (result.has_value()) {
state.set_anyConformanceViolation();
if (state.warnOnNonstandardUsage()) {
if (state.strictConformance()) {
return {};
}
- auto at = state.GetLocation();
- auto result = parser_.Parse(state);
+ auto at{state.GetLocation()};
+ auto result{parser_.Parse(state)};
if (result) {
state.set_anyConformanceViolation();
if (state.warnOnDeprecatedUsage()) {
constexpr SourcedParser(const PA &parser) : parser_{parser} {}
std::optional<resultType> Parse(ParseState &state) const {
const char *start{state.GetLocation()};
- auto result = parser_.Parse(state);
+ auto result{parser_.Parse(state)};
if (result.has_value()) {
result->source = CharBlock{start, state.GetLocation()};
}
// R507 declaration-construct ->
// specification-construct | data-stmt | format-stmt |
// entry-stmt | stmt-function-stmt
-constexpr auto execPartLookAhead = first(actionStmt >> ok, "ASSOCIATE ("_tok,
+constexpr auto execPartLookAhead{first(actionStmt >> ok, "ASSOCIATE ("_tok,
"BLOCK"_tok, "SELECT"_tok, "CHANGE TEAM"_sptok, "CRITICAL"_tok, "DO"_tok,
- "IF ("_tok, "WHERE ("_tok, "FORALL ("_tok);
-constexpr auto declErrorRecovery =
- errorRecoveryStart >> !execPartLookAhead >> stmtErrorRecovery;
+ "IF ("_tok, "WHERE ("_tok, "FORALL ("_tok)};
+constexpr auto declErrorRecovery{
+ errorRecoveryStart >> !execPartLookAhead >> stmtErrorRecovery};
TYPE_CONTEXT_PARSER("declaration construct"_en_US,
recovery(
first(construct<DeclarationConstruct>(specificationConstruct),
construct<DeclarationConstruct>(declErrorRecovery)))
// R507 variant of declaration-construct for use in limitedSpecificationPart.
-constexpr auto limitedDeclarationConstruct =
+constexpr auto limitedDeclarationConstruct{
inContext("declaration construct"_en_US,
recovery(
first(construct<DeclarationConstruct>(specificationConstruct),
construct<DeclarationConstruct>(statement(indirect(dataStmt)))),
construct<DeclarationConstruct>(
- errorRecoveryStart >> stmtErrorRecovery)));
+ errorRecoveryStart >> stmtErrorRecovery)))};
// R508 specification-construct ->
// derived-type-def | enum-def | generic-stmt | interface-block |
// not-op | and-op | or-op | equiv-op
// R610 extended-intrinsic-op -> intrinsic-operator
// These parsers must be ordered carefully to avoid misrecognition.
-constexpr auto namedIntrinsicOperator = ".LT." >>
- pure(DefinedOperator::IntrinsicOperator::LT) ||
+constexpr auto namedIntrinsicOperator{
+ ".LT." >> pure(DefinedOperator::IntrinsicOperator::LT) ||
".LE." >> pure(DefinedOperator::IntrinsicOperator::LE) ||
".EQ." >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
".NE." >> pure(DefinedOperator::IntrinsicOperator::NE) ||
".N." >> pure(DefinedOperator::IntrinsicOperator::NOT) ||
".A." >> pure(DefinedOperator::IntrinsicOperator::AND) ||
".O." >> pure(DefinedOperator::IntrinsicOperator::OR) ||
- ".X." >> pure(DefinedOperator::IntrinsicOperator::XOR));
+ ".X." >> pure(DefinedOperator::IntrinsicOperator::XOR))};
-constexpr auto intrinsicOperator = "**" >>
- pure(DefinedOperator::IntrinsicOperator::Power) ||
+constexpr auto intrinsicOperator{
+ "**" >> pure(DefinedOperator::IntrinsicOperator::Power) ||
"*" >> pure(DefinedOperator::IntrinsicOperator::Multiply) ||
"//" >> pure(DefinedOperator::IntrinsicOperator::Concat) ||
"/=" >> pure(DefinedOperator::IntrinsicOperator::NE) ||
"==" >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
">=" >> pure(DefinedOperator::IntrinsicOperator::GE) ||
">" >> pure(DefinedOperator::IntrinsicOperator::GT) ||
- namedIntrinsicOperator;
+ namedIntrinsicOperator};
// R609 defined-operator ->
// defined-unary-op | defined-binary-op | extended-intrinsic-op
}
// R1024 logical-expr -> expr
-constexpr auto logicalExpr = logical(indirect(expr));
-constexpr auto scalarLogicalExpr = scalar(logicalExpr);
+constexpr auto logicalExpr{logical(indirect(expr))};
+constexpr auto scalarLogicalExpr{scalar(logicalExpr)};
// R1025 default-char-expr -> expr
-constexpr auto defaultCharExpr = defaultChar(indirect(expr));
-constexpr auto scalarDefaultCharExpr = scalar(defaultCharExpr);
+constexpr auto defaultCharExpr{defaultChar(indirect(expr))};
+constexpr auto scalarDefaultCharExpr{scalar(defaultCharExpr)};
// R1026 int-expr -> expr
-constexpr auto intExpr = integer(indirect(expr));
-constexpr auto scalarIntExpr = scalar(intExpr);
+constexpr auto intExpr{integer(indirect(expr))};
+constexpr auto scalarIntExpr{scalar(intExpr)};
// R1029 constant-expr -> expr
-constexpr auto constantExpr = constant(indirect(expr));
+constexpr auto constantExpr{constant(indirect(expr))};
// R1030 default-char-constant-expr -> default-char-expr
-constexpr auto scalarDefaultCharConstantExpr =
- scalar(defaultChar(constantExpr));
+constexpr auto scalarDefaultCharConstantExpr{scalar(defaultChar(constantExpr))};
// R1031 int-constant-expr -> int-expr
-constexpr auto intConstantExpr = integer(constantExpr);
-constexpr auto scalarIntConstantExpr = scalar(intConstantExpr);
+constexpr auto intConstantExpr{integer(constantExpr)};
+constexpr auto scalarIntConstantExpr{scalar(intConstantExpr)};
// R501 program -> program-unit [program-unit]...
// This is the top-level production for the Fortran language.
// preclude FORMAT, ENTRY, and statement functions, and benefit from
// specialized error recovery in the event of a spurious executable
// statement.
-constexpr auto limitedSpecificationPart = inContext("specification part"_en_US,
+constexpr auto limitedSpecificationPart{inContext("specification part"_en_US,
construct<SpecificationPart>(many(statement(indirect(Parser<UseStmt>{}))),
many(statement(indirect(Parser<ImportStmt>{}))), implicitPart,
- many(limitedDeclarationConstruct)));
+ many(limitedDeclarationConstruct)))};
// R505 implicit-part -> [implicit-part-stmt]... implicit-stmt
// TODO: Can overshoot; any trailing PARAMETER, FORMAT, & ENTRY
construct<ImplicitPartStmt>(statement(indirect(entryStmt)))))
// R512 internal-subprogram -> function-subprogram | subroutine-subprogram
-constexpr auto internalSubprogram =
+constexpr auto internalSubprogram{
(construct<InternalSubprogram>(indirect(functionSubprogram)) ||
construct<InternalSubprogram>(indirect(subroutineSubprogram))) /
- endOfStmt;
+ endOfStmt};
// R511 internal-subprogram-part -> contains-stmt [internal-subprogram]...
TYPE_CONTEXT_PARSER("internal subprogram part"_en_US,
// case-construct | change-team-construct | critical-construct |
// do-construct | if-construct | select-rank-construct |
// select-type-construct | where-construct | forall-construct
-constexpr auto executableConstruct =
+constexpr auto executableConstruct{
first(construct<ExecutableConstruct>(statement(actionStmt)),
construct<ExecutableConstruct>(indirect(Parser<AssociateConstruct>{})),
construct<ExecutableConstruct>(indirect(Parser<BlockConstruct>{})),
construct<ExecutableConstruct>(indirect(whereConstruct)),
construct<ExecutableConstruct>(indirect(forallConstruct)),
construct<ExecutableConstruct>(indirect(openmpConstruct)),
- construct<ExecutableConstruct>(indirect(compilerDirective)));
+ construct<ExecutableConstruct>(indirect(compilerDirective)))};
// R510 execution-part-construct ->
// executable-construct | format-stmt | entry-stmt | data-stmt
// Extension (PGI/Intel): also accept NAMELIST in execution part
-constexpr auto obsoleteExecutionPartConstruct = recovery(
- ignoredStatementPrefix >>
+constexpr auto obsoleteExecutionPartConstruct{recovery(ignoredStatementPrefix >>
fail<ExecutionPartConstruct>(
"obsolete legacy extension is not supported"_err_en_US),
construct<ExecutionPartConstruct>(
statement("REDIMENSION" >> name >>
parenthesized(nonemptyList(Parser<AllocateShapeSpec>{})) >> ok) >>
- errorRecovery));
+ errorRecovery))};
TYPE_CONTEXT_PARSER("execution part construct"_en_US,
recovery(
TYPE_PARSER(construct<NamedConstant>(name))
// R701 type-param-value -> scalar-int-expr | * | :
-constexpr auto star = construct<Star>("*"_tok);
+constexpr auto star{construct<Star>("*"_tok)};
TYPE_PARSER(construct<TypeParamValue>(scalarIntExpr) ||
construct<TypeParamValue>(star) ||
construct<TypeParamValue>(construct<TypeParamValue::Deferred>(":"_tok)))
// N.B. A sign constitutes a whole token, so a space is allowed in free form
// after the sign and before a real-literal-constant or
// complex-literal-constant. A sign is not a unary operator in these contexts.
-constexpr auto sign = "+"_tok >> pure(Sign::Positive) ||
- "-"_tok >> pure(Sign::Negative);
+constexpr auto sign{
+ "+"_tok >> pure(Sign::Positive) || "-"_tok >> pure(Sign::Negative)};
// R713 signed-real-literal-constant -> [sign] real-literal-constant
-constexpr auto signedRealLiteralConstant =
- construct<SignedRealLiteralConstant>(maybe(sign), realLiteralConstant);
+constexpr auto signedRealLiteralConstant{
+ construct<SignedRealLiteralConstant>(maybe(sign), realLiteralConstant)};
// R714 real-literal-constant ->
// significand [exponent-letter exponent] [_ kind-param] |
// R716 exponent-letter -> E | D
// Extension: Q
// R717 exponent -> signed-digit-string
-constexpr auto exponentPart =
- ("ed"_ch || extension("q"_ch)) >> SignedDigitString{};
+constexpr auto exponentPart{
+ ("ed"_ch || extension("q"_ch)) >> SignedDigitString{}};
TYPE_CONTEXT_PARSER("REAL literal constant"_en_US,
space >>
// PGI extension: nc'...' is Kanji.
// N.B. charLiteralConstantWithoutKind does not skip preceding space.
// N.B. the parsing of "name" takes care to not consume the '_'.
-constexpr auto charLiteralConstantWithoutKind =
- "'"_ch >> CharLiteral<'\''>{} || "\""_ch >> CharLiteral<'"'>{};
+constexpr auto charLiteralConstantWithoutKind{
+ "'"_ch >> CharLiteral<'\''>{} || "\""_ch >> CharLiteral<'"'>{}};
TYPE_CONTEXT_PARSER("CHARACTER literal constant"_en_US,
construct<CharLiteralConstant>(
charLiteralConstantWithoutKind))
// deprecated: Hollerith literals
-constexpr auto rawHollerithLiteral = deprecated(HollerithLiteral{});
+constexpr auto rawHollerithLiteral{deprecated(HollerithLiteral{})};
TYPE_CONTEXT_PARSER(
"Hollerith"_en_US, construct<HollerithLiteralConstant>(rawHollerithLiteral))
construct<PrivateOrSequence>(Parser<SequenceStmt>{}))
// R730 end-type-stmt -> END TYPE [type-name]
-constexpr auto missingOptionalName = defaulted(cut >> maybe(name));
-constexpr auto noNameEnd = "END" >> missingOptionalName;
-constexpr auto bareEnd = noNameEnd / lookAhead(endOfStmt);
-constexpr auto endStmtErrorRecovery =
- ("END"_tok / SkipTo<'\n'>{} || consumedAllInput) >> missingOptionalName;
+constexpr auto missingOptionalName {defaulted(cut >> maybe(name))};
+constexpr auto noNameEnd{"END" >> missingOptionalName};
+constexpr auto bareEnd{noNameEnd / lookAhead(endOfStmt)};
+constexpr auto endStmtErrorRecovery{("END"_tok / SkipTo<'\n'>{} || consumedAllInput) >> missingOptionalName};
TYPE_PARSER(construct<EndTypeStmt>(
recovery("END TYPE" >> maybe(name), endStmtErrorRecovery)))
// access-spec | ALLOCATABLE |
// CODIMENSION lbracket coarray-spec rbracket |
// CONTIGUOUS | DIMENSION ( component-array-spec ) | POINTER
-constexpr auto allocatable = construct<Allocatable>("ALLOCATABLE"_tok);
-constexpr auto contiguous = construct<Contiguous>("CONTIGUOUS"_tok);
-constexpr auto pointer = construct<Pointer>("POINTER"_tok);
+constexpr auto allocatable{construct<Allocatable>("ALLOCATABLE"_tok)};
+constexpr auto contiguous{construct<Contiguous>("CONTIGUOUS"_tok)};
+constexpr auto pointer{construct<Pointer>("POINTER"_tok)};
TYPE_PARSER(construct<ComponentAttrSpec>(accessSpec) ||
construct<ComponentAttrSpec>(allocatable) ||
construct<ComponentAttrSpec>("CODIMENSION" >> coarraySpec) ||
// R742 proc-component-attr-spec ->
// access-spec | NOPASS | PASS [(arg-name)] | POINTER
-constexpr auto noPass = construct<NoPass>("NOPASS"_tok);
-constexpr auto pass = construct<Pass>("PASS" >> maybe(parenthesized(name)));
+constexpr auto noPass{construct<NoPass>("NOPASS"_tok)};
+constexpr auto pass{construct<Pass>("PASS" >> maybe(parenthesized(name)))};
TYPE_PARSER(construct<ProcComponentAttrSpec>(accessSpec) ||
construct<ProcComponentAttrSpec>(noPass) ||
construct<ProcComponentAttrSpec>(pass) ||
construct<ProcComponentAttrSpec>(pointer))
// R744 initial-data-target -> designator
-constexpr auto initialDataTarget = indirect(designator);
+constexpr auto initialDataTarget{indirect(designator)};
// R743 component-initialization ->
// = constant-expr | => null-init | => initial-data-target
TYPE_PARSER(construct<BOZLiteralConstant>(BOZLiteral{}))
// R1124 do-variable -> scalar-int-variable-name
-constexpr auto doVariable = scalar(integer(name));
+constexpr auto doVariable{scalar(integer(name))};
template<typename PA> inline constexpr auto loopBounds(const PA &p) {
return construct<LoopBounds<typename PA::resultType>>(
// DIMENSION ( array-spec ) | EXTERNAL | INTENT ( intent-spec ) |
// INTRINSIC | language-binding-spec | OPTIONAL | PARAMETER | POINTER |
// PROTECTED | SAVE | TARGET | VALUE | VOLATILE
-constexpr auto optional = construct<Optional>("OPTIONAL"_tok);
-constexpr auto protectedAttr = construct<Protected>("PROTECTED"_tok);
-constexpr auto save = construct<Save>("SAVE"_tok);
+constexpr auto optional{construct<Optional>("OPTIONAL"_tok)};
+constexpr auto protectedAttr{construct<Protected>("PROTECTED"_tok)};
+constexpr auto save{construct<Save>("SAVE"_tok)};
TYPE_PARSER(construct<AttrSpec>(accessSpec) ||
construct<AttrSpec>(allocatable) ||
construct<AttrSpec>(construct<Asynchronous>("ASYNCHRONOUS"_tok)) ||
construct<AttrSpec>(construct<Volatile>("VOLATILE"_tok)))
// R804 object-name -> name
-constexpr auto objectName = name;
+constexpr auto objectName{name};
// R803 entity-decl ->
// object-name [( array-spec )] [lbracket coarray-spec rbracket]
// R847 constant-subobject -> designator
// R846 int-constant-subobject -> constant-subobject
-constexpr auto constantSubobject = constant(indirect(designator));
+constexpr auto constantSubobject{constant(indirect(designator))};
// R844 data-stmt-repeat -> scalar-int-constant | scalar-int-constant-subobject
// R607 int-constant -> constant
"VOLATILE" >> maybe("::"_tok) >> nonemptyList(objectName)))
// R866 implicit-name-spec -> EXTERNAL | TYPE
-constexpr auto implicitNameSpec = "EXTERNAL" >>
- pure(ImplicitStmt::ImplicitNoneNameSpec::External) ||
- "TYPE" >> pure(ImplicitStmt::ImplicitNoneNameSpec::Type);
+constexpr auto implicitNameSpec{
+ "EXTERNAL" >> pure(ImplicitStmt::ImplicitNoneNameSpec::External) ||
+ "TYPE" >> pure(ImplicitStmt::ImplicitNoneNameSpec::Type)};
// R863 implicit-stmt ->
// IMPLICIT implicit-spec-list |
// IMPLICIT REAL(I-N). The variant form needs to attempt to reparse only
// types with optional parenthesized kind/length expressions, so derived
// type specs, DOUBLE PRECISION, and DOUBLE COMPLEX need not be considered.
-constexpr auto noKindSelector = construct<std::optional<KindSelector>>();
-constexpr auto implicitSpecDeclarationTypeSpecRetry =
+constexpr auto noKindSelector{construct<std::optional<KindSelector>>()};
+constexpr auto implicitSpecDeclarationTypeSpecRetry{
construct<DeclarationTypeSpec>(first(
construct<IntrinsicTypeSpec>(
construct<IntegerTypeSpec>("INTEGER" >> noKindSelector)),
construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Character>(
"CHARACTER" >> construct<std::optional<CharSelector>>())),
construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Logical>(
- "LOGICAL" >> noKindSelector))));
+ "LOGICAL" >> noKindSelector))))};
TYPE_PARSER(construct<ImplicitSpec>(declarationTypeSpec,
parenthesized(nonemptyList(Parser<LetterSpec>{}))) ||
TYPE_CONTEXT_PARSER("designator"_en_US,
construct<Designator>(substring) || construct<Designator>(dataRef))
-constexpr auto percentOrDot = "%"_tok ||
+constexpr auto percentOrDot{"%"_tok ||
// legacy VAX extension for RECORD field access
- extension("."_tok / lookAhead(OldStructureComponentName{}));
+ extension("."_tok / lookAhead(OldStructureComponentName{}))};
// R902 variable -> designator | function-reference
// This production appears to be left-recursive in the grammar via
// that are NOPASS). However, Fortran constrains the use of a variable in a
// proc-component-ref to be a data-ref without coindices (C1027).
// Some array element references will be misrecognized as function references.
-constexpr auto noMoreAddressing = !"("_tok >> !"["_tok >> !percentOrDot;
+constexpr auto noMoreAddressing{!"("_tok >> !"["_tok >> !percentOrDot};
TYPE_CONTEXT_PARSER("variable"_en_US,
construct<Variable>(indirect(functionReference / noMoreAddressing)) ||
construct<Variable>(indirect(designator)))
// R904 logical-variable -> variable
// Appears only as part of scalar-logical-variable.
-constexpr auto scalarLogicalVariable = scalar(logical(variable));
+constexpr auto scalarLogicalVariable{scalar(logical(variable))};
// R905 char-variable -> variable
-constexpr auto charVariable = construct<CharVariable>(variable);
+constexpr auto charVariable{construct<CharVariable>(variable)};
// R906 default-char-variable -> variable
// Appears only as part of scalar-default-char-variable.
-constexpr auto scalarDefaultCharVariable = scalar(defaultChar(variable));
+constexpr auto scalarDefaultCharVariable{scalar(defaultChar(variable))};
// R907 int-variable -> variable
// Appears only as part of scalar-int-variable.
-constexpr auto scalarIntVariable = scalar(integer(variable));
+constexpr auto scalarIntVariable{scalar(integer(variable))};
// R908 substring -> parent-string ( substring-range )
// R909 parent-string ->
// R915 complex-part-designator -> designator % RE | designator % IM
// %RE and %IM are initially recognized as structure components.
-constexpr auto complexPartDesignator =
- construct<ComplexPartDesignator>(dataRef);
+constexpr auto complexPartDesignator{construct<ComplexPartDesignator>(dataRef)};
// R916 type-param-inquiry -> designator % type-param-name
// Type parameter inquiries are initially recognized as structure components.
// R918 array-section ->
// data-ref [( substring-range )] | complex-part-designator
-constexpr auto arraySection = construct<ArraySection>(designator);
+constexpr auto arraySection{construct<ArraySection>(designator)};
// R919 subscript -> scalar-int-expr
-constexpr auto subscript = scalarIntExpr;
+constexpr auto subscript{scalarIntExpr};
// R923 vector-subscript -> int-expr
-constexpr auto vectorSubscript = intExpr;
+constexpr auto vectorSubscript{intExpr};
// R920 section-subscript -> subscript | subscript-triplet | vector-subscript
// N.B. The distinction that needs to be made between "subscript" and
maybe(subscript), ":" >> maybe(subscript), maybe(":" >> subscript)))
// R925 cosubscript -> scalar-int-expr
-constexpr auto cosubscript = scalarIntExpr;
+constexpr auto cosubscript{scalarIntExpr};
// R924 image-selector ->
// lbracket cosubscript-list [, image-selector-spec-list] rbracket
defaulted("," >> nonemptyList(Parser<ImageSelectorSpec>{})) / "]"))
// R1115 team-variable -> scalar-variable
-constexpr auto teamVariable = scalar(indirect(variable));
+constexpr auto teamVariable{scalar(indirect(variable))};
// R926 image-selector-spec ->
// STAT = stat-variable | TEAM = team-variable |
// R930 errmsg-variable -> scalar-default-char-variable
// R1207 iomsg-variable -> scalar-default-char-variable
-constexpr auto msgVariable = construct<MsgVariable>(scalarDefaultCharVariable);
+constexpr auto msgVariable{construct<MsgVariable>(scalarDefaultCharVariable)};
// R932 allocation ->
// allocate-object [( allocate-shape-spec-list )]
// R935 lower-bound-expr -> scalar-int-expr
// R936 upper-bound-expr -> scalar-int-expr
-constexpr auto boundExpr = scalarIntExpr;
+constexpr auto boundExpr{scalarIntExpr};
// R934 allocate-shape-spec -> [lower-bound-expr :] upper-bound-expr
// R938 allocate-coshape-spec -> [lower-bound-expr :] upper-bound-expr
// literal-constant | designator | array-constructor |
// structure-constructor | function-reference | type-param-inquiry |
// type-param-name | ( expr )
-constexpr auto primary = instrumented("primary"_en_US,
+constexpr auto primary{instrumented("primary"_en_US,
first(construct<Expr>(indirect(Parser<CharLiteralConstantSubstring>{})),
construct<Expr>(literalConstant),
construct<Expr>(construct<Expr::Parentheses>(parenthesized(expr))),
extension(construct<Expr>(parenthesized(
construct<Expr::ComplexConstructor>(expr, "," >> expr)))),
extension(construct<Expr>("%LOC" >>
- parenthesized(construct<Expr::PercentLoc>(indirect(variable)))))));
+ parenthesized(construct<Expr::PercentLoc>(indirect(variable)))))))};
// R1002 level-1-expr -> [defined-unary-op] primary
// TODO: Reasonable extension: permit multiple defined-unary-ops
-constexpr auto level1Expr = first(
+constexpr auto level1Expr{first(
construct<Expr>(construct<Expr::DefinedUnary>(definedOpName, primary)),
primary,
extension(construct<Expr>(construct<Expr::UnaryPlus>("+" >> primary))),
- extension(construct<Expr>(construct<Expr::Negate>("-" >> primary))));
+ extension(construct<Expr>(construct<Expr::Negate>("-" >> primary))))};
// R1004 mult-operand -> level-1-expr [power-op mult-operand]
// R1007 power-op -> **
inline std::optional<Expr> MultOperand::Parse(ParseState &state) {
std::optional<Expr> result{level1Expr.Parse(state)};
if (result) {
- static constexpr auto op = attempt("**"_tok);
+ static constexpr auto op{attempt("**"_tok)};
if (op.Parse(state)) {
std::function<Expr(Expr &&)> power{[&result](Expr &&right) {
return Expr{Expr::Power(std::move(result).value(), std::move(right))};
return Expr{
Expr::Divide(std::move(result).value(), std::move(right))};
}};
- auto more = "*" >> applyLambda(multiply, multOperand) ||
- "/" >> applyLambda(divide, multOperand);
+ auto more{"*" >> applyLambda(multiply, multOperand) ||
+ "/" >> applyLambda(divide, multOperand)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
using resultType = Expr;
constexpr Level2Expr() {}
static inline std::optional<Expr> Parse(ParseState &state) {
- static constexpr auto unary =
+ static constexpr auto unary{
construct<Expr>(construct<Expr::UnaryPlus>("+" >> addOperand)) ||
construct<Expr>(construct<Expr::Negate>("-" >> addOperand)) ||
- addOperand;
+ addOperand};
std::optional<Expr> result{unary.Parse(state)};
if (result) {
std::function<Expr(Expr &&)> add{[&result](Expr &&right) {
return Expr{
Expr::Subtract(std::move(result).value(), std::move(right))};
}};
- auto more = "+" >> applyLambda(add, addOperand) ||
- "-" >> applyLambda(subtract, addOperand);
+ auto more{"+" >> applyLambda(add, addOperand) ||
+ "-" >> applyLambda(subtract, addOperand)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
std::function<Expr(Expr &&)> concat{[&result](Expr &&right) {
return Expr{Expr::Concat(std::move(result).value(), std::move(right))};
}};
- auto more = "//" >> applyLambda(concat, level2Expr);
+ auto more{"//" >> applyLambda(concat, level2Expr)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
gt{[&result](Expr &&right) {
return Expr{Expr::GT(std::move(result).value(), std::move(right))};
}};
- auto more = (".LT."_tok || "<"_tok) >> applyLambda(lt, level3Expr) ||
+ auto more{(".LT."_tok || "<"_tok) >> applyLambda(lt, level3Expr) ||
(".LE."_tok || "<="_tok) >> applyLambda(le, level3Expr) ||
(".EQ."_tok || "=="_tok) >> applyLambda(eq, level3Expr) ||
(".NE."_tok || "/="_tok ||
"<>"_tok /* PGI/Cray extension; Cray also has .LG. */)) >>
applyLambda(ne, level3Expr) ||
(".GE."_tok || ">="_tok) >> applyLambda(ge, level3Expr) ||
- (".GT."_tok || ">"_tok) >> applyLambda(gt, level3Expr);
+ (".GT."_tok || ">"_tok) >> applyLambda(gt, level3Expr)};
if (std::optional<Expr> next{attempt(more).Parse(state)}) {
return next;
}
} andOperand;
inline std::optional<Expr> AndOperand::Parse(ParseState &state) {
- static constexpr auto op = attempt(".NOT."_tok);
+ static constexpr auto op{attempt(".NOT."_tok)};
int complements{0};
while (op.Parse(state)) {
++complements;
std::function<Expr(Expr &&)> logicalAnd{[&result](Expr &&right) {
return Expr{Expr::AND(std::move(result).value(), std::move(right))};
}};
- auto more = ".AND." >> applyLambda(logicalAnd, andOperand);
+ auto more{".AND." >> applyLambda(logicalAnd, andOperand)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
std::function<Expr(Expr &&)> logicalOr{[&result](Expr &&right) {
return Expr{Expr::OR(std::move(result).value(), std::move(right))};
}};
- auto more = ".OR." >> applyLambda(logicalOr, orOperand);
+ auto more{".OR." >> applyLambda(logicalOr, orOperand)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
logicalXor{[&result](Expr &&right) {
return Expr{Expr::XOR(std::move(result).value(), std::move(right))};
}};
- auto more = ".EQV." >> applyLambda(eqv, equivOperand) ||
+ auto more{".EQV." >> applyLambda(eqv, equivOperand) ||
".NEQV." >> applyLambda(neqv, equivOperand) ||
- extension(".XOR." >> applyLambda(logicalXor, equivOperand));
+ extension(".XOR." >> applyLambda(logicalXor, equivOperand))};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
return Expr{Expr::DefinedBinary(
std::move(op), std::move(result).value(), std::move(right))};
}};
- auto more = applyLambda(defBinOp, definedOpName, level5Expr);
+ auto more{applyLambda(defBinOp, definedOpName, level5Expr)};
while (std::optional<Expr> next{attempt(more).Parse(state)}) {
result = std::move(next);
}
"FORALL" >> indirect(concurrentHeader), forallAssignmentStmt))
// R1101 block -> [execution-part-construct]...
-constexpr auto block = many(executionPartConstruct);
+constexpr auto block{many(executionPartConstruct)};
// R1102 associate-construct -> associate-stmt block end-associate-stmt
TYPE_CONTEXT_PARSER("ASSOCIATE construct"_en_US,
recovery("END SELECT" >> maybe(name), endStmtErrorRecovery)))
// R1145 case-selector -> ( case-value-range-list ) | DEFAULT
-constexpr auto defaultKeyword = construct<Default>("DEFAULT"_tok);
+constexpr auto defaultKeyword{construct<Default>("DEFAULT"_tok)};
TYPE_PARSER(parenthesized(construct<CaseSelector>(
nonemptyList(Parser<CaseValueRange>{}))) ||
construct<CaseSelector>(defaultKeyword))
// R1147 case-value -> scalar-constant-expr
-constexpr auto caseValue = scalar(constantExpr);
+constexpr auto caseValue{scalar(constantExpr)};
// R1146 case-value-range ->
// case-value | case-value : | : case-value | case-value : case-value
")"))
// R1174 until-spec -> UNTIL_COUNT = scalar-int-expr
-constexpr auto untilSpec = "UNTIL_COUNT =" >> scalarIntExpr;
+constexpr auto untilSpec{"UNTIL_COUNT =" >> scalarIntExpr};
// R1173 event-wait-spec -> until-spec | sync-stat
TYPE_PARSER(construct<EventWaitStmt::EventWaitSpec>(untilSpec) ||
construct<FormTeamStmt::FormTeamSpec>(statOrErrmsg))
// R1181 lock-variable -> scalar-variable
-constexpr auto lockVariable = scalar(variable);
+constexpr auto lockVariable{scalar(variable)};
// R1178 lock-stmt -> LOCK ( lock-variable [, lock-stat-list] )
TYPE_CONTEXT_PARSER("LOCK statement"_en_US,
construct<OpenStmt>("OPEN (" >> nonemptyList(Parser<ConnectSpec>{}) / ")"))
// R1206 file-name-expr -> scalar-default-char-expr
-constexpr auto fileNameExpr = scalarDefaultCharExpr;
+constexpr auto fileNameExpr{scalarDefaultCharExpr};
// R1205 connect-spec ->
// [UNIT =] file-unit-number | ACCESS = scalar-default-char-expr |
// POSITION = scalar-default-char-expr | RECL = scalar-int-expr |
// ROUND = scalar-default-char-expr | SIGN = scalar-default-char-expr |
// STATUS = scalar-default-char-expr
-constexpr auto statusExpr = construct<StatusExpr>(scalarDefaultCharExpr);
-constexpr auto errLabel = construct<ErrLabel>(label);
+constexpr auto statusExpr{construct<StatusExpr>(scalarDefaultCharExpr)};
+constexpr auto errLabel{construct<ErrLabel>(label)};
TYPE_PARSER(first(construct<ConnectSpec>(maybe("UNIT ="_tok) >> fileUnitNumber),
construct<ConnectSpec>(construct<ConnectSpec::CharExpr>(
// [UNIT =] file-unit-number | IOSTAT = scalar-int-variable |
// IOMSG = iomsg-variable | ERR = label |
// STATUS = scalar-default-char-expr
-constexpr auto closeSpec = first(
+constexpr auto closeSpec{first(
construct<CloseStmt::CloseSpec>(maybe("UNIT ="_tok) >> fileUnitNumber),
construct<CloseStmt::CloseSpec>("IOSTAT =" >> statVariable),
construct<CloseStmt::CloseSpec>("IOMSG =" >> msgVariable),
construct<CloseStmt::CloseSpec>("ERR =" >> errLabel),
- construct<CloseStmt::CloseSpec>("STATUS =" >> statusExpr));
+ construct<CloseStmt::CloseSpec>("STATUS =" >> statusExpr))};
// R1208 close-stmt -> CLOSE ( close-spec-list )
TYPE_CONTEXT_PARSER("CLOSE statement"_en_US,
// R1210 read-stmt ->
// READ ( io-control-spec-list ) [input-item-list] |
// READ format [, input-item-list]
-constexpr auto inputItemList =
+constexpr auto inputItemList{
extension(some("," >> inputItem)) || // legacy extension: leading comma
- optionalList(inputItem);
+ optionalList(inputItem)};
TYPE_CONTEXT_PARSER("READ statement"_en_US,
construct<ReadStmt>("READ (" >>
construct<std::list<IoControlSpec>>(), many("," >> inputItem)))
// R1214 id-variable -> scalar-int-variable
-constexpr auto idVariable = construct<IdVariable>(scalarIntVariable);
+constexpr auto idVariable{construct<IdVariable>(scalarIntVariable)};
// R1213 io-control-spec ->
// [UNIT =] io-unit | [FMT =] format | [NML =] namelist-group-name |
// POS = scalar-int-expr | REC = scalar-int-expr |
// ROUND = scalar-default-char-expr | SIGN = scalar-default-char-expr |
// SIZE = scalar-int-variable
-constexpr auto endLabel = construct<EndLabel>(label);
-constexpr auto eorLabel = construct<EorLabel>(label);
+constexpr auto endLabel{construct<EndLabel>(label)};
+constexpr auto eorLabel{construct<EorLabel>(label)};
TYPE_PARSER(first(construct<IoControlSpec>("UNIT =" >> ioUnit),
construct<IoControlSpec>("FMT =" >> format),
construct<IoControlSpec>("NML =" >> name),
"SIZE =" >> construct<IoControlSpec::Size>(scalarIntVariable))))
// R1211 write-stmt -> WRITE ( io-control-spec-list ) [output-item-list]
-constexpr auto outputItemList =
+constexpr auto outputItemList{
extension(some("," >> outputItem)) || // legacy: allow leading comma
- optionalList(outputItem);
+ optionalList(outputItem)};
TYPE_CONTEXT_PARSER("WRITE statement"_en_US,
construct<WriteStmt>("WRITE (" >>
// R1220 io-implied-do-control ->
// do-variable = scalar-int-expr , scalar-int-expr [, scalar-int-expr]
-constexpr auto ioImpliedDoControl = loopBounds(scalarIntExpr);
+constexpr auto ioImpliedDoControl{loopBounds(scalarIntExpr)};
// R1218 io-implied-do -> ( io-implied-do-object-list , io-implied-do-control )
// R1219 io-implied-do-object -> input-item | output-item
// [UNIT =] file-unit-number | END = label | EOR = label | ERR = label |
// ID = scalar-int-expr | IOMSG = iomsg-variable |
// IOSTAT = scalar-int-variable
-constexpr auto idExpr = construct<IdExpr>(scalarIntExpr);
+constexpr auto idExpr{construct<IdExpr>(scalarIntExpr)};
TYPE_PARSER(first(construct<WaitSpec>(maybe("UNIT ="_tok) >> fileUnitNumber),
construct<WaitSpec>("END =" >> endLabel),
result.push_front(std::move(x));
return result;
}
-constexpr auto bareUnitNumberAsList =
+constexpr auto bareUnitNumberAsList{
applyFunction(singletonList<PositionOrFlushSpec>,
- construct<PositionOrFlushSpec>(fileUnitNumber));
-constexpr auto positionOrFlushSpecList =
- parenthesized(nonemptyList(positionOrFlushSpec)) || bareUnitNumberAsList;
+ construct<PositionOrFlushSpec>(fileUnitNumber))};
+constexpr auto positionOrFlushSpecList{
+ parenthesized(nonemptyList(positionOrFlushSpec)) || bareUnitNumberAsList};
// R1224 backspace-stmt ->
// BACKSPACE file-unit-number | BACKSPACE ( position-spec-list )
// R1321 char-string-edit-desc
// N.B. C1313 disallows any kind parameter on the character literal.
-constexpr auto charStringEditDesc = space >>
- (charLiteralConstantWithoutKind || rawHollerithLiteral);
+constexpr auto charStringEditDesc{
+ space >> (charLiteralConstantWithoutKind || rawHollerithLiteral)};
// R1303 format-items -> format-item [[,] format-item]...
-constexpr auto formatItems =
- nonemptySeparated(space >> Parser<format::FormatItem>{}, maybe(","_tok));
+constexpr auto formatItems{
+ nonemptySeparated(space >> Parser<format::FormatItem>{}, maybe(","_tok))};
// R1306 r -> digit-string
constexpr DigitStringIgnoreSpaces repeat;
// R1309 m -> digit-string
// R1310 d -> digit-string
// R1311 e -> digit-string
-constexpr auto width = repeat;
-constexpr auto mandatoryWidth = construct<std::optional<int>>(width);
-constexpr auto digits = repeat;
-constexpr auto noInt = construct<std::optional<int>>();
-constexpr auto mandatoryDigits = construct<std::optional<int>>("." >> width);
+constexpr auto width{repeat};
+constexpr auto mandatoryWidth{construct<std::optional<int>>(width)};
+constexpr auto digits{repeat};
+constexpr auto noInt{construct<std::optional<int>>()};
+constexpr auto mandatoryDigits{construct<std::optional<int>>("." >> width)};
// R1307 data-edit-desc ->
// I w [. m] | B w [. m] | O w [. m] | Z w [. m] | F w . d |
construct<ModuleSubprogram>(indirect(Parser<SeparateModuleSubprogram>{})))
// R1410 module-nature -> INTRINSIC | NON_INTRINSIC
-constexpr auto moduleNature = "INTRINSIC" >>
- pure(UseStmt::ModuleNature::Intrinsic) ||
- "NON_INTRINSIC" >> pure(UseStmt::ModuleNature::Non_Intrinsic);
+constexpr auto moduleNature{
+ "INTRINSIC" >> pure(UseStmt::ModuleNature::Intrinsic) ||
+ "NON_INTRINSIC" >> pure(UseStmt::ModuleNature::Non_Intrinsic)};
// R1409 use-stmt ->
// USE [[, module-nature] ::] module-name [, rename-list] |
statement(endSubroutineStmt))))
// R1507 specific-procedure -> procedure-name
-constexpr auto specificProcedure = name;
+constexpr auto specificProcedure{name};
// R1506 procedure-stmt -> [MODULE] PROCEDURE [::] specific-procedure-list
TYPE_PARSER(construct<ProcedureStmt>("MODULE PROCEDURE"_sptok >>
// Directives, extensions, and deprecated statements
// !DIR$ IVDEP
// !DIR$ IGNORE_TKR [ [(tkr...)] name ]...
-constexpr auto beginDirective = skipEmptyLines >> space >> "!"_ch;
-constexpr auto endDirective = space >> endOfLine;
-constexpr auto ivdep = construct<CompilerDirective::IVDEP>("DIR$ IVDEP"_tok);
-constexpr auto ignore_tkr = "DIR$ IGNORE_TKR" >>
- optionalList(construct<CompilerDirective::IgnoreTKR>(
- defaulted(parenthesized(some("tkr"_ch))), name));
+constexpr auto beginDirective{skipEmptyLines >> space >> "!"_ch};
+constexpr auto endDirective{space >> endOfLine};
+constexpr auto ivdep{construct<CompilerDirective::IVDEP>("DIR$ IVDEP"_tok)};
+constexpr auto ignore_tkr{
+ "DIR$ IGNORE_TKR" >> optionalList(construct<CompilerDirective::IgnoreTKR>(
+ defaulted(parenthesized(some("tkr"_ch))), name))};
TYPE_PARSER(beginDirective >> sourced(construct<CompilerDirective>(ivdep) ||
construct<CompilerDirective>(ignore_tkr)) /
endDirective)