From eb217683eba08d51c089cd71860e3581f73ec073 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 17 Feb 2024 23:02:43 +0100 Subject: Remove the need of backing up inside the rule lexer. --- .gitignore | 1 + src/analysis/scan/Makefile.am | 2 +- src/analysis/scan/tokens.l | 157 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index af62759..7fa51d9 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ grammar.[ch] grammar.output tokens.[ch] ylwrap +lex.backup # i18n gettext.h diff --git a/src/analysis/scan/Makefile.am b/src/analysis/scan/Makefile.am index ed4f8c7..f7e85ad 100644 --- a/src/analysis/scan/Makefile.am +++ b/src/analysis/scan/Makefile.am @@ -8,7 +8,7 @@ BUILT_SOURCES = grammar.h AM_YFLAGS = -v -d -p rost_ -Wno-yacc -Wcounterexamples -AM_LFLAGS = -P rost_ -o lex.yy.c --header-file=tokens.h \ +AM_LFLAGS = -b -Cf -P rost_ -o lex.yy.c --header-file=tokens.h \ -Dyyget_lineno=rost_get_lineno \ -Dyy_scan_bytes=rost__scan_bytes \ -Dyy_delete_buffer=rost__delete_buffer diff --git a/src/analysis/scan/tokens.l b/src/analysis/scan/tokens.l index 0dff9f4..86e3e92 100644 --- a/src/analysis/scan/tokens.l +++ b/src/analysis/scan/tokens.l @@ -297,6 +297,26 @@ static void rost_unescape_bytes(const char *src, size_t len, sized_string_t *out #define POP_STATE yy_pop_state(yyscanner) +#define STOP_LEXER(msg, fbmsg) \ + do \ + { \ + char *__text; \ + int __ret; \ + __ret = asprintf(&__text, "%s: '%s'", msg, yytext); \ + if (__ret == -1) \ + YY_FATAL_ERROR(fbmsg); \ + else \ + { \ + YY_FATAL_ERROR(__text); \ + free(__text); \ + } \ + } \ + while (0) + +#define HANDLE_UNCOMPLETED_TOKEN \ + STOP_LEXER("Uncompleted token in rule definition", "Undisclosed uncompleted token in rule definition") + + %} @@ -994,6 +1014,143 @@ bytes_fuzzy_id [\*A-Za-z_][\*A-Za-z0-9_]* <*>"//"[^\n]* { } +%{ /* Suppression du besoin de sauvegardes pour retours en arrière */ %} + +"i" { HANDLE_UNCOMPLETED_TOKEN; } +"in" { HANDLE_UNCOMPLETED_TOKEN; } +"inc" { HANDLE_UNCOMPLETED_TOKEN; } +"incl" { HANDLE_UNCOMPLETED_TOKEN; } +"inclu" { HANDLE_UNCOMPLETED_TOKEN; } +"includ" { HANDLE_UNCOMPLETED_TOKEN; } + +\" { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_not_escaped}+ { HANDLE_UNCOMPLETED_TOKEN; } + +\"\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + +"g" { HANDLE_UNCOMPLETED_TOKEN; } +"gl" { HANDLE_UNCOMPLETED_TOKEN; } +"glo" { HANDLE_UNCOMPLETED_TOKEN; } +"glob" { HANDLE_UNCOMPLETED_TOKEN; } +"globa" { HANDLE_UNCOMPLETED_TOKEN; } + +"p" { HANDLE_UNCOMPLETED_TOKEN; } +"pr" { HANDLE_UNCOMPLETED_TOKEN; } +"pri" { HANDLE_UNCOMPLETED_TOKEN; } +"priv" { HANDLE_UNCOMPLETED_TOKEN; } +"priva" { HANDLE_UNCOMPLETED_TOKEN; } +"privat" { HANDLE_UNCOMPLETED_TOKEN; } + +"r" { HANDLE_UNCOMPLETED_TOKEN; } +"ru" { HANDLE_UNCOMPLETED_TOKEN; } +"rul" { HANDLE_UNCOMPLETED_TOKEN; } + +"m" { HANDLE_UNCOMPLETED_TOKEN; } +"me" { HANDLE_UNCOMPLETED_TOKEN; } +"met" { HANDLE_UNCOMPLETED_TOKEN; } + +"b" { HANDLE_UNCOMPLETED_TOKEN; } +"by" { HANDLE_UNCOMPLETED_TOKEN; } +"byt" { HANDLE_UNCOMPLETED_TOKEN; } +"byte" { HANDLE_UNCOMPLETED_TOKEN; } + +"c" { HANDLE_UNCOMPLETED_TOKEN; } +"co" { HANDLE_UNCOMPLETED_TOKEN; } +"con" { HANDLE_UNCOMPLETED_TOKEN; } +"cond" { HANDLE_UNCOMPLETED_TOKEN; } +"condi" { HANDLE_UNCOMPLETED_TOKEN; } +"condit" { HANDLE_UNCOMPLETED_TOKEN; } +"conditi" { HANDLE_UNCOMPLETED_TOKEN; } +"conditio" { HANDLE_UNCOMPLETED_TOKEN; } + + +"t" { HANDLE_UNCOMPLETED_TOKEN; } +"tr" { HANDLE_UNCOMPLETED_TOKEN; } +"tru" { HANDLE_UNCOMPLETED_TOKEN; } + +"f" { HANDLE_UNCOMPLETED_TOKEN; } +"fa" { HANDLE_UNCOMPLETED_TOKEN; } +"fal" { HANDLE_UNCOMPLETED_TOKEN; } +"fals" { HANDLE_UNCOMPLETED_TOKEN; } + +-0x { HANDLE_UNCOMPLETED_TOKEN; } + +0x { HANDLE_UNCOMPLETED_TOKEN; } + +\"{str_mixed}* { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}*\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}*\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}*\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +-0x { HANDLE_UNCOMPLETED_TOKEN; } + + +0x { HANDLE_UNCOMPLETED_TOKEN; } + + +\"{str_not_escaped}* { HANDLE_UNCOMPLETED_TOKEN; } + +\" { HANDLE_UNCOMPLETED_TOKEN; } +\"\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +\" { HANDLE_UNCOMPLETED_TOKEN; } +\"\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\ { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x { HANDLE_UNCOMPLETED_TOKEN; } +\"{str_mixed}+\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +\"{str_not_escaped}+ { HANDLE_UNCOMPLETED_TOKEN; } + + +{hbyte}([ ]*{hbyte})*[ ]* { HANDLE_UNCOMPLETED_TOKEN; } +{hbyte}([ ]*{hbyte})*[ ]*[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +[\?]{2}([ ]*[\?]{2})*[ ]* { HANDLE_UNCOMPLETED_TOKEN; } +[\?]{2}([ ]*[\?]{2})*[ ]*[\?] { HANDLE_UNCOMPLETED_TOKEN; } + + +{mbyte}([ ]*{mbyte})*[ ]* { HANDLE_UNCOMPLETED_TOKEN; } +{mbyte}([ ]*{mbyte})*[ ]*\? { HANDLE_UNCOMPLETED_TOKEN; } +{mbyte}([ ]*{mbyte})*[ ]*[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +\\ { HANDLE_UNCOMPLETED_TOKEN; } +\\x { HANDLE_UNCOMPLETED_TOKEN; } +\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } +({regular_chars})+\\ { HANDLE_UNCOMPLETED_TOKEN; } +({regular_chars})+\\x { HANDLE_UNCOMPLETED_TOKEN; } +({regular_chars})+\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + +({reg_classes})+\\ + + +({regular_chars}|({regular_chars}-{regular_chars})|{reg_classes})+\\ { HANDLE_UNCOMPLETED_TOKEN; } +({regular_chars}|({regular_chars}-{regular_chars})|{reg_classes})+\\x { HANDLE_UNCOMPLETED_TOKEN; } +({regular_chars}|({regular_chars}-{regular_chars})|{reg_classes})+\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } +\\x { HANDLE_UNCOMPLETED_TOKEN; } +\\x[0-9a-fA-F] { HANDLE_UNCOMPLETED_TOKEN; } + + %{ /* Actions par défaut */ %} <*>[ \t]+ { } -- cgit v0.11.2-87-g4458