diff --git a/snark-document-builder/src/main/python/SnarkParser.py b/snark-document-builder/src/main/python/SnarkParser.py new file mode 100644 index 0000000..fb71d7f --- /dev/null +++ b/snark-document-builder/src/main/python/SnarkParser.py @@ -0,0 +1,26 @@ +import sys +import re +import json + +assert(len(sys.argv) >= 2) + +string = sys.argv[1] + +outputfile = sys.argv[2] if len(sys.argv) >= 3 else None + +pattern = r'^([\n|\t| ]*@include\([a-z|0-9|.|_]*.md\)[\n|\t| ]*)*$' + +files = [] + +if re.search("@include", string, re.IGNORECASE): + if re.match(pattern, string): + matches = re.findall(r'@include\((.*?)\)', string) + files.extend(matches) + else: + sys.exit("Illformed string") + +if outputfile is None: + print(json.dumps(files)) +else: + with open(outputfile, 'w+') as f: + json.dump(files, f) \ No newline at end of file