Last active
June 16, 2020 13:07
-
-
Save jansindl3r/44deab6094f7423b1b19e3cecd221f23 to your computer and use it in GitHub Desktop.
flatten linnked feature files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pathlib import Path | |
def solveFeatureLinking(path, container=''): | |
if not container: | |
with open(path, 'r') as inputFile: | |
container = inputFile.read() | |
pattern = re.compile(r'include\ *?\((.*)\)\ *?\;') | |
matches = list(re.finditer(pattern, container)) | |
if matches: | |
for match in matches[::-1]: | |
left, right = match.span(0) | |
with open(path.parent/match.group(1), 'r') as includeFile: | |
includeData = includeFile.read() | |
container = container[:left] + includeData + container[right:] | |
return solveFeatureLinking(path, container) | |
else: | |
return container | |
''' | |
usage: | |
feature = solveFeatureLinking(Path('a.fea').absolute()) | |
print(feature) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment