3 Eã\?ã @s”dZddlmZy(ddlZddlmZddlmZdZWne e fk rTdZYnXdd d gZ Gd d „d eƒZ Gd d„de ƒZGdd„de ƒZdS)z@Lexical analysis of formal languages (i.e. code) using Pygments.é)ÚApplicationErrorN)Úget_lexer_by_name)Ú_get_ttype_classTFÚtokenÚtextÚc@s eZdZdS)Ú LexerErrorN)Ú__name__Ú __module__Ú __qualname__©r r úv/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/utils/code_analyzer.pyrsrc@s*eZdZdZd dd„Zdd„Zdd„Zd S) ÚLexera¡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. Úshortc Csr||_||_||_d|_|dks(|dkr,dSts8tdƒ‚yt|jƒ|_Wn$tjj k rltd|ƒ‚YnXdS)zE Set up a lexical analyzer for `code` in `language`. NrrÚnonez0Cannot analyze code. Pygments package not found.z6Cannot analyze code. No Pygments lexer found for "%s".)rr) ÚcodeÚlanguageÚ tokennamesÚlexerÚ with_pygmentsrrÚpygmentsÚutilZ ClassNotFound)Úselfrrrr r r Ú__init__0szLexer.__init__ccstt|ƒ}t|ƒ\}}x6|D].\}}||kr4||7}q||fV||}}qW|jdƒrb|dd…}|rp||fVdS)zrMerge subsequent tokens of same token-type. Also strip the final newline (added by pygments). Ú Nééÿÿÿÿ)ÚiterÚnextÚendswith)rÚtokensZlasttypeZlastvalÚttypeÚvaluer r r ÚmergeHs     z Lexer.mergeccs†|jdkrg|jfVdStj|j|jƒ}xV|j|ƒD]H\}}|jdkr\t|ƒjƒjdƒ}n t |ƒg}dd„|Dƒ}||fVq6WdS)z7Parse self.code and yield "classified" tokens. NÚlongÚ.cSsg|]}|tkr|‘qSr )Úunstyled_tokens)Ú.0Úclsr r r ú fsz"Lexer.__iter__..) rrrÚlexr#rÚstrÚlowerÚsplitr)rr Z tokentyper"Úclassesr r r Ú__iter__Zs    zLexer.__iter__N)r)r r r Ú__doc__rr#r/r r r r rs rc@s eZdZdZdd„Zdd„ZdS)Ú NumberLinesatInsert 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)Nz%%%dd )r Ú startlineÚlenr+Úfmt_str)rr r2Úendliner r r rwszNumberLines.__init__ccs†|j}dg|j|fVxh|jD]^\}}|jdƒ}x<|dd…D],}||dfV|d7}dg|j|fVq@W||dfVq WdS)NÚlnrrrr)r2r4r r-)rÚlinenor!r"ÚlinesÚliner r r r/}s zNumberLines.__iter__N)r r r r0rr/r r r r r1js r1)r0ZdocutilsrrZpygments.lexersrZpygments.formatters.htmlrrÚ ImportErrorÚ SyntaxErrorr&rÚobjectrr1r r r r Ús    N