Here's an all-Forest version thanks to Sašo's explaining how to detokenize to test for a string in multi-line content. No xstring
or amsmath
required!
\documentclass[12pt,border=25pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[linguistics]{forest}
\forestset{%
declare toks={dntoks}{},
declare toks={ndtoks}{},
nd/.style={%
delay={%
% detokenize to test for string in multi-line content: Sašo Živanović: https://tex.stackexchange.com/questions/330228/annotating-a-forest-tree-with-its-corresponding-bracketing/330237?noredirect=1#comment809615_330237
temptoksa/.expanded=\detokenize{\\},
temptoksb/.option=content,
temptoksb/.wrap value=\detokenize{##1},
temptoksb/.expanded/.register=temptoksb,
if={instr(temptoksa,temptoksb)}{%
split register/.wrap pgfmath arg={{temptoksb}{##1}{ndtoks,temptoksc}}{(temptoksa)},
}{%
ndtoks/.option=content,
},
},
before typesetting nodes={%
content/.wrap value={\llap{\textcolor{red}{[\textsubscript{\foresteoption{ndtoks}}}}##1},
},
},
dn/.style={%
repeat=#1{%
dntoks+={]},
},
before typesetting nodes={%
content/.wrap value={##1\rlap{\textcolor{red}{\foresteoption{dntoks}}}},
},
},
}
\begin{document}
\begin{forest}
[TP, nd
[DP, nd
[D, nd
]
[NP
[N\\man, dn=2
]
]
]
[T', nd
[T\\will, nd, dn=1
]
[VP, nd
[V\\eat, nd, dn=1
]
[DP, nd
[D\\a, nd, dn=1
]
[NP, nd
[N\\burger, nd, dn=6
]
]
]
]
]
]
\end{forest}
\end{document}

If all nodes should take the nd
style (like the example in the question), then this can obviously be simplified further.
\documentclass[12pt,border=25pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[linguistics]{forest}
\forestset{%
declare toks={dntoks}{},
declare toks={ndtoks}{},
nd/.style={%
delay={%
% detokenize to test for string in multi-line content: Sašo Živanović: https://tex.stackexchange.com/questions/330228/annotating-a-forest-tree-with-its-corresponding-bracketing/330237?noredirect=1#comment809615_330237
temptoksa/.expanded=\detokenize{\\},
temptoksb/.option=content,
temptoksb/.wrap value=\detokenize{##1},
temptoksb/.expanded/.register=temptoksb,
if={instr(temptoksa,temptoksb)}{%
split register/.wrap pgfmath arg={{temptoksb}{##1}{ndtoks,temptoksc}}{(temptoksa)},
}{%
ndtoks/.option=content,
},
},
before typesetting nodes={%
content/.wrap value={\llap{\textcolor{red}{[\textsubscript{\foresteoption{ndtoks}}}}##1},
},
},
dn/.style={%
repeat=#1{%
dntoks+={]},
},
before typesetting nodes={%
content/.wrap value={##1\rlap{\textcolor{red}{\foresteoption{dntoks}}}},
},
},
default preamble={%
for tree={nd},
},
}
\begin{document}
\begin{forest}
[TP
[DP
[D
]
[NP
[N\\man, dn=2
]
]
]
[T'
[T\\will, dn=1
]
[VP
[V\\eat, dn=1
]
[DP
[D\\a, dn=1
]
[NP
[N\\burger, dn=6
]
]
]
]
]
]
\end{forest}
\end{document}

instr
did not work for multi-linecontent
.... (The manual doesn't mention this as far as I can see.) – cfr Sep 18 '16 at 20:47