Report the unexpected token for P_UNEXPECTED_TOKEN returns - close #11
This commit is contained in:
parent
fa7a781a5d
commit
fff9700f91
@ -113,6 +113,9 @@ public struct <%= @grammar.prefix %>context_t
|
|||||||
|
|
||||||
/** Parse result value. */
|
/** Parse result value. */
|
||||||
<%= @grammar.prefix %>value_t parse_result;
|
<%= @grammar.prefix %>value_t parse_result;
|
||||||
|
|
||||||
|
/** Unexpected token received. */
|
||||||
|
<%= @grammar.prefix %>token_t token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@ -842,6 +845,7 @@ private size_t check_reduce(size_t state_id, <%= @grammar.prefix %>token_t token
|
|||||||
* can be accessed with <%= @grammar.prefix %>result().
|
* can be accessed with <%= @grammar.prefix %>result().
|
||||||
* @retval P_UNEXPECTED_TOKEN
|
* @retval P_UNEXPECTED_TOKEN
|
||||||
* An unexpected token was encountered that does not match any grammar rule.
|
* An unexpected token was encountered that does not match any grammar rule.
|
||||||
|
* The value context.token holds the unexpected token.
|
||||||
* @reval P_DECODE_ERROR
|
* @reval P_DECODE_ERROR
|
||||||
* The decoder encountered invalid text encoding.
|
* The decoder encountered invalid text encoding.
|
||||||
* @reval P_UNEXPECTED_INPUT
|
* @reval P_UNEXPECTED_INPUT
|
||||||
@ -917,6 +921,7 @@ public size_t <%= @grammar.prefix %>parse(<%= @grammar.prefix %>context_t * cont
|
|||||||
* after it, so that if the caller wants to report the error position,
|
* after it, so that if the caller wants to report the error position,
|
||||||
* it will point to the correct position of the unexpected token. */
|
* it will point to the correct position of the unexpected token. */
|
||||||
context.text_position = token_info.position;
|
context.text_position = token_info.position;
|
||||||
|
context.token = token;
|
||||||
return P_UNEXPECTED_TOKEN;
|
return P_UNEXPECTED_TOKEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,13 @@ unittest
|
|||||||
p_context_init(&context, input);
|
p_context_init(&context, input);
|
||||||
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
||||||
assert(p_position(&context) == p_position_t(2, 3));
|
assert(p_position(&context) == p_position_t(2, 3));
|
||||||
|
assert(context.token == TOKEN_a);
|
||||||
|
|
||||||
input = "12";
|
input = "12";
|
||||||
p_context_init(&context, input);
|
p_context_init(&context, input);
|
||||||
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
||||||
assert(p_position(&context) == p_position_t(0, 0));
|
assert(p_position(&context) == p_position_t(0, 0));
|
||||||
|
assert(context.token == TOKEN_num);
|
||||||
|
|
||||||
input = "a 12\n\nab";
|
input = "a 12\n\nab";
|
||||||
p_context_init(&context, input);
|
p_context_init(&context, input);
|
||||||
|
@ -13,6 +13,7 @@ unittest
|
|||||||
p_context_init(&context, input);
|
p_context_init(&context, input);
|
||||||
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
||||||
assert(p_position(&context) == p_position_t(0, 1));
|
assert(p_position(&context) == p_position_t(0, 1));
|
||||||
|
assert(context.token == TOKEN___EOF);
|
||||||
|
|
||||||
input = "a b";
|
input = "a b";
|
||||||
p_context_init(&context, input);
|
p_context_init(&context, input);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user