<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1062,7 +1062,7 @@ void parse_annotations(std::istream&amp; in, amount_t&amp; price,
 	      &lt;&lt; &quot;  tag &quot; &lt;&lt; tag);
 }
 
-void amount_t::parse(std::istream&amp; in, unsigned char flags)
+bool amount_t::parse(std::istream&amp; in, unsigned char flags)
 {
   // The possible syntax for an amount is:
   //
@@ -1114,8 +1114,12 @@ void amount_t::parse(std::istream&amp; in, unsigned char flags)
     }
   }
 
-  if (quant.empty())
-    throw new amount_error(&quot;No quantity specified for amount&quot;);
+  if (quant.empty()) {
+    if (flags &amp; AMOUNT_PARSE_SOFT_FAIL)
+      return false;
+    else
+      throw new amount_error(&quot;No quantity specified for amount&quot;);
+  }
 
   _init();
 
@@ -1205,6 +1209,8 @@ void amount_t::parse(std::istream&amp; in, unsigned char flags)
 
   if (! (flags &amp; AMOUNT_PARSE_NO_REDUCE))
     reduce();
+
+  return true;
 }
 
 void amount_t::reduce()
@@ -1215,7 +1221,7 @@ void amount_t::reduce()
   }
 }
 
-void amount_t::parse(const std::string&amp; str, unsigned char flags)
+bool amount_t::parse(const std::string&amp; str, unsigned char flags)
 {
   std::istringstream stream(str);
   parse(stream, flags);</diff>
      <filename>amount.cc</filename>
    </modified>
    <modified>
      <diff>@@ -263,9 +263,10 @@ class amount_t
 
 #define AMOUNT_PARSE_NO_MIGRATE 0x01
 #define AMOUNT_PARSE_NO_REDUCE  0x02
+#define AMOUNT_PARSE_SOFT_FAIL  0x04
 
-  void parse(std::istream&amp; in, unsigned char flags = 0);
-  void parse(const std::string&amp; str, unsigned char flags = 0);
+  bool parse(std::istream&amp; in, unsigned char flags = 0);
+  bool parse(const std::string&amp; str, unsigned char flags = 0);
   void reduce();
 
   amount_t reduced() const {</diff>
      <filename>amount.h</filename>
    </modified>
    <modified>
      <diff>@@ -772,29 +772,21 @@ value_expr_t * parse_value_term(std::istream&amp; in, scope_t * scope,
       // When in relaxed parsing mode, we do want to migrate commodity
       // flags, so that any precision specified by the user updates
       // the current maximum precision displayed.
-      try {
-	pos = (long)in.tellg();
+      pos = (long)in.tellg();
 
-	unsigned char parse_flags = 0;
-	if (flags &amp; PARSE_VALEXPR_NO_MIGRATE)
-	  parse_flags |= AMOUNT_PARSE_NO_MIGRATE;
-	if (flags &amp; PARSE_VALEXPR_NO_REDUCE)
-	  parse_flags |= AMOUNT_PARSE_NO_REDUCE;
+      unsigned char parse_flags = 0;
+      if (flags &amp; PARSE_VALEXPR_NO_MIGRATE)
+	parse_flags |= AMOUNT_PARSE_NO_MIGRATE;
+      if (flags &amp; PARSE_VALEXPR_NO_REDUCE)
+	parse_flags |= AMOUNT_PARSE_NO_REDUCE;
 
-	temp.parse(in, parse_flags);
-      }
-      catch (amount_error * err) {
-	// If the amount had no commodity, it must be an unambiguous
-	// variable reference
-	if (std::strcmp(err-&gt;what(), &quot;No quantity specified for amount&quot;) == 0) {
-	  in.clear();
-	  in.seekg(pos, std::ios::beg);
-	  c = prev_c;
-	  goto parse_ident;
-	} else {
-	  throw err;
-	}
+      if (! temp.parse(in, parse_flags | AMOUNT_PARSE_SOFT_FAIL)) {
+	in.clear();
+	in.seekg(pos, std::ios::beg);
+	c = prev_c;
+	goto parse_ident;
       }
+
       node.reset(new value_expr_t(value_expr_t::CONSTANT));
       node-&gt;value = new value_t(temp);
       goto parsed;</diff>
      <filename>valexpr.cc</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7848dbd7f76e580760b585eba3f67cf3a4ebaed9</id>
    </parent>
  </parents>
  <author>
    <name>John Wiegley</name>
    <email>johnw@newartisans.com</email>
  </author>
  <url>http://github.com/jwiegley/ledger/commit/9b7725ee181617b2e0ea13189837b0724ab964b8</url>
  <id>9b7725ee181617b2e0ea13189837b0724ab964b8</id>
  <committed-date>2008-07-26T20:55:06-07:00</committed-date>
  <authored-date>2008-07-26T20:55:06-07:00</authored-date>
  <message>Added a simple optimization to the way amount strings are parsed.</message>
  <tree>c69dd5865a7c6e32ff824984a914924450ca4947</tree>
  <committer>
    <name>John Wiegley</name>
    <email>johnw@newartisans.com</email>
  </committer>
</commit>
