Skip to content

Commit f49cfe1

Browse files
committed
parser debugging output: strip token name prefixes
Some of the names of parser (perly.y) tokens have a common prefix, such as PERLY_SEMICOLON PERLY_AMPERSAND KW_PACKAGE KW_CLASS Perl's -Dpv switch produces debugging output that also displays the top few items on the parse stack. The token names are truncated for compactness' sake. This currently leads to a display where its mostly just the token name's prefix that is displayed, e.g. $ perl -Dpv -e'package Foo' ... index: 1 2 3 4 5 6 7 8 state: 1 9 17 149 91 263 412 503 token: GRAMPROG @1 remember stmtseq KW_PACKA BAREWORD BAREWORD PERLY_SE value: 0 0 63 (Nullop) 0 (Nullop) const 735909768 After this commit, PERLY_, KW_ etc prefixes are stripped, allowing more of the actual token name is displayed: index: 1 2 3 4 5 6 7 8 state: 1 9 17 149 91 263 412 503 token: GRAMPROG @1 remember stmtseq PACKAGE BAREWORD BAREWORD SEMICOLO value: 0 0 63 (Nullop) 0 (Nullop) const 227539304
1 parent 7bcccf4 commit f49cfe1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

perly.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ yysymprint(pTHX_ PerlIO * const yyoutput, int yytype, const YYSTYPE * const yyva
128128
}
129129

130130

131+
/* common prefixes of token names to strip when displaying in compact form
132+
*/
133+
static const char *name_prefixes[] = {
134+
"PERLY_",
135+
"KW_",
136+
"bare_statement_",
137+
NULL,
138+
};
139+
131140
/* yy_stack_print()
132141
* print the top 8 items on the parse stack.
133142
*/
@@ -150,8 +159,21 @@ yy_stack_print (pTHX_ const yy_parser *parser)
150159
PerlIO_printf(Perl_debug_log, " %8d", ps->state);
151160

152161
PerlIO_printf(Perl_debug_log, "\ntoken:");
153-
for (ps = min; ps <= parser->ps; ps++)
154-
PerlIO_printf(Perl_debug_log, " %8.8s", ps->name);
162+
for (ps = min; ps <= parser->ps; ps++) {
163+
const char *name = ps->name;
164+
const char **p = name_prefixes;
165+
/* strip some common prefixes off the name to better display
166+
* truncated names */
167+
for (; *p; p++) {
168+
const char *prefix = *p;
169+
STRLEN l = strlen(prefix);
170+
if (strnEQ(name, prefix, l)) {
171+
name += l;
172+
break;
173+
}
174+
}
175+
PerlIO_printf(Perl_debug_log, " %8.8s", name);
176+
}
155177

156178
PerlIO_printf(Perl_debug_log, "\nvalue:");
157179
for (ps = min; ps <= parser->ps; ps++) {

0 commit comments

Comments
 (0)