From 3c4fb8abe4e28091cb857705af2d762cd00b985a Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Sun, 18 Jul 2010 00:59:02 +0000 Subject: Theme Editor: Added column number to parser error messages git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27477 a1c6a512-1295-4272-9138-f99709370657 --- lib/skin_parser/skin_debug.c | 18 +++++++++++++++++- lib/skin_parser/skin_debug.h | 3 ++- lib/skin_parser/skin_parser.c | 26 ++++++++++++++------------ utils/themeeditor/gui/skindocument.cpp | 4 +++- utils/themeeditor/models/parsetreemodel.cpp | 1 + 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/skin_parser/skin_debug.c b/lib/skin_parser/skin_debug.c index 4abe6252f0..c03b32e910 100644 --- a/lib/skin_parser/skin_debug.c +++ b/lib/skin_parser/skin_debug.c @@ -30,15 +30,25 @@ /* Global variables for debug output */ int debug_indent_level = 0; extern int skin_line; +extern char* skin_start; /* Global error variables */ int error_line; +int error_col; char* error_message; /* Debugging functions */ -void skin_error(enum skin_errorcode error) +void skin_error(enum skin_errorcode error, char* cursor) { + error_col = 0; + + while(cursor > skin_start && *cursor != '\n') + { + cursor--; + error_col++; + } + error_line = skin_line; switch(error) @@ -91,6 +101,11 @@ int skin_error_line() return error_line; } +int skin_error_col() +{ + return error_col; +} + char* skin_error_message() { return error_message; @@ -99,6 +114,7 @@ char* skin_error_message() void skin_clear_errors() { error_line = 0; + error_col = 0; error_message = NULL; } diff --git a/lib/skin_parser/skin_debug.h b/lib/skin_parser/skin_debug.h index 8fc061a9f9..fbff5cbb4c 100644 --- a/lib/skin_parser/skin_debug.h +++ b/lib/skin_parser/skin_debug.h @@ -31,8 +31,9 @@ extern "C" #include "skin_parser.h" #ifndef ROCKBOX /* Debugging functions */ -void skin_error(enum skin_errorcode error); +void skin_error(enum skin_errorcode error, char* cursor); int skin_error_line(void); +int skin_error_col(void); char* skin_error_message(void); void skin_clear_errors(void); void skin_debug_tree(struct skin_element* root); diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c index 5bc5984fb7..3e23067258 100644 --- a/lib/skin_parser/skin_parser.c +++ b/lib/skin_parser/skin_parser.c @@ -34,6 +34,7 @@ /* Global variables for the parser */ int skin_line = 0; +char* skin_start = 0; int viewport_line = 0; /* Auxiliary parsing functions (not visible at global scope) */ @@ -66,6 +67,7 @@ struct skin_element* skin_parse(const char* document) char* cursor = (char*)document; /*Keeps track of location in the document*/ skin_line = 1; + skin_start = (char*)document; viewport_line = 0; skin_clear_errors(); @@ -381,7 +383,7 @@ static struct skin_element* skin_parse_sublines_optional(char** document, if(*cursor != MULTILINESYM && i != sublines - 1) { - skin_error(MULTILINE_EXPECTED); + skin_error(MULTILINE_EXPECTED, cursor); return NULL; } else if(i != sublines - 1) @@ -433,7 +435,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) if(!tag) { - skin_error(ILLEGAL_TAG); + skin_error(ILLEGAL_TAG, cursor); return 0; } @@ -464,7 +466,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) /* Checking the number of arguments and allocating args */ if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|') { - skin_error(ARGLIST_EXPECTED); + skin_error(ARGLIST_EXPECTED, cursor); return 0; } else @@ -512,7 +514,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) /* Making sure we haven't run out of arguments */ if(*tag_args == '\0') { - skin_error(TOO_MANY_ARGS); + skin_error(TOO_MANY_ARGS, cursor); return 0; } @@ -545,7 +547,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) } else { - skin_error(DEFAULT_NOT_ALLOWED); + skin_error(DEFAULT_NOT_ALLOWED, cursor); return 0; } } @@ -554,7 +556,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) /* Scanning an int argument */ if(!isdigit(*cursor) && *cursor != '-') { - skin_error(INT_EXPECTED); + skin_error(INT_EXPECTED, cursor); return 0; } @@ -610,12 +612,12 @@ static int skin_parse_tag(struct skin_element* element, char** document) if(*cursor != ARGLISTSEPERATESYM && i < num_args - 1) { - skin_error(SEPERATOR_EXPECTED); + skin_error(SEPERATOR_EXPECTED, cursor); return 0; } else if(*cursor != ARGLISTCLOSESYM && i == num_args - 1) { - skin_error(CLOSE_EXPECTED); + skin_error(CLOSE_EXPECTED, cursor); return 0; } else @@ -639,7 +641,7 @@ static int skin_parse_tag(struct skin_element* element, char** document) /* Checking for a premature end */ if(*tag_args != '\0' && !optional) { - skin_error(INSUFFICIENT_ARGS); + skin_error(INSUFFICIENT_ARGS, cursor); return 0; } @@ -724,7 +726,7 @@ static int skin_parse_conditional(struct skin_element* element, char** document) /* Counting the children */ if(*(cursor++) != ENUMLISTOPENSYM) { - skin_error(ARGLIST_EXPECTED); + skin_error(ARGLIST_EXPECTED, cursor); return 0; } bookmark = cursor; @@ -768,12 +770,12 @@ static int skin_parse_conditional(struct skin_element* element, char** document) if(i < children - 1 && *cursor != ENUMLISTSEPERATESYM) { - skin_error(SEPERATOR_EXPECTED); + skin_error(SEPERATOR_EXPECTED, cursor); return 0; } else if(i == children - 1 && *cursor != ENUMLISTCLOSESYM) { - skin_error(CLOSE_EXPECTED); + skin_error(CLOSE_EXPECTED, cursor); return 0; } else diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp index f04c12d213..18877d14ee 100644 --- a/utils/themeeditor/gui/skindocument.cpp +++ b/utils/themeeditor/gui/skindocument.cpp @@ -211,7 +211,9 @@ void SkinDocument::cursorChanged() skin_parse(line.selectedText().toAscii()); if(skin_error_line() > 0) parseStatus = tr("Error on line ") + - QString::number(line.blockNumber() + 1) + tr(": ") + + QString::number(line.blockNumber() + 1) + + tr(", column ") + QString::number(skin_error_col()) + + tr(": ") + skin_error_message(); statusLabel->setText(parseStatus); } diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index 66c96213ab..8e49118e2e 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp @@ -72,6 +72,7 @@ QString ParseTreeModel::changeTree(const char *document) { QString error = tr("Error on line ") + QString::number(skin_error_line()) + + tr(", column ") + QString::number(skin_error_col()) + tr(": ") + QString(skin_error_message()); return error; } -- cgit v1.2.3