4 import xml.etree.ElementTree
9 text = root.text if i == 0 else root[i - 1].tail
10 return '' if text is None else text
16 for i in range(len(root))
17 for j in [get_text(root, i), to_text(root[i])]
19 [get_text(root, len(root))]
22 text = to_text(xml.etree.ElementTree.parse(sys.stdin).getroot()[0])
24 # see tests/scan-code.l
25 text = text.replace(r'{tag}([^\0\n>]|->)+', '{tag}')
26 text = text.replace(r'{tag}(?:([^\0\n>]|->)+)', '{tag}')
28 text = text.replace(r'{splice}(\\[ \f\t\v]*\n)*', '{splice}')
29 text = text.replace(r'{splice}(?:(\\[ \f\t\v]*\n)*)', '{splice}')
31 text = text.replace(r'{letter}[.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]', '{letter}')
32 text = text.replace(r'{letter}(?:[.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_])', '{letter}')
33 text = text.replace(r'{id}{letter}({letter}|[-0-9])*', '{id}')
34 text = text.replace(r'{id}(?:{letter}({letter}|[-0-9])*)', '{id}')
35 text = text.replace(r'{ref}-?[0-9]+|{id}|"["{id}"]"|"$"', '{ref}')
36 text = text.replace(r'{ref}(?:-?[0-9]+|{id}|"["{id}"]"|"$")', '{ref}')
38 # we can only calculate column numbering once all substitutions done
40 j = text.find(' /*COLUMN32*/ ', i)
42 k = text.rfind('\n', 0, j)
47 tab = '\t' * ((32 - col + 7) // 8)
48 text = text[:j] + tab + text[j + 14:]
50 j = text.find(' /*COLUMN32*/ ', i)
52 sys.stdout.write(text)