Skip to content

Commit

Permalink
Merge pull request #1057 from sstsimulator/devel
Browse files Browse the repository at this point in the history
Automatically Merged using SST Master Branch Merger
  • Loading branch information
sst-autotester committed Mar 12, 2024
2 parents 74376bc + cee8deb commit 6bc0ceb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ EXTRA_DIST = \
VERSION.md

include tests/Makefile.inc

dist_bin_SCRIPTS = scripts/sst-snippets.py
64 changes: 64 additions & 0 deletions scripts/sst-snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#! /usr/bin/env python3

import os
import sys
import json

if not os.path.exists("snippets"):
os.mkdir("snippets")

srcpath = os.path.dirname(sys.argv[1])

configFile = open(sys.argv[1],'r')
config = json.load(configFile)

for tag in config["snippets"]:
snip = config["snippets"][tag]

# python or c++?
language = "c++"
try:
if snip["language"] == "python":
language = "python"
except: pass

# a unique tag
scoped_tag = "SSTSnippet::" + tag

# read the input file
infile = open( os.path.join(srcpath, snip["file"]), 'r')
lines = infile.readlines()

# open the output file
outfile = open( "snippets/" + snip["file"].replace("/","-") + '-' + tag, 'w')

snippeting = False
for line in lines:
if line.find(scoped_tag) != -1:
if line.find("start") != -1:
snippeting = True
elif line.find("pause") != -1:
snippeting = False
elif line.find("end") != -1:
break

if line.find("highlight") != -1:
if (language == "python"):
outfile.write("#")
else:
outfile.write("//")
if line.find("highlight-start") != -1:
outfile.write("highlight-start")
elif line.find("highlight-stop") != -1:
outfile.write("highlight-stop")
else:
outfile.write("highlight-next-line\n")
elif snippeting and line.find("SSTSnippet::") == -1:
outfile.write(line)

infile.close()
outfile.close()

configFile.close()


0 comments on commit 6bc0ceb

Please sign in to comment.