Skip to content

Instantly share code, notes, and snippets.

@interstar
Last active August 27, 2021 14:31
Show Gist options
  • Save interstar/715c75996c444666c9c5bf2a1ca6d2b8 to your computer and use it in GitHub Desktop.
Save interstar/715c75996c444666c9c5bf2a1ca6d2b8 to your computer and use it in GitHub Desktop.
recursively include text files
import sys, re
# Run like this :
# python3 rectext.py toplevel.txt
#
# include statement looks like this
# @include fname.txt
def slurp(fName) :
with open(fName) as f :
return (l.strip() for l in f.readlines())
def xclude(fName) :
for l in slurp(fName) :
if re.match("@include",l) :
for l2 in xclude(l.split(" ")[1]) : yield l2
else :
yield l
for l in xclude(sys.argv[1]) : print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment