Fix a crash on main.py aa b zz.

The "leftmost object" in the string `b` does span the whole string,
but it's not a `Group`, so the old code would crash when it got
to the evaluation of `group.objectList` (since `Letter`s don't have
`objectList`s).
This commit is contained in:
Arthur O'Dwyer
2017-04-18 00:51:06 -07:00
parent fd74290d39
commit db7dc21f83

View File

@ -680,25 +680,20 @@ def group_scout__whole_string(ctx, codelet):
random = ctx.random random = ctx.random
slipnet = ctx.slipnet slipnet = ctx.slipnet
workspace = ctx.workspace workspace = ctx.workspace
if random.coinFlip(): string = random.choice([workspace.initial, workspace.target])
string = workspace.target
logging.info('target string selected: %s', workspace.target)
else:
string = workspace.initial
logging.info('initial string selected: %s', workspace.initial)
# find leftmost object & the highest group to which it belongs # find leftmost object & the highest group to which it belongs
leftmost = None leftmost = next(o for o in string.objects if o.leftmost)
for objekt in string.objects:
if objekt.leftmost:
leftmost = objekt
while leftmost.group and leftmost.group.bondCategory == slipnet.sameness: while leftmost.group and leftmost.group.bondCategory == slipnet.sameness:
leftmost = leftmost.group leftmost = leftmost.group
if leftmost.spansString(): if leftmost.spansString():
# the object already spans the string - propose this object # the object already spans the string - propose this object
group = leftmost if isinstance(leftmost, Group):
coderack.proposeGroup(group.objectList, group.bondList, group = leftmost
group.groupCategory, group.directionCategory, coderack.proposeGroup(group.objectList, group.bondList,
group.facet) group.groupCategory, group.directionCategory,
group.facet)
else:
coderack.proposeSingleLetterGroup(leftmost)
return return
bonds = [] bonds = []
objects = [leftmost] objects = [leftmost]