settings: Extend parser so we can parse settings from a string
[strongswan.git] / src / libstrongswan / settings / settings_lexer.l
index c6546f4..ce9d4ee 100644 (file)
@@ -119,16 +119,11 @@ static void include_files(parser_helper_t *ctx);
 <str>{
        "\""                            |
        <<EOF>>                         |
-       \n                                      |
        \\                                      {
                if (!streq(yytext, "\""))
                {
-                       if (streq(yytext, "\n"))
-                       {       /* put the newline back to fix the line numbers */
-                               unput('\n');
-                               yy_set_bol(0);
-                       }
                        PARSER_DBG1(yyextra, "unterminated string detected");
+                       return STRING_ERROR;
                }
                if (yy_top_state(yyscanner) == inc)
                {       /* string include */
@@ -146,12 +141,9 @@ static void include_files(parser_helper_t *ctx);
        \\n     yyextra->string_add(yyextra, "\n");
        \\r     yyextra->string_add(yyextra, "\r");
        \\t     yyextra->string_add(yyextra, "\t");
-       \\b     yyextra->string_add(yyextra, "\b");
-       \\f     yyextra->string_add(yyextra, "\f");
-       \\(.|\n)                        {
-               yyextra->string_add(yyextra, yytext+1);
-       }
-       [^\\\n"]+                       {
+       \\\r?\n /* merge lines that end with EOL characters */
+       \\.     yyextra->string_add(yyextra, yytext+1);
+       [^\\"]+                 {
                yyextra->string_add(yyextra, yytext);
        }
 }
@@ -199,3 +191,11 @@ static void include_files(parser_helper_t *ctx)
 
        settings_parser_open_next_file(ctx);
 }
+
+/**
+ * Load the given string to be parsed next
+ */
+void settings_parser_load_string(parser_helper_t *ctx, const char *content)
+{
+       settings_parser__scan_string(content, ctx->scanner);
+}