From 4019cbfe6bdca62d179f29f695fb15a35c5d7876 Mon Sep 17 00:00:00 2001 From: "liubar.pa" Date: Sat, 6 May 2023 00:17:33 +0300 Subject: [PATCH] SnarkParser.py is added --- .../src/main/python/SnarkParser.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 snark-document-builder/src/main/python/SnarkParser.py 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