py/parse: Expose rule-name printing as MICROPY_DEBUG_PARSE_RULE_NAME.
So it can be enabled without modifying the source. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
d4b61b0017
commit
843dcd4f85
@ -454,6 +454,11 @@
|
|||||||
#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
|
#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether to print parse rule names (rather than integers) in mp_parse_node_print
|
||||||
|
#ifndef MICROPY_DEBUG_PARSE_RULE_NAME
|
||||||
|
#define MICROPY_DEBUG_PARSE_RULE_NAME (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Whether to enable a simple VM stack overflow check
|
// Whether to enable a simple VM stack overflow check
|
||||||
#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
|
#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
|
||||||
#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
|
#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
|
||||||
|
@ -55,9 +55,6 @@
|
|||||||
#define RULE_ARG_RULE (0x2000)
|
#define RULE_ARG_RULE (0x2000)
|
||||||
#define RULE_ARG_OPT_RULE (0x3000)
|
#define RULE_ARG_OPT_RULE (0x3000)
|
||||||
|
|
||||||
// (un)comment to use rule names; for debugging
|
|
||||||
// #define USE_RULE_NAME (1)
|
|
||||||
|
|
||||||
// *FORMAT-OFF*
|
// *FORMAT-OFF*
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -192,7 +189,7 @@ static const size_t FIRST_RULE_WITH_OFFSET_ABOVE_255 =
|
|||||||
#undef DEF_RULE_NC
|
#undef DEF_RULE_NC
|
||||||
0;
|
0;
|
||||||
|
|
||||||
#if USE_RULE_NAME
|
#if MICROPY_DEBUG_PARSE_RULE_NAME
|
||||||
// Define an array of rule names corresponding to each rule
|
// Define an array of rule names corresponding to each rule
|
||||||
STATIC const char *const rule_name_table[] = {
|
STATIC const char *const rule_name_table[] = {
|
||||||
#define DEF_RULE(rule, comp, kind, ...) #rule,
|
#define DEF_RULE(rule, comp, kind, ...) #rule,
|
||||||
@ -410,7 +407,7 @@ void mp_parse_node_print(const mp_print_t *print, mp_parse_node_t pn, size_t ind
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
size_t n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
|
size_t n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
|
||||||
#if USE_RULE_NAME
|
#if MICROPY_DEBUG_PARSE_RULE_NAME
|
||||||
mp_printf(print, "%s(%u) (n=%u)\n", rule_name_table[MP_PARSE_NODE_STRUCT_KIND(pns)], (uint)MP_PARSE_NODE_STRUCT_KIND(pns), (uint)n);
|
mp_printf(print, "%s(%u) (n=%u)\n", rule_name_table[MP_PARSE_NODE_STRUCT_KIND(pns)], (uint)MP_PARSE_NODE_STRUCT_KIND(pns), (uint)n);
|
||||||
#else
|
#else
|
||||||
mp_printf(print, "rule(%u) (n=%u)\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns), (uint)n);
|
mp_printf(print, "rule(%u) (n=%u)\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns), (uint)n);
|
||||||
|
Loading…
Reference in New Issue
Block a user