-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdkc.oz
99 lines (95 loc) · 3.13 KB
/
xdkc.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
%% 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
Application(exit getArgs)
Property(get)
System(showError showInfo printInfo show)
Helpers(addHandlers e2V vs2S changeSuffix) at 'Helpers.ozf'
Principles(principles) at 'Solver/Principles/Principles.ozf'
Outputs(outputs) at 'Outputs/Outputs.ozf'
Compiler(files2SLE sLE2File) at 'Compiler/Compiler.ozf'
define
{Helpers.addHandlers}
%%
S2A = String.toAtom
%%
AArgRec =
{Application.getArgs
record(help(single type:bool char:&h default:false)
grammars(single type:list(string) char:&g default:nil)
input(single type:string char:&i default:"")
output(single type:string char:&o default:unit)
debug(single type:bool char:&d default:false)
)}
%% help
if AArgRec.help then
{System.showError
'*XDG Development Kit (XDK): Grammar file compiler*\n'#
'--(no)help display this help\n'#
' -h\n'#
'--grammars <File1,...,FileN> select grammar files\n'#
' -g (e.g. -g Acl01.ul,Acl01-2.ul\n'#
' default: no files)\n'#
'--input provide input\n'#
' -i (e.g. --input "peter maria liebt"\n'#
' default: "")\n'#
'--output File specify filename for compiled grammar\n'#
' -o (e.g. -o Acl01.slp\n'#
' default: name of the first\n'#
' grammar file with suffix changed to ".slp")\n'#
'--(no)debug toggle debug mode\n'#
' -d (default: nodebug)'
}
{Application.exit 1}
end
%% grammars
GSs = AArgRec.grammars
%% input
InputS = AArgRec.input
%% output
OS = AArgRec.output
%% debug
DebugB = AArgRec.debug
%%
if GSs==nil then
{System.showError 'No grammar.'}
{Application.exit 1}
end
try
PrincipleILs = Principles.principles
OutputILs = Outputs.outputs
GS = {Helpers.vs2S GSs}
{System.printInfo 'Compiling grammar "'#GS#'" ... '}
I1 = {Property.get 'time.total'}
InputA = {S2A InputS}
MetaX = InputA
SLE = {Compiler.files2SLE GSs MetaX PrincipleILs OutputILs DebugB System.showError}
I2 = {Property.get 'time.total'}
I = I2-I1
{System.showInfo 'done. ('#I#'ms)'}
%%
GS1 =
if OS==unit then
GS1 = GSs.1
in
{Helpers.changeSuffix GS1 "slp"}
else
OS
end
in
{Compiler.sLE2File SLE GS1 DebugB System.showError}
{System.showInfo 'Saved compiled grammar as "'#GS1#'".'}
catch E then
V = {Helpers.e2V E}
in
{System.showError '\n'#V}
if DebugB orelse V=='unhandled error' then {System.show E} end
end
in
{Application.exit 0}
end