Skip to content

Instantly share code, notes, and snippets.

@jansindl3r
Last active June 16, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jansindl3r/44deab6094f7423b1b19e3cecd221f23 to your computer and use it in GitHub Desktop.
Save jansindl3r/44deab6094f7423b1b19e3cecd221f23 to your computer and use it in GitHub Desktop.
flatten linnked feature files
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