4 print('Usage: apply_gloss.py filename.egg')
8 def __process_line(idx
, line
, _out_lines
):
9 if line
.strip() != '<Scalar> envtype { GLOSS }':
10 mth
= __process_nongloss_line
11 else: mth
= __process_gloss_line
12 return mth(idx
, line
, _out_lines
)
15 def __process_nongloss_line(idx
, line
, _out_lines
):
16 is_scal
= line
.strip().startswith('<Scalar> alpha-file { ')
17 if not idx
or not (line
.strip() == _out_lines
[-1].strip() and is_scal
):
18 _out_lines
+= [line
.rstrip()]
22 def __process_gloss_line(idx
, line
, _out_lines
):
23 _out_lines
+= [line
.rstrip()]
26 if char
== ' ': outl
+= ' '
28 outl
+= '<Scalar> alpha-file { %s }' % lines
[idx
- 1].strip()
29 return _out_lines
+ [outl
]
33 with
open(sys
.argv
[1]) as fin
:
34 lines
= fin
.readlines()
35 for _idx
, _line
in enumerate(lines
):
36 out_lines
= __process_line(_idx
, _line
, out_lines
)
39 with
open(sys
.argv
[1], 'w') as fout
:
40 list(map(lambda outl
: fout
.write(outl
+ '\n'), out_lines
))