change parse in random_expression

This commit is contained in:
Lafrite 2014-11-23 10:45:13 +01:00
parent 2aed89855f
commit 39cc36869c

View File

@ -5,6 +5,8 @@ from random import randint
from .expression import Expression from .expression import Expression
from .render import tex, txt from .render import tex, txt
import re import re
import pyparsing
from .generic import flatten_list
from .arithmetic import gcd from .arithmetic import gcd
@ -54,14 +56,17 @@ class RdExpression(object):
:returns: set for elements which have to be replaced :returns: set for elements which have to be replaced
""" """
pattern = "\{(.*?)\}" #select inside {} non greedy way #pattern = "\{(.*?)\}" #select inside {} non greedy way
#varia_form = re.findall(pattern, self._form)
varia_form = re.findall(pattern, self._form) # TODO: Bug with varia with spaces |dim. nov. 23 10:44:34 CET 2014
varia_form = flatten_list([eval(str(i[0])) for i in pyparsing.nestedExpr('{','}').searchString(self._form)])
varia_form = set(varia_form) varia_form = set(varia_form)
varia_cond = set() varia_cond = set()
for c in self._conditions: for c in self._conditions:
varia_cond = varia_cond | set(re.findall(pattern, c)) c_varia_cond = flatten_list([eval(str(i[0])) for i in pyparsing.nestedExpr('{','}').searchString(c)])
varia_cond = varia_cond | set(c_varia_cond)
self._2replaced = varia_cond | varia_form self._2replaced = varia_cond | varia_form