about summary refs log tree commit diff stats
path: root/011load.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-09-02 21:18:58 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-09-02 21:18:58 -0700
commit076f39b82e45a19c2aa16215b5f66aa9d72a43b9 (patch)
tree847af4fc45febf31107285227957a4c719a6b05b /011load.cc
parent6f13d68bfa47accf1396bf736135c23d8f3067e5 (diff)
downloadmu-076f39b82e45a19c2aa16215b5f66aa9d72a43b9.tar.gz
2134 - bugfix: comment terminated by eof
I ran into this inside 'reload' when I left a trailing comment at the
end of the editor.
Diffstat (limited to '011load.cc')
-rw-r--r--011load.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/011load.cc b/011load.cc
index 796a0bc7..b1c60b07 100644
--- a/011load.cc
+++ b/011load.cc
@@ -163,7 +163,7 @@ string next_word(istream& in) {
 
 void slurp_word(istream& in, ostream& out) {
   char c;
-  if (in.peek() == ',') {
+  if (!in.eof() && in.peek() == ',') {
     in >> c;
     out << c;
     return;
@@ -178,13 +178,14 @@ void slurp_word(istream& in, ostream& out) {
 }
 
 void skip_whitespace(istream& in) {
-  while (isspace(in.peek()) && in.peek() != '\n') {
+  while (!in.eof() && isspace(in.peek()) && in.peek() != '\n') {
     in.get();
   }
 }
 
 void skip_whitespace_and_comments(istream& in) {
   while (true) {
+    if (in.eof()) break;
     if (isspace(in.peek())) in.get();
     else if (in.peek() == '#') skip_comment(in);
     else break;
@@ -192,15 +193,15 @@ void skip_whitespace_and_comments(istream& in) {
 }
 
 void skip_comment(istream& in) {
-  if (in.peek() == '#') {
+  if (!in.eof() && in.peek() == '#') {
     in.get();
-    while (in.peek() != '\n') in.get();
+    while (!in.eof() && in.peek() != '\n') in.get();
   }
 }
 
 void skip_comma(istream& in) {
   skip_whitespace(in);
-  if (in.peek() == ',') in.get();
+  if (!in.eof() && in.peek() == ',') in.get();
   skip_whitespace(in);
 }
 
@@ -350,3 +351,14 @@ recipe main [
   1:number:address/lookup <- copy 23
 ]
 +parse:   product: {name: "1", properties: ["1": "number":"address", "lookup": ]}
+
+//: this test we can't represent with a scenario
+:(code)
+void test_parse_comment_terminated_by_eof() {
+  Trace_file = "parse_comment_terminated_by_eof";
+  load("recipe main [\n"
+       "  a:number <- copy 34\n"
+       "]\n"
+       "# abc");  // no newline after comment
+  cerr << ".";  // termination = success
+}