From 613997fd7ed0f78bbcffcbc78d76addb04d53937 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Thu, 16 Feb 2012 07:51:33 -0800 Subject: [PATCH] Add generic support extended conditional syntax extended conditionals use a syntax of cond=value cond=(value1 value2) cond=(value1,value2) where the comma is optional and supported as such because the flags syntax used them The mount patch extends, and improves on this patch, the changes probably should have been separated out but ... Signed-off-by: John Johansen Acked-by: Kees Cook --- parser/parser_lex.l | 41 +++++++++++++++++++++++++++++++++++++++++ parser/parser_yacc.y | 1 + 2 files changed, 42 insertions(+) diff --git a/parser/parser_lex.l b/parser/parser_lex.l index a0517d860..83812fc28 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -213,6 +213,7 @@ ARROW -> LT_EQUAL <= %x SUB_NAME +%x EXTCOND_MODE %x NETWORK_MODE %x LIST_VAL_MODE %x ASSIGN_MODE @@ -306,6 +307,34 @@ LT_EQUAL <= } } +{ + {WS}+ { DUMP_PREPROCESS; /* Eat whitespace */ } + + {EQUALS} { + DUMP_PREPROCESS; + return TOK_EQUALS; + } + + {OPEN_PAREN} { + DUMP_PREPROCESS; + PDEBUG("extcond listv\n"); + /* Don't push state here as this is a transition + * start condition and we want to return to the start + * condition that invoked when + * SUB_NAME is done + */ + BEGIN(LIST_VAL_MODE); + return TOK_OPENPAREN; + } + + [^\n] { + DUMP_PREPROCESS; + /* Something we didn't expect */ + yyerror(_("Found unexpected character: '%s'"), yytext); + } + +} + { {WS}+ { DUMP_PREPROCESS; /* Eat whitespace */ } @@ -536,6 +565,18 @@ LT_EQUAL <= return TOK_OPENPAREN; } +{VARIABLE_NAME}/{WS}*={WS}* { + /* we match to the = in the lexer so that + * can switch scanner state. By the time + * the parser see the = it may be to late + * as bison may have requested the next + * token from the scanner + */ + yylval.id = processid(yytext, yyleng); + yy_push_state(EXTCOND_MODE); + return TOK_CONDID; + } + {VARIABLE_NAME} { DUMP_PREPROCESS; int token = get_keyword_token(yytext); diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y index 4e683214e..516cf57d4 100644 --- a/parser/parser_yacc.y +++ b/parser/parser_yacc.y @@ -78,6 +78,7 @@ void add_local_entry(struct codomain *cod); %} %token TOK_ID +%token TOK_CONDID %token TOK_CARET %token TOK_OPEN %token TOK_CLOSE