Skip to content

Commit 843dcd4

Browse files
committed
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 <[email protected]>
1 parent d4b61b0 commit 843dcd4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@
454454
#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
455455
#endif
456456

457+
// Whether to print parse rule names (rather than integers) in mp_parse_node_print
458+
#ifndef MICROPY_DEBUG_PARSE_RULE_NAME
459+
#define MICROPY_DEBUG_PARSE_RULE_NAME (0)
460+
#endif
461+
457462
// Whether to enable a simple VM stack overflow check
458463
#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
459464
#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)

py/parse.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
#define RULE_ARG_RULE (0x2000)
5656
#define RULE_ARG_OPT_RULE (0x3000)
5757

58-
// (un)comment to use rule names; for debugging
59-
// #define USE_RULE_NAME (1)
60-
6158
// *FORMAT-OFF*
6259

6360
enum {
@@ -192,7 +189,7 @@ static const size_t FIRST_RULE_WITH_OFFSET_ABOVE_255 =
192189
#undef DEF_RULE_NC
193190
0;
194191

195-
#if USE_RULE_NAME
192+
#if MICROPY_DEBUG_PARSE_RULE_NAME
196193
// Define an array of rule names corresponding to each rule
197194
STATIC const char *const rule_name_table[] = {
198195
#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
410407
#endif
411408
} else {
412409
size_t n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
413-
#if USE_RULE_NAME
410+
#if MICROPY_DEBUG_PARSE_RULE_NAME
414411
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);
415412
#else
416413
mp_printf(print, "rule(%u) (n=%u)\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns), (uint)n);

0 commit comments

Comments
 (0)