llvm-project/flang/lib/Parser
Peter Klausler 52601325f1 [flang] Improve syntax error messages by fixing withMessage() parser combinator
The parser combinator withMessage("error message"_err_en_US, PARSER) is meant
to run the parser PARSER and, if it fails, override its error messages if
it failed silently or it was unable to recognize any tokens at all.  This
gives the parser a way to avoid emitting some confusing or missing error
messages.  Unfortunately, the implementation could sometimes lose track of
whether any tokens had been recognized, leading to problems with outer usage
of withMessage() and also -- more seriously -- with ParseState::CombineFailedParses().
That's a utility that determines which error messages to retain when two
or more parsers have been attempted at the same starting point and none
of them succceed.  Its policy is to retain the state from the parser that
consumed the most input text before failing, so long as it had recognized at
least one token.

So anyway, fix up withMessage(), adjust the tests, and add a test of the
original motivating confusing error situation, in which a syntax error in
a COMMON statement was being diagnosed as a problem with a statement function
definition because withMessage() had lost the fact that the parse of the
COMMON statement had recognized some tokens, and the last attempted parse
later was a failed attempt to parse a statement function.

Differential Revision: https://reviews.llvm.org/D135216
2022-10-06 14:00:06 -07:00
..
CMakeLists.txt [flang][driver] Add options for unparsing 2021-02-16 09:32:51 +00:00
Fortran-parsers.cpp [flang] Allow a generic-spec on a PUBLIC/PRIVATE statement to declare a generic 2022-09-23 14:17:42 -07:00
basic-parsers.h [flang] Improve syntax error messages by fixing withMessage() parser combinator 2022-10-06 14:00:06 -07:00
char-block.cpp
char-buffer.cpp [flang][MSVC] Use list<Message> rather than forward_list<> in Messages 2020-11-11 16:38:38 -08:00
char-set.cpp
characters.cpp
debug-parser.cpp
debug-parser.h
executable-parsers.cpp [flang] Add explanatory messages to grammar for language extensions 2022-03-18 16:14:27 -07:00
expr-parsers.cpp [flang] Fix parsing and semantics for array element substring%KIND/%LEN 2022-07-22 16:54:46 -07:00
expr-parsers.h
instrumented-parser.cpp
io-parsers.cpp [flang] Avoid spurious warnings in pedantic mode from FORMAT items 2022-07-06 18:54:11 -07:00
message.cpp [flang] Support the color diagnostics on scanning, parsing, and semantics 2022-07-27 23:45:41 +08:00
misc-parsers.h
openacc-parsers.cpp [flang][openacc] Use TableGen to generate the clause parser 2022-07-18 09:26:57 +02:00
openmp-parsers.cpp [flang][OpenMP] Parser support for Target directive and Device clause 2022-08-21 22:26:02 +05:30
parse-tree.cpp [flang] Disambiguate F(X)=Y case where F is a function returning a pointer 2022-04-25 09:25:09 -07:00
parsing.cpp [flang] Support the color diagnostics on scanning, parsing, and semantics 2022-07-27 23:45:41 +08:00
preprocessor.cpp [flang] Distinguish usage and portability warning messages 2022-03-08 17:24:52 -08:00
preprocessor.h [flang] NFC: change non-nullable pointer arguments to references 2021-09-02 14:15:27 -07:00
prescan.cpp [flang] Skip `D` when including D debug line 2022-03-31 10:56:25 +02:00
prescan.h [flang] Enforce fixed form rules about END continuation 2021-09-17 10:59:17 -07:00
program-parsers.cpp [flang] Add explanatory messages to grammar for language extensions 2022-03-18 16:14:27 -07:00
provenance.cpp [flang] Support the color diagnostics on scanning, parsing, and semantics 2022-07-27 23:45:41 +08:00
source.cpp [flang] Search for #include "file" in right directory (take 2) 2021-01-27 15:41:29 -08:00
stmt-parser.h
token-parsers.h [flang] Add explanatory messages to grammar for language extensions 2022-03-18 16:14:27 -07:00
token-sequence.cpp [flang] Catch mismatched parentheses in prescanner 2021-10-06 14:00:15 -07:00
token-sequence.h [flang] Catch mismatched parentheses in prescanner 2021-10-06 14:00:15 -07:00
tools.cpp [flang] Add & use a better visit() (take 2) 2022-04-16 16:00:48 -07:00
type-parser-implementation.h
type-parsers.h [flang]Add Parser Support for Allocate Directive 2020-12-10 16:21:19 +00:00
unparse.cpp [flang][OpenMP] Parser support for Target directive and Device clause 2022-08-21 22:26:02 +05:30
user-state.cpp [flang] Implement semantics for DEC STRUCTURE/RECORD 2022-01-13 13:17:13 -08:00