Commit 758971c8 authored by POTTIER Francois's avatar POTTIER Francois

Removed the TODO item about use-site %inline, and documented a trick that allows simulating it.

parent 5bab93eb
* A use-site %inline would sometimes be useful!
And would allow removing the duplication between option/ioption, etc.
* Another crazy idea: if we had a special "void" non-terminal symbol,
we could use it as a parameter, which would allow us to make extensible
definitions. (Any production that contains void would be removed after
......
......@@ -2648,6 +2648,26 @@ incremental API (\sref{sec:incremental}) does not mention the type
\verb+Lexing.lexbuf+. In this API, the parser expects to be supplied with
triples of a token and start/end positions of type \verb+Lexing.position+.
\question{I need both \dinline and non-\dinline versions of a non-terminal
symbol. Is this possible?} Define an \dinline version first, then use it to
define a non-\dinline version, like this:
\begin{verbatim}
%inline ioption(X): (* nothing *) { None } | x = X { Some x }
option(X): o = ioption(X) { o }
\end{verbatim}
This can work even in the presence of recursion, as illustrated by the
following definition of (reversed, left-recursive, possibly empty) lists:
\begin{verbatim}
%inline irevlist(X): (* nothing *) { [] } | xs = revlist(X) x = X { x :: xs }
revlist(X): xs = irevlist(X) { xs }
\end{verbatim}
The definition of \verb+irevlist+ is expanded into the definition of \verb+revlist+,
so in the end, \verb+revlist+ receives its normal, recursive definition. One can
then view \verb+irevlist+ as a variant of \verb+revlist+ that is inlined one level
deep.
% Intentionally do not call this "list", because people may copy-paste this
% definition, and will end up unintentionally redefining the meaning of *.
% ---------------------------------------------------------------------------------------------------------------------
\section{Technical background}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment