]> granicus.if.org Git - re2c/commitdiff
- Improve error messages and flush output before error out
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 22 Jan 2006 17:15:03 +0000 (17:15 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 22 Jan 2006 17:15:03 +0000 (17:15 +0000)
- Use minimal buffering when outputting single chars

17 files changed:
bootstrap/scanner.cc
code.cc
main.cc
scanner.h
scanner.re
stream_lc.h
test/error1.c
test/error10.c
test/error11.c
test/error2.c
test/error3.c
test/error4.c
test/error5.c
test/error6.c
test/error7.c
test/error8.c
test/error9.c

index 1e4916db8cbfc9b90e2a8b5992a9823f0c7d5571..31a4117b6c495b2458f0d8bdec18e0ea3184bca5 100644 (file)
@@ -1,13 +1,15 @@
-/* Generated by re2c 0.10.0.dev on Sat Jan 21 16:15:00 2006 */
+/* Generated by re2c 0.10.0.dev on Sun Jan 22 18:04:36 2006 */
 #line 1 "scanner.re"
 /* $Id$ */
 #include <stdlib.h>
 #include <string.h>
 #include <iostream>
+#include <sstream>
 #include "scanner.h"
 #include "parser.h"
 #include "y.tab.h"
 #include "globals.h"
+#include "dfa.h"
 
 extern YYSTYPE yylval;
 
@@ -28,9 +30,11 @@ extern YYSTYPE yylval;
 namespace re2c
 {
 
-Scanner::Scanner(std::istream& i) : in(i),
-       bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL),
-       top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0)
+Scanner::Scanner(std::istream& i, std::ostream& o)
+       : in(i)
+       , out(o)
+       , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
+       , top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0)
 {
     ;
 }
@@ -72,7 +76,7 @@ char *Scanner::fill(char *cursor)
        return cursor;
 }
 
-#line 91 "scanner.re"
+#line 95 "scanner.re"
 
 
 int Scanner::echo(std::ostream &out){
@@ -88,10 +92,11 @@ int Scanner::echo(std::ostream &out){
     tok = cursor;
 echo:
 
-#line 92 "scanner.cc"
+#line 96 "scanner.cc"
 {
        YYCTYPE yych;
        unsigned int yyaccept = 0;
+
        if((YYLIMIT - YYCURSOR) < 11) YYFILL(11);
        yych = *YYCURSOR;
        if(yych <= ')') {
@@ -106,40 +111,40 @@ echo:
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych == '*') goto yy12;
 yy3:
-#line 137 "scanner.re"
+#line 141 "scanner.re"
        {
                                        goto echo;
                                }
-#line 114 "scanner.cc"
+#line 119 "scanner.cc"
 yy4:
        yych = *++YYCURSOR;
        if(yych == '/') goto yy10;
        goto yy3;
 yy5:
        ++YYCURSOR;
-#line 126 "scanner.re"
+#line 130 "scanner.re"
        {
                                        out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        tok = pos = cursor; cline++;
                                        goto echo;
                                }
-#line 127 "scanner.cc"
+#line 132 "scanner.cc"
 yy7:
        ++YYCURSOR;
-#line 131 "scanner.re"
+#line 135 "scanner.re"
        {
                                        out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1); // -1 so we don't write out the \0
                                        if(cursor == eof) {
                                                RETURN(0);
                                        }
                                }
-#line 137 "scanner.cc"
+#line 142 "scanner.cc"
 yy9:
        yych = *++YYCURSOR;
        goto yy3;
 yy10:
        ++YYCURSOR;
-#line 117 "scanner.re"
+#line 121 "scanner.re"
        {
                                        if (ignore_eoc) {
                                                ignore_eoc = false;
@@ -149,7 +154,7 @@ yy10:
                                        tok = pos = cursor;
                                        goto echo;
                                }
-#line 153 "scanner.cc"
+#line 158 "scanner.cc"
 yy12:
        yych = *++YYCURSOR;
        if(yych == '!') goto yy14;
@@ -175,13 +180,13 @@ yy16:
        yych = *++YYCURSOR;
        if(yych != 'c') goto yy13;
        ++YYCURSOR;
-#line 106 "scanner.re"
+#line 110 "scanner.re"
        { 
                                        out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok));
                                        tok = cursor;
                                        RETURN(1);
                                }
-#line 185 "scanner.cc"
+#line 190 "scanner.cc"
 yy21:
        yych = *++YYCURSOR;
        if(yych != 'x') goto yy13;
@@ -196,16 +201,16 @@ yy21:
        yych = *++YYCURSOR;
        if(yych != 'c') goto yy13;
        ++YYCURSOR;
-#line 111 "scanner.re"
+#line 115 "scanner.re"
        {
                                        out << "#define YYMAXFILL " << maxFill << std::endl;
                                        tok = pos = cursor;
                                        ignore_eoc = true;
                                        goto echo;
                                }
-#line 207 "scanner.cc"
+#line 212 "scanner.cc"
 }
