@@ -880,6 +880,9 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
880
880
edit.descriptor = DataEdit::ListDirectedImaginaryPart;
881
881
}
882
882
auto fastField{io.GetUpcomingFastAsciiField ()};
883
+ // Reaching EOF is okay when peeking at list-directed defined input;
884
+ // pretend that there's an END= in that case.
885
+ bool oldHasEnd{maxRepeat == 0 && !io.GetIoErrorHandler ().SetHasEnd ()};
883
886
auto ch{io.GetNextNonBlank (byteCount, &fastField)};
884
887
if (ch && *ch == comma && eatComma_) {
885
888
// Consume comma & whitespace after previous item.
@@ -890,19 +893,23 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
890
893
ch = io.GetNextNonBlank (byteCount, &fastField);
891
894
}
892
895
eatComma_ = true ;
893
- if (!ch ) {
894
- return common:: nullopt ;
896
+ if (maxRepeat == 0 && !oldHasEnd ) {
897
+ io. GetIoErrorHandler (). SetHasEnd ( false ) ;
895
898
}
896
- if (*ch == ' /' ) {
899
+ if (!ch) { // EOF
900
+ if (maxRepeat == 0 ) {
901
+ return edit; // DataEdit::ListDirected for look-ahead
902
+ } else {
903
+ return common::nullopt ;
904
+ }
905
+ } else if (*ch == ' /' ) {
897
906
hitSlash_ = true ;
898
907
edit.descriptor = DataEdit::ListDirectedNullValue;
899
908
return edit;
900
- }
901
- if (*ch == comma) { // separator: null value
909
+ } else if (*ch == comma) { // separator: null value
902
910
edit.descriptor = DataEdit::ListDirectedNullValue;
903
911
return edit;
904
- }
905
- if (imaginaryPart_) { // can't repeat components
912
+ } else if (imaginaryPart_) { // can't repeat components
906
913
return edit;
907
914
}
908
915
if (*ch >= ' 0' && *ch <= ' 9' && fastField.MightBeRepetitionCount ()) {
@@ -1103,10 +1110,19 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
1103
1110
: ChildIoStatementState<DIR>{child, sourceFile, sourceLine} {
1104
1111
#if !defined(RT_DEVICE_AVOID_RECURSION)
1105
1112
if constexpr (DIR == Direction::Input) {
1106
- if (auto *listInput{child.parent ()
1113
+ if (const auto *listInput{child.parent ()
1107
1114
.get_if <ListDirectedStatementState<Direction::Input>>()}) {
1108
1115
this ->set_eatComma (listInput->eatComma ());
1109
1116
this ->namelistGroup_ = listInput->namelistGroup ();
1117
+ if (auto *childListInput{child.parent ()
1118
+ .get_if <ChildListIoStatementState<Direction::Input>>()}) {
1119
+ // Child list input whose parent is child list input: can advance
1120
+ // if the parent can.
1121
+ this ->canAdvance_ = childListInput->CanAdvance ();
1122
+ } else {
1123
+ // Child list input of top-level list input: can advance.
1124
+ this ->canAdvance_ = true ;
1125
+ }
1110
1126
}
1111
1127
}
1112
1128
#else
@@ -1117,12 +1133,7 @@ ChildListIoStatementState<DIR>::ChildListIoStatementState(
1117
1133
template <Direction DIR>
1118
1134
bool ChildListIoStatementState<DIR>::AdvanceRecord(int n) {
1119
1135
#if !defined(RT_DEVICE_AVOID_RECURSION)
1120
- // Allow child NAMELIST input to advance
1121
- if (DIR == Direction::Input && this ->mutableModes ().inNamelist ) {
1122
- return this ->child ().parent ().AdvanceRecord (n);
1123
- } else {
1124
- return false ;
1125
- }
1136
+ return this ->CanAdvance () && this ->child ().parent ().AdvanceRecord (n);
1126
1137
#else
1127
1138
this ->ReportUnsupportedChildIo ();
1128
1139
#endif
0 commit comments