-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
65 lines (54 loc) · 1.58 KB
/
generate.py
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
import os
import sys
from os.path import *
import re
tmplt_1_fname="NMEA.Messages.%(MSG)s";
tmplt_1="""package body NMEA.Messages.%(MSG)s is
-----------------
-- Constructor --
-----------------
overriding function Constructor
(Stream : not null access Ada.Streams.Root_Stream_Type'Class)
return %(MSG)s_Message
is
begin
return Result : %(MSG)s_Message do
%(MSG)s_Message'Read (Stream, Result);
end return;
end Constructor;
overriding function Image (This : %(MSG)s_Message) return String is separate;
begin
Register ("%(MSG)s", %(MSG)s_Message'Tag);
end NMEA.Messages.%(MSG)s;
"""
tmplt_2_fname="NMEA.Messages.%(MSG)s.Image";
tmplt_2="""separate (NMEA.Messages.%(MSG)s)
overriding
function Image (This : %(MSG)s_Message) return String is
pragma Unreferenced (This);
begin
return "Image ""%(MSG)s"" not implemented";
end;
"""
m=re.compile("package NMEA.Messages.([a-zA-Z0-9]*) .*")
def ada2file(s):
return s.lower().replace(".","-")
def gen(src):
name=None
dir=dirname(src)
with file(src) as inf:
for line in inf:
ma=m.match(line)
if ma:
name=ma.group(1)
if name:
f1=join(dir, "impl", ada2file(tmplt_1_fname % {"MSG" : name}) + ".adb")
f2=join(dir, "impl", ada2file(tmplt_2_fname % {"MSG" : name}) + ".adb")
if not exists(f1):
with file(f1,"w") as outf:
outf.write(tmplt_1 % {"MSG" : name})
if not exists(f2):
with file(f2,"w") as outf:
outf.write(tmplt_2 % {"MSG" : name})
for src in sys.argv[1:]:
gen(abspath(src))