-#line 140 "scanner.re"
+#line 144 "scanner.re"
 
 }
 
@@ -228,7 +233,7 @@ scan:
                goto value;
     }
 
-#line 232 "scanner.cc"
+#line 237 "scanner.cc"
 {
        YYCTYPE yych;
        unsigned int yyaccept = 0;
@@ -302,42 +307,42 @@ yy31:
                if(yych <= '9') goto yy95;
        }
 yy32:
-#line 162 "scanner.re"
+#line 166 "scanner.re"
        { depth = 1;
                                  goto code;
                                }
-#line 310 "scanner.cc"
+#line 315 "scanner.cc"
 yy33:
        ++YYCURSOR;
        if((yych = *YYCURSOR) == '*') goto yy92;
 yy34:
-#line 192 "scanner.re"
+#line 196 "scanner.re"
        { RETURN(*tok); }
-#line 317 "scanner.cc"
+#line 322 "scanner.cc"
 yy35:
        ++YYCURSOR;
        if((yych = *YYCURSOR) == '/') goto yy90;
 yy36:
-#line 194 "scanner.re"
+#line 198 "scanner.re"
        { yylval.op = *tok;
                                  RETURN(CLOSE); }
-#line 325 "scanner.cc"
+#line 330 "scanner.cc"
 yy37:
        yyaccept = 1;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych != 0x0A) goto yy86;
 yy38:
-#line 179 "scanner.re"
+#line 183 "scanner.re"
        { fatal("unterminated string constant (missing \")"); }
-#line 333 "scanner.cc"
+#line 338 "scanner.cc"
 yy39:
        yyaccept = 2;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych != 0x0A) goto yy81;
 yy40:
-#line 180 "scanner.re"
+#line 184 "scanner.re"
        { fatal("unterminated string constant (missing ')"); }
-#line 341 "scanner.cc"
+#line 346 "scanner.cc"
 yy41:
        yyaccept = 3;
        yych = *(YYMARKER = ++YYCURSOR);
@@ -345,9 +350,9 @@ yy41:
        if(yych == '^') goto yy72;
        goto yy71;
 yy42:
-#line 190 "scanner.re"
+#line 194 "scanner.re"
        { fatal("unterminated range (missing ])"); }
-#line 351 "scanner.cc"
+#line 356 "scanner.cc"
 yy43:
        yych = *++YYCURSOR;
        goto yy34;
@@ -359,57 +364,51 @@ yy45:
        if((yych = *YYCURSOR) == 'e') goto yy62;
        goto yy61;
 yy46:
-#line 221 "scanner.re"
+#line 225 "scanner.re"
        { cur = cursor;
                                  yylval.symbol = Symbol::find(token());
                                  return ID; }
-#line 367 "scanner.cc"
+#line 372 "scanner.cc"
 yy47:
        yych = *++YYCURSOR;
        goto yy61;
 yy48:
        ++YYCURSOR;
