aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Parser/expr-parsers.cpp
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2024-06-13 10:46:09 -0700
committerGitHub <noreply@github.com>2024-06-13 10:46:09 -0700
commit010c55bf44144f6370a0c4995c30ec51b06e1efe (patch)
treed5a11711cfc509f521637049869239743031469a /flang/lib/Parser/expr-parsers.cpp
parent3dd73dc1996940645620fd191110b57c49183531 (diff)
downloadllvm-010c55bf44144f6370a0c4995c30ec51b06e1efe.zip
llvm-010c55bf44144f6370a0c4995c30ec51b06e1efe.tar.gz
llvm-010c55bf44144f6370a0c4995c30ec51b06e1efe.tar.bz2
[flang] Improve error recovery in tricky situation (#95168)
When the very first statement of the executable part has syntax errors, it's not at all obvious whether the error messages that are reported to the user should be those from its failure to be the last statement of the specification part or its failure to be the first executable statement when both failures are at the same character in the cooked character stream. Fortran makes this problem more exciting by allowing statement function definitions look a lot like several executable statements. The current error recovery scheme for declaration constructs depends on a look-ahead test to see whether the failed construct is actually the first executable statement. This works fine when the first executable statement is not in error, but should also allow for some error cases that begin with the tokens of an executable statement. This can obviously still go wrong for declaration constructs that are unparseable and also have ambiguity in their leading tokens with executable statements, but that seems to be a less likely case. Also improves error recovery for parenthesized items.
Diffstat (limited to 'flang/lib/Parser/expr-parsers.cpp')
-rw-r--r--flang/lib/Parser/expr-parsers.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/flang/lib/Parser/expr-parsers.cpp b/flang/lib/Parser/expr-parsers.cpp
index a47aae1..77a13de 100644
--- a/flang/lib/Parser/expr-parsers.cpp
+++ b/flang/lib/Parser/expr-parsers.cpp
@@ -70,7 +70,8 @@ TYPE_PARSER(construct<AcImpliedDoControl>(
constexpr auto primary{instrumented("primary"_en_US,
first(construct<Expr>(indirect(Parser<CharLiteralConstantSubstring>{})),
construct<Expr>(literalConstant),
- construct<Expr>(construct<Expr::Parentheses>(parenthesized(expr))),
+ construct<Expr>(construct<Expr::Parentheses>("(" >>
+ expr / !","_tok / recovery(")"_tok, SkipPastNested<'(', ')'>{}))),
construct<Expr>(indirect(functionReference) / !"("_tok / !"%"_tok),
construct<Expr>(designator / !"("_tok / !"%"_tok),
construct<Expr>(indirect(Parser<SubstringInquiry>{})), // %LEN or %KIND