[totem-pl-parser/wip/hadess/fix-xml-trailing-space: 1/3] core: Add state names to debug in XML parser
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem-pl-parser/wip/hadess/fix-xml-trailing-space: 1/3] core: Add state names to debug in XML parser
- Date: Tue, 2 Mar 2021 11:44:04 +0000 (UTC)
commit a365e60245170686a147c3871cc518aa05deb565
Author: Bastien Nocera <hadess hadess net>
Date: Tue Mar 2 12:35:53 2021 +0100
core: Add state names to debug in XML parser
plparse/xmllexer.c | 26 ++++++++++++++++++++++++--
plparse/xmlparser.c | 46 +++++++++++++++++++++++++++++++++++-----------
2 files changed, 59 insertions(+), 13 deletions(-)
---
diff --git a/plparse/xmllexer.c b/plparse/xmllexer.c
index bb06cbe..818e7f8 100644
--- a/plparse/xmllexer.c
+++ b/plparse/xmllexer.c
@@ -159,6 +159,28 @@ typedef enum {
STATE_IDENT /* must be last */
} lexer_state_t;
+static const char *const states[] = {
+ "STATE_UNKNOWN",
+ "STATE_IDLE",
+ "STATE_EOL",
+ "STATE_SEPAR",
+ "STATE_T_M_START",
+ "STATE_T_M_STOP_1",
+ "STATE_T_M_STOP_2",
+ "STATE_T_EQUAL",
+ "STATE_T_STRING_SINGLE",
+ "STATE_T_STRING_DOUBLE",
+ "STATE_T_COMMENT",
+ "STATE_T_TI_STOP",
+ "STATE_T_DASHDASH",
+ "STATE_T_C_STOP",
+ "STATE_IDENT"
+};
+
+static inline const char *state_to_str(lexer_state_t state) {
+ return states[state + 1];
+}
+
/* for ABI compatibility */
int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) {
return lexer_get_token_d_r(static_lexer, _tok, _tok_size, fixed);
@@ -175,7 +197,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
if (tok) {
while ((tok_pos < tok_size) && (lexer->lexbuf_pos < lexer->lexbuf_size)) {
c = lexer->lexbuf[lexer->lexbuf_pos];
- lprintf("c=%c, state=%d, in_comment=%d\n", c, state, lexer->in_comment);
+ lprintf("c=%c, state=%s (%d), in_comment=%d\n", c, state_to_str(state), state, lexer->in_comment);
switch (lexer->lex_mode) {
case NORMAL:
@@ -597,7 +619,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
lprintf("unknown state, state=%d\n", state);
}
} else {
- lprintf("abnormal end of buffer, state=%d\n", state);
+ lprintf("abnormal end of buffer, state=%s (%d)\n", state_to_str(state), state);
}
}
return T_ERROR;
diff --git a/plparse/xmlparser.c b/plparse/xmlparser.c
index 5d0e289..3015960 100644
--- a/plparse/xmlparser.c
+++ b/plparse/xmlparser.c
@@ -210,6 +210,30 @@ typedef enum {
STATE_CDATA,
} parser_state_t;
+static const char *const states[] = {
+ "STATE_IDLE",
+ "STATE_NODE",
+ "STATE_ATTRIBUTE",
+ "STATE_NODE_CLOSE",
+ "STATE_TAG_TERM",
+ "STATE_ATTRIBUTE_EQUALS",
+ "STATE_STRING",
+ "STATE_TAG_TERM_IGNORE",
+ "STATE_Q_NODE",
+ "STATE_Q_ATTRIBUTE",
+ "STATE_Q_NODE_CLOSE",
+ "STATE_Q_TAG_TERM",
+ "STATE_Q_ATTRIBUTE_EQUALS",
+ "STATE_Q_STRING",
+ "STATE_COMMENT",
+ "STATE_DOCTYPE",
+ "STATE_CDATA"
+};
+
+static inline const char *state_to_str(parser_state_t state) {
+ return states[state];
+}
+
static xml_node_t *xml_parser_append_text (xml_node_t *node, xml_node_t *subnode, const char *text, int
flags)
{
if (!text || !*text)
@@ -316,7 +340,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
lprintf("info: node data : %s\n", current_node->data);
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -348,7 +372,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
lprintf("info: current node name \"%s\"\n", node_name);
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -439,7 +463,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
lprintf("info: current property name \"%s\"\n", property_name);
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -456,7 +480,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
case (T_IDENT):
goto new_prop;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -493,7 +517,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
}
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -506,7 +530,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
return retval;
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -541,7 +565,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
state = STATE_ATTRIBUTE;
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -576,7 +600,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
state = STATE_Q_ATTRIBUTE;
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -606,7 +630,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
state = Q_STATE(STRING, ATTRIBUTE);
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -643,7 +667,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
state = STATE_IDLE;
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
@@ -656,7 +680,7 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
state = STATE_IDLE;
break;
default:
- lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
return -1;
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]