@@ -27,21 +27,22 @@ template <typename PA>
27
27
inline constexpr auto unterminatedStatement (const PA &p) {
28
28
return skipStuffBeforeStatement >>
29
29
sourced (construct<Statement<typename PA::resultType>>(
30
- maybe (label), space >> p));
30
+ maybe (label / space), p));
31
31
}
32
32
33
33
constexpr auto atEndOfStmt{space >>
34
34
withMessage (" expected end of statement" _err_en_US, lookAhead (" ;\n " _ch))};
35
35
constexpr auto checkEndOfKnownStmt{recovery (atEndOfStmt, SkipTo<' \n ' >{})};
36
36
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 )};
39
39
40
40
constexpr auto semicolons{" ;" _ch >> skipMany (" ;" _tok) / space / maybe (" \n " _ch)};
41
41
constexpr auto endOfStmt{
42
42
space >> withMessage (" expected end of statement" _err_en_US,
43
43
semicolons || endOfLine)};
44
- constexpr auto forceEndOfStmt{recovery (endOfStmt, SkipPast<' \n ' >{})};
44
+ constexpr auto skipToNextLineIfAny{consumedAllInput || SkipPast<' \n ' >{}};
45
+ constexpr auto forceEndOfStmt{recovery (endOfStmt, skipToNextLineIfAny)};
45
46
46
47
template <typename PA> inline constexpr auto statement (const PA &p) {
47
48
return unterminatedStatement (p) / endOfStmt;
@@ -70,17 +71,17 @@ constexpr auto ignoredStatementPrefix{
70
71
// Error recovery within a statement() call: skip *to* the end of the line,
71
72
// unless at an END or CONTAINS statement.
72
73
constexpr auto inStmtErrorRecovery{!" END" _tok >> !" CONTAINS" _tok >>
73
- SkipTo<' \n ' >{} >> construct<ErrorRecovery>()};
74
+ (consumedAllInput || SkipTo<' \n ' >{}) >> construct<ErrorRecovery>()};
74
75
75
76
// Error recovery within statement sequences: skip *past* the end of the line,
76
77
// but not over an END or CONTAINS statement.
77
78
constexpr auto skipStmtErrorRecovery{!" END" _tok >> !" CONTAINS" _tok >>
78
- SkipPast<' \n ' >{} >> construct<ErrorRecovery>()};
79
+ (consumedAllInput || SkipPast<' \n ' >{}) >> construct<ErrorRecovery>()};
79
80
80
81
// Error recovery across statements: skip the line, unless it looks
81
82
// like it might end the containing construct.
82
83
constexpr auto stmtErrorRecoveryStart{ignoredStatementPrefix};
83
- constexpr auto skipBadLine{SkipPast< ' \n ' >{} >> construct<ErrorRecovery>()};
84
+ constexpr auto skipBadLine{skipToNextLineIfAny >> construct<ErrorRecovery>()};
84
85
constexpr auto executionPartErrorRecovery{stmtErrorRecoveryStart >>
85
86
!" END" _tok >> !" CONTAINS" _tok >> !" ELSE" _tok >> !" CASE" _tok >>
86
87
!" TYPE IS" _tok >> !" CLASS" _tok >> !" RANK" _tok >>
@@ -93,7 +94,7 @@ constexpr auto noNameEnd{"END" >> missingOptionalName};
93
94
94
95
// For unrecognizable construct END statements. Be sure to not consume
95
96
// a program unit's END statement.
96
- constexpr auto progUnitEndStmt{
97
+ constexpr auto progUnitEndStmt{consumedAllInput ||
97
98
" END" >> (lookAhead (" \n " _ch) || " SUBROUTINE" _tok || " FUNCTION" _tok ||
98
99
" PROCEDURE" _tok || " MODULE" _tok || " SUBMODULE" _tok ||
99
100
" PROGRAM" _tok || " BLOCK DATA" _tok)};
@@ -103,9 +104,8 @@ constexpr auto namedConstructEndStmtErrorRecovery{
103
104
constructEndStmtErrorRecovery >> missingOptionalName};
104
105
105
106
constexpr 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};
109
109
110
110
constexpr auto beginDirective{skipStuffBeforeStatement >> " !" _ch};
111
111
constexpr auto endDirective{space >> endOfLine};
0 commit comments