diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 110b23f7..fb005919 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -142,6 +142,7 @@ YY_LLOC_START %{ if ( queue == NULL ){ queue = g_queue_new ( ); + yylloc->filename = current->filename; } %} @@ -219,6 +220,7 @@ if ( queue == NULL ){ yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE )); yylloc->first_line = yylloc->last_line = 1; yylloc->first_column = yylloc->last_column = 1; + yylloc->filename = current->filename; } else { char *str = g_markup_printf_escaped ( "Failed to open theme: %s\nError: %s", filename, strerror ( errno ) ); diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 78269fe7..e304ff29 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -7,6 +7,35 @@ %parse-param {const char *what} %code requires { #include "theme.h" + +typedef struct YYLTYPE { + int first_line; + int first_column; + int last_line; + int last_column; + char *filename; +} YYLTYPE; +# define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */ + +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + (Current).filename = YYRHSLOC (Rhs, 1).filename; \ + } \ + else \ + { /* empty RHS */ \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + (Current).filename = NULL; /* new */ \ + } \ + while (0) } %{ #include diff --git a/source/theme.c b/source/theme.c index 26824275..122fa6a4 100644 --- a/source/theme.c +++ b/source/theme.c @@ -270,9 +270,15 @@ void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) g_string_printf ( str, "Error while parsing theme: %s\n", what_esc ); g_free ( what_esc ); char *esc = g_markup_escape_text ( s, -1 ); - g_string_append_printf ( str, "\tParser error: %s\n", esc ); + g_string_append_printf ( str, "\tParser error: %s\n", esc ); g_free ( esc ); - g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column ); + if ( yylloc->filename != NULL ) { + g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d.\n"\ + "\tFile '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yylloc->filename); + + }else { + g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column ); + } rofi_add_error_message ( str ); }