Feat: Add doctest to rdstr2

This commit is contained in:
Bertrand Benjamin 2019-10-30 10:49:07 +01:00
parent 2317296534
commit 975728f8dc

View File

@ -818,31 +818,8 @@ def rdstr2(sink):
>>> rdstr2list = rdstr2(list_sink) >>> rdstr2list = rdstr2(list_sink)
>>> rdstr2list("{a}+{a*b}-2") >>> rdstr2list("{a}+{a*b}-2")
[<RdLeaf a>, '+', <RdLeaf a*b>, '+', <MOnumber - 2>] [<RdLeaf a>, '+', <RdLeaf a*b>, '+', <MOnumber - 2>]
""" >>> rdstr2list("{a}({b}x+{c})")
lfop = lookfor(is_operator) [<RdLeaf a>, [<RdLeaf b>, <MOstr x>, '+', <RdLeaf c>]]
operator_corout = partial(concurent_broadcast, lookfors=[lfop])
def pipeline(expression):
str2_corout = look_for_rdleaf(
lookforNumbers(operator_corout(missing_times(moify_cor(pparser(sink)))))
)
for i in expression.replace(" ", ""):
str2_corout.send(i)
a = str2_corout.throw(STOOOP)
return a
return pipeline
def rdstr2(sink):
""" Return a pipeline which parse random expression and with sink as endpoint
:example:
>>> rdstr2list = rdstr2(list_sink)
>>> rdstr2list("{a}+{a*b}-2")
[<RdLeaf a>, '+', <RdLeaf a*b>, '+', <MOnumber - 2>]
""" """
lfop = lookfor(is_operator) lfop = lookfor(is_operator)
operator_corout = partial(concurent_broadcast, lookfors=[lfop]) operator_corout = partial(concurent_broadcast, lookfors=[lfop])