X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/4324be9622f8a1a05da22301a624e872cf2b04ae..9d4541acd3fa4962bd0a17ff8b09c0373c465e1d:/newsearch/newsearch.l?ds=sidebyside diff --git a/newsearch/newsearch.l b/newsearch/newsearch.l index ba5a096a..043c6e03 100644 --- a/newsearch/newsearch.l +++ b/newsearch/newsearch.l @@ -1,18 +1,33 @@ %option noyywrap %{ + +#include +#include +#ifndef __POSIX_VISIBLE +#define fileno(x) 0 +#endif + #include "../lib/sstring.h" #define YYSTYPE sstring * extern YYSTYPE yylval; #include "y.tab.h" - -#include #include "../lib/stringbuf.h" #define MAX_STR_CONST 512 +int lexpos, lexerror; + +#define addpos(x) lexpos+=x; +#define incpos() addpos(1); + +void lexreset(void) { + lexerror = 0; + lexpos = -1; +} + %} digit [0-9] @@ -24,51 +39,79 @@ letter [a-zA-Z] char bufdata[MAX_STR_CONST]; StringBuf buf; -\" { +\" { incpos(); sbinit(&buf, bufdata, sizeof(bufdata)); BEGIN(str); } { - \" { + \" { incpos(); BEGIN(INITIAL); sbterminate(&buf); yylval = getsstring(bufdata, 512); return STRING; } - \\\\ { sbaddchar(&buf, '\\'); } - \\\" { sbaddchar(&buf, '"'); } - [^\\] { sbaddchar(&buf, *yytext); } + \\\\ { addpos(2); + sbaddchar(&buf, '\\'); + } + \\\" { addpos(2); + sbaddchar(&buf, '"'); + } + [^\\] { incpos(); + sbaddchar(&buf, *yytext); + } } -\' { +\' { incpos(); sbinit(&buf, bufdata, sizeof(bufdata)); BEGIN(pascalstr); } { - \'\' { sbaddchar(&buf, '\''); } - \' { + \'\' { addpos(2); + sbaddchar(&buf, '\''); + } + \' { incpos(); BEGIN(INITIAL); sbterminate(&buf); yylval = getsstring(bufdata, 512); return STRING; } - . { sbaddchar(&buf, *yytext); } + . { incpos(); + sbaddchar(&buf, *yytext); + } } -"(" { return LPAREN; } -")" { return RPAREN; } -[ \t]+ { return WHITESPACE; } -{letter}+ { +"(" { incpos(); + return LPAREN; + } +")" { incpos(); + return RPAREN; + } +[ \t]+ { addpos(strlen(yytext)); + return WHITESPACE; + } +({letter}|{digit}|[#\-\+\.\*])+ { addpos(strlen(yytext)); yylval = getsstring(yytext, 512); return IDENTIFIER; } -[\n\r] /* ignore */; +[\n\r] { incpos(); + /* ignore */; + } + +. { + incpos(); + lexerror = 1; + yyterminate(); + } <> { BEGIN(INITIAL); yyterminate(); } %% + +void ydummyfn(void) { + yyunput(0, NULL); +}