From 00e297c5caefa21daf896a22ab1092131d60999a Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 9 May 2017 14:12:03 +0200 Subject: [PATCH] Update highlight style parsing --- lexer/theme-lexer.l | 36 ++++++++++++------------------------ lexer/theme-parser.y | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 0829ef33..e80d57a0 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -377,11 +377,11 @@ if ( queue == NULL ){
":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return PSEP; } ";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return PCLOSE;} -(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} +(true|false) { yylval->bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;} {PNNUMBER} { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} {PNNUMBER}\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} -\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} -@{WORD} { +\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} +@{WORD} { yylval->sval = g_strdup(yytext); return T_LINK; } @@ -539,27 +539,15 @@ if ( queue == NULL ){ return T_COLOR; } -{CENTER} { return T_POS_CENTER; } -{EAST} { return T_POS_EAST; } -{WEST} { return T_POS_WEST; } -{SOUTH} { return T_POS_SOUTH; } -{NORTH} { return T_POS_NORTH; } -{NONE} { - yylval->ival = HL_NONE; - return T_HIGHLIGHT_STYLE; -} -{BOLD} { - yylval->ival = HL_BOLD; - return T_HIGHLIGHT_STYLE; -} -{ITALIC} { - yylval->ival = HL_ITALIC; - return T_HIGHLIGHT_STYLE; -} -{UNDERLINE} { - yylval->ival = HL_UNDERLINE; - return T_HIGHLIGHT_STYLE; -} +{CENTER} { return T_POS_CENTER; } +{EAST} { return T_POS_EAST; } +{WEST} { return T_POS_WEST; } +{SOUTH} { return T_POS_SOUTH; } +{NORTH} { return T_POS_NORTH; } +{NONE} { return T_NONE; } +{BOLD} { return T_BOLD; } +{ITALIC} { return T_ITALIC; } +{UNDERLINE} { return T_UNDERLINE; } <> { ParseObject *po = g_queue_pop_head ( file_queue ); if ( po ) { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 6a414f70..d82dc4a5 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -101,7 +101,6 @@ int yylex (YYSTYPE *, YYLTYPE *); %token T_DOUBLE %token T_STRING %token N_STRING "property name" -%token T_HIGHLIGHT_STYLE %token NAME_ELEMENT "Element name" %token T_BOOLEAN %token T_COLOR @@ -114,6 +113,11 @@ int yylex (YYSTYPE *, YYLTYPE *); %token T_POS_NORTH "North" %token T_POS_SOUTH "South" +%token T_NONE "None" +%token T_BOLD "Bold" +%token T_ITALIC "Italic" +%token T_UNDERLINE "Underline" + %token BOPEN "bracket open ('{')" %token BCLOSE "bracket close ('}')" @@ -126,6 +130,7 @@ int yylex (YYSTYPE *, YYLTYPE *); %token CONFIGURATION "Configuration block" %type highlight_styles +%type highlight_style %type t_position %type t_position_ew %type t_position_sn @@ -292,12 +297,18 @@ t_position_sn /** * Highlight style, allow mulitple styles to be combined. + * Empty not allowed */ -highlight_styles: - T_HIGHLIGHT_STYLE { $$ = $1; } -| highlight_styles T_HIGHLIGHT_STYLE { - $$ = $1 | $2; -} +highlight_styles +: highlight_style { $$ = $1;} +| highlight_styles highlight_style { $$ = $1|$2;} +; +/** Single style. */ +highlight_style +: T_NONE { $$ = HL_NONE; } +| T_BOLD { $$ = HL_BOLD; } +| T_UNDERLINE { $$ = HL_UNDERLINE; } +| T_ITALIC { $$ = HL_ITALIC; } ; pvalue: N_STRING { $$ = $1; }