Open mingodad opened 1 month ago
The problem of start repeating again is due to output to both stdout
and stderr
but probably we only want stderr
see the complete possible fix bellow:
-------------------------- src/include/lrstar_lexer.h --------------------------
index f02d187..8e42cc5 100644
@@ -88,7 +88,6 @@ public:
char *ls;
if (linenumb > linenumb_printed) {
if (linenumb == 1) {
- printf ( "\n");
fprintf (stderr, "\nInput File ...\n\n");
}
@@ -96,8 +95,9 @@ public:
linenumb_printed = linenumb;
if (*ls != 26) { // Not end of file?
- printf("%6d %s\n", linenumb, ls);
- fprintf(stderr, "%6d %s\n", linenumb, ls);
+ char *eol = ls;
+ while(*eol && *eol != '\n' && *eol != 26 ) ++eol;
+ fprintf(stderr, "%6d %.*s\n", linenumb, eol - ls, ls);
}
}
}
The way that Paul originally wrote the logging facilities is certainly unique. I haven't looked at it in any detail, but I'm sure there's room for some pretty extensive cleanup. I notice that in your proposed patch, ASCII 25 is being used to determine EOF; that's non-portable (but, IIRC, the original code also puts ASCII 26 at the end of the file when it is read into memory, so it should be ok... though very Windows specific). It would be nice if these uses of 26 were turned into a preprocessor symbol, or a constant value present in a header file.
When testing
grammars/ANTLR
we get incorrect output fromlrstar_lexer::print_line
due to missing line termination/length see bello a possible fix for it: Possible fix:Using the https://github.com/thutt/lrstar/blob/24.0.018/grammars/ANTLR/test.input.txt :
With the fix:
But still there is something else going on because after line 118 it start repeating again once more: