root/scripts/util/simplify_xpath @ 51
1 |
#!/usr/bin/env python
|
---|---|
2 |
# Removes duplication from XPath expressions
|
3 |
|
4 |
import re |
5 |
import sys |
6 |
|
7 |
def main(): |
8 |
while True: |
9 |
line = sys.stdin.readline() |
10 |
if line == '': break |
11 |
# Forward * abbrs
|
12 |
line = re.sub(r'(/)(\w+)(?=\w*(?:->/[^/]*)?/\2\b)', r'\1*', line) |
13 |
# Backward * abbrs
|
14 |
line = re.sub(r'(/(\w+)->/[^/]*/[^/]*\[)\2', r'\1*', line) |
15 |
sys.stdout.write(line) |
16 |
|
17 |
main() |