-#line 225 "scanner.re"
+#line 229 "scanner.re"
        { cur = cursor;
                                  yylval.regexp = mkDot();
                                  return RANGE;
                                }
-#line 378 "scanner.cc"
+#line 383 "scanner.cc"
 yy50:
        ++YYCURSOR;
        yych = *YYCURSOR;
        goto yy59;
 yy51:
-#line 230 "scanner.re"
+#line 234 "scanner.re"
        { goto scan; }
-#line 386 "scanner.cc"
+#line 391 "scanner.cc"
 yy52:
        ++YYCURSOR;
 yy53:
-#line 232 "scanner.re"
+#line 236 "scanner.re"
        { if(cursor == eof) RETURN(0);
                                  pos = cursor; cline++;
                                  goto scan;
                                }
-#line 395 "scanner.cc"
+#line 400 "scanner.cc"
 yy54:
        ++YYCURSOR;
        if((yych = *YYCURSOR) == 0x0A) goto yy57;
 yy55:
-#line 237 "scanner.re"
-       { std::cerr << "line " << tline << ", column " << (tchar + 1) 
-                                               << ": unexpected character: ";
-                                 if (isprint(*tok))
-                                 {
-                                       std::cerr << *tok << std::endl;
-                                 }
-                                 else
-                                 {
-                                       std::cerr << "0x" << hexCh(*tok >> 4) << hexCh(*tok) << std::endl;
-                                 }
+#line 241 "scanner.re"
+       { std::ostringstream msg;
+                                 msg << "unexpected character: ";
+                                 prtChOrHex(msg, *tok);
+                                 fatal(msg.str().c_str());
                                  goto scan;
                                }
-#line 413 "scanner.cc"
+#line 412 "scanner.cc"
 yy56:
        yych = *++YYCURSOR;
        goto yy55;
@@ -487,14 +486,14 @@ yy67:
                }
        }
 yy69:
-#line 214 "scanner.re"
+#line 218 "scanner.re"
        { cur = cursor;
                                  tok+= 5; /* skip "re2c:" */
                                  iscfg = 1;
                                  yylval.str = new Str(token());
                                  return CONFIG;
                                }
-#line 498 "scanner.cc"
+#line 497 "scanner.cc"
 yy70:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -528,11 +527,11 @@ yy74:
        goto yy70;
 yy75:
        ++YYCURSOR;
-#line 186 "scanner.re"
+#line 190 "scanner.re"
        { cur = cursor;
                                  yylval.regexp = ranToRE(token());
                                  return RANGE; }
-#line 536 "scanner.cc"
+#line 535 "scanner.cc"
 yy77:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -541,11 +540,11 @@ yy77:
        goto yy72;
 yy78:
        ++YYCURSOR;
-#line 182 "scanner.re"
+#line 186 "scanner.re"
        { cur = cursor;
                                  yylval.regexp = invToRE(token());
                                  return RANGE; }
-#line 549 "scanner.cc"
+#line 548 "scanner.cc"
 yy80:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -565,11 +564,11 @@ yy81:
        goto yy80;
 yy83:
        ++YYCURSOR;
-#line 175 "scanner.re"
+#line 179 "scanner.re"
        { cur = cursor;
                                  yylval.regexp = strToCaseInsensitiveRE(token());
                                  return STRING; }
-#line 573 "scanner.cc"
+#line 572 "scanner.cc"
 yy85:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -589,23 +588,23 @@ yy86:
        goto yy85;
 yy88:
        ++YYCURSOR;
-#line 171 "scanner.re"
+#line 175 "scanner.re"
        { cur = cursor;
                                  yylval.regexp = strToRE(token());
                                  return STRING; }
-#line 597 "scanner.cc"
+#line 596 "scanner.cc"
 yy90:
        ++YYCURSOR;
-#line 168 "scanner.re"
+#line 172 "scanner.re"
        { tok = cursor;
                                  RETURN(0); }
