f$ddlZddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZddlmZmZddlmZmZddlZGddZedZed ZGd d e Zed dZedZddZ ddZ!e jDdfdZ#e jDfdZ$edZ%edZ&ddZ'dZ(dZ)dZ*dZ+dZ,dZ-edZ.y) N)ExpressionAtomE GroundedAtom OperationAtom ValueAtom NoReduceErrorAtomTypeMatchableObjectGSAtomsget_string_valueGroundedObject SymbolAtom) Tokenizer SExprParser)register_atomsregister_tokensc(eZdZdZdZdZdZdZy)Charz)Emulate Char type as in a traditional FPLcDt|dk7r td||_y)Nrz:A Char object must be initialized with a single character.)len ValueErrorchar)selfrs W/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/hyperon/stdlib.py__init__z Char.__init__ s t9>YZ Z c|jSNrrs r__str__z Char.__str__s yyrc"d|jdS)N'r"r#s r__repr__z Char.__repr__s499+QrcVt|tr|j|jk(Sy)NF) isinstancerr)rothers r__eq__z Char.__eq__s" eT "99 * *rN)__name__ __module__ __qualname____doc__rr$r'r+rrrr s3  rrctddgd}tddgd}tddgd}tdd gd}td d gd}|||||d S) N-c ||z Sr!r0abs rzarithm_ops..a!er)Numberr9r9*c ||zSr!r0r4s rr7zarithm_ops.. r8r+c ||zSr!r0r4s rr7zarithm_ops..!r8r/c ||z Sr!r0r4s rr7zarithm_ops.."r8r%c ||zSr!r0r4s rr7zarithm_ops..#r8r)z\+r2z\*r>r@r)subAtommulAtomaddAtomdivAtommodAtoms r arithm_opsrHskC!35STGC!35STGC!35STGC!35STGC!35STG  rc tddgdd}tddgd}td d gd}td d gd}td dgd}tddgd}tddgd}tddddg}||||||||dS)N==c"t||k(dgS)NBoolrr4s rr7zbool_ops...s)AFF2K1Lr)$trNrLFunwrap>c ||kDSr!r0r4s rr7zbool_ops..0s!a%r)r9r9rL.1sq1ur>=c ||k\Sr!r0r4s rr7zbool_ops..2sQ!Vr<=c ||kSr!r0r4s rr7zbool_ops..3s!q&rorc|xs|Sr!r0r4s rr7zbool_ops..4s af1fr)rLrLrLandc|xr|Sr!r0r4s rr7zbool_ops..5s arnotc| Sr!r0r5s rr7zbool_ops..6sUrrL)rJrSrQrWrUrYr[r]rB) equalAtom greaterAtomlessAtom greaterEqAtom lessEqAtomorAtomandAtomnotAtoms rbool_opsrh,sd$L25BI%79UVKS"46RSH!$(;=YZMt%8:VWJ 4!46N OFE#79QRGE?VV4DEG  rc0eZdZdZdfd ZdZdZxZS)RegexMatchableObjectz( To match atoms with regular expressionsct||||jjddjddjdd|_y)Nz[[(z]])~ )superrcontentreplace)rrqid __class__s rrzRegexMatchableObject.__init__EsF "%||++D#6>>tSIQQRUWZ[ rcjtj||jtjS)N)patternstringflags)researchstrip IGNORECASE)rtextregexprs r match_textzRegexMatchableObject.match_textJsyyR]]SSrc6|j}t|}dj|jDcgc]}|j c}}|j dr0t|dd}|j ||}|dt|igSgScc}w)Nrozregex:matched_pattern)rqrjoinsplitr{ startswithrr )ratomrvr}xmatcheds rmatch_zRegexMatchableObject.match_Ms,,%xxDJJL9q9:   h '&wqr{3GoodG4G"*AgJ788 :sBr!)r,r-r.r/rrr __classcell__)rts@rrjrjBs2\ T rrjT) pass_mettactddddgd}tdfdddgd}td d ddgd}td d ddgd}||||d S)zAdd text operators repr: convert Atom to string. parse: convert String to Atom. stringToChars: convert String to tuple of Char. charsToString: convert tuple of Char to String. see test_stdlib.py for examples. reprc,tt|gSr!)rrr_s rr7ztext_ops..es $q'0B/CrAtomStringFrOparsecntt|ddjjgSNr)rstrr tokenizer)s run_contexts rr7ztext_ops..gs,+c!fQrl2K2Q2QR]RgRgRi2j1kr stringToCharsc vtt|ddDcgc]}tt|c}gScc}wr)rrrr)rcs rr7ztext_ops..is7!befgbhijkmbnEo]^iPTUVPWFXEoBpAqEos6 charsToStringc tdj|jDcgc]}t|ddc}gScc}w)Nrr)rr get_childrenr)r5rs rr7ztext_ops..ks>)BGGklkykyk{T|fgUXYZU[\]^`UaT|L}B~AT|sA )rrrrrB)rreprAtom parseAtomstringToCharsAtomcharsToStringAtoms` rtext_opsrXsV%C$h/?Hg'k'0@I%o7q'/&8H%o7'-x&8H++  rc$ddddddddS) Nc,tt|dSNr9)rinttokens rr7ztype_tokens..wsIc%j($Crc,tt|dSrrfloatrs rr7ztype_tokens..xs %,(Irc,tt|dSrrrs rr7ztype_tokens..ysyux7Xrc2tt|dddS)Nrrr)rrrs rr7ztype_tokens..zsIc%"+.>$Irc2tt|ddS)Nrr)rrrs rr7ztype_tokens..{s9T%(^V#Drc t|dk(dS)NTruerLrMrs rr7ztype_tokens..|sYu%GrcHtt|tjSr!)r rjr UNDEFINEDrs rr7ztype_tokens..}s*>u*EHZHZ([r)z[-+]?\d+z [-+]?\d+\.\d+z[-+]?\d+(\.\d+)?[eE][-+]?\d+z"[^"]*"z'[^']'z True|Falsez regex:"[^"]*"r0r0rr type_tokensrts$DI)XIDG[ rc|jd}|}|ddl}tj}d}|tj vr!tj j |d}tt|D]:}t||z } |jdj|d|}||d}n|rtj j||J|D]} t|| }|S#Y{xYw)N.rFT) r importlibosgetcwdsyspathappendranger import_modulerremovegetattr) rmodpsobjrcurrent_directoryappendedijps rimport_from_modulers CB C {IIK CHH , HHOO- .Hs2wAB! A --chhr"1v.>?V    HHOO- . c1o J s (C..C2c t||}|S#ttjj d|rt tjd|cYSi} t d|i||d}Y|S#td|dxYwxYw)N__main__z__obj = __objzFailed to find "")rhasattrrmodulesgetrexec RuntimeError)rrr local_scopes r find_py_objrs ; s+ J ; 3;;??:. 53;;z2D9 9  ; 8D6"B 4g&C J ;!1$q9: :s" AB B A55BB c@tt|tr|jjn|}|4t|ts t |jj}t ||}t|rt|||dgSt||gS)NTrO) rr)r get_objectrqr rcallablerr)rtyprnamers r get_py_atomrs Jt\,Jt ((PT UD #|,/ !nn&& dC C}dCT:;;#s#$$rct|||Sr!)r)rrrs r do_py_dotrs tS# &&rcLtdtdtdtddS)Npy-atomFrOpy-dot)rr)rrrr0rr py_obj_atomsrs&")[G 9UC rc,d}td|d}d|iS)Nc|j}tj|j|jt j gSr!)rhp load_asciiget_namecspacerUNIT)spacer space_objs rload_ascii_atomz#load_ascii..load_ascii_atoms6$$&  dmmoy'7'78 |rz load-asciiFrOrB)rloadAtoms rrrs+ \?$)+H x rct|trHt|jtr|jjS|jS|r t|t r|j S|Sr!)r)rrrrqrr)r5is_symbol_to_strs rtry_unwrap_python_objectrsY!\")3ALLNN)Sq||~%%gYZYeYeYggJq*5zz| Hrcg}|jD]H}t|tr|jt ||/|jt |J||Sr!)rr)rr_py_tuple_listr) tuple_list metta_tuplerezr5s rrrsU C  % % ' a ( JJ~j!4 5 JJ/2 3 ( c?rc6ttt|gSr!)rrtuplers rpy_tuplers nUK8 9 ::rc6ttt|gSr!)rrlistrs rpy_listrs nT;7 8 99rc|j}t|dk7r tdt|ddt|dfS)Nz!Syntax error in tuple_to_keyvaluerT)rr)rr Exceptionr)r5acs rtuple_to_keyvaluersH  B 2w!|;<< #BqEd CE]^`ab^cEd ddrc tt|jDcgc] }t|c}gScc}wr!)rdictrr)rr5s rpy_dictrs2 d+:R:R:TUQ-a0UV W XXUs; c|jDcgc] }t|}}|d}|ddD]}||z} t|gScc}w)Nrr)rrr)rr5objectsresultrs rpy_chainrsZ4?4L4L4NOq'*OGO QZFqr{# f   PsActdtdtdtdtdtdtdtddS)Npy-tupleFrOpy-listpy-dictpy-chain)r r r r )rrrrrr0rrpy_funsr s>%j(UK%i'UK%i'UK%j(UK MMrr!)F)/ryrratomsrrrrrr r r r r rrrrbaserrextrr hyperonpyrrrHrhrjrrrrrrrrrrrrrrrrr r0rrrs( >>>>(0$  *?,4 !6  4"#,,$ %&//'   ;:eYMMr