[flang-commits] [flang] [flang] Better recovery from errors in a loop control (PR #117025)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Thu Nov 21 08:36:50 PST 2024


================
@@ -282,18 +281,26 @@ TYPE_CONTEXT_PARSER("loop control"_en_US,
                 "CONCURRENT" >> concurrentHeader,
                 many(Parser<LocalitySpec>{})))))
 
+// "DO" is a valid statement, so the loop control is optional; but for
+// better recovery from errors in the loop control, don't parse a
+// DO statement with a bad loop control as a DO statement that has
+// no loop control and is followed by garbage.
+static constexpr auto loopControlOrEndOfStmt{
+    construct<std::optional<LoopControl>>(Parser<LoopControl>{}) ||
+    lookAhead(":\n"_ch) >> construct<std::optional<LoopControl>>()};
----------------
eugeneepshteyn wrote:

Ok, I figured out `_ch` part, but still have a question about why `:` is used in `lookAhead()`

https://github.com/llvm/llvm-project/pull/117025


More information about the flang-commits mailing list