@@ -27,21 +27,22 @@ template <typename PA>
2727inline constexpr auto unterminatedStatement (const PA &p) {
2828 return skipStuffBeforeStatement >>
2929 sourced (construct<Statement<typename PA::resultType>>(
30- maybe (label), space >> p));
30+ maybe (label / space), p));
3131}
3232
3333constexpr auto atEndOfStmt{space >>
3434 withMessage (" expected end of statement" _err_en_US, lookAhead (" ;\n " _ch))};
3535constexpr auto checkEndOfKnownStmt{recovery (atEndOfStmt, SkipTo<' \n ' >{})};
3636
37- constexpr auto endOfLine{
38- " \n " _ch >> ok || fail (" expected end of line" _err_en_US)};
37+ constexpr auto endOfLine{consumedAllInput ||
38+ withMessage (" expected end of line" _err_en_US, " \n " _ch >> ok )};
3939
4040constexpr auto semicolons{" ;" _ch >> skipMany (" ;" _tok) / space / maybe (" \n " _ch)};
4141constexpr auto endOfStmt{
4242 space >> withMessage (" expected end of statement" _err_en_US,
4343 semicolons || endOfLine)};
44- constexpr auto forceEndOfStmt{recovery (endOfStmt, SkipPast<' \n ' >{})};
44+ constexpr auto skipToNextLineIfAny{consumedAllInput || SkipPast<' \n ' >{}};
45+ constexpr auto forceEndOfStmt{recovery (endOfStmt, skipToNextLineIfAny)};
4546
4647template <typename PA> inline constexpr auto statement (const PA &p) {
4748 return unterminatedStatement (p) / endOfStmt;
@@ -70,17 +71,17 @@ constexpr auto ignoredStatementPrefix{
7071// Error recovery within a statement() call: skip *to* the end of the line,
7172// unless at an END or CONTAINS statement.
7273constexpr auto inStmtErrorRecovery{!" END" _tok >> !" CONTAINS" _tok >>
73- SkipTo<' \n ' >{} >> construct<ErrorRecovery>()};
74+ (consumedAllInput || SkipTo<' \n ' >{}) >> construct<ErrorRecovery>()};
7475
7576// Error recovery within statement sequences: skip *past* the end of the line,
7677// but not over an END or CONTAINS statement.
7778constexpr auto skipStmtErrorRecovery{!" END" _tok >> !" CONTAINS" _tok >>
78- SkipPast<' \n ' >{} >> construct<ErrorRecovery>()};
79+ (consumedAllInput || SkipPast<' \n ' >{}) >> construct<ErrorRecovery>()};
7980
8081// Error recovery across statements: skip the line, unless it looks
8182// like it might end the containing construct.
8283constexpr auto stmtErrorRecoveryStart{ignoredStatementPrefix};
83- constexpr auto skipBadLine{SkipPast< ' \n ' >{} >> construct<ErrorRecovery>()};
84+ constexpr auto skipBadLine{skipToNextLineIfAny >> construct<ErrorRecovery>()};
8485constexpr auto executionPartErrorRecovery{stmtErrorRecoveryStart >>
8586 !" END" _tok >> !" CONTAINS" _tok >> !" ELSE" _tok >> !" CASE" _tok >>
8687 !" TYPE IS" _tok >> !" CLASS" _tok >> !" RANK" _tok >>
@@ -93,7 +94,7 @@ constexpr auto noNameEnd{"END" >> missingOptionalName};
9394
9495// For unrecognizable construct END statements. Be sure to not consume
9596// a program unit's END statement.
96- constexpr auto progUnitEndStmt{
97+ constexpr auto progUnitEndStmt{consumedAllInput ||
9798 " END" >> (lookAhead (" \n " _ch) || " SUBROUTINE" _tok || " FUNCTION" _tok ||
9899 " PROCEDURE" _tok || " MODULE" _tok || " SUBMODULE" _tok ||
99100 " PROGRAM" _tok || " BLOCK DATA" _tok)};
@@ -103,9 +104,8 @@ constexpr auto namedConstructEndStmtErrorRecovery{
103104 constructEndStmtErrorRecovery >> missingOptionalName};
104105
105106constexpr auto progUnitEndStmtErrorRecovery{
106- (many (!" END" _tok >> SkipPast<' \n ' >{}) >>
107- (" END" _tok >> SkipTo<' \n ' >{} || consumedAllInput)) >>
108- missingOptionalName};
107+ many (!" END" _tok >> SkipPast<' \n ' >{}) >>
108+ maybe (" END" _tok >> SkipTo<' \n ' >{}) >> missingOptionalName};
109109
110110constexpr auto beginDirective{skipStuffBeforeStatement >> " !" _ch};
111111constexpr auto endDirective{space >> endOfLine};
0 commit comments