Improved the error message given when there is a write statement but no machine
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Fri, 22 Jun 2007 03:50:05 +0000 (03:50 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Fri, 22 Jun 2007 03:50:05 +0000 (03:50 +0000)
instantiations and hence no state machine.

git-svn-id: http://svn.complang.org/ragel/trunk@256 052ea7fc-9027-0410-9066-f65837a77df0

redfsm/xmlparse.kh
redfsm/xmlparse.kl

index 12424c4..439ab1c 100644 (file)
@@ -139,6 +139,7 @@ struct Parser
        ostream &error();
        ostream &error( const InputLoc &loc );
        ostream &parser_error( int tokId, Token &token );
+       ostream &source_error( const InputLoc &loc );
 
        /* The name of the root section, this does not change during an include. */
        char *fileName;
index 5149171..8bf526f 100644 (file)
@@ -253,16 +253,18 @@ tag_write_head: TAG_write
                        error($1->loc) << "tag <write> requires a col attribute" << endp;
 
                if ( nameAttr != 0 && lineAttr != 0 && colAttr != 0 ) {
+                       $$->loc.line = atoi(lineAttr->value);
+                       $$->loc.col = atoi(colAttr->value);
+
                        CodeGenMapEl *mapEl = codeGenMap.find( nameAttr->value );
-                       if ( mapEl == 0 )
-                               error($1->loc) << "internal error: cannot find codeGen" << endp;
+                       if ( mapEl == 0 ) {
+                               source_error($$->loc) << "write statement given "
+                                               "but there are no machine instantiations" << endp;
+                       }
                        else {
                                cgd = mapEl->value;
                                ::keyOps = &cgd->thisKeyOps;
                        }
-
-                       $$->loc.line = atoi(lineAttr->value);
-                       $$->loc.col = atoi(colAttr->value);
                }
        };
 
@@ -917,6 +919,15 @@ ostream &Parser::parser_error( int tokId, Token &token )
        return cerr;
 }
 
+ostream &Parser::source_error( const InputLoc &loc )
+{
+       gblErrorCount += 1;
+       assert( sourceFileName != 0 );
+       cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": ";
+       return cerr;
+}
+
+
 int Parser::token( int tokenId, Token &tok )
 {
        int res = parseLangEl( tokenId, &tok );