ó LzñWc@s)dZddlZddd„ƒYZdS(s… LaTeX document building system for Rubber. This module defines the class that parses the input LaTeX to load the expected modules. iÿÿÿÿNt TexParsercBskeZejdƒZejdƒZd„Zd„Zd„Zd d„Z d d„Z d„Z d„Z RS( s\\input +(?P[^{} \\]+)s (?P([^\\%]|\\%|\\)*)(%.*)?cCsF||_d|_g|_i|jd6|jd6|_|jƒdS(Nt%t usepackages begin{btSect}(tdoct comment_markt exclude_modst h_usepackaget h_bibtopicthookstupdate_rehooks(tselfR((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyt__init__s    cCsQg|jD]}|jddƒ^q }d}tj|dj|ƒƒ|_dS(sÇ Update the regular expression used to match macro calls using the keys in the `hook' dictionary. We don't match all control sequences for obvious efficiency reasons. t*s\*sL\\(?P%s)\*? *(\[(?P[^\]]*)\])? *({(?P[^{}]*)}|(?=[^A-Za-z]))t|N(Rtreplacetretcompiletjointrehooks(R txthooklisttpattern((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyR s(cCs||j|<|jƒdS(sq Register a given function to be called (with no arguments) when a given macro is found. N(RR (R tnametfun((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pytadd_hook(s cCs:|p g|_d|_x|D]}|j|ƒqWdS(sV Process a LaTeX source. The file must be open, it is read to the end calling the handlers for the macro calls. This recursively processes the included sources. If the optional argument 'dump' is not None, then it is considered as a stream on which all text not matched as a macro is written. iN(Rtlinenot parse_line(R tfdRtline((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pytparse0s   cCsc|jd7_|jj|ƒjdƒ}|jj|ƒ}x |rH|jƒ}|d}|dkr¢|d r¢|jj|ƒ}|r¢|}|jƒ}q¢n|rÂ|j||j ƒ ƒn||j ƒ|j ƒ!|d<||j ƒ|ds,     cCsg|dsdSxR|djdƒD]=}|jƒ}||jkrIq"n|jjj||ƒq"WdS(s Called when a \usepackage macro is found. If there is a package in the directory of the source file, then it is treated as an include file unless there is a supporting module in the current directory, otherwise it is treated as a package. RNt,(tsplittstripRRtmodulestregister(R R,R((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyRbs  cCs-d|jkrdS|jjjd|ƒdS(sÏ Called when a \btSect macro is found. It can also be loaded by a usepackage of bibtopic. Note that once loaded the btSect hook will be preempted by the bibtopic module hook. tbibtopicN(RRR1R2(R R,((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyRtsN(t__name__t __module__RRR(R$R R RtNoneRRRR(((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyR s    $ ((t__doc__RR(((sE/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/texparser.pyts