-#line 603 "scanner.cc"
+#line 602 "scanner.cc"
 yy92:
        ++YYCURSOR;
-#line 165 "scanner.re"
+#line 169 "scanner.re"
        { depth = 1;
                                  goto comment; }
-#line 609 "scanner.cc"
+#line 608 "scanner.cc"
 yy94:
        yych = *++YYCURSOR;
        if(yych == ',') goto yy108;
@@ -626,16 +625,16 @@ yy96:
 yy97:
        ++YYCURSOR;
 yy98:
-#line 212 "scanner.re"
+#line 216 "scanner.re"
        { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); }
-#line 632 "scanner.cc"
+#line 631 "scanner.cc"
 yy99:
        ++YYCURSOR;
-#line 200 "scanner.re"
+#line 204 "scanner.re"
        { yylval.extop.minsize = atoi((char *)tok+1);
                                  yylval.extop.maxsize = atoi((char *)tok+1);
                                  RETURN(CLOSESIZE); }
-#line 639 "scanner.cc"
+#line 638 "scanner.cc"
 yy101:
        yyaccept = 6;
        yych = *(YYMARKER = ++YYCURSOR);
@@ -643,11 +642,11 @@ yy101:
        if(yych <= '9') goto yy104;
        if(yych != '}') goto yy98;
        ++YYCURSOR;
-#line 208 "scanner.re"
+#line 212 "scanner.re"
        { yylval.extop.minsize = atoi((char *)tok+1);
                                  yylval.extop.maxsize = -1;
                                  RETURN(CLOSESIZE); }
-#line 651 "scanner.cc"
+#line 650 "scanner.cc"
 yy104:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -656,11 +655,11 @@ yy104:
        if(yych <= '9') goto yy104;
        if(yych != '}') goto yy66;
        ++YYCURSOR;
-#line 204 "scanner.re"
+#line 208 "scanner.re"
        { yylval.extop.minsize = atoi((char *)tok+1);
                                  yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1));
                                  RETURN(CLOSESIZE); }
-#line 664 "scanner.cc"
+#line 663 "scanner.cc"
 yy108:
        yyaccept = 6;
        yych = *(YYMARKER = ++YYCURSOR);
@@ -668,17 +667,17 @@ yy108:
        if(yych <= '9') goto yy104;
        if(yych != '}') goto yy98;
        ++YYCURSOR;
-#line 197 "scanner.re"
+#line 201 "scanner.re"
        { yylval.op = '*';
                                  RETURN(CLOSE); }
-#line 675 "scanner.cc"
+#line 674 "scanner.cc"
 }
-#line 249 "scanner.re"
+#line 247 "scanner.re"
 
 
 code:
 
-#line 682 "scanner.cc"
+#line 681 "scanner.cc"
 {
        YYCTYPE yych;
        unsigned int yyaccept = 0;
@@ -702,34 +701,34 @@ code:
                }
        }
        ++YYCURSOR;
-#line 253 "scanner.re"
+#line 251 "scanner.re"
        { if(--depth == 0){
                                        cur = cursor;
                                        yylval.token = new Token(token(), tline);
                                        return CODE;
                                  }
                                  goto code; }
-#line 713 "scanner.cc"
+#line 712 "scanner.cc"
 yy115:
        ++YYCURSOR;
-#line 259 "scanner.re"
+#line 257 "scanner.re"
        { ++depth;
                                  goto code; }
-#line 719 "scanner.cc"
+#line 718 "scanner.cc"
 yy117:
        ++YYCURSOR;
-#line 261 "scanner.re"
+#line 259 "scanner.re"
        { if(cursor == eof) fatal("missing '}'");
                                  pos = cursor; cline++;
                                  goto code;
                                }
-#line 727 "scanner.cc"
+#line 726 "scanner.cc"
 yy119:
        ++YYCURSOR;
 yy120:
-#line 265 "scanner.re"
+#line 263 "scanner.re"
        { goto code; }
