# - - - w r i t e A b b r F i l e s
def writeAbbrFiles ( txny ):
'''Write the abbreviation and collision flat files.
[ txny is a Txny instance ->
if files abbr-file(Args()) and coll-file(Args()) can be
opened new for writing ->
file abbr-file(Args()) := flat abbreviation file
representing txny
file coll-file(Args()) := flat collisions file
representing txny
else ->
Log() +:= error message(s)
stop execution ]
'''
#-- 1 --
# [ if file Args().abbrFileName can be opened new for writing ->
# abbrFile := that file, so opened
# else ->
# Log() +:= error message(s)
# stop execution ]
try:
abbrFile = file ( Args().abbrFileName, 'w' )
except IOError, detail:
Log().fatal ( "Can't open the abbreviations file '%s' for "
"writing: %s." % (Args().abbrFileName, detail) )
#-- 2 --
# [ if file Args().collFileName can be opened new for writing ->
# collFile := that file, so opened
# else ->
# Log() +:= error message(s)
# stop execution ]
try:
collFile = file ( Args().collFileName, 'w' )
except IOError, detail:
Log().fatal ( "Can't open the collisions file '%s' for "
"writing: %s." % (Args().collFileName, detail) )
Both these files are enumerations of codes in the symbol table
txny.abTab. The method described in Section 24.4, “AbTab.__iter__(): Generate all symbol
table entries” generates all the unique codes in
the symbol table in alphabetical order. We inspect each one to
see what kind of binding it has.
If the code has a CollBind binding, we write
one record to the collisions file for each of the related
disambiguated codes. See Section 29.6, “CollBind.writeFlat(): Write a collisions
file record”.
If the code has either a StdBind or EqBind binding, we write a record to the
abbreviations file for that binding. See Section 26.2, “AbBind.writeFlat(): Write an abbreviations
file record”, which serves both those
derived classes.
#-- 3 --
# [ collFile := collision records representing CollBind
# bindings in txny.abTab, in alphabetical order
# abbrFile := abbreviation records representing StdBind
# and EqBind bindings in txny.abTab, in alphabetical order
for sym in txny.abTab:
#-- 3 body --
# [ if sym has a CollBind binding ->
# collFile := collision records representing the
# alternatives in that binding
# else ->
# abbrFile := an abbreviation record representing
# sym.binding ]
if isinstance(sym.binding, CollBind):
#-- 3.1 --
# [ collFile +:= collision records representing
# sym.binding ]
sym.binding.writeFlat ( collFile )
else:
#-- 3.2 --
# [ abbrFile +:= an abbreviation record representing
# sym.binding ]
sym.binding.writeFlat ( abbrFile )
#-- 4 --
collFile.close()
abbrFile.close()