%\iffalse
%
% File overword.dtx
% Copyright (C) 1996 by Frank Bennett.  All rights reserved.
%
% IMPORTANT NOTICE:
% 
% You are not allowed to change this file.  You may however copy
% this file to a file with a different name and then change the
% copy if (a) you do not charge for the modified code, (b) you
% acknowledge the author(s) in the new file, if it
% is distributed to others, and (c) you attach these same
% conditions to the new file.
% 
% You are not allowed to distribute this file alone.  You are not
% allowed to take money for the distribution or use of this file
% (or a changed version) except for a nominal charge for copying
% etc.
% 
% You are allowed to distribute this file under the condition that
% it is distributed with all of its contents, intact.
% 
% For error reports, or offers to help make this a more powerful,
% friendlier, and altogether more thrilling package, please contact me on
% fb@soas.ac.uk
% 
%<*dtx>
          \ProvidesFile{overword.dtx}
%</dtx>
%<style>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<style>\ProvidesPackage{overword}
%<style>          [1997/01/09 v1.1 Overword parsing support (Frank Bennett)]
% \fi
%
% \def\fileversion{v1.2}
% \def\filedate{1997/01/09}
%
%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
%\CodelineIndex
%\EnableCrossrefs
\begin{document}
%\OnlyDescription            % comment out for implementation details
\DocInput{overword.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{v1.0}{1996/11/10}{Initial version separated from calendar.dtx}
% \changes{v1.1}{1996/11/10}{Fixed error in the installation file.}
% \changes{v1.2}{1997/01/09}{Added @preoverwordspace, for use with Camel 1.0s.}
%
% \title{User's Guide to the Overword package\thanks{This file is version number
%    \fileversion{}.  It was last revised on
%    \filedate.}}
%
% \author{Frank G. Bennett, Jr.}
%
%  \maketitle
%
% \DoNotIndex{\@,\@@par,\@beginparpenalty,\@empty}
% \DoNotIndex{\@flushglue,\@gobble,\@input}
% \DoNotIndex{\@makefnmark,\@makeother,\@maketitle}
% \DoNotIndex{\@namedef,\@ne,\@spaces,\@tempa}
% \DoNotIndex{\@tempb,\@tempswafalse,\@tempswatrue}
% \DoNotIndex{\@thanks,\@thefnmark,\@topnum}
% \DoNotIndex{\@@,\@elt,\@forloop,\@fortmp,\@gtempa,\@totalleftmargin}
% \DoNotIndex{\",\/,\@ifundefined,\@nil,\@verbatim,\@vobeyspaces}
% \DoNotIndex{\|,\~,\ ,\active,\advance,\aftergroup,\begingroup,\bgroup}
% \DoNotIndex{\cal,\csname,\def,\documentstyle,\dospecials,\edef}
% \DoNotIndex{\egroup}
% \DoNotIndex{\else,\endcsname,\endgroup,\endinput,\endtrivlist}
% \DoNotIndex{\expandafter,\fi,\fnsymbol,\futurelet,\gdef,\global}
% \DoNotIndex{\hbox,\hss,\if,\if@inlabel,\if@tempswa,\if@twocolumn}
% \DoNotIndex{\ifcase}
% \DoNotIndex{\ifcat,\iffalse,\ifx,\ignorespaces,\index,\input,\item}
% \DoNotIndex{\jobname,\kern,\leavevmode,\leftskip,\let,\llap,\lower}
% \DoNotIndex{\m@ne,\next,\newpage,\nobreak,\noexpand,\nonfrenchspacing}
% \DoNotIndex{\obeylines,\or,\protect,\raggedleft,\rightskip,\rm,\sc}
% \DoNotIndex{\setbox,\setcounter,\small,\space,\string,\strut}
% \DoNotIndex{\strutbox}
% \DoNotIndex{\thefootnote,\thispagestyle,\topmargin,\trivlist,\tt}
% \DoNotIndex{\twocolumn,\typeout,\vss,\vtop,\xdef,\z@}
% \DoNotIndex{\,,\@bsphack,\@esphack,\@noligs,\@vobeyspaces,\@xverbatim}
% \DoNotIndex{\catcode,\end,\escapechar,\frenchspacing,\glossary}
% \DoNotIndex{\hangindent,\hfil,\hfill,\hskip,\hspace,\ht,\it,\langle}
% \DoNotIndex{\leaders,\long,\makelabel,\marginpar,\markboth,\mathcode}
% \DoNotIndex{\mathsurround,\mbox,\newcount,\newdimen,\newskip}
% \DoNotIndex{\nopagebreak}
% \DoNotIndex{\parfillskip,\parindent,\parskip,\penalty,\raise,\rangle}
% \DoNotIndex{\section,\setlength,\TeX,\topsep,\underline,\unskip,\verb}
% \DoNotIndex{\vskip,\vspace,\widetilde,\\,\%,\@date,\@defpar}
% \DoNotIndex{\[,\{,\},\]}
% \DoNotIndex{\count@,\ifnum,\loop,\today,\uppercase,\uccode}
% \DoNotIndex{\baselineskip,\begin,\tw@}
% \DoNotIndex{\a,\b,\c,\d,\e,\f,\g,\h,\i,\j,\k,\l,\m,\n,\o,\p,\q}
% \DoNotIndex{\r,\s,\t,\u,\v,\w,\x,\y,\z,\A,\B,\C,\D,\E,\F,\G,\H}
% \DoNotIndex{\I,\J,\K,\L,\M,\N,\O,\P,\Q,\R,\S,\T,\U,\V,\W,\X,\Y,\Z}
% \DoNotIndex{\1,\2,\3,\4,\5,\6,\7,\8,\9,\0}
% \DoNotIndex{\!,\#,\$,\&,\',\(,\),\+,\.,\:,\;,\<,\=,\>,\?,\_}
% \DoNotIndex{\discretionary,\immediate,\makeatletter,\makeatother}
% \DoNotIndex{\meaning,\newenvironment,\par,\relax,\renewenvironment}
% \DoNotIndex{\repeat,\scriptsize,\selectfont,\the,\undefined}
% \DoNotIndex{\arabic,\do,\makeindex,\null,\number,\show,\write,\@ehc}
% \DoNotIndex{\@author,\@ehc,\@ifstar,\@sanitize,\@title,\everypar}
% \DoNotIndex{\if@minipage,\if@restonecol,\ifeof,\ifmmode}
% \DoNotIndex{\lccode,\newtoks,\onecolumn,\openin,\p@,\SelfDocumenting}
% \DoNotIndex{\settowidth,\@resetonecoltrue,\@resetonecolfalse,\bf}
% \DoNotIndex{\clearpage,\closein,\lowercase,\@inlabelfalse}
% \DoNotIndex{\selectfont,\mathcode,\newmathalphabet,\rmdefault}
% \DoNotIndex{\bfdefault}
% \setcounter{StandardModuleDepth}{1}
% \DeleteShortVerb{\|}
% \MakeShortVerb{\"}
%
% \begin{abstract}
% \noindent This package provides two low-level macros for the parsing of text
%  using \LaTeXe{}.
% \end{abstract}
%
%
% \CheckSum{259}
%
% \section{Using the macros}
%
% This package provides two macros which can be used as
% building blocks for the parsing of text.  For an example
% of their use, see the Calendar package ("calendar.dtx").
%
% The "\@ifoverword" macro takes four arguments.  These
% are, in order, a token to match, a text to expand when
% a match is found, a text to expand if the match is
% not found, and a text to expand if the macro encounters
% "\end".  This last is required to allow macros to be
% built which will react gracefully when the end of an
% environment or a document is encountered.
%
% This macro hops over word units (delimited by a space or spaces),
% and expands text according to what it finds on the other side.
% Within the text arguments, the "\@overword" can be used to
% insert the word that has been gobbled.  The expanded
% text can contain the name of the macro that invokes
% "\@ifoverword"; which makes it easy to build text-parsing loops.
% Note that "\@overword" is relaxed at each invocation of
% the macro.  This can be used to detect whether the macro
% has encountered an "\end" immediately after itself or
% beyond a word, and thereby exit cleanly in either case.
%
% The file "demo.tex" contains a sample of the use of this macro.
% This can be used as a model for building text-parsing loops.
%
%\StopEventually{\PrintIndex}
%
% \begin{macro}{\@overword}
%    \begin{macrocode}
%<*style>
\long\def\@ifoverword#1#2#3#4{%
  \let\reserved@a=#1%
  \def\reserved@d{#4}\def\reserved@b{#2}\def\reserved@c{#3}%
  \gdef\@preoverwordspace{}%
  \let\@overword\relax%
  \futurelet\@let@token\@ifowd}
\long\def\@ifowd{%
  \ifx\@let@token\@sptoken%
    \gdef\@preoverwordspace{ }%
    \let\reserved@e\@xifowd%
  \else%
    \ifx\@let@token\end%
      \let\reserved@e\reserved@d%
    \else%
      \ifx\@let@token\par%
        \let\reserved@e\@xifpargobble%
      \else%
        \long\def\reserved@e##1 {\long\gdef\@overword{##1}\@@ifowd}%
      \fi%
    \fi%
  \fi%
  \reserved@e}
\long\def\@xifpargobble#1{\futurelet\@let@token\@ifowd}
\def\:{\@xifowd} \expandafter\def\: {\futurelet\@let@token\@ifowd}
\def\@@ifowd{\futurelet\@let@token\@ifnparnch}
%    \end{macrocode}
% We hack the internals of "\@ifnextchar" so that it
% will also ignore "\par".
%    \begin{macrocode}
\long\def\@xifpargobblench#1{\futurelet\@let@token\@ifparnch}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@ifoverword}
%    \begin{macrocode}
\long\def\@ifnextnparchar#1#2#3#4{%
  \let\reserved@a=#1%
  \def\reserved@b{#2}\def\reserved@c{#3}\def\reserved@d{#4}%
  \futurelet\@let@token\@ifnparnch}
\long\def\@ifnparnch{%
  \ifx\@let@token\@sptoken%
    \let\reserved@e\@xifnparnch%
  \else%
    \ifx\@let@token\end%
      \let\reserved@e\reserved@d%
    \else%
      \ifx\@let@token\par%
        \let\reserved@e\@xifpargobblench%
      \else%
        \ifx\@let@token\reserved@a%
          \let\reserved@e\reserved@b%
        \else%
          \let\reserved@e\reserved@c%
        \fi%
      \fi%
    \fi%
  \fi%
  \reserved@e}
\long\def\@xifpargobblench#1{\futurelet\@let@token\@ifnparnch}
\def\:{\@xifnparnch}
\expandafter\def\: {\futurelet\@let@token\@ifnparnch}
%</style>
%    \end{macrocode}
% \end{macro}
% 
% \section{Demo file}
%
%    \begin{macrocode}
%<*demo>
\documentclass{minimal}
\usepackage{overword}

\begin{document}

\makeatletter

\newtoks\registerone
\newtoks\registertwo
\def\list{}

\def\stashonright{%
  \registerone=\expandafter{\@overword}
  \registertwo=\expandafter{\list}
  \edef\list{%
    \noexpand\\{\the\registerone}\the\registertwo}}

\def\showlist{%
  \def\\##1{\message{##1}}
  \message{\space\space -> }
  \list
  \message{^^J}}

\def\readlistagain{%
  \def\\##1{ ##1 }
  \edef\listtext{\list}
\message{\listtext}
  \expandafter\store\listtext\enditall}

\def\storeandshow{%
  \@ifoverword\enditall
   {\message{^^J^^JRan into enditall!^^J}
    \stashonright
    \expandafter\showlist\@gobble}
   {\stashonright
    \storeandshow}
   {\message{^^J^^JRan into end!^^J}
    \stashonright
    \showlist}}

\storeandshow This is a demonstration of the overword package \enditall

\let\listclone\list
\def\list{}
\def\\#1{ #1 }
\edef\listtext{\listclone}
\expandafter\storeandshow\listtext

\end{document}
%</demo>
%    \end{macrocode}
%
% \section{The Installation File}
%    \begin{macrocode}
%<*installer>
\def\batchfile{overword.ins}
\input docstrip.tex

\keepsilent

\preamble

This file is part of the Overword package.
Copyright (C) 1996 Frank Bennett, Jr.
All rights reserved.
------------------------------------------
This is a generated file.

IMPORTANT NOTICE:

You are not allowed to change this file.  You may however copy
this file to a file with a different name and then change the
copy if (a) you do not charge for the modified code, (b) you
acknowledge the author(s) in the new file, if it
is distributed to others, and (c) you attach these same
conditions to the new file.

You are not allowed to distribute this file alone.  You are not
allowed to take money for the distribution or use of this file
(or a changed version) except for a nominal charge for copying
etc.

You are allowed to distribute this file under the condition that
it is distributed with all of its contents, intact.

For error reports, or offers to help make this a more powerful,
friendlier, and better package, please contact me on
`fb' at soas.ac.uk

\endpreamble

\generate{\file{overword.sty}{\from{overword.dtx}{style}}
   }

\preamble

This file is part of the Overword package,
Copyright (C) 1996 Frank Bennett, Jr.
All rights reserved.
------------------------------------------
This file is provided for demonstration purposes; feel free
to edit it in any way whatsoever.
------------------------------------------



\endpreamble

\postamble
\endpostamble

\generate{\file{demo.tex}{\from{overword.dtx}{demo}}
   }

\Msg{***********************************************************}
\Msg{*}
\Msg{* To finish the installation, you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{* \space\space overword.sty}
\Msg{*}
\Msg{***********************************************************}
}
%</installer>
%    \end{macrocode}
% \Finale \PrintChanges



