cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Chris_Rodrigues
Level III

Get entire contents of table script (including comments)?

I am trying to come up with a system to organize all the JSL scripts attached to my data table.  I want to insert a header in the comments at the top of each of my scripts.  It will look like this:

 

/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 
 * Script Name:		my script name
 * Script Category:		<<category>>
 * Author:				author name
 * Rev Date:			date
 * Purpose:			purpose
 * * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */

Inside of this header I will keep some metadata about each of the scripts.  For example, the "script category" field which is enclosed in angle brackets.  I want to be able to iterate over the scripts and manipulate them based on this metadata.

 

I know that I can obtain a list of all the scripts attached to my data table  like this:

dt = Current Data Table();
scriptList = dt << Get Table Script Names;

 

And then I can get the contents of a script like this:

scriptText = Char(dt << Get Table Property(scriptList[1]));

However, the scriptText does not contain any of the comments.  The header section is missing, so I can't access the metadata contained within those comments.

 

Is there a way to get the full text of a table script, including comments?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Chris_Rodrigues
Level III

Re: Get entire contents of table script (including comments)?

Thanks.  That's what I was afraid of - there's no way to programmatically access the comments except using some kind of ugly kludge on the comments side of things.

 

I did figure out a nicer-looking way to accomplish this.  I enclose the header comment block inside of JSL Quote() which tricks the JSL interpreter into keeping my comment block instead of deleting it.  So now I can read the category field and use it accordingly.

 

Here's my example script:

 

JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 
 * Script Name:			my script name
 * Script Category:		<<my category>>
 * Author:				author name
 * Rev Date:			date
 * Purpose:				purpose
 * * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
);

//this comment will be deleted

dt = Current Data Table();
scriptText = Char(dt << Get Table Property("my script name"));
scriptCategory = Char(Regex(scriptText,"\<\<([A-Za-z0-9 \/]*)\>\>", "\1"));
Write("\!n" || scriptText || "\!n");
Write("\!n" || scriptCategory || "\!n");

And the output to the log:

 

JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 
 * Script Name:			my script name
 * Script Category:		<<my category>>
 * Author:				author name
 * Rev Date:			date
 * Purpose:				purpose
 * * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
); dt = Current Data Table(); scriptText = Char(dt << Get Table Property("my script name")); scriptCategory = Char(Regex(scriptText, "\<\<([A-Za-z0-9 \/]*)\>\>", "\1")); Write("
" || scriptText || "
"); Write("
" || scriptCategory || "
")

my category

 

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Get entire contents of table script (including comments)?

The only way that I know of to kluge my way around this is to place each comment into a dummy literal string

dt=current data table();
eval(parse("\[dt << new script("mysct", 
comment="/**************************************/";
names default to here(1);
dt=current data table();
comment="// Here come more comments";
;]\")); 
Jim
Chris_Rodrigues
Level III

Re: Get entire contents of table script (including comments)?

Thanks.  That's what I was afraid of - there's no way to programmatically access the comments except using some kind of ugly kludge on the comments side of things.

 

I did figure out a nicer-looking way to accomplish this.  I enclose the header comment block inside of JSL Quote() which tricks the JSL interpreter into keeping my comment block instead of deleting it.  So now I can read the category field and use it accordingly.

 

Here's my example script:

 

JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 
 * Script Name:			my script name
 * Script Category:		<<my category>>
 * Author:				author name
 * Rev Date:			date
 * Purpose:				purpose
 * * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
);

//this comment will be deleted

dt = Current Data Table();
scriptText = Char(dt << Get Table Property("my script name"));
scriptCategory = Char(Regex(scriptText,"\<\<([A-Za-z0-9 \/]*)\>\>", "\1"));
Write("\!n" || scriptText || "\!n");
Write("\!n" || scriptCategory || "\!n");

And the output to the log:

 

JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 
 * Script Name:			my script name
 * Script Category:		<<my category>>
 * Author:				author name
 * Rev Date:			date
 * Purpose:				purpose
 * * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
); dt = Current Data Table(); scriptText = Char(dt << Get Table Property("my script name")); scriptCategory = Char(Regex(scriptText, "\<\<([A-Za-z0-9 \/]*)\>\>", "\1")); Write("
" || scriptText || "
"); Write("
" || scriptCategory || "
")

my category