20.7 DG_Demo.oz

We now turn to the application that binds it all together

<DG_Demo.oz>=
functor 
import 
   Application Tk Explorer TkTools FS
   DtreeFrame at 'DG_DTreeFrame.ozf' 
   Parser     at 'DG_Parser.ozf' 
define 
   fun {Normalize L}
      case L of nil then nil
      elseof ||then {Normalize |T}
      elseof &"||then Umlaut.X|{Normalize T}
      elseof    X |then X|{Normalize T} end 
   end 
   Umlaut = o(&a: &o: &u: &s:)
   ToLower = Char.toLower
   ToAtom  = String.toAtom
   proc {Parse}
      S = {In tkReturnString(get $)}
      L = case {Normalize {Map S ToLower}} of |then T
          elseof T then T end 
      Words = {Map {String.tokens L } ToAtom}
   in 
      try 
         {Out clear}
         {Parser.checkWords Words}
         {Explorer.all
          {Parser.makeScript Words}}
      catch unknown(W) then 
         {New TkTools.error
          tkInit(master:Top text:'unknown word: '#W) _}
      end 
   end 
   fun {MakeSpec N}
      o(index:N.index string:N.word
        parent:if {Not {IsDet N.mother}} then unit 
               elsecase {FS.reflect.lowerBoundList N.mother}
               of [I] then I else unit end 
        label: if {IsDet N.roleLabel} then N.roleLabel else '' end)
   end 
   proc {Show I R}
      {Out show({Map R MakeSpec})}
   end 
   {Explorer.object add(information Show label:'DTree')}
   Status
   Top = {New Tk.toplevel tkInit}
   Out = {New DtreeFrame.'class' tkInit(parent:Top)}
   Bot = {New Tk.frame  tkInit(parent:Top)}
   In  = {New Tk.entry  tkInit(parent:Bot width:50)}
   B1  = {New Tk.button tkInit(parent:Bot text:'Quit' 
                               action:proc{$} Status=0 end)}
   B2  = {New Tk.button tkInit(parent:Bot text:'Clear' 
                               action:proc{$}
                                         {In tk(delete 0 'end')}
                                      end)}
   B3  = {New Tk.button tkInit(parent:Bot text:'Parse' 
                               action:Parse)}
   {In tkBind(event:'<Return>' action:Parse)}
   {Tk.batch [grid(rowconfigure Top 0 weight:1)
              grid(columnconfigure Top 0 weight:1)
              grid(Out row:0 column:0 sticky:nswe)
              grid(Bot row:1 column:0 sticky:we)
              grid(columnconfigure Bot 1 weight:1)
              grid(B1 row:0 column:0 sticky:w)
              grid(In row:0 column:1 sticky:we)
              grid(B2 row:0 column:2 sticky:w)
              grid(B3 row:0 column:3 sticky:w)]}
   {Application.exit Status}
end


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)