After T/S for a few days I found there's no way to do this in jsl w/o losing the comments within the jsl code being rewritten.
So I wrote a code in python that do that instead
# This code will replace code in .jsl files that match the Regex in parameters dictionary (pattern(1) and repl(2)) below.
# It is based on the simple def replace(source, dest) function, with pattern now being the source and the repl as the dest.
# The pattern in this code is to replace old JMP column naming syntax to the new JMP column naming syntax,
# e.g :Name( "variable@property" ) into :"variable@property"n
# for jsl code to run more efficiently in JMP17 and above
import os
import re
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
WORKING_DIR = filedialog.askdirectory()
# pattern(1)
pattern = r':\s*Name\s*\(\s*"([^"]+)"\s*\)'
# repl(2)
repl = r':"\1"n'
parameters = {pattern: repl}
def pat_replace(pat, rep):
for dname, dirs, files in os.walk(WORKING_DIR):
for fname in files:
if fname.endswith(".jsl"):
fpath = os.path.join(dname, fname)
with open(fpath, encoding="utf8") as f:
s = f.read()
s_out = re.sub(pat, rep, s)
with open(fpath, "w", encoding="utf8") as f:
f.write(s_out)
for i, (key, value) in enumerate(parameters.items()):
pat_replace(key, value)