Match 匹配
1. 结构声明
- TS Declaration
- JSON Schema
class Match extends LogicItem {
    expression: LogicItem;
    isExpression: boolean = false;
    cases: Array<MatchCase>;
}
{
    "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"
            ]
        },
        "expression": {
            "$ref": "#/definitions/LogicItem"
        },
        "isExpression": {
            "type": "boolean"
        },
        "cases": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/MatchCase"
            }
        }
    },
    "required": [
        "expression",
        "isExpression",
        "cases"
    ],
    "additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
    "concept": "Match",
    "expression": {
        "concept": "MemberExpression",
        "object": {
            "concept": "MemberExpression",
            "object": {
                "concept": "Identifier",
                "namespace": "",
                "name": "item"
            },
            "property": {
                "concept": "Identifier",
                "namespace": "",
                "name": "productReport"
            }
        },
        "property": {
            "concept": "Identifier",
            "namespace": "",
            "name": "executed"
        }
    },
    "isExpression": true,
    "cases": [
        {
            "concept": "MatchCase",
            "patterns": [
                {
                    "concept": "BooleanLiteral",
                    "value": "true"
                }
            ],
            "body": [
                {
                    "concept": "NumericLiteral",
                    "value": "1",
                    "typeAnnotation": {
                        "concept": "TypeAnnotation",
                        "typeKind": "primitive",
                        "typeNamespace": "nasl.core",
                        "typeName": "Long",
                        "inferred": false,
                        "ruleMap": {}
                    }
                }
            ],
            "isMatchedTypeEnumable": true
        },
        {
            "concept": "MatchCase",
            "patterns": [
                {
                    "concept": "BooleanLiteral",
                    "value": "false"
                }
            ],
            "body": [
                {
                    "concept": "NumericLiteral",
                    "value": "0",
                    "typeAnnotation": {
                        "concept": "TypeAnnotation",
                        "typeKind": "primitive",
                        "typeNamespace": "nasl.core",
                        "typeName": "Long",
                        "inferred": false,
                        "ruleMap": {}
                    }
                }
            ],
            "isMatchedTypeEnumable": true
        },
        {
            "concept": "MatchCase",
            "patterns": [],
            "body": [],
            "isMatchedTypeEnumable": false
        }
    ]
}
concept: Match
expression:
  concept: MemberExpression
  object:
    concept: MemberExpression
    object:
      concept: Identifier
      namespace: ""
      name: item
    property:
      concept: Identifier
      namespace: ""
      name: productReport
  property:
    concept: Identifier
    namespace: ""
    name: executed
isExpression: true
cases:
  - concept: MatchCase
    patterns:
      - concept: BooleanLiteral
        value: "true"
    body:
      - concept: NumericLiteral
        value: "1"
        typeAnnotation:
          concept: TypeAnnotation
          typeKind: primitive
          typeNamespace: nasl.core
          typeName: Long
          inferred: false
          ruleMap: {}
    isMatchedTypeEnumable: true
  - concept: MatchCase
    patterns:
      - concept: BooleanLiteral
        value: "false"
    body:
      - concept: NumericLiteral
        value: "0"
        typeAnnotation:
          concept: TypeAnnotation
          typeKind: primitive
          typeNamespace: nasl.core
          typeName: Long
          inferred: false
          ruleMap: {}
    isMatchedTypeEnumable: true
  - concept: MatchCase
    patterns: []
    body: []
    isMatchedTypeEnumable: false
对应的代码如下:
- 文本化 NASL
- Natural TS
match item.productReport.executed {
    true => 1
    false => 0
}
(function match(_value) {
    if (item.productReport.executed === true) {
        return 1
    }     else if (item.productReport.executed === false) {
        return 0
    }     else {
    }
})(item.productReport.executed)