-#line 733 "scanner.cc"
+#line 732 "scanner.cc"
 yy121:
        yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
@@ -781,12 +780,12 @@ yy128:
        if(yych == 0x0A) goto yy125;
        goto yy127;
 }
-#line 266 "scanner.re"
+#line 264 "scanner.re"
 
 
 comment:
 
-#line 790 "scanner.cc"
+#line 789 "scanner.cc"
 {
        YYCTYPE yych;
        if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
@@ -803,47 +802,47 @@ yy132:
        ++YYCURSOR;
        if((yych = *YYCURSOR) == '/') goto yy140;
 yy133:
-#line 281 "scanner.re"
+#line 279 "scanner.re"
        { if(cursor == eof) RETURN(0);
                                  goto comment; }
-#line 810 "scanner.cc"
+#line 809 "scanner.cc"
 yy134:
        yych = *++YYCURSOR;
        if(yych == '*') goto yy138;
        goto yy133;
 yy135:
        ++YYCURSOR;
-#line 277 "scanner.re"
+#line 275 "scanner.re"
        { if(cursor == eof) RETURN(0);
                                  tok = pos = cursor; cline++;
                                  goto comment;
                                }
-#line 822 "scanner.cc"
+#line 821 "scanner.cc"
 yy137:
        yych = *++YYCURSOR;
        goto yy133;
 yy138:
        ++YYCURSOR;
-#line 274 "scanner.re"
+#line 272 "scanner.re"
        { ++depth;
                                  fatal("ambiguous /* found");
                                  goto comment; }
-#line 832 "scanner.cc"
+#line 831 "scanner.cc"
 yy140:
        ++YYCURSOR;
-#line 270 "scanner.re"
+#line 268 "scanner.re"
        { if(--depth == 0)
                                        goto scan;
                                    else
                                        goto comment; }
-#line 840 "scanner.cc"
+#line 839 "scanner.cc"
 }
-#line 283 "scanner.re"
+#line 281 "scanner.re"
 
 
 config:
 
-#line 847 "scanner.cc"
+#line 846 "scanner.cc"
 {
        YYCTYPE yych;
        if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
@@ -860,25 +859,25 @@ yy144:
        yych = *YYCURSOR;
        goto yy153;
 yy145:
-#line 287 "scanner.re"
+#line 285 "scanner.re"
        { goto config; }
-#line 866 "scanner.cc"
+#line 865 "scanner.cc"
 yy146:
        ++YYCURSOR;
        yych = *YYCURSOR;
        goto yy151;
 yy147:
-#line 288 "scanner.re"
+#line 286 "scanner.re"
        { iscfg = 2;
                                  cur = cursor;
                                  RETURN('='); 
                                }
-#line 877 "scanner.cc"
+#line 876 "scanner.cc"
 yy148:
        ++YYCURSOR;
-#line 292 "scanner.re"
+#line 290 "scanner.re"
        { fatal("missing '='"); }
-#line 882 "scanner.cc"
+#line 881 "scanner.cc"
 yy150:
        ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -896,12 +895,12 @@ yy153:
        if(yych == ' ') goto yy152;
        goto yy145;
 }
-#line 293 "scanner.re"
+#line 291 "scanner.re"
 
 
 value:
 
-#line 905 "scanner.cc"
+#line 904 "scanner.cc"
 {
        YYCTYPE yych;
        unsigned int yyaccept = 0;
@@ -935,13 +934,13 @@ value:
                }
        }
 yy156:
-#line 302 "scanner.re"
+#line 300 "scanner.re"
        { cur = cursor;
                                  yylval.str = new Str(token());
                                  iscfg = 0;
                                  return VALUE;
                                }
-#line 945 "scanner.cc"
+#line 944 "scanner.cc"
 yy157:
        ++YYCURSOR;
        if((yych = *YYCURSOR) <= 0x0D) {
@@ -956,13 +955,13 @@ yy157:
                }
        }
 yy158:
