-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdk.oz
2408 lines (2299 loc) · 64.9 KB
/
xdk.oz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% Copyright 2001-2011
%% by Ralph Debusmann <[email protected]> (Saarland University) and
%% Denys Duchier <[email protected]> (LIFO, Orleans) and
%% Jorge Marques Pelizzoni <[email protected]> (ICMC, Sao Paulo) and
%% Jochen Setz <[email protected]> (Saarland University)
%%
functor
import
% Ozcar(breakpoint:Breakpoint)
Application(exit getArgs)
Browser(browse close)
Inspector(close configure inspect)
Module(link)
Open(file text)
OS(pipe system)
Property(put)
Search(base)
System(show showError showInfo printInfo)
Tk(addYScrollbar batch button entry frame label listbox
menu menuentry return scrollbar toplevel variable)
TkTools(menubar)
Helpers(allButLast addHandlers changeSuffix e2V getFilePart getWords segment
tkDialog tkDialogImage tkDialog2 tkGetOpenFiles tkError tkGetI tkGetS tkGetSublist
memberInd x2V vs2S getLines getTime getSuffix putV
fileV2TmpUrlV) at 'Helpers.ozf'
Compiler(files2SLC sLC2File) at 'Compiler/Compiler.ozf'
NodesCompiler(partitionAs as2WordAs fileAs2NodesProc) at 'Compiler/NodesCompiler.ozf'
Converter(convert) at 'Compiler/Converter.ozf'
% Outputs(close outputs open) at 'Outputs/Outputs.ozf'
Pretty(pretty) at 'Outputs/Pretty.ozf'
Solver(make getProfile) at 'Solver/Solver.ozf'
% Principles(principles) at 'Solver/Principles/Principles.ozf'
LemComparer(compare) at 'Extras/LemComparer.ozf'
OrderingsGenerator(generate) at 'Extras/OrderingsGenerator.ozf'
SolvingStatistics(perform) at 'Extras/SolvingStatistics.ozf'
CPKit(options kits optionDef optionsStr) at 'Solver/Principles/Lib/CPKit.hub.ozf'
PrincipleManager(open) at 'PrincipleManager/PrincipleManager.ozf'
OutputManager(open) at 'OutputManager/OutputManager.ozf'
prepare
ListMapInd = List.mapInd
ListToTuple = List.toTuple
ListToRecord = List.toRecord
define
{Helpers.addHandlers}
%%
A2S = Atom.toString
%%
S2A = String.toAtom
%%
S2I = String.toInt
%%
V2A = VirtualString.toAtom
%%
%% GetInput: U -> WordAsFileAsTup
%% Gets a pair of word atoms WordAs and file atoms FileAs from
%% widget SInputW.
fun {GetInput}
As = {Helpers.getWords SInputW}
WordAs#FileAs = {NodesCompiler.partitionAs As}
in
WordAs#FileAs
end
%% GetWords: U -> WordAs
%% Gets atoms WordAs from widget SInputW.
fun {GetWords}
WordAs#_ = {GetInput}
in
WordAs
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Create global variables (arranged in dictionary GlobalDict)
GlobalDict = {NewDictionary}
%% grammar
proc {ResetG}
GlobalDict.g := unit
end
{ResetG}
%% grammar path
proc {ResetGPathSs}
GlobalDict.gPathSs := nil
end
{ResetGPathSs}
%% examples
proc {ResetEAs}
GlobalDict.eAs := nil
end
{ResetEAs}
%% examples
proc {ResetEPathS}
GlobalDict.ePathS := ""
end
{ResetEPathS}
%% solutions
proc {ResetSolutionsI}
GlobalDict.solutionsI := 9999
end
{ResetSolutionsI}
%% failures
proc {ResetFailuresI}
GlobalDict.failuresI := 9999
end
{ResetFailuresI}
%% timeout
proc {ResetTimeoutI}
GlobalDict.timeoutI := 3600
end
{ResetTimeoutI}
%% recomputation
proc {ResetRecoI}
GlobalDict.recoI := 1
end
{ResetRecoI}
%% open outputs
proc {ResetOpenOutputsProc}
Proc = proc {$ _ _} skip end
in
GlobalDict.openOutputsProc := Proc
end
{ResetOpenOutputsProc}
%% close outputs
proc {ResetCloseOutputsProc}
Proc = proc {$} skip end
in
GlobalDict.closeOutputsProc := Proc
end
{ResetCloseOutputsProc}
%% DIDATkvarTups
proc {ResetDIDATkvarTups}
GlobalDict.dIDATkvarTups := nil
end
{ResetDIDATkvarTups}
%% DCheckButtonWs
proc {ResetDCheckButtonWs}
GlobalDict.dCheckButtonWs := nil
end
{ResetDCheckButtonWs}
%% PnTkvarTups
proc {ResetPnTkvarTups}
GlobalDict.pnTkvarTups := nil
end
{ResetPnTkvarTups}
%% PSubMenuWs
proc {ResetPSubMenuWs}
GlobalDict.pSubMenuWs := nil
end
{ResetPSubMenuWs}
%% PCascadeWs
proc {ResetPCascadeWs}
GlobalDict.pCascadeWs := nil
end
{ResetPCascadeWs}
%% PCheckButtonWs
proc {ResetPCheckButtonWs}
GlobalDict.pCheckButtonWs := nil
end
{ResetPCheckButtonWs}
%% OnTkvarTups
proc {ResetOnTkvarTups}
GlobalDict.onTkvarTups := nil
end
{ResetOnTkvarTups}
%% OSubMenuWs
proc {ResetOSubMenuWs}
GlobalDict.oSubMenuWs := nil
end
{ResetOSubMenuWs}
%% OCascadeWs
proc {ResetOCascadeWs}
GlobalDict.oCascadeWs := nil
end
{ResetOCascadeWs}
%% OCheckButtonWs
proc {ResetOCheckButtonWs}
GlobalDict.oCheckButtonWs := nil
end
{ResetOCheckButtonWs}
%% OracleO
proc {ResetOracleO}
GlobalDict.oracleO := unit
end
{ResetOracleO}
%% ConnectedPortI
proc {ResetConnectedPortI}
GlobalDict.connectedPortI := unit
end
{ResetConnectedPortI}
%% PortI
proc {ResetPortI}
GlobalDict.portI := 4711
end
{ResetPortI}
%% PortI
proc {ResetOrderedDIDAs}
GlobalDict.orderedDIDAs := [lp]
end
{ResetOrderedDIDAs}
%% InputAs
proc {ResetInputAs}
GlobalDict.inputAs := nil
end
{ResetInputAs}
%% PrinciplesFunctor
proc {ResetPrinciplesFunctor}
GlobalDict.principlesFunctor := unit
end
{ResetPrinciplesFunctor}
%% OutputsFunctor
proc {ResetOutputsFunctor}
GlobalDict.principlesFunctor := unit
end
{ResetOutputsFunctor}
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ExplorerFunctor
IOzSeFFunctor
[ExplorerFunctor] = {Module.link ['x-oz://system/Explorer.ozf']}
[IOzSeFFunctor] = {Module.link ['x-ozlib://tack/iozsef/iozsef.ozf']}
[OracleFunctor] = {Module.link ['SXDG/XDGOracle.ozf']}
[XDGExternaliserFunctor] = {Module.link ['SXDG/XDGExternaliser.ozf']}
%%
{Inspector.configure widgetTreeFont font(family:courier size:10 weight:normal)}
{Inspector.configure widgetShowStrings false}
%%
{Property.put 'errors.depth' 10000}
{Property.put 'errors.width' 10000}
{Property.put 'print.depth' 10000}
{Property.put 'print.width' 10000}
%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Error handling
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% HandleException: E -> U
%% Displays an error dialog using Helpers.tkError, with title 'XDK:
%% Error' and text specified by the exception E.
proc {HandleException E}
DebugB = {DebugTkvar tkReturnInt($)}==1
V = {Helpers.e2V E}
if DebugB orelse V=='unhandled error' then {Inspector.inspect E} end
in
{Helpers.tkError 'XDK: Error' V}
end
%%
proc {CheckG G}
if G==unit then
raise error1('functor':'xdk.ozf' 'proc':'CheckG' msg:'No successfully compiled grammar.' info:o coord:noCoord file:noFile) end
end
end
%%
proc {CheckGPathSs Ss}
if Ss==nil then
raise error1('functor':'xdk.ozf' 'proc':'CheckGPathSs' msg:'No grammar.' info:o coord:noCoord file:noFile) end
end
end
%%
proc {CheckEAs As}
if As==nil then
raise error1('functor':'xdk.ozf' 'proc':'CheckEAs' msg:'No examples.' info:o coord:noCoord file:noFile) end
end
end
%%
proc {CheckEPathS S}
if S==nil then
raise error1('functor':'xdk.ozf' 'proc':'CheckEPathS' msg:'No examples path.' info:o coord:noCoord file:noFile) end
end
end
%%
proc {CheckWords As}
if As==nil then
raise error1('functor':'xdk.ozf' 'proc':'CheckWords' msg:'No input.' info:o coord:noCoord file:noFile) end
end
%%
% {Inspector.inspect 'CheckWords'#As}
Ss = GlobalDict.gPathSs
in
{CheckGPathSs Ss}
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Grammars
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% GetSearchProc: U -> SearchProc
%% Gets search procedure depending on the value of SearchTkvar.
fun {GetSearchProc}
SearchA = {SearchTkvar tkReturnAtom($)}
SearchProc =
proc {$ Proc}
Nodes
in
case SearchA
of first then
{MetaExplorerOne Proc}
[] all then
{MetaExplorerAll Proc}
else
{Proc Nodes}
end
end
in
SearchProc
end
%% GetPrintProc: U -> PrintProc
%% Gets print procedure depending on the value of PrintTkvar.
fun {GetPrintProc}
PrintA = {PrintTkvar tkReturnAtom($)}
PrintProc =
case PrintA
of browse then
Browser.browse
[] stdout then
proc {$ X}
if {IsVirtualString X} then
{System.showInfo X}
else
{System.show X}
end
end
[] file then
proc {$ X}
S =
{Tk.return tk_getSaveFile(title: 'XDK: Print to file'
filetypes: q(q('All files' '*')))}
in
if {Not S==""} then
V = if {IsVirtualString X} then
X
else
{Helpers.x2V X}
end
in
{Helpers.putV V S}
end
end
else
Inspector.inspect
end
in
PrintProc
end
%% SetGrammar: Ss InputAs1 -> U
%% Sets a grammar composed from the grammars located at paths Ss
%% and for input sentence InputAs1.
proc {SetGrammar Ss InputAs1}
if Ss==nil then
raise error1('functor':'xdk.ozf' 'proc':'SetGrammar' msg:'No grammar.' info:o coord:noCoord file:noFile) end
end
InputAs = if InputAs1==nil then ['test'] else InputAs1 end
in
try
%% assign path S1 to GlobalDict.gPathS
GlobalDict.gPathSs := Ss
%% set grammar status
Ss1 = {Map Ss Helpers.getFilePart}
S1 = {Helpers.vs2S Ss1}
{GStatusW tk(configure text: 'Grammar: '#S1#' (not successfully compiled)')}
%% load new grammar
InputA = {V2A
{FoldL InputAs
fun {$ AccA InputA}
AccA#InputA#' '
end ''}}
MetaX = InputA
[PrinciplesFunctor] = {Module.link ['Solver/Principles/Principles.ozf']}
GlobalDict.principlesFunctor := PrinciplesFunctor
PrincipleILs = PrinciplesFunctor.principles
[OutputsFunctor] = {Module.link ['Outputs/Outputs.ozf']}
GlobalDict.outputsFunctor := OutputsFunctor
OutputILs = OutputsFunctor.outputs
DebugB = {DebugTkvar tkReturnInt($)}==1
G = {Compiler.files2SLC Ss MetaX PrincipleILs OutputILs DebugB Inspector.inspect}
%% and assign grammar G to GlobalDict.g
GlobalDict.g := G
%% get open outputs procedure (OpenOutputsProc)
PrintProc = {GetPrintProc}
OpenOutputsProc = {OutputsFunctor.open G PrintProc}
%% and assign Proc to GlobalDict.openOutputsProc
GlobalDict.openOutputsProc := OpenOutputsProc
%% get close outputs procedure
CloseOutputsProc = {OutputsFunctor.close G}
GlobalDict.closeOutputsProc := CloseOutputsProc
%%
GlobalDict.inputAs := InputAs
in
{GStatusW tk(configure text: 'Grammar: '#S1)}
%%
{SetDimensions G}
%%
{SetPrinciples G}
%%
{SetOutputs G}
catch E then
{HandleException E}
end
end
%% GetGrammar: InputAs -> G
%% Gets grammar G for input sentence InputAs.
fun {GetGrammar InputAs}
OldG = GlobalDict.g
OldInputAs = GlobalDict.inputAs
GSs = GlobalDict.gPathSs
GlobalDict.inputAs := InputAs
G =
if OldG==unit orelse
({Not InputAs==OldInputAs} andthen
{Some GSs
fun {$ S}
SuffixS = {Helpers.getSuffix S}
in
SuffixS=="ulsocket" orelse SuffixS=="xmlsocket"
end}) then
{ResetGrammar}
{SetGrammar GSs InputAs}
G = GlobalDict.g
in
G
else
OldG
end
%%
if G==unit then
raise error1('functor':'xdk.ozf' 'proc':'GetGrammar' msg:'No grammar.' info:o coord:noCoord file:noFile) end
end
%%
CheckAsInEntries = G.checkAsInEntries
{CheckAsInEntries InputAs}
in
G
end
%% ResetGrammar: U -> U
%% Resets a grammar:
%% * closes the output windows
%% * resets the meta explorer (closes it)
%% * resets the output menu
%% * resets the principle menu
%% * resets the dimensions menu
%% * resets the GStatusW widget
%% * resets G
%% * resets OpenOutputsProc
%% * resets CloseOutputsProc
%% * resets GPathSs
proc {ResetGrammar}
{CloseOutputWindows}
%%
{MetaExplorerClose}
%%
{ResetOutputs}
%%
{ResetPrinciples}
%%
{ResetDimensions}
%% reset grammar status
{GStatusW tk(configure text: 'Grammar: ')}
%% reset G
{ResetG}
%% reset OpenOutputsProc
{ResetOpenOutputsProc}
%% reset CloseOutputsProc
{ResetCloseOutputsProc}
%% reset GPathS
{ResetGPathSs}
end
%% UpdateDimensions: U -> U
%% Updates usedDIDAs feature of the current grammar and updates the
%% outputs.
proc {UpdateDimensions}
WordAs = {GetWords}
% {Inspector.inspect 'UpdateDimensions'#WordAs}
G = {GetGrammar WordAs}
in
if {Not G==nil} then
UsedDIDAs = {GetUsedDIDAs}
G1 = {AdjoinAt G usedDIDAs UsedDIDAs}
in
GlobalDict.g := G1
end
%%
{UpdateOutputs}
end
%% UpdatePrinciples: U -> U
%% Updates usedPns feature of the current grammar and updates the
%% outputs.
proc {UpdatePrinciples}
WordAs = {GetWords}
% {Inspector.inspect 'UpdatePrinciples'#WordAs}
G = {GetGrammar WordAs}
in
if {Not G==nil} then
UsedPns = {GetUsedPns}
G1 = {AdjoinAt G usedPns UsedPns}
in
GlobalDict.g := G1
end
%%
{UpdateOutputs}
end
%% UpdateOutputs: U -> U
%% Updates usedOns feature of the current grammar, the open outputs
%% procedure in GlobalDict.openOutputsProc, and the close outputs
%% procedure in GlobalDict.closeOutputsProc.
proc {UpdateOutputs}
WordAs = {GetWords}
% {Inspector.inspect 'UpdateOutputs'#WordAs}
G = {GetGrammar WordAs}
in
if {Not G==nil} then
UsedOns = {GetUsedOns}
G1 = {AdjoinAt G usedOns UsedOns}
%%
PrintProc = {GetPrintProc}
% OutputsFunctor = GlobalDict.outputsFunctor
[OutputsFunctor] = {Module.link ['Outputs/Outputs.ozf']}
GlobalDict.outputsFunctor := OutputsFunctor
OpenOutputsProc = {OutputsFunctor.open G1 PrintProc}
CloseOutputsProc = {OutputsFunctor.close G1}
in
GlobalDict.g := G1
%%
GlobalDict.openOutputsProc := OpenOutputsProc
GlobalDict.closeOutputsProc := CloseOutputsProc
end
end
%% MakeSolverScript: WordAs FileAs -> Proc
%% Makes a solver script Proc for words WordAs and files FileAs.
fun {MakeSolverScript WordAs FileAs}
% {Inspector.inspect 'MakeSolverScript'#WordAs}
G = {GetGrammar WordAs}
%%
DebugB = {DebugTkvar tkReturnInt($)}==1
I = {Length WordAs}
WordA = {V2A
{FoldL WordAs
fun {$ AccA WordA}
AccA#WordA#' '
end ''}}
MetaX = WordA
NodesProc = {NodesCompiler.fileAs2NodesProc FileAs I G MetaX DebugB Inspector.inspect}
in
if {Not G==nil} then
LazyvarsB = {LazyvarsTkvar tkReturnInt($)}==1
MemoizeA = {MemoizeTkvar tkReturnAtom($)}
ModeA = {ModeTkvar tkReturnAtom($)}
ProfileB = {ProfileTkvar tkReturnInt($)}==1
SearchA = {SearchTkvar tkReturnAtom($)}
FileS =
case SearchA
of print then
FileS = {Tk.return tk_getSaveFile(title: 'XDK: Print CSP'
filetypes: q(q('CSP files' '*.csp*')
q('All files' '*')))}
in
if FileS=="" then
raise error1('functor':'xdk.ozf' 'proc':'MakeSolverScript' msg:'Cannot print CSP without a file name.' info:o coord:noCoord file:noFile) end
end
FileS
[] flatzinc then
FileS = {Tk.return tk_getSaveFile(title: 'XDK: Print FlatZinc'
filetypes: q(q('FlatZinc files' '*.fzn*')
q('All files' '*')))}
in
if FileS=="" then
raise error1('functor':'xdk.ozf' 'proc':'MakeSolverScript' msg:'Cannot print FlatZinc without a file name.' info:o coord:noCoord file:noFile) end
end
FileS
else
""
end
Options = o(debug:DebugB
lazyvars:LazyvarsB
memoize:MemoizeA
mode:ModeA
profile:ProfileB
search:SearchA#FileS)
PrinciplesFunctor = GlobalDict.principlesFunctor
Proc = {{Solver.make G Options PrinciplesFunctor} WordAs NodesProc}
in
Proc
end
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Examples
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SetExamples: S -> U
%% Sets the example sentences contained in the file corresponding
%% to path S.
proc {SetExamples S}
try
ESs = {Helpers.getLines S}
EAs = {Map ESs S2A}
%% assign examples path S to GlobalDict.ePathS
GlobalDict.ePathS := S
%% assign examples EAs to GlobalDict.eAs
GlobalDict.eAs := EAs
%% set examples status
S1 = {Helpers.getFilePart S}
{EStatusW tk(configure text: 'Examples: '#S1)}
in
if {Not EAs==nil} then
ATup = {ListToTuple o EAs}
in
{EListW tk(insert 'end' ATup)}
end
catch E then
{HandleException E}
end
end
%% ResetExamples: U -> U
%% Resets the EListW widget, the EStatusW widget, and EAs and
%% EPathS.
proc {ResetExamples}
%% reset the list of examples
I = {EListW tkReturnInt(size $)}
in
{EListW tk(delete 0 I-1)}
%% reset examples status
{EStatusW tk(configure text: 'Examples: ')}
%% reset EAs
{ResetEAs}
%% reset EPathS
{ResetEPathS}
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Menus/Buttons
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Project-menu
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% About: U -> U
%% Displays the about dialog.
proc {About}
{Helpers.tkDialogImage 'XDK: About' 'XDG Development Kit: Graphical User Interface\n\nCopyright 2001-2011\n\nVersion 1.6.51\n\nby Ralph Debusmann <[email protected]> (Saarland University) and\nDenys Duchier <[email protected]> (LIFO, Orleans)' 'xdk.gif'}
end
%% GetOpenFiles: U -> Ss
%% Lets the user select a list of files Ss with a file dialog.
fun {GetOpenFiles}
Ss = {Helpers.tkGetOpenFiles
'XDK: Open grammars'
q(q('Grammar files' '*.ul')
q('Grammar files' '*.xml')
q('Grammar files' '*.ilp')
q('Grammar files' '*.ozf')
q('Grammar files' '*.slp')
q('All files' '*'))}
in
Ss
end
%% OpenGrammars1: Ss -> U
%% Opens grammars Ss.
proc {OpenGrammars1 Ss}
if {Not Ss==nil} then
{ResetGrammar}
{SetGrammar Ss nil}
%%
S1 = Ss.1
S2 = {Helpers.changeSuffix S1 "txt"}
in
{ResetExamples}
{SetExamples S2}
end
end
%% OpenGrammars: U -> U
%% Opens a list of grammars (using a file dialog).
proc {OpenGrammars}
Ss = {GetOpenFiles}
in
if {Not Ss==nil} then
{OpenGrammars1 Ss}
end
end
%% OpenGrammarSocket: U -> U
%% Opens a grammar or a socket (using a string dialog).
proc {OpenGrammarSocket}
S =
{Helpers.tkGetS
'XDK: Open grammar' 'Grammar file/socket'
"4712.ulsocket"}
in
if {Not S==""} then
{OpenGrammars1 [S]}
end
end
%% ReloadGrammars: U -> U
%% Reloads the grammars whose urls are in GlobalDict.gPathSs.
proc {ReloadGrammars}
try
Ss = GlobalDict.gPathSs
{CheckGPathSs Ss}
{ResetGrammar}
{SetGrammar Ss nil}
%%
S1 = Ss.1
S2 = {Helpers.changeSuffix S1 "txt"}
in
{ResetExamples}
{SetExamples S2}
catch E then
{HandleException E}
end
end
%% ConvertGrammar: U -> U
%% Converts grammars (and nodesets).
proc {ConvertGrammar}
try
FromS =
{Tk.return tk_getOpenFile(title: 'XDK: Convert grammar/nodeset: Source'
filetypes: q(q('Grammar/nodeset files' '*.ul')
q('Grammar/nodeset files' '*.xml')
q('Grammar/nodeset files' '*.ilp')
q('Grammar/nodeset files' '*.ozf')
q('All files' '*')))}
in
if {Not FromS==""} then
ToS =
{Tk.return tk_getSaveFile(title: 'XDK: Convert grammar/nodeset: Destination'
filetypes: q(q('Grammar/nodeset files' '*.ul')
q('Grammar/nodeset files' '*.xml')
q('Grammar/nodeset files' '*.ilp')
q('All files' '*')))}
in
if {Not ToS==""} then
{Converter.convert FromS ToS Inspector.inspect}
end
end
catch E then
{HandleException E}
end
end
%% SaveCompiledGrammar: U -> U
%% Saves the currently loaded grammar.
proc {SaveCompiledGrammar}
try
WordAs = {GetWords}
% {Inspector.inspect 'SaveCompiledGrammar'#WordAs}
G = {GetGrammar WordAs}
{CheckG G}
S = {Tk.return tk_getSaveFile(title: 'XDK: Save compiled grammar'
filetypes: q(q('Grammar files (compiled, record)' '*.slp')
q('All files' '*')))}
in
if {Not S==""} then
DebugB = {DebugTkvar tkReturnInt($)}==1
in
{Compiler.sLC2File G S DebugB Inspector.inspect}
end
catch E then
{HandleException E}
end
end
%% OpenExamples: U -> U
%% Opens an examples file (using a file dialog).
proc {OpenExamples}
S = {Tk.return tk_getOpenFile(title: 'XDK: Open examples'
filetypes: q(q('Text files' '*.txt')
q('All files' '*')))}
in
if {Not S==""} then
{ResetExamples}
{SetExamples S}
end
end
%% ReloadExamples: U -> U
%% Reloads the examples file whose url is in GlobalDict.ePathS.
proc {ReloadExamples}
try
S = GlobalDict.ePathS
in
{CheckEPathS S}
{ResetExamples}
{SetExamples S}
catch E then
{HandleException E}
end
end
%% CloseOutputWindows: U -> U
%% Closes all output windows.
proc {CloseOutputWindows}
CloseOutputsProc = GlobalDict.closeOutputsProc
in
{CloseOutputsProc}
end
%% OpenPrincipleManager: U -> U
%% Opens the Principle Manager.
proc {OpenPrincipleManager}
try
%% Filter
FilterV =
if GlobalDict.g==unit then
""
else
WordAs#_ = {GetInput}
G = {GetGrammar WordAs}
PnPrincipleRec = G.pnPrincipleRec
PIDAs =
for Pn in G.usedPns collect:Collect do
Principle = PnPrincipleRec.Pn
PIDA = Principle.pIDA
in
{Collect PIDA}
end
PIDA1|PIDAs1 = PIDAs
FilterV1 = PIDA1#"$"#{FoldL PIDAs1
fun {$ AccV PIDA}
AccV#"|"#PIDA#"$"
end ""}
in
FilterV1
end
%% Debug
DebugB = {DebugTkvar tkReturnInt($)}==1
%%
PostBuildProc =
proc {$}
ReloadB = {ReloadTkvar tkReturnInt($)}==1
in
if ReloadB andthen {Not GlobalDict.g==unit} then
{ReloadGrammars}
end
end
%%
AXRec = o(filter: FilterV
grammar: ""
builddeffile: BuildDefFileB
ozeditor: OzEditorS
uleditor: ULEditorS
xmleditor: XMLEditorS
%%
pwoptimize: PWOptimizeB
pwseon: PWSeonB
pwadhoc: PWAdhocB
%%
log: LogA
debug: DebugB
%%
postbuild: PostBuildProc)
in
{PrincipleManager.open AXRec}
catch E then
{HandleException E}
end
end
%% OpenOutputManager: U -> U
%% Opens the Output Manager.
% proc {OpenOutputManager}
% try
% %% Filter
% FilterV =
% if GlobalDict.g==unit then
% ""
% else
% WordAs#_ = {GetInput}
% G = {GetGrammar WordAs}
% PnPrincipleRec = G.pnPrincipleRec
% PIDAs =
% for Pn in G.usedPns collect:Collect do
% Principle = PnPrincipleRec.Pn
% PIDA = Principle.pIDA
% in
% {Collect PIDA}
% end
% PIDA1|PIDAs1 = PIDAs
% FilterV1 = PIDA1#"$"#{FoldL PIDAs1
% fun {$ AccV PIDA}
% AccV#"|"#PIDA#"$"
% end ""}
% in
% FilterV1
% end
% %% Debug
% DebugB = {DebugTkvar tkReturnInt($)}==1
% %%
% PostBuildProc =
% proc {$}
% ReloadB = {ReloadTkvar tkReturnInt($)}==1
% in
% if ReloadB andthen {Not GlobalDict.g==unit} then
% {ReloadGrammars}
% end
% end
% %%
% AXRec = o(filter: FilterV
% grammar: ""
% builddeffile: BuildDefFileB
% ozeditor: OzEditorS
% uleditor: ULEditorS
% xmleditor: XMLEditorS
% %%
% pwoptimize: PWOptimizeB
% pwseon: PWSeonB
% pwadhoc: PWAdhocB
% %%
% log: LogA
% debug: DebugB
% %%
% postbuild: PostBuildProc)
% in
% {OutputManager.open AXRec}
% catch E then
% {HandleException E}
% end
% end
%% Quit: U -> U
%% Quits the application.
proc {Quit}
Status=0
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Search-menu
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SetOraclePort: U -> U
%% Sets GlobalDict.portI.
proc {SetOraclePort}
PortI =
{Helpers.tkGetI
'XDK: Set oracle port' 'Oracle port'
GlobalDict.portI}
in
GlobalDict.portI := PortI
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Dimensions-menu
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SetDimensions: G -> U
%% Sets up the dimensions menu for grammar G.
proc {SetDimensions G}
if {Not G==unit} then
AllDIDAs = G.allDIDAs
UsedDIDAs = G.usedDIDAs
DIDATkvarTups =
{Map AllDIDAs
fun {$ DIDA}
B = {Member DIDA UsedDIDAs}
Tkvar = {New Tk.variable tkInit(B)}
in
DIDA#Tkvar
end}