katef / kgt

BNF wrangling and railroad diagrams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bugs found in rrtext output.

perlawk opened this issue · comments

Hi:
A bug is found:
when using rrtext with the following example:
p = [a] , [b] ;

kgt -l ebnf -e rrtext < bug.ebnf >bug.txt

bug.ebnf.txt
patch.txt

There are trailing spaces at the end of output:

p:
>-------v >-------v <- trailing spaces
| | | | <- trailing spaces
||--^-- a -->--^-- b -->--||

if the production rule output is shorter than the console width, it's not
obvious, with a long production rule, like:

block = [const-declaration] ,
[var-declaration] ,
[proc-declaration] ,
compund-statement
;

break of lines occurred.

So, some fix required. I made a simple patch for temporary fix.
Just right trim the output string:

#include <ctype.h>

char *rtrim(char *s) {
int n = strlen(s);
while(--n>=0 && ( iscntrl(s[n]) || isspace(s[n]) || isblank(s[n])))
;
s[++n] = 0;
return s;
}

or a patch file attached for the src/rrtext/output.c

Thanks.

Good idea, thanks! Committed in 62e82c0.