# abtab.icn: Abbreviation table object for Txny (q.v.) #-- $define AB_TAB_REVISION "$Revision: 1.4 $" $define AB_TAB_DATE "$Date: 1996/10/31 20:59:17 $" #================================================================ # Class AbTab: An instance represents a symbol table for Abbr # objects; an AbTab is a container for AbSym objects that describe # bindings between Abbrs and roles those abbreviations can play. #---------------------------------------------------------------- # EXPORTED METHODS #---------------------------------------------------------------- # Ab_Tab_New ( ) # [ returns a new, empty AbTab # ] #-- # Ab_Tab_Lookup_Abbr ( self, abbr ) # [ if abbr is a valid Abbr -> # if abbr is in self -> # return the AbSym object for that abbr # else -> fail # ] #-- # Ab_Tab_Add_Abbr ( self, abbr ) # [ if abbr is a valid Abbr -> # if abbr is in self -> # return the AbSym object for that abbr # else -> # self +:= a new AbSym object for abbr with no binding # return that new AbSym object # ] #-- # Ab_Tab_Gen_Ab_Syms ( self ) # [ generate the AbSym objects in self in ascending order by Abbr # ] #-- # - - - State/Invariant - - - #-- # An AbTab object is an Icon table that maps the Abbr |-> the # corresponding AbSym object. #-- # - - - A b _ T a b _ N e w - - - #-- 1996-08-19: Verified with Stavely procedure Ab_Tab_New ( ) return table ( ); end # - - - A b _ T a b _ L o o k u p _ A b b r - - - #-- 1996-08-19: Verified with Stavely #-- 1996-10-31: Although this procedure technically has a precondition # that the abbr is a valid Abbr, and hence must be uppercase, in # practice it would result in Txny_Lookup_Abbr() having to upshift # the string. The error of not upshifting an Abbr is highly likely # so rather than play the blame game with the caller, we'll just # upshift it here for general robustness. procedure Ab_Tab_Lookup_Abbr ( self, abbr ) return \ self [ map ( abbr, &lcase, &ucase ) ]; end # - - - A b _ T a b _ A d d _ A b b r - - - #-- 1996-08-19: Verified with Stavely procedure Ab_Tab_Add_Abbr ( self, abbr ) local result #-- 1 -- #-[ if there is an entry for abbr in self -> # result := that entry # | else -> # result := a new AbSym with no binding # self +:= an entry mapping abbr |-> that new AbSym #-] if not ( result := \ self[abbr] ) then { #-- 1.1 -- #-[ result := a new AbSym with no binding # self +:= an entry mapping abbr |-> that new AbSym #-] result := Ab_Sym_New ( abbr ); self[abbr] := result; } #-- 1.1 -- #-- 2 -- return result; end # --- Ab_Tab_Add_Abbr --- # - - - A b _ T a b _ G e n _ A b _ S y m s - - - #-- 1996-08-19: Verified with Stavely procedure Ab_Tab_Gen_Ab_Syms ( self ) local pair every pair := ! sort ( self ) do # For every [key,value] pair... suspend pair[2]; # ...generate the value fail; end