about summary refs log tree commit diff stats
path: root/054dilated_reagent.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-17 00:49:36 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-17 00:49:36 -0800
commit21c277062ef151ad86e2003ad0e2bfb09f3d4c2d (patch)
tree58e09d64f4f6b3b36af3d271ffae046a150910e7 /054dilated_reagent.cc
parentd18d1d3d2ac7ba0909db010649a94d01a65d98d4 (diff)
downloadmu-21c277062ef151ad86e2003ad0e2bfb09f3d4c2d.tar.gz
2453 - bugfix: trailing space after curly bracket
I ran into this when edit/ couldn't handle spaces after curly brackets,
even though .mu files could. Turns out edit/ loads code using
istringstreams rather than ifstreams, and you can't putback a different
character than you read from an istringstream. Craptastic gotcha..
Diffstat (limited to '054dilated_reagent.cc')
-rw-r--r--054dilated_reagent.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/054dilated_reagent.cc b/054dilated_reagent.cc
index e68ccb4a..f1d3b267 100644
--- a/054dilated_reagent.cc
+++ b/054dilated_reagent.cc
@@ -9,6 +9,13 @@ recipe main [
 ]
 +parse:   product: {"1": "number", "foo": "bar"}
 
+:(scenario load_trailing_space_after_curly_bracket)
+recipe main [
+  # line below has a space at the end
+  { 
+]
+# successfully parsed
+
 //: First augment next_word to group balanced brackets together.
 
 :(before "End next_word Special-cases")
@@ -21,14 +28,13 @@ if (start_of_dilated_reagent(in))
 :(code)
 // A curly is considered a label if it's the last thing on a line. Dilated
 // reagents should remain all on one line.
-//
-// Side-effect: This might delete some whitespace after an initial '{'.
 bool start_of_dilated_reagent(istream& in) {
   if (in.peek() != '{') return false;
+  long long int pos = in.tellg();
   in.get();  // slurp '{'
   skip_whitespace(in);
   char next = in.peek();
-  in.putback('{');
+  in.seekg(pos);
   return next != '\n';
 }