ó V!¶\c@sÁdZddlmZy6ddlZddlmZddlmZeZ Wne e fk rke Z nXdddgZ d efd „ƒYZd efd „ƒYZd efd„ƒYZdS(s@Lexical analysis of formal languages (i.e. code) using Pygments.iÿÿÿÿ(tApplicationErrorN(tget_lexer_by_name(t_get_ttype_classttokenttexttt LexerErrorcBseZRS((t__name__t __module__(((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyRstLexercBs,eZdZdd„Zd„Zd„ZRS(s¡Parse `code` lines and yield "classified" tokens. Arguments code -- string of source code to parse, language -- formal language the code is written in, tokennames -- either 'long', 'short', or '' (see below). Merge subsequent tokens of the same token-type. Iterating over an instance yields the tokens as ``(tokentype, value)`` tuples. The value of `tokennames` configures the naming of the tokentype: 'long': downcased full token type name, 'short': short name defined by pygments.token.STANDARD_TYPES (= class argument used in pygments html output), 'none': skip lexical analysis. tshortcCs™||_||_||_d|_|dks<|dkr@dStsUtdƒ‚nyt|jƒ|_Wn'tj j k r”td|ƒ‚nXdS(sE Set up a lexical analyzer for `code` in `language`. RRtnoneNs0Cannot analyze code. Pygments package not found.s6Cannot analyze code. No Pygments lexer found for "%s".(Rstext( tcodetlanguaget tokennamestNonetlexert with_pygmentsRRtpygmentstutilt ClassNotFound(tselfR R R((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyt__init__0s    ccsšt|ƒ}|jƒ\}}xE|D]=\}}||krJ||7}q%||fV||}}q%W|jdƒr‚|d }n|r–||fVndS(srMerge subsequent tokens of same token-type. Also strip the final newline (added by pygments). s iÿÿÿÿN(titertnexttendswith(Rttokenstlasttypetlastvaltttypetvalue((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pytmergeHs     ccsÉ|jdkr!g|jfVdStj|j|jƒ}x‰|j|ƒD]x\}}|jdkr‚t|ƒjƒj dƒ}nt |ƒg}g|D]}|t kr˜|^q˜}||fVqIWdS(s7Parse self.code and yield "classified" tokens. Ntlongt.( RRR RtlexRRtstrtlowertsplitRtunstyled_tokens(RRt tokentypeRtclassestcls((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyt__iter__Zs%(RRt__doc__RRR*(((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyR s  t NumberLinescBs eZdZd„Zd„ZRS(stInsert linenumber-tokens at the start of every code line. Arguments tokens -- iterable of ``(classes, value)`` tuples startline -- first line number endline -- last line number Iterating over an instance yields the tokens with a ``(['ln'], '')`` token added for every code line. Multi-line tokens are splitted.cCs/||_||_dtt|ƒƒ|_dS(Ns%%%dd (Rt startlinetlenR#tfmt_str(RRR-tendline((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyRws  ccs|j}dg|j|fVxx|jD]m\}}|jdƒ}x@|d D]4}||dfV|d7}dg|j|fVqNW||dfVq(WdS(Ntlns iÿÿÿÿi(R-R/RR%(RtlinenoRRtlinestline((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyR*}s  (RRR+RR*(((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyR,js  (R+tdocutilsRRtpygments.lexersRtpygments.formatters.htmlRtTrueRt ImportErrort SyntaxErrortFalseR&RtobjectR R,(((s@/tmp/pip-install-usGedi/docutils/docutils/utils/code_analyzer.pyts    N