Hi,

At the beginning I would like to thank you for the great project Ragel.
It allows us (www.knot-dns.cz) to have realy fast parser for DNS zone files.

But I have recently noticed that there is a small bug in C code generation with G{0,1,2},
because there is different behaviour between G and T, F modes.

Meaningless and very pruned snippet of code which can demonstrate the problem:

== test.rl ==
#include <stdlib.h>
#include <stdio.h>

%%{
        machine zone_scanner;

        newline = '\n';
        comment = ';' . (^newline)*;
        wchar = [ \t\n;];

        sep = ( [ \t]
              | (comment? . newline) when { 0 }
)+;

        err_line := (^newline)* . newline @{ fgoto main; };

        action _text_char_error {
printf("!TXT_ERROR!\n");
                fhold; fgoto err_line;
}

        text = ^wchar . (alpha $!_text_char_error)+;

        main := "$INCLUDE" . sep . text . newline;
}%%

%% write data;

int main(int argc, char **argv)
{
        char buffer[4096];
        FILE* f;
        long numbytes;

        f = fopen(argv[1], "r");
        fseek(f, 0, SEEK_END);
        numbytes = ftell(f);
        fseek(f, 0, SEEK_SET);
        fread(buffer, 1, numbytes, f);

        char *p = buffer;
        char *pe = buffer + numbytes;
        char *eof = pe;
        int stack[16];
        int  cs = zone_scanner_start;
        int top;

        %% write exec;

        if (cs == zone_scanner_error) {
printf("!MISC_ERROR!\n");
                return -1;
}

        return 0;
}

== input.txt ==
$INCLUDE        ; Missing filename
==========

ragel -T0 test.rl -o testT.c
gcc testT.c -o testT
./testT ./input.txt
!MISC_ERROR!

ragel -G0 test.rl -o testG.c
gcc testG.c -o testG
./testG ./input.txt
!TXT_ERROR!

Here you can see the state machines stop in different states.

Although this problem is marginal in our project, it would be nice if Ragel is absolute perfect :-)

Best regards,
Dan



_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to