3

V'ícÙ(ã@sZdZddlZddlmZddlmZmZmZmZm	Z	m
Z
mZmZdgZ
Gdd„deƒZdS)zÏ
    pygments.lexers.tnt
    ~~~~~~~~~~~~~~~~~~~

    Lexer for Typographic Number Theory.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
éN)ÚLexer)ÚTextÚCommentÚOperatorÚKeywordÚNameÚNumberÚPunctuationÚErrorÚTNTLexerc@sÐeZdZdZdZdZdgZdgZgZe	dƒZ
e	dƒZe	dƒZe	d	ƒZ
e	d
ƒZe	dƒZe	dƒZe	d
ƒZejdƒZejdƒZejdƒZdd„Zd%dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$S)&ru•
    Lexer for Typographic Number Theory, as described in the book
    Gödel, Escher, Bach, by Douglas R. Hofstadter

    .. versionadded:: 2.7
    zTypographic Number Theoryz,https://github.com/Kenny2github/language-tntZtntz*.tntu⊃→]&∧^|∨Vvu+.⋅*Zabcdeu'′z~!uAE∀∃Ú
0123456789z	 
ax(?xi)
        joining | separation | double-tilde | fantasy\ rule
        | carry[- ]over(?:\ of)?(?:\ line)?\ ([0-9]+) | detachment
        | contrapositive | De\ Morgan | switcheroo
        | specification | generalization | interchange
        | existence | symmetry | transitivity
        | add\ S | drop\ S | induction
        | axiom\ ([1-5]) | premise | push | pop
    z((?:[0-9]+)(?:(?:, ?|,? and )(?:[0-9]+))*z\[[^\n\]]+\]cOstj|f|ž|Žg|_dS)N)rÚ__init__Úcur)ÚselfÚargsÚkwargs©rú7/tmp/pip-build-gk9425m9/Pygments/pygments/lexers/tnt.pyr
8szTNTLexer.__init__FcCsx|}y x|||jkr |d7}qWWntk
r@t|ƒ}YnX|rR||krRt‚||krt|jj|t|||…fƒ|S)zTokenize whitespace.é)Ú
WHITESPACEÚ
IndexErrorÚlenÚAssertionErrorrÚappendr)rÚstartÚtextÚrequiredÚendrrrÚ
whitespace<szTNTLexer.whitespacecCsV|||jkrt‚|d}x|||jkr4|d7}qW|jj|tj|||…fƒ|S)zTokenize a variable.r)Ú	VARIABLESrÚPRIMESrrrÚVariable)rrrrrrrÚvariableJszTNTLexer.variablecCs@||dkrV|d}x||dkr,|d7}qW|jj|tj|||…fƒ|j||ƒS||dkr‚|jj|tj||fƒ|dS|||jkrœ|j||ƒS||dkr8|jj|t||fƒ|j|d|ƒ}|||jkrât	‚|jj|t
||fƒ|j|d|ƒ}||dkrt	‚|jj|t||fƒ|dSt	‚dS)zTokenize a term.ÚSrÚ0ú(ú)N)rrrÚIntegerÚtermrr"r	Ú	OPERATORSrr)rrrrrrrr(Ts.z
TNTLexer.termcCsª|||jkrX|d}x|||jkr0|d7}qW|jj|t|||…fƒ|j||ƒS|||jkrÄ|jj|tj||fƒ|j|d|ƒ}||dkržt	‚|jj|t
||fƒ|j|d|ƒS||dkrb|jj|t
||fƒ|j|d|ƒ}|||jkrt	‚|jj|t||fƒ|j|d|ƒ}||dkrDt	‚|jj|t
||fƒ|dS|j||ƒ}||dkr€t	‚|jj|t||fƒ|j|d|ƒ}|S)zTokenize a formula.rú:ú<ú>ú=)
ÚNEGATORSrrrÚformulaÚQUANTIFIERSrZDeclarationr"rr	ÚLOGICr()rrrrrrrr/ns<zTNTLexer.formulacCsê|jj||ƒ}|dkrt‚t|jdd…ƒ}x´|D]Ž}|ddkr2|jj|t|||d…fƒ|jj|dtj	||d|d…fƒ|d|j
ƒkr¾|jj|dt||d|j
ƒ…fƒPq2W|jj|t|||j
ƒ…fƒ|j
ƒS)zTokenize a rule.Nrr)ÚRULESÚmatchrÚsortedÚregsrrrrr'r)rrrr3ÚgroupsÚgrouprrrÚrules
z
TNTLexer.rulecCsÒ|}x|||jkr|d7}qW|jj|t||fƒ|jj|dt||d|…fƒ|}|jj||ƒ}|dkrvt‚||jƒdkrŠt‚|jj|j	ƒt
j|jdƒfƒ|jj|jƒt||jƒfƒ|jƒdS)zTokenize a line referral.rNr&r)
ÚNUMBERSrrr	rÚLINENOSr3rrrrr'r7)rrrrr3rrrÚlineno£s"zTNTLexer.linenocCsr|}yx||dkr|d7}qWWntk
r>t|ƒ}YnX||krb|jj|t|||…fƒ|j||ƒ}|S)z?Mark everything from ``start`` to the end of the line as Error.Ú
r)rrrrr
r)rrrrrrrÚerror_till_line_end´szTNTLexer.error_till_line_endc1Csdg|_|jd|ƒ}}xD||ko0t|ƒknr\yÔx|||jkrV|d7}q>W||krÐ|jj|tj|||…fƒt|jƒ}y|j||dƒ}}Wn2tk
rÎ|j|d…=|j||ƒ}}wYnX|j	j
||ƒ}|dk	r$|jj|t|||jƒ…fƒ|jƒ}}|j||ƒ}}w~||dkr\|jj|t
||fƒ|d7}|d7}n„t|jƒ}y|j||ƒ}}Wndttfk
rÞ|j|d…=x|||jkrº|d7}qžW|jj|t|||…fƒ|}YnXt|jƒ}y|j||dƒ}}Wn4tk
r4|j|d…=|j||ƒ}}wYnXt|jƒ}y|j||ƒ}}Wn4tk
rˆ|j|d…=|j||ƒ}}wYnX|j||ƒ}}||dkrt|jƒ}y|j||ƒ}}Wn4tk
rú|j|d…=|j||ƒ}}wYnX|j||ƒ}}Wqtk
rXy|j|d…=Wntk
rFYnX|j||ƒYqXqW|jS)zReturns a list of TNT tokens.rrTNz[]r%)rrrr9rrr'rr=ÚCOMMENTr3rrrr/ÚRecursionErrorrr
r8r;rÚ	NameError)rrrrÚorigr3rrrÚget_tokens_unprocessedÁs„"







zTNTLexer.get_tokens_unprocessedN)F) Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚurlÚaliasesÚ	filenamesrÚsetr1r)rr r.r0r9rÚreÚcompiler2r:r>r
rr"r(r/r8r;r=rBrrrrrs6



"
)rFrLZpygments.lexerrZpygments.tokenrrrrrrr	r
Ú__all__rrrrrÚ<module>	s
(