From 860cbef43b482513f0518efd8096e1916e782bb6 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 13 May 2017 01:41:29 +0300 Subject: ragel.rl: better error matching Combine tail action into mark. Tokenize on 'space ' or on punctuation. Treat single printable or valid* as word. --- src/ragel/ragel.rl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ragel/ragel.rl b/src/ragel/ragel.rl index 4974bd5..03c6eb3 100644 --- a/src/ragel/ragel.rl +++ b/src/ragel/ragel.rl @@ -4,8 +4,6 @@ #include #include -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) - %%{ machine ragel; write data noerror nofinal; @@ -13,16 +11,18 @@ action red { fputs("\x1b[31m", stderr); } action reset { fputs("\x1b[0m", stderr); } action end { fputs("\x1b[0m\n", stderr); } - action mark { fputc('^', stderr); } - action tail { fputc('~', stderr); } + action mark { fputc((fpc == *error ? '^' : '~'), stderr); } action lead { fputc(' ', stderr); } + action char { fputc(fc, stderr); } + + valid = ^cntrl - space - punct; + mark_token = (space valid | punct) ${ *error = fpc; }; + search_err := ((any | mark_token) when { fpc != ragel->pe && fpc <= ragel->p })*; - word = alnum*; - token = ' ' | punct; + word = print | valid*; until_err = (any when { fpc != *error })*; - search_err := ((any | token %{ *error = fpc; }) when { fpc != ragel->pe && fpc <= ragel->p })*; - print_err := (until_err %red <: word %reset <: (any - '\n')*) ${ fputc(fc, stderr); } >lead %!end %/end; - print_mark := (until_err ${ fputc(' ', stderr); } %red %mark <: any word $tail) >lead %!end %/end; + print_err := (until_err <: word >red %reset <: (print - '\n')*) $char >*lead %!end %/end; + print_mark := (until_err $lead <: word >red $mark) >*lead %!end %/end; }%% static void -- cgit v1.2.3