Pip -s
, 152 150 148 139 137 126 125 123123 120 bytes
YaRs" ("R';')R`\["R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\[)`;]`{c." pointer to"X#b}{[b"is"g@>2a]}Vy^s
Takes the declaration as a command-line input. Try it online!Try it online!
We want the whole declaration to be parenthesized (this helps with the loop later on), so we change type ...;
into type (...)
. Then, observe that no reordering is done with the descriptions of functions and arrays, so we can perform all those replacements first without affecting the final output.
Y Yank into y variable...
a The result of a (the cmdline arg)...
R s Replace the space
" (" with " ("
R '; Replace the semicolon
') with a closing paren
R `\[(\d+)]` Replace digits in square brackets
` array of \1` with " array of <digits>"
R "()" Replace function parens
" function returning" with " function returning"
If our original input was float *((*p()))[16];
, we now have float (*((*p function returning)) array of 16)16;
.
L#a Loop len(a) times (enough to complete all replacements):
Y Yank into y variable...
y The result of y...
R `\((\**)(.+)\[)`;]` Replace open paren, 0 or more asterisks (group 1), 1 or more
characters (group 2), and close paren or semicolon
{ with this callback function (b = group 1, c = group 2):
c . The stuff in the middle, concatenated to...
" pointer to" that string
X #b repeated len(asterisks) times
}
float (*((*p function returning)) array of 16)16;
float ((*p function returning)) array of 16 pointer to
float (*p function returning) array of 16 pointer to
float p function returning pointer to array of 16 pointer to