Feat: Split moify into the function and the coroutine
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user