-#line 297 "scanner.re"
+#line 295 "scanner.re"
        { cur = cursor;
                                  yylval.number = atoi(token().to_string().c_str());
                                  iscfg = 0;
                                  return NUMBER;
                                }
-#line 966 "scanner.cc"
+#line 965 "scanner.cc"
 yy159:
        yych = *++YYCURSOR;
        if(yych <= '0') goto yy163;
@@ -1142,20 +1141,18 @@ yy177:
        if(yych == 0x0A) goto yy170;
        goto yy174;
 }
-#line 307 "scanner.re"
+#line 305 "scanner.re"
 
 }
 
 void Scanner::fatal(uint ofs, const char *msg) const
 {
-    std::cerr << "line " << tline << ", column " << (tchar + ofs + 1) << ": "
+       out.flush();
+       std::cerr << "re2c: error: "
+               << "line " << tline << ", column " << (tchar + ofs + 1) << ": "
                << msg << std::endl;
-    exit(1);
-}
-
-void Scanner::fatal(const char *msg) const
-{
-    fatal(0, msg);
+       exit(1);
 }
 
 } // end namespace re2c
+
diff --git a/code.cc b/code.cc
index d913fa6ab6816383c6bf43088c827cc18eabd955..9d54677409319a98facc17b83475207ea484cc4a 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -1182,7 +1182,8 @@ void DFA::emit(std::ostream &o, uint ind)
        bool hasFillLabels = (0<=vFillIndexes);
        if (hasFillLabels==true && label!=0)
        {
-               std::cerr << "re2c : error : multiple /*!re2c blocks aren't supported when -f is specified\n";
+               o.flush();
+               std::cerr << "re2c: error: multiple /*!re2c blocks aren't supported when -f is specified\n";
                exit(1);
        }
 
diff --git a/main.cc b/main.cc
index e1bd13dc61a2cad61e212df1517484d0c4e6c3b2..875474d4b0fb9bb8d8be8274ec4dc8fd9b0e9182 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -249,7 +249,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       Scanner in(*input);
+       Scanner in(*input, output);
        
        if (!iFlag)
        {
index e863cb620669a7e3ae9b03b932589f9a303fdd75..ce09f4b9010e60ec16971749ad997b472dc21b9e 100644 (file)
--- a/scanner.h
+++ b/scanner.h
@@ -16,6 +16,7 @@ class Scanner:
 {
 private:
        std::istream&   in;
+       std::ostream&   out;
        char    *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof;
        uint    tchar, tline, cline, iscfg;
 
@@ -25,10 +26,10 @@ private:
        Scanner& operator=(const Scanner&); //unimplemented
 
 public:
-       Scanner(std::istream&);
+       Scanner(std::istream&, std::ostream&);
        int echo(std::ostream&);
        int scan();
-
+       
        void fatal(const char*) const;
        void fatal(uint, const char*) const;
 
@@ -52,6 +53,11 @@ public:
        RegExp * mkDot() const;
 };
 
+inline void Scanner::fatal(const char *msg) const
+{
+       fatal(0, msg);
+}
+
 inline SubStr Scanner::token() const
 {
        return SubStr(tok, cur - tok);
index 583cb8aa36272e304a2326c586794a5ecde613d7..bbc9380356972fa64bbac3f002ff300cb4b76d74 100644 (file)
@@ -2,10 +2,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <iostream>
+#include <sstream>
 #include "scanner.h"
 #include "parser.h"
 #include "y.tab.h"
 #include "globals.h"
+#include "dfa.h"
 
 extern YYSTYPE yylval;
 
@@ -26,9 +28,11 @@ extern YYSTYPE yylval;
 namespace re2c
 {
 
-Scanner::Scanner(std::istream& i) : in(i),
-       bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL),
-       top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0)
+Scanner::Scanner(std::istream& i, std::ostream& o)
+       : in(i)
+       , out(o)
+       , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
+       , top(NULL), eof(NULL), tchar(0), tline(0), cline(1), iscfg(0)
 {
     ;
 }
@@ -234,16 +238,10 @@ scan:
                                  goto scan;
                                }
 
