获取表脚本的全部内容(包括注释)?我正在尝试提出一个系统来组织附加到我的数据表的所有JSL脚本。我想在每个脚本顶部的注释中插入标题。它看起来像这样:
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **
* Script Name: my script name
* Script Category: <<CATEGORY>>
* Author: author name
* Rev Date: date
* Purpose: purpose
* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */</CATEGORY>
在此标头中,我将保留一些有关每个脚本的元数据。例如,括在尖括号中的“脚本类别”字段。我希望能够遍历脚本并根据此元数据对其进行操作。
我知道我可以像这样获得连接到我的数据表的所有脚本的列表:
dt = Current Data Table();
scriptList = dt << Get Table Script Names;
然后,我可以获取如下脚本的内容:
scriptText = Char(dt << Get Table Property(scriptList[1]));
但是,scriptText不包含任何注释。标头部分丢失,因此我无法访问这些注释中包含的元数据。
有没有办法让满的表脚本的文本,包括注释?
脚本编写回复:获取表脚本的全部内容(包括注释)吗?我知道解决此问题的唯一方法是将每个注释放入虚拟文字字符串中
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";
;]\")); 回复:获取表脚本的全部内容(包括注释)吗?谢谢。那就是我所担心的-除了在事物的评论方面使用某种丑陋的kludge之外,无法以编程方式访问这些评论。
我确实找到了一种看起来更好的方法来完成此任务。我将标题注释块放在JSL Quote()的内部,这会欺骗JSL解释器保留我的注释块而不是删除它。现在,我可以阅读类别字段并相应地使用它。
这是我的示例脚本:
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");</MY>并输出到日志:
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</MY>