summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-05-13 01:41:29 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-02-23 12:53:53 +0200
commit860cbef43b482513f0518efd8096e1916e782bb6 (patch)
treecdf21b4494da948ac1e4f68120092fef38a505b0
parent72f823675f6d260f18dd1172e970e22c31d7e103 (diff)
ragel.rl: better error matching
Combine tail action into mark. Tokenize on 'space <valid>' or on punctuation. Treat single printable or valid* as word.
-rw-r--r--src/ragel/ragel.rl18
1 files 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 <stdarg.h>
#include <assert.h>
-#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