-       any                     { std::cerr << "line " << tline << ", column " << (tchar + 1) 
-                                               << ": unexpected character: ";
-                                 if (isprint(*tok))
-                                 {
-                                       std::cerr << *tok << std::endl;
-                                 }
-                                 else
-                                 {
-                                       std::cerr << "0x" << hexCh(*tok >> 4) << hexCh(*tok) << std::endl;
-                                 }
+       any                     { std::ostringstream msg;
+                                 msg << "unexpected character: ";
+                                 prtChOrHex(msg, *tok);
+                                 fatal(msg.str().c_str());
                                  goto scan;
                                }
 */
@@ -309,14 +307,12 @@ value:
 
 void Scanner::fatal(uint ofs, const char *msg) const
 {
-    std::cerr << "line " << tline << ", column " << (tchar + ofs + 1) << ": "
+       out.flush();
+       std::cerr << "re2c: error: "
+               << "line " << tline << ", column " << (tchar + ofs + 1) << ": "
                << msg << std::endl;
-    exit(1);
-}
-
-void Scanner::fatal(const char *msg) const
-{
-    fatal(0, msg);
+       exit(1);
 }
 
 } // end namespace re2c
+
index 41ca65b006d76a49a6e4dd264083f56c0682e2ba..37e89d4321d3a150ee29d29c3b734e3aee50a739 100755 (executable)
@@ -165,7 +165,8 @@ protected:
                }
                else
                {
-                       return fputc(_Tr::to_char_type(c), fp) ? c : _Tr::eof();
+                       buffer += _Tr::to_char_type(c);
+                       return c;
                }
        }
 
@@ -210,6 +211,8 @@ protected:
 
        virtual int sync()
        {
+               fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp);
+               buffer.clear();
                return fp == 0
                        || _Tr::eq_int_type(_Tr::eof(), overflow())
                        || 0 <= fflush(fp) ? 0 : -1;
@@ -222,6 +225,8 @@ protected:
 
        std::streamsize xsputn(const _E *buf, std::streamsize cnt)
        {
+               fwrite(buffer.c_str(), sizeof(_E), buffer.length(), fp);
+               buffer.clear();
                oline += std::count(buf, buf + cnt, '\n');
                return fwrite(buf, sizeof(_E), cnt, fp);
        }
@@ -231,6 +236,7 @@ private:
        FILE * fp;
        bool   must_close;
        uint   oline;
+       std::basic_string<_E, _Tr> buffer;
 };
 
 typedef basic_filebuf_lc<char> filebuf_lc;
index 145d8fd3ddcc1197402fefa558038f91c595b8c0..96ce7cacaf6a46d7cfbc419998d64aae45a531ff 100755 (executable)
@@ -1,4 +1,3 @@
-line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers
 /* Generated by re2c */
 #line 1 "error1.re"
 #include <stdlib.h>
@@ -15,3 +14,4 @@ const char *q;
 #define YYLIMIT         (s+l)
 #define YYMARKER        q
 #define YYFILL(n)
+re2c: error: line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers
index 3f841c40e876f9b015ec7059b8543129dbe320f3..566b382445114adfb08f7bd746ccade07f942819 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 6: Illegal unicode character, eight hexadecimal digits are required
 /* Generated by re2c */
 #line 1 "error10.re"
+re2c: error: line 2, column 6: Illegal unicode character, eight hexadecimal digits are required
index 1b6154a1cd95c60fdbac2ee58751a349e2516b90..a9b7ad0d87ade14c4431a54714d20f8670b3e0dc 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 9: Illegal unicode character, non hexadecimal digit found
 /* Generated by re2c */
 #line 1 "error11.re"
