chiark / gitweb /
@@ -9,6 +9,7 @@
[userv.git] / lexer.l
diff --git a/lexer.l b/lexer.l
index 6af03455119af5b06c40af9146834c38247aaf29..5b98073c2b8cc88f697680784c60afcf8566cdfb 100644 (file)
--- 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
 
@@ -188,6 +190,7 @@ parameter { lr_bispa= bispa_parameter; lr_bisexec= bisexec_parameter; return tok
 version { lr_bispa= bispa_none; lr_bisexec= bisexec_version; return tokv_word_version; }
 toplevel { lr_bispa= bispa_none; lr_bisexec= bisexec_toplevel; return tokv_word_toplevel; }
 override { lr_bispa= bispa_none; lr_bisexec= bisexec_override; return tokv_word_override; }
+shutdown { lr_bispa= bispa_none; lr_bisexec= bisexec_shutdown; return tokv_word_shutdown; }
 reset { lr_bispa= bispa_none; lr_bisexec= bisexec_reset; lr_dir= df_reset; return tokv_word_reset; }
 execute { lr_bispa= bispa_none; lr_bisexec= bisexec_execute; lr_dir= df_execute; return tokv_word_execute; }
 help { lr_bispa= bispa_none; lr_bisexec= bisexec_help; return tokv_word_help; }
@@ -249,10 +252,8 @@ error { lr_dir= df_error; lr_loglevel= LOG_ERR; return tokv_word_error; }
                          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}-            {
@@ -263,22 +264,20 @@ error { lr_dir= df_error; lr_loglevel= LOG_ERR; return tokv_word_error; }
                          lr_max=-1;
                          return tokv_fdstoend;
                        }
-[\ \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;
-<<EOF>>                        return tokv_eof;
+[^\ \t\n\\\"]+         return tokv_barestring;
+<<EOF>>                        return tokv_eof;
+\"                     return parseerrprint("misquoted or unterminated string");
+\\                     return parseerrprint("unexpected backslash");
+.                      abort(); /* expect lex warning "rule cannot be matched" */
 
 
 %%
@@ -289,6 +288,7 @@ const char *const builtinservicehelpstrings[]= {
   "version",
   "toplevel",
   "override",
+  "shutdown",
   "reset",
   "execute",
   "help",