File tree Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,8 @@ class MessageFixedText {
6565 return severity_ == Severity::Error || severity_ == Severity::Todo;
6666 }
6767
68+ static const MessageFixedText endOfFileMessage; // "end of file"_err_en_US
69+
6870private:
6971 CharBlock text_;
7072 Severity severity_{Severity::None};
Original file line number Diff line number Diff line change @@ -828,7 +828,7 @@ struct NextCh {
828828 if (std::optional<const char *> result{state.GetNextChar ()}) {
829829 return result;
830830 }
831- state.Say (" end of file " _err_en_US );
831+ state.Say (MessageFixedText::endOfFileMessage );
832832 return std::nullopt ;
833833 }
834834};
Original file line number Diff line number Diff line change 2121
2222namespace Fortran ::parser {
2323
24+ // The nextCh parser emits this, and Message::GetProvenanceRange() looks for it.
25+ const MessageFixedText MessageFixedText::endOfFileMessage{
26+ " end of file" _err_en_US};
27+
2428llvm::raw_ostream &operator <<(llvm::raw_ostream &o, const MessageFixedText &t) {
2529 std::size_t n{t.text ().size ()};
2630 for (std::size_t j{0 }; j < n; ++j) {
@@ -232,7 +236,20 @@ std::optional<ProvenanceRange> Message::GetProvenanceRange(
232236 const AllCookedSources &allCooked) const {
233237 return common::visit (
234238 common::visitors{
235- [&](CharBlock cb) { return allCooked.GetProvenanceRange (cb); },
239+ [&](CharBlock cb) -> std::optional<ProvenanceRange> {
240+ if (auto pr{allCooked.GetProvenanceRange (cb)}) {
241+ return pr;
242+ } else if (const auto *fixed{std::get_if<MessageFixedText>(&text_)};
243+ fixed &&
244+ fixed->text () == MessageFixedText::endOfFileMessage.text () &&
245+ cb.begin () && cb.size () == 1 ) {
246+ // Failure from "nextCh" due to reaching EOF. Back up one byte
247+ // to the terminal newline so that the output looks better.
248+ return allCooked.GetProvenanceRange (CharBlock{cb.begin () - 1 , 1 });
249+ } else {
250+ return std::nullopt ;
251+ }
252+ },
236253 [](const ProvenanceRange &pr) { return std::make_optional (pr); },
237254 },
238255 location_);
Original file line number Diff line number Diff line change 1+ ! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
2+ ! CHECK: error: end of file
3+ ! CHECK: ^
4+ ! CHECK: in the context: END PROGRAM statement
5+ ! CHECK: in the context: main program
6+
7+ integer :: i
8+
9+ ! Add empty lines for emphasis
10+
11+ i = 5
You can’t perform that action at this time.
0 commit comments