7 PAT
= r
'\(= i(?P<i>\d+)x(?P<x>\d+)y(?P<y>\d+) (?P<v>true|false)\)'
9 def print_board(data
, tofile
):
10 """Prints a peg solitaire board"""
13 pos
= [d
for d
in data
if d
[0] == xco
and d
[1] == yco
]
17 tofile
.write('.' if pos
[0][2] else 'o')
20 def parse(lines
, output
):
21 """Parse the model from yices"""
25 match
= re
.match(PAT
, line
)
27 ite
= int(match
.group('i'))
30 data
[ite
].append((int(match
.group('x')), int(match
.group('y')),
31 match
.group('v') == 'true'))
32 for _
, dat
in sorted(data
.items()):
33 print_board(dat
, output
)
36 if __name__
== '__main__':
37 if len(sys
.argv
) == 1:
38 parse(sys
.stdin
, sys
.stdout
)
39 elif len(sys
.argv
) == 2:
40 with
open(sys
.argv
[1], 'r') as fin
:
41 parse(fin
, sys
.stdout
)
43 with
open(sys
.argv
[1], 'r') as fin
, open(sys
.argv
[2], 'w') as fout
: