[Tex/LaTex] macro for empty nodes in tikz-qtree

macrosnodestikz-qtreetikz-trees

I'm trying to define a macro for writing empty nodes in a binary tree using tikz-qtree.
Referring to the code below, I want the string \missing in my code to be replaced by \edge[draw=none]; {} as-is (just like if I simply did a find and replace in my code).

Is this possible and how can it be done? I don't want to paste \edge[draw=none]; {} every time there is an empty node in my binary tree.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}


\newcommand{\missing}{ \edge[draw=none]; {} }
%intended usage inside tikzpicture enviornment: 
%\Tree  [.3  1
%               \missing ]
%To producce the same result as code below but
%it gave me an error:
%! Undefined control sequence.
%\missing -> \edge 
%                  [draw=none]; {} 

\begin{document}

\begin{tikzpicture}
\Tree  [.3  1
               \edge[draw=none]; {} ]
\end{tikzpicture}

\end{document}

Best Answer

You need to encourage \missing to expand at the right time:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\makeatletter

\let\old@@children\@@children
\def\@@children{\futurelet\my@next\my@@children}
\def\my@@children{%
\ifx\my@next\missing\else
\expandafter\@gobble
\fi
\expandafter\old@@children}

\makeatother

\newcommand{\missing}{ \edge[draw=none]; {} }
%intended usage inside tikzpicture enviornment: 
%\Tree  [.3  1
%               \missing ]
%To producce the same result as code below but
%it gave me an error:
%! Undefined control sequence.
%\missing -> \edge 
%                  [draw=none]; {} 

\begin{document}

\begin{tikzpicture}

\Tree  [.3  1 \missing ]
\end{tikzpicture}

\end{document}