tabular operators in a custom environment code?

My question concerns the combination of the tabular environment and the \DeclareDocumentEnvironment command (from the xparse package).

How do I set up an environment that contains in its code some of the operators of the tabular environment, such as & or \\ ?

Here is my minimal (not) working example of what I thought I could do, but I get an error :

\documentclass{article}
\usepackage{xparse,booktabs}
\DeclareDocumentEnvironment{env}{mm}{\toprule #1 & #2 &}{\\ \bottomrule}

\begin{document}
\begin{tabular}{lll}
\begin{env}{one}{two}
three
\end{env}
\end{tabular}
\end{document}


Any idea of what I could do to have this environment working Inside the tabular environment?

Pierric

-
AFAIK, it is not possible to span an environment across cell boundaries. – quinmars Mar 6 '14 at 12:32
@quinmars It's not the only problem: \begin{env} expands to \env which is \protected, so expansion ends here as far as \halign is concerned for finding \noalign, so \toprule shows up too late, when a cell has already been started. – egreg Mar 6 '14 at 14:34

The \toprule will complain if something unexpandable was encountered before. You can circumvent the issue by using plain old commands:

\documentclass{article}
%\usepackage{xparse,booktabs}
%\DeclareDocumentEnvironment{env}{mm}{\toprule #1 & #2 &}{\\ \bottomrule}

\usepackage{booktabs}
\newcommand{\env}[2]{\toprule #1 & #2 &}
\newcommand{\envend}{\\ \bottomrule}

\begin{document}\thispagestyle{empty}
\begin{tabular}{lll}
\env{one}{two}
three
\envend
\env{four}{five}
six
\envend
\end{tabular}
\end{document}

-