SLAX 语法规则概述
SLAX 语法规则类似于 C 和 PERL 等传统编程语言的语法规则。以下各节讨论 SLAX 语法规则的一般方面:
代码块
SLAX 用大括号分隔代码块。代码块可以定义元素、层次结构或代码段的边界,可以与其他代码块处于同一级别,也可以嵌套在其他代码块中。在特定代码块中定义的声明具有仅限于该块的作用域。
下面的示例显示了两个代码块。大括号定义块的 match /
边界。包含元素 <op-script-results>
的第二个块嵌套在第一个块中。
match / { <op-script-results> { <output> "Script summary:"; } }
评论
在 SLAX 中,您可以在脚本中的任意位置添加注释。对脚本进行注释可以提高所有用户(包括作者)的可读性,他们可能需要在脚本最初编写后很久才返回到脚本。建议您在编写脚本时在整个脚本中添加注释。
在 SLAX 中,以传统的 C 样式插入注释,以 /*
开头,以 */
结尾。例如:
/* This is a comment. */
多行注释遵循相同的格式。在以下示例中,为了便于阅读,将附加的“*”字符添加到行首,但这不是必需的。
/* Script Title * Author: Jane Doe * Last modified: 01/01/10 * Summary of modifications: ... */
XSLT 等效项为:
<!-- Script Title Author: Jane Doe Last modified: 01/01/10 Summary of modifications: ... -->
以下示例在脚本中插入注释,以提醒程序员输出已发送到控制台。
match / { <op-script-results> { /* Output script summary to the console */ <output> "Script summary: ..."; } }
线路终端
与许多传统编程语言一样,SLAX 语句以分号结尾。
在以下示例中,命名空间声明、import 语句和 output 元素都以分号结尾。以块开头或结尾的行不以分号结尾。
version 1.2; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match / { <op-script-results> { <output> "Script summary:"; /* ... */ } }
字符串
字符串是文本字符序列。SLAX 字符串可以括在单引号或双引号中。但是,您必须使用用于打开字符串的相同类型的引号来关闭字符串。可以使用 SLAX 串联运算(即下划线 (_))将字符串连接在一起。
例如:
match / { <op-script-results> { /* Output script summary to the console */ <output> "Script" _ "summary: ..."; } }