MpjdZddlmZmZddlmZmZddlmZddl m Z ddl m Z Gdd eZ Gd d e eZGd d eZy)z@Provides a post-lexer for implementing Python-style indentation.)ABCabstractmethod)ListIterator) LarkError)PostLex)Tokenc eZdZy) DedentErrorN)__name__ __module__ __qualname__[/mnt/ssd/data/Dropbox/adrian/scripts/msg_venv/lib/python3.12/site-packages/lark/indenter.pyr r srr c2eZdZUdZeed<eeed<ddZdede efdZ d Z d Z e d Ze edefd Ze edeefd Ze edeefdZe edefdZe edefdZe edefdZy)IndenteraThis is a postlexer that "injects" indent/dedent tokens based on indentation. It keeps track of the current indentation, as well as the current level of parentheses. Inside parentheses, the indentation is ignored, and no indent/dedent tokens get generated. Note: This is an abstract class. To use it, inherit and implement all its abstract methods: - tab_len - NL_type - OPEN_PAREN_types, CLOSE_PAREN_types - INDENT_type, DEDENT_type See also: the ``postlex`` option in `Lark`. paren_level indent_levelreturnNcDd|_dg|_|jdkDsJyNr)rrtab_lenselfs r__init__zIndenter.__init__ s&C||artokenc#K|jdkDry||jddd}|jd|jd|jzz}||jdkDr?|jj |t j|j||y||jdkrP|jjt j|j||||jdkrP||jdk7rtd|d|jdyw) Nr r  zUnexpected dedent to column z. Expected dedent to ) rrsplitcountrrappendr new_borrow_pos INDENT_typepop DEDENT_typer )rr indent_strindents r handle_NLzIndenter.handle_NL%s)   a   \\$*1- !!#&)9)9$)?$,,)NN D%%b) )    $ $V ,&&t'7'7UK K4,,R00!!%%'**4+;+;ZOO4,,R00**2..!]ceievevwyez"{||/s D E1Ec #Kd}|D]}|j|jk(r|j|Ed{n||j|jvr|xjdz c_h|j|j vs|xjdzc_|jdk\rJt |jdkDrt|jj|r!tj|jd|nt|jdddddddt |jdkDrt|jdgk(sJ|jy7'w)Nrr) typeNL_typer-OPEN_PAREN_typesrCLOSE_PAREN_typeslenrr)r r'r*)rstreamrs r_processzIndenter._process9s@ -EzzT\\)>>%000 zzT222  A% t555  A% ''1,,, -$##$q(    ! ! #GL%&&t'7'7UCRWX\XhXhjlnoqrtuwxz{}~R $##$q(  QC':):)::'1s#5E!EAE!$E!-BE!<#E!cBd|_dg|_|j|Sr)rrr6)rr5s rprocesszIndenter.processMs#C}}V$$rc|jfS)N)r1rs r always_acceptzIndenter.always_acceptSs rct)zThe name of the newline tokenNotImplementedErrorrs rr1zIndenter.NL_typeW "##rct)z/The names of the tokens that open a parenthesisr<rs rr2zIndenter.OPEN_PAREN_types]r>rct)z9The names of the tokens that close a parenthesis r<rs rr3zIndenter.CLOSE_PAREN_typescs "##rct)zeThe name of the token that starts an indentation in the grammar. See also: %declare r<rs rr(zIndenter.INDENT_typej "##rct)zbThe name of the token that end an indentation in the grammar. See also: %declare r<rs rr*zIndenter.DEDENT_typesrBrct)z How many spaces does a tab equalr<rs rrzIndenter.tab_len|r>r)rN)r rr__doc__int__annotations__rrr rr-r6r8propertyr:rstrr1r2r3r(r*rrrrrrs0 s) }u}%}(;(% $$$$$s)$$$49$$ $S$$$S$$$$$rrc0eZdZdZdZgdZgdZdZdZdZ y) PythonIndenterzA postlexer that "injects" _INDENT/_DEDENT tokens based on indentation, according to the Python syntax. See also: the ``postlex`` option in `Lark`. _NEWLINE)LPARLSQBLBRACE)RPARRSQBRBRACE_INDENT_DEDENTN) r rrrEr1r2r3r(r*rrrrrKrKs) G12KKGrrKN)rEabcrrtypingrr exceptionsrlarkr lexerr r rrKrrrr[s@B#!! ) q$wq$h X r