SwitchCase 选择分支情况
1. 结构声明
- TS Declaration
- JSON Schema
class SwitchCase extends LogicItem {
test?: LogicItem;
consequent: Array<LogicItem>;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"changedTime": {
"$ref": "#/definitions/long"
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"folded": {
"type": "boolean"
},
"offsetX": {
"type": "number"
},
"offsetY": {
"type": "number"
},
"typeAnnotation": {
"$ref": "#/definitions/TypeAnnotation"
},
"breakpoint": {
"type": "string",
"enum": [
"ENABLED",
"DISABLED"
]
},
"test": {
"$ref": "#/definitions/LogicItem"
},
"consequent": {
"type": "array",
"items": {
"$ref": "#/definitions/LogicItem"
}
}
},
"required": [
"consequent"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "SwitchCase",
"test": {
"concept": "BinaryExpression",
"left": {
"concept": "MemberExpression",
"object": {
"concept": "Identifier",
"namespace": "",
"name": "list"
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "length"
}
},
"right": {
"concept": "NumericLiteral",
"value": "10",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
},
"operator": "<="
},
"consequent": [
{
"concept": "CallLogic",
"uuid": "08d83151df934c3e904ab8704e14b2ae",
"calleeNamespace": "nasl.logging",
"calleeName": "INFO",
"shortcut": true,
"arguments": [
{
"concept": "Argument",
"keyword": "模板",
"expression": {
"concept": "StringLiteral",
"value": "情况2"
}
}
]
}
]
}
concept: SwitchCase
test:
concept: BinaryExpression
left:
concept: MemberExpression
object:
concept: Identifier
namespace: ""
name: list
property:
concept: Identifier
namespace: ""
name: length
right:
concept: NumericLiteral
value: "10"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
operator: <=
consequent:
- concept: CallLogic
uuid: 08d83151df934c3e904ab8704e14b2ae
calleeNamespace: nasl.logging
calleeName: INFO
shortcut: true
arguments:
- concept: Argument
keyword: 模板
expression:
concept: StringLiteral
value: 情况2
对应的代码如下:
- 文本化 NASL
- Natural TS
list.length <= 10 => {
nasl::logging::INFO('情况2')
}
if (list.length <= 10) {
nasl.logging.INFO('情况2')
}
(2) else
AST 如下:
- JSON
- YAML
{
"concept": "SwitchCase",
"consequent": [
{
"concept": "CallLogic",
"uuid": "11fe6dacbd3f42749c14c272fad6ffbb",
"calleeNamespace": "nasl.logging",
"calleeName": "INFO",
"shortcut": true,
"arguments": [
{
"concept": "Argument",
"keyword": "模板",
"expression": {
"concept": "StringLiteral",
"value": "其它情况"
}
}
]
}
]
}
concept: SwitchCase
consequent:
- concept: CallLogic
uuid: 11fe6dacbd3f42749c14c272fad6ffbb
calleeNamespace: nasl.logging
calleeName: INFO
shortcut: true
arguments:
- concept: Argument
keyword: 模板
expression:
concept: StringLiteral
value: 其它情况
对应的代码如下:
- 文本化 NASL
- Natural TS
_ => {
nasl::logging::INFO('其它情况')
}
if (______) {
nasl.logging.INFO('其它情况')
}