SnarkParser.py is added
This commit is contained in:
parent
225b7346a8
commit
4019cbfe6b
26
snark-document-builder/src/main/python/SnarkParser.py
Normal file
26
snark-document-builder/src/main/python/SnarkParser.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user