Feat: Split moify into the function and the coroutine
This commit is contained in:
parent
037fd9f68a
commit
ca33a00877
@ -11,7 +11,7 @@ MO: math objects
|
||||
"""
|
||||
|
||||
from .mo import MO
|
||||
from .atoms import MOnumber, MOstr, moify
|
||||
from .atoms import MOnumber, MOstr, moify, moify_cor
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
|
@ -16,13 +16,23 @@ from ..coroutine import coroutine, STOOOP
|
||||
__all__ = ["moify", "MOnumber", "MOstr"]
|
||||
|
||||
|
||||
def moify(token):
|
||||
try:
|
||||
return MOnumber(token)
|
||||
except MOError:
|
||||
pass
|
||||
try:
|
||||
return MOstr(token)
|
||||
except MOError:
|
||||
return token
|
||||
|
||||
@coroutine
|
||||
def moify(target):
|
||||
def moify_cor(target):
|
||||
""" Coroutine which try to convert a parsed token into an MO
|
||||
|
||||
:example:
|
||||
>>> from ..str2 import list_sink
|
||||
>>> list2molist = moify(list_sink)
|
||||
>>> list2molist = moify_cor(list_sink)
|
||||
>>> for i in [-2, "+", "x", "*", Decimal("3.3")]:
|
||||
... list2molist.send(i)
|
||||
>>> list2molist.throw(STOOOP)
|
||||
@ -37,13 +47,7 @@ def moify(target):
|
||||
try:
|
||||
while True:
|
||||
tok = yield
|
||||
try:
|
||||
target_.send(MOnumber(tok))
|
||||
except MOError:
|
||||
try:
|
||||
target_.send(MOstr(tok))
|
||||
except MOError:
|
||||
target_.send(tok)
|
||||
target_.send(moify(tok))
|
||||
|
||||
except STOOOP as err:
|
||||
yield target_.throw(err)
|
||||
|
@ -14,7 +14,7 @@ from functools import partial
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from .coroutine import *
|
||||
from .operator import is_operator
|
||||
from .MO import moify
|
||||
from .MO import moify_cor
|
||||
from .random.leaf import look_for_rdleaf
|
||||
|
||||
__all__ = ["str2"]
|
||||
@ -797,7 +797,7 @@ def str2(sink, convert_to_mo=True):
|
||||
def pipeline(expression):
|
||||
if convert_to_mo:
|
||||
str2_corout = lookforNumbers(
|
||||
operator_corout(missing_times(moify(pparser(sink))))
|
||||
operator_corout(missing_times(moify_cor(pparser(sink))))
|
||||
)
|
||||
else:
|
||||
str2_corout = lookforNumbers(operator_corout(missing_times(pparser(sink))))
|
||||
@ -824,7 +824,7 @@ def rdstr2(sink):
|
||||
|
||||
def pipeline(expression):
|
||||
str2_corout = look_for_rdleaf(
|
||||
lookforNumbers(operator_corout(missing_times(moify(pparser(sink)))))
|
||||
lookforNumbers(operator_corout(missing_times(moify_cor(pparser(sink)))))
|
||||
)
|
||||
|
||||
for i in expression.replace(" ", ""):
|
||||
|
Loading…
Reference in New Issue
Block a user