X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=lexer.l;h=17b757d9a12aa2669f3074a84c7774e2a156e574;hp=ac21f695e6c8265e787859a153f3b4ec525a6dc1;hb=bc730637ae2abc44a1e1013bc64d85a92923cf6e;hpb=c7ad3b51358d0b7704e5670d973ad1a376caf4e1 diff --git a/lexer.l b/lexer.l index ac21f69..17b757d 100644 --- a/lexer.l +++ b/lexer.l @@ -43,6 +43,7 @@ #include "common.h" #include "daemon.h" #include "lib.h" +#include "both.h" #include "tokens.h" #define HYPHEN '-' @@ -132,6 +133,7 @@ struct error_handling { static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 }; static int dequote(char *inplace); +static void countnewlines(void); #define YY_NO_UNPUT @@ -247,40 +249,35 @@ error { lr_dir= df_error; lr_loglevel= LOG_ERR; return tokv_word_error; } char *ep; lr_min= (int)strtoul(yytext,&ep,10); assert(*ep == HYPHEN); - assert(*++ep); + ep++; assert(*ep); lr_max= (int)strtoul(ep,&ep,10); assert(!*ep); - if (lr_max < lr_min) { - parseerrprint("fd range has min > max"); - return tokv_error; - } + if (lr_max < lr_min) + return parseerrprint("fd range has min > max"); return tokv_fdrange; } [0-9]{1,8}- { char *ep; lr_min= (int)strtoul(yytext,&ep,10); assert(*ep == HYPHEN); - assert(!*++ep); + ep++; assert(!*ep); lr_max=-1; return tokv_fdstoend; } -([\ \t]*\\[\ \t]*\n[\ \t]*)+ return tokv_lwsp; +([\ \t]*\\[\ \t]*\n[\ \t]*)+ countnewlines(); return tokv_lwsp; [\ \t]+ return tokv_lwsp; [\ \t]*\n cstate->lineno++; return tokv_newline; [\ \t]*\#[^\n]*\n cstate->lineno++; return tokv_newline; -[\ \t]*\#[^\n]* { - parseerrprint("missing newline at eof after comment"); - return tokv_error; - } +[\ \t]*\#[^\n]* return parseerrprint("missing newline at eof after comment"); \"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[[:punct:]]|\\[ \t]*\n)*\" { + countnewlines(); return dequote(yytext); } -\".* { - parseerrprint("misquoted or unterminated string"); - return tokv_error; - } -[^\ \t\n\\]+ return tokv_barestring; -<> return tokv_eof; +[^\ \t\n\\\"]+ return tokv_barestring; +<> return tokv_eof; +\" return parseerrprint("misquoted or unterminated string"); +\\ return parseerrprint("unexpected backslash"); +. abort(); /* expect lex warning "rule cannot be matched" */ %%