]> mj.ucw.cz Git - paperjam.git/blobdiff - parse.cc
Better error messages from instantiating and running of commands
[paperjam.git] / parse.cc
index cc0a58235e1c35e119c5190eb9a1ebdd689ef549..8e7de38b3aec6a52f57a3f72bb23a98158f3aee4 100644 (file)
--- a/parse.cc
+++ b/parse.cc
@@ -78,7 +78,8 @@ static token_type get_next_token()
       while (*in_pos >= 'A' && *in_pos <= 'Z' ||
             *in_pos >= 'a' && *in_pos <= 'z' ||
             *in_pos >= '0' && *in_pos <= '9' ||
       while (*in_pos >= 'A' && *in_pos <= 'Z' ||
             *in_pos >= 'a' && *in_pos <= 'z' ||
             *in_pos >= '0' && *in_pos <= '9' ||
-            *in_pos == '_')
+            *in_pos == '_' ||
+            *in_pos == '-')
        token += *in_pos++;
       return TOK_IDENT;
     }
        token += *in_pos++;
       return TOK_IDENT;
     }
@@ -218,7 +219,14 @@ static double parse_dimen(const arg_def *adef)
 
   t = next_token();
   if (t != TOK_IDENT)
 
   t = next_token();
   if (t != TOK_IDENT)
-    parse_error("Parameter %s must have a unit", adef->name);
+    {
+      if (is_zero(tmp))
+       {
+         return_token();
+         return 0;
+       }
+      parse_error("Parameter %s must have a unit", adef->name);
+    }
   for (uint i=0; units[i].name; i++)
     if (token == units[i].name)
       return tmp * units[i].multiplier;
   for (uint i=0; units[i].name; i++)
     if (token == units[i].name)
       return tmp * units[i].multiplier;
@@ -467,7 +475,14 @@ static void instantiate(list<cmd *> &cmds)
 {
   for (auto c: cmds)
     {
 {
   for (auto c: cmds)
     {
-      c->exec = c->def->constructor(c);
+      try
+       {
+         c->exec = c->def->constructor(c);
+       }
+      catch (exception &e)
+       {
+         die("Error in %s: %s", c->def->name, e.what());
+       }
       if (c->pipe)
        {
          for (auto pb: c->pipe->branches)
       if (c->pipe)
        {
          for (auto pb: c->pipe->branches)