<< Prev | - Up - | Next >> |
DG.oz
Here is the implementation of the demo functor (also in Section A.12):
DG.oz
>=functor
import
Application Tk Explorer TkTools FS
DtreeFrame at 'DTreeFrame.ozf'
Parser at 'Parser.ozf'
define
fun {Normalize L}
case L of nil then nil
elseof & |& |T then {Normalize & |T}
elseof &"|X |T then Umlaut.X|{Normalize T}
elseof X |T 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 & |T then T
elseof T then T end
Words = {Map {String.tokens L & } ToAtom}
in
try
{Out clear}
{Explorer.all
{Parser.parsePredicate Words}}
catch unknownword(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.role} then N.role 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
<< Prev | - Up - | Next >> |