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 {
65
65
return severity_ == Severity::Error || severity_ == Severity::Todo;
66
66
}
67
67
68
+ static const MessageFixedText endOfFileMessage; // "end of file"_err_en_US
69
+
68
70
private:
69
71
CharBlock text_;
70
72
Severity severity_{Severity::None};
Original file line number Diff line number Diff line change @@ -828,7 +828,7 @@ struct NextCh {
828
828
if (std::optional<const char *> result{state.GetNextChar ()}) {
829
829
return result;
830
830
}
831
- state.Say (" end of file " _err_en_US );
831
+ state.Say (MessageFixedText::endOfFileMessage );
832
832
return std::nullopt ;
833
833
}
834
834
};
Original file line number Diff line number Diff line change 21
21
22
22
namespace Fortran ::parser {
23
23
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
+
24
28
llvm::raw_ostream &operator <<(llvm::raw_ostream &o, const MessageFixedText &t) {
25
29
std::size_t n{t.text ().size ()};
26
30
for (std::size_t j{0 }; j < n; ++j) {
@@ -232,7 +236,20 @@ std::optional<ProvenanceRange> Message::GetProvenanceRange(
232
236
const AllCookedSources &allCooked) const {
233
237
return common::visit (
234
238
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
+ },
236
253
[](const ProvenanceRange &pr) { return std::make_optional (pr); },
237
254
},
238
255
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