+re2c: error: line 2, column 9: Illegal unicode character, non hexadecimal digit found
index 8ea7e6a22af5deef09af56e762928d7c543c7612..b9340ae3d8984e28fb91871a60702f5952686ab3 100755 (executable)
@@ -1,4 +1,3 @@
-line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers
 /* Generated by re2c */
 #line 1 "error2.re"
 #include <stdlib.h>
@@ -15,3 +14,4 @@ const char *q;
 #define YYLIMIT         (s+l)
 #define YYMARKER        q
 #define YYFILL(n)
+re2c: error: line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers
index 2369521d38cd7767524dcc63cbf7e08c837b8aa6..ccd05205566a5a1210290af8702534dc96cf31ff 100755 (executable)
@@ -1,4 +1,3 @@
-line 18, column 5: unexpected character: ]
 /* Generated by re2c */
 #line 1 "error3.re"
 #include <stdlib.h>
@@ -15,28 +14,4 @@ const char *q;
 #define YYLIMIT         (s+l)
 #define YYMARKER        q
 #define YYFILL(n)
-
-#line 19 "<stdout>"
-{
-       YYCTYPE yych;
-
-       if(YYLIMIT == YYCURSOR) YYFILL(1);
-       yych = *YYCURSOR;
-       switch(yych){
-       case 'a':       goto yy2;
-       default:        goto yy4;
-       }
-yy2:
-       ++YYCURSOR;
-#line 18 "error3.re"
-       {RET(1);}
-#line 33 "<stdout>"
-yy4:
-       ++YYCURSOR;
-#line 19 "error3.re"
-       {RET(0);}
-#line 38 "<stdout>"
-}
-#line 20 "error3.re"
-
-}
+re2c: error: line 18, column 5: unexpected character: ']'
index b9c46b864fba7a27d3041183bb318daa9e730255..4b8eed83b7f264a78e678052a0bbf5d4f34ef09a 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 5: Illegal hexadecimal character code, two hexadecimal digits are required
 /* Generated by re2c */
 #line 1 "error4.re"
+re2c: error: line 2, column 5: Illegal hexadecimal character code, two hexadecimal digits are required
index 6bcdc5a0331d5a678694603f9c421b8dfa86c02a..c90b4b9f8e799bfb7afe551dbdaa8bf27cf397d3 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 5: Illegal hexadecimal character code
 /* Generated by re2c */
 #line 1 "error5.re"
+re2c: error: line 2, column 5: Illegal hexadecimal character code
index 943d1a4014d6ef4f4ef5fdfdc94e5ac808c5df14..720d8a662f40373ab37afe278d7c8114af519239 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 7: Illegal hexadecimal character code, four hexadecimal digits are required
 /* Generated by re2c */
 #line 1 "error6.re"
+re2c: error: line 2, column 7: Illegal hexadecimal character code, four hexadecimal digits are required
index 6456b1f81bd3f7d715c45d008f1788342391c2c9..b5e89b892c710e2911e5228d56217644b6fc11b4 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 3: Illegal octal character code, first digit must be 0 thru 3
 /* Generated by re2c */
 #line 1 "error7.re"
+re2c: error: line 2, column 3: Illegal octal character code, first digit must be 0 thru 3
index f676fcda9f4a49564f2c7d719b27cfb59a0a8ed8..653f07fc34bbe03e92e62d0605020327d11cd1ce 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 4: Illegal octal character code, non octal digit found
 /* Generated by re2c */
 #line 1 "error8.re"
+re2c: error: line 2, column 4: Illegal octal character code, non octal digit found
index 1bbcc9088428a1eaab97507023a257331d4b7070..7fc510632bab82ebc4fadd386fa3b23f6c8b8b62 100755 (executable)
@@ -1,3 +1,3 @@
-line 2, column 5: Illegal octal character code, non octal digit found
 /* Generated by re2c */
 #line 1 "error9.re"
+re2c: error: line 2, column 5: Illegal octal character code, non octal digit found