From: Michael Tremer Date: Fri, 15 Mar 2019 04:42:33 +0000 (+0000) Subject: libpakfire: parser: Add T_ prefix to all tokens X-Git-Tag: 0.9.28~1285^2~1048 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf24f81dab48d6add389c843934336cf9152ecdd;p=pakfire.git libpakfire: parser: Add T_ prefix to all tokens Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 17080342d..0daf8ad06 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -62,14 +62,14 @@ static int pakfire_parser_append_declaration(Pakfire pakfire, char* current_block = NULL; %} -%token APPEND -%token ASSIGN -%token DEFINE -%token END -%token EQUALS -%token IF -%token NEWLINE -%token WORD +%token T_APPEND +%token T_ASSIGN +%token T_DEFINE +%token T_END +%token T_EQUALS +%token T_IF +%token T_NEWLINE +%token T_WORD %type define; %type line; @@ -79,10 +79,10 @@ char* current_block = NULL; %type word; %type words; -%precedence WORD +%precedence T_WORD -%left APPEND -%left ASSIGN +%left T_APPEND +%left T_ASSIGN %union { char* string; @@ -99,10 +99,10 @@ thing : assignment | empty ; -empty : NEWLINE +empty : T_NEWLINE ; -variable : WORD; +variable : T_WORD; value : words | %empty @@ -112,7 +112,7 @@ value : words // IF can show up in values and therefore this // hack is needed to parse those properly -word : WORD | IF; +word : T_WORD | T_IF; words : word | words word @@ -124,12 +124,12 @@ words : word } }; -line : words NEWLINE +line : words T_NEWLINE { // Only forward words $$ = $1; } - | NEWLINE { + | T_NEWLINE { $$ = NULL; }; @@ -144,17 +144,17 @@ text : text line | line ; -if_stmt : IF WORD EQUALS WORD NEWLINE block_assignments end +if_stmt : T_IF T_WORD T_EQUALS T_WORD T_NEWLINE block_assignments end { printf("IF STATEMENT NOT EVALUATED, YET: %s %s\n", $2, $4); }; -block_opening : variable NEWLINE +block_opening : variable T_NEWLINE { current_block = pakfire_strdup($1); }; -block_closing : END NEWLINE +block_closing : T_END T_NEWLINE { pakfire_free(current_block); current_block = NULL; @@ -169,13 +169,13 @@ block_assignment : assignment | if_stmt | empty; -assignment : variable ASSIGN value NEWLINE +assignment : variable T_ASSIGN value T_NEWLINE { int r = pakfire_parser_add_declaration(pakfire, declarations, $1, $3); if (r < 0) ABORT; } - | variable APPEND value NEWLINE + | variable T_APPEND value T_NEWLINE { int r = pakfire_parser_append_declaration(pakfire, declarations, $1, $3); if (r < 0) @@ -188,16 +188,16 @@ assignment : variable ASSIGN value NEWLINE ABORT; }; -define : DEFINE variable NEWLINE +define : T_DEFINE variable T_NEWLINE { $$ = $2; } - | variable NEWLINE + | variable T_NEWLINE { $$ = $1; }; -end : END NEWLINE; +end : T_END T_NEWLINE; %% diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l index 04d00200d..cb41d5b32 100644 --- a/src/libpakfire/parser/scanner.l +++ b/src/libpakfire/parser/scanner.l @@ -43,15 +43,15 @@ word ({quoted_string}|({digit}|{letter}|{special})+) #.*$ { /* ignore comments */ } {whitespace} {} -\n { num_lines++; return NEWLINE; } +\n { num_lines++; return T_NEWLINE; } -"==" { return EQUALS; } -"=" { return ASSIGN; } -"+=" { return APPEND; } +"==" { return T_EQUALS; } +"=" { return T_ASSIGN; } +"+=" { return T_APPEND; } -"if" { return IF; } -"def(ine)?" { return DEFINE; } -"end" { return END; } +"if" { return T_IF; } +"def(ine)?" { return T_DEFINE; } +"end" { return T_END; } {quoted_string} { // Remove quotes @@ -59,12 +59,12 @@ word ({quoted_string}|({digit}|{letter}|{special})+) yytext[len-1] = '\0'; yylval.string = pakfire_strdup(yytext + 1); - return WORD; + return T_WORD; } {word} { yylval.string = pakfire_strdup(yytext); - return WORD; + return T_WORD; } %%