@@ -653,13 +653,13 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
653
653
comma = ' ;' ;
654
654
}
655
655
if (remaining_ > 0 && !realPart_) { // "r*c" repetition in progress
656
- while (connection.currentRecordNumber > initialRecordNumber_ ) {
656
+ while (connection.currentRecordNumber > repeatRecordNumber_ ) {
657
657
io.BackspaceRecord ();
658
658
}
659
- connection.HandleAbsolutePosition (initialPositionInRecord_ );
659
+ connection.HandleAbsolutePosition (repeatPositionInRecord_ );
660
660
if (!imaginaryPart_) {
661
661
edit.repeat = std::min<int >(remaining_, maxRepeat);
662
- auto ch{io.GetNextNonBlank ()};
662
+ auto ch{io.GetCurrentChar ()};
663
663
if (!ch || *ch == ' ' || *ch == ' \t ' || *ch == comma) {
664
664
// "r*" repeated null
665
665
edit.descriptor = DataEdit::ListDirectedNullValue;
@@ -669,14 +669,22 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
669
669
return edit;
670
670
}
671
671
// Skip separators, handle a "r*c" repeat count; see 13.10.2 in Fortran 2018
672
- auto ch{io.GetNextNonBlank ()};
673
672
if (imaginaryPart_) {
674
673
imaginaryPart_ = false ;
675
674
} else if (realPart_) {
676
675
realPart_ = false ;
677
676
imaginaryPart_ = true ;
678
677
edit.descriptor = DataEdit::ListDirectedImaginaryPart;
679
678
}
679
+ auto ch{io.GetNextNonBlank ()};
680
+ if (ch && *ch == comma && eatComma_) {
681
+ // Consume comma & whitespace after previous item.
682
+ // This includes the comma between real and imaginary components
683
+ // in list-directed/NAMELIST complex input.
684
+ io.HandleRelativePosition (1 );
685
+ ch = io.GetNextNonBlank ();
686
+ }
687
+ eatComma_ = true ;
680
688
if (!ch) {
681
689
return std::nullopt;
682
690
}
@@ -685,25 +693,9 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
685
693
edit.descriptor = DataEdit::ListDirectedNullValue;
686
694
return edit;
687
695
}
688
- bool isFirstItem{isFirstItem_};
689
- isFirstItem_ = false ;
690
- if (*ch == comma) {
691
- if (isFirstItem) {
692
- edit.descriptor = DataEdit::ListDirectedNullValue;
693
- return edit;
694
- }
695
- // Consume comma & whitespace after previous item.
696
- // This includes the comma between real and imaginary components
697
- // in list-directed/NAMELIST complex input.
698
- io.HandleRelativePosition (1 );
699
- ch = io.GetNextNonBlank ();
700
- if (!ch) {
701
- return std::nullopt;
702
- }
703
- if (*ch == comma || *ch == ' /' ) {
704
- edit.descriptor = DataEdit::ListDirectedNullValue;
705
- return edit;
706
- }
696
+ if (*ch == comma) { // separator: null value
697
+ edit.descriptor = DataEdit::ListDirectedNullValue;
698
+ return edit;
707
699
}
708
700
if (imaginaryPart_) { // can't repeat components
709
701
return edit;
@@ -734,8 +726,8 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
734
726
}
735
727
edit.repeat = std::min<int >(r, maxRepeat);
736
728
remaining_ = r - edit.repeat ;
737
- initialRecordNumber_ = connection.currentRecordNumber ;
738
- initialPositionInRecord_ = connection.positionInRecord ;
729
+ repeatRecordNumber_ = connection.currentRecordNumber ;
730
+ repeatPositionInRecord_ = connection.positionInRecord ;
739
731
} else { // not a repetition count, just an integer value; rewind
740
732
connection.positionInRecord = start;
741
733
}
0 commit comments