├── .gitignore ├── EventRule.g4 ├── Makefile ├── README.md ├── examples ├── test.go └── test.json ├── go.mod ├── go.sum ├── jar └── antlr-4.7.1-complete.jar └── visitor ├── eventrule.go └── parser ├── EventRule.interp ├── EventRule.tokens ├── EventRuleLexer.interp ├── EventRuleLexer.tokens ├── eventrule_base_visitor.go ├── eventrule_lexer.go ├── eventrule_parser.go └── eventrule_visitor.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /EventRule.g4: -------------------------------------------------------------------------------- 1 | grammar EventRule; 2 | 3 | // Tokens 4 | AND: 'and'; 5 | OR: 'or'; 6 | NOT: 'not' | '!'; 7 | EQU: '=' | '=='; 8 | NEQ: '!='; 9 | GT: '>'; 10 | LT: '<'; 11 | GTE: '>='; 12 | LTE: '<='; 13 | CONTAINS: 'contains'; 14 | NOTCONTAINS: 'not contains'; 15 | IN: 'in'; 16 | NOTIN: 'not in'; 17 | LIKE: 'like'; 18 | NOTLIKE: 'not like'; 19 | REGEX: 'regex'; 20 | NOTREGEX: 'not regex'; 21 | EXISTS: 'exists'; 22 | NOTEXISTS: 'not exists'; 23 | COMMA: ','; 24 | NUMBER: [-]?[0-9]+('.'[0-9]+)?; 25 | BOOLEAN: 'True'|'TRUE'|'true'|'False'|'FALSE'|'false'; 26 | STRING: '"' (ESC|.)*? '"'; 27 | //VAR: [a-zA-Z0-9_.-]+; 28 | VAR: [a-zA-Z_][a-zA-Z0-9_-]*('['('*'|[0-9]+|(([0-9]+)?':'([0-9]+)?))']')?('.'[a-zA-Z_][a-zA-Z0-9_-]*('['('*'|[0-9]+|(([0-9]+)?':'([0-9]+)?))']')?('.')?)*; 29 | WHITESPACE: [ \t\r\n] ->skip; 30 | 31 | fragment 32 | ESC: '\\"' | '\\\\'; 33 | 34 | // Rules 35 | start 36 | : expression EOF 37 | ; 38 | 39 | expression 40 | : expression op=(AND|OR) expression # AndOr 41 | | NOT expression # Not 42 | | '(' expression ')' # Parenthesis 43 | | VAR op=(EQU|NEQ|GT|LT|GTE|LTE) (STRING|NUMBER) # Compare 44 | | VAR op=(EQU|NEQ) BOOLEAN # BoolCompare 45 | | VAR op=(CONTAINS|NOTCONTAINS) (STRING|NUMBER) # ContainsOrNot 46 | | VAR op=(IN|NOTIN) '(' (NUMBER|STRING) (COMMA (NUMBER|STRING))* ')' # InOrNot 47 | | VAR op=(REGEX|NOTREGEX|LIKE|NOTLIKE) STRING # RegexOrNot 48 | | VAR op=(EXISTS|NOTEXISTS) # ExistsOrNot 49 | | VAR # Variable 50 | | NOT VAR # NotVariable 51 | ; -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY:all visitor 2 | antlr4=java -Xmx500M -cp "jar/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool 3 | all:visitor test 4 | visitor: 5 | $(antlr4) -Xlog -Dlanguage=Go -no-listener -visitor -o visitor/parser EventRule.g4 6 | test: 7 | go build -o eventruleengine examples/test.go 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Event Rule Engine 2 | [![License](http://img.shields.io/badge/license-apache%20v2-blue.svg)](https://github.com/KubeSphere/KubeSphere/blob/master/LICENSE) 3 | 4 | ---- 5 | 6 | ## Introduction 7 | 8 | Event Rule Engine is an rule script evaluating engine for KubeSphere event processing. It can run expression calculation on json members. 9 | 10 | ## Supported grammer 11 | 12 | ### Boolean calculation 13 | 14 | Operation supported: and, or, not, =, != 15 | 16 | Variables contain json boolean member can calculate directly. 17 | 18 | ``` 19 | Examples 20 | open and involvedObject.apiVersion="v1" 21 | !open 22 | open = true 23 | open != true 24 | ``` 25 | 26 | >The bool value suport three formates, TRUE True true 27 | 28 | ### Number comparision 29 | 30 | Operation supported: =, !=, >, <, >=, <=, in, not in 31 | 32 | Data type supported: int, long, float, double 33 | 34 | ``` 35 | Examples 36 | count >= 20 37 | ``` 38 | 39 | ### String comparision 40 | 41 | Operation supported: =, !=, >, <, >=, <=, in, not in, contains, not contains 42 | 43 | ``` 44 | Examples 45 | metadata.namespace = "kube-system" 46 | metadata.namespace in ("kube-system", "default") 47 | metadata.namespace contains "system" 48 | ``` 49 | 50 | ### Regular comparision 51 | 52 | Operation supported: like, not like, regex, not regex 53 | 54 | ``` 55 | Examples 56 | metadata.namespace like "ks*" 57 | metadata.name like "redis-?" 58 | metadata.namespace in ("kube-system", "default") 59 | metadata.namespace contains "system" 60 | ``` 61 | 62 | >Use '*' to substitute any string, use '?' to substitute a character。 63 | >Regexp, not regexp operation only suport standard regular syntax. 64 | 65 | ### Array comparision 66 | 67 | Operation supported: all 68 | 69 | ``` 70 | Examples 71 | ResponseObject.status.images[28].names[0].names = "redis" 72 | ``` 73 | 74 | >You can use '*' to substitute the index of array, this means if any element of the array match the right value, then expression holds。 75 | >You can use "start:end" such as "1:5" to specify a subset of th array. You can omitted either the start index or the end index, 76 | >it means the subset start at the begining of array, or end at the ending of array. 77 | 78 | ## Complex examples 79 | 80 | ``` 81 | Examples 82 | (metadata.namespace in ("kube-system", "default") or count >= 20) and involvedObject.apiVersion contains "v1" 83 | ``` -------------------------------------------------------------------------------- /examples/test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "github.com/kubesphere/event-rule-engine/visitor" 23 | "io/ioutil" 24 | "os" 25 | ) 26 | 27 | func Flatten(m map[string]interface{}) map[string]interface{} { 28 | o := make(map[string]interface{}) 29 | for k, v := range m { 30 | switch child := v.(type) { 31 | case map[string]interface{}: 32 | nm := Flatten(child) 33 | for nk, nv := range nm { 34 | o[k+"."+nk] = nv 35 | } 36 | default: 37 | o[k] = v 38 | } 39 | } 40 | return o 41 | } 42 | 43 | var fm map[string]interface{} 44 | 45 | func executor(in string) { 46 | 47 | if _, err := visitor.CheckRule(in); err != nil { 48 | fmt.Printf("rule condition is not correct, %s", err.Error()) 49 | return 50 | } 51 | 52 | err, res := visitor.EventRuleEvaluate(fm, in) 53 | if err != nil { 54 | fmt.Println(err) 55 | return 56 | } 57 | fmt.Printf("Answer: %v\n", res) 58 | } 59 | 60 | func readJson() { 61 | f, err := os.Open("examples//test.json") 62 | if err != nil { 63 | fmt.Println(err.Error()) 64 | return 65 | } 66 | 67 | data, _ := ioutil.ReadAll(f) 68 | var m map[string]interface{} 69 | err = json.Unmarshal(data, &m) 70 | if err != nil { 71 | fmt.Println("Unmarshal failed, ", err) 72 | return 73 | } 74 | 75 | fm = Flatten(m) 76 | fmt.Println(fm) 77 | } 78 | 79 | func main() { 80 | readJson() 81 | executor("ResponseObject.status.images[*].names[*] contains \"kubesphere\"") 82 | } 83 | -------------------------------------------------------------------------------- /examples/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "Annotations": { 3 | "authorization.k8s.io/decision": "allow", 4 | "authorization.k8s.io/reason": "" 5 | }, 6 | "AuditID": "ca76e8b3-63ef-4f9e-9af6-851def38395c", 7 | "ConsumeRetrys": 1, 8 | "ConsumeTime": "2019-12-27T03:55:37.968468081Z", 9 | "ImpersonatedUser": null, 10 | "Level": false, 11 | "MatchTime": "2019-12-27T03:55:38.053886462Z", 12 | "Message": { 13 | "0a14c3c7-0d42-41f1-979a-8da691bea63f": "system:node:ks-allinone 更新 了 节点 ks-allinone" 14 | }, 15 | "ObjectRef": { 16 | "APIGroup": "", 17 | "APIVersion": "v1", 18 | "Name": "ks-allinone", 19 | "Namespace": "", 20 | "Resource": "nodes", 21 | "ResourceVersion": "", 22 | "Subresource": "status", 23 | "UID": "" 24 | }, 25 | "OutputTime": "0001-01-01T00:00:00Z", 26 | "PublishRetrys": 1, 27 | "PublishTime": "2019-12-27T03:55:37.919559947Z", 28 | "PullTime": "2019-12-27T03:55:37.972441141Z", 29 | "ReceiviedTime": "2019-12-27T03:55:37.919548878Z", 30 | "RequestObject": { 31 | "status": { 32 | "$setElementOrder/conditions": [ 33 | { 34 | "type": "NetworkUnavailable" 35 | }, 36 | { 37 | "type": "MemoryPressure" 38 | }, 39 | { 40 | "type": "DiskPressure" 41 | }, 42 | { 43 | "type": "PIDPressure" 44 | }, 45 | { 46 | "type": "Ready" 47 | } 48 | ], 49 | "conditions": [ 50 | { 51 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 52 | "type": "MemoryPressure" 53 | }, 54 | { 55 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 56 | "type": "DiskPressure" 57 | }, 58 | { 59 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 60 | "type": "PIDPressure" 61 | }, 62 | { 63 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 64 | "type": "Ready" 65 | } 66 | ] 67 | } 68 | }, 69 | "RequestReceivedTimestamp": "2019-12-27T03:55:32.463587Z", 70 | "RequestURI": "/api/v1/nodes/ks-allinone/status?timeout=10s", 71 | "ResponseObject": { 72 | "kind": "Node", 73 | "apiVersion": "v1", 74 | "metadata": { 75 | "name": "ks-allinone", 76 | "selfLink": "/api/v1/nodes/ks-allinone/status", 77 | "uid": "a759cefa-d742-4d19-a285-3bb402138803", 78 | "resourceVersion": "8752554", 79 | "creationTimestamp": "2019-11-11T03:33:17Z", 80 | "labels": { 81 | "beta.kubernetes.io/arch": "amd64", 82 | "beta.kubernetes.io/os": "linux", 83 | "kubernetes.io/arch": "amd64", 84 | "kubernetes.io/hostname": "ks-allinone", 85 | "kubernetes.io/os": "linux", 86 | "node-role.kubernetes.io/master": "" 87 | }, 88 | "annotations": { 89 | "alpha.kubernetes.io/provided-node-ip": "192.168.0.20", 90 | "kubeadm.alpha.kubernetes.io/cri-socket": "/var/run/dockershim.sock", 91 | "node.alpha.kubernetes.io/ttl": "0", 92 | "volumes.kubernetes.io/controller-managed-attach-detach": "true" 93 | } 94 | }, 95 | "spec": { 96 | "podCIDR": "10.233.64.0/24" 97 | }, 98 | "status": { 99 | "capacity": { 100 | "cpu": "8", 101 | "ephemeral-storage": "309502832Ki", 102 | "hugepages-2Mi": "0", 103 | "memory": "32780324Ki", 104 | "pods": "110" 105 | }, 106 | "allocatable": { 107 | "cpu": "7800m", 108 | "ephemeral-storage": "285237809499", 109 | "hugepages-2Mi": "0", 110 | "memory": "32177924Ki", 111 | "pods": "110" 112 | }, 113 | "conditions": [ 114 | { 115 | "type": "NetworkUnavailable", 116 | "status": "False", 117 | "lastHeartbeatTime": "2019-12-24T07:08:41Z", 118 | "lastTransitionTime": "2019-12-24T07:08:41Z", 119 | "reason": "CalicoIsUp", 120 | "message": "Calico is running on this node" 121 | }, 122 | { 123 | "type": "MemoryPressure", 124 | "status": "False", 125 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 126 | "lastTransitionTime": "2019-12-24T08:04:22Z", 127 | "reason": "KubeletHasSufficientMemory", 128 | "message": "kubelet has sufficient memory available" 129 | }, 130 | { 131 | "type": "DiskPressure", 132 | "status": "False", 133 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 134 | "lastTransitionTime": "2019-12-24T08:04:22Z", 135 | "reason": "KubeletHasNoDiskPressure", 136 | "message": "kubelet has no disk pressure" 137 | }, 138 | { 139 | "type": "PIDPressure", 140 | "status": "False", 141 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 142 | "lastTransitionTime": "2019-12-24T08:04:22Z", 143 | "reason": "KubeletHasSufficientPID", 144 | "message": "kubelet has sufficient PID available" 145 | }, 146 | { 147 | "type": "Ready", 148 | "status": "True", 149 | "lastHeartbeatTime": "2019-12-27T03:55:32Z", 150 | "lastTransitionTime": "2019-12-24T08:04:22Z", 151 | "reason": "KubeletReady", 152 | "message": "kubelet is posting ready status" 153 | } 154 | ], 155 | "addresses": [ 156 | { 157 | "type": "InternalIP", 158 | "address": "192.168.0.20" 159 | }, 160 | { 161 | "type": "Hostname", 162 | "address": "ks-allinone" 163 | } 164 | ], 165 | "daemonEndpoints": { 166 | "kubeletEndpoint": { 167 | "Port": 10250 168 | } 169 | }, 170 | "nodeInfo": { 171 | "machineID": "6e8163a216c035f3b80bd4325be8c430", 172 | "systemUUID": "6E8163A2-16C0-35F3-B80B-D4325BE8C430", 173 | "bootID": "6057446f-2f61-4185-b349-c1f5622126fc", 174 | "kernelVersion": "3.10.0-862.el7.x86_64", 175 | "osImage": "CentOS Linux 7 (Core)", 176 | "containerRuntimeVersion": "docker://18.9.7", 177 | "kubeletVersion": "v1.15.5", 178 | "kubeProxyVersion": "v1.15.5", 179 | "operatingSystem": "linux", 180 | "architecture": "amd64" 181 | }, 182 | "images": [ 183 | { 184 | "names": [ 185 | "mirrorgitlabcontainers/gitaly@sha256:921e4cf80a42dcd52c8f30bb92bcb6ab6c0dec5b391f8c38d7942a9005741cde", 186 | "mirrorgitlabcontainers/gitaly:v12-3-4" 187 | ], 188 | "sizeBytes": 1676374977 189 | }, 190 | { 191 | "names": [ 192 | "mirrorgitlabcontainers/gitlab-task-runner-ce@sha256:52eccaf96b1dc2b8d97c4a081b2004db47f6aed9ef57fee6451de614219f211f", 193 | "mirrorgitlabcontainers/gitlab-task-runner-ce:v12.4.1" 194 | ], 195 | "sizeBytes": 1312186404 196 | }, 197 | { 198 | "names": [ 199 | "mirrorgitlabcontainers/gitlab-unicorn-ce@sha256:afd98c87a79bec7a4c421f0a991ae4f896bef4c6d9dd507f932627fa032cd24b", 200 | "mirrorgitlabcontainers/gitlab-unicorn-ce:v12.4.1" 201 | ], 202 | "sizeBytes": 1233980870 203 | }, 204 | { 205 | "names": [ 206 | "mirrorgitlabcontainers/gitlab-sidekiq-ce@sha256:f31a9937f25d40272876e55c0ee1e207800b94f3ac83adbda24aebd633ecd405", 207 | "mirrorgitlabcontainers/gitlab-sidekiq-ce:v12.4.1" 208 | ], 209 | "sizeBytes": 1149314249 210 | }, 211 | { 212 | "names": [ 213 | "mirrorgitlabcontainers/gitlab-rails-ce@sha256:e95c627e955e8e33cbde680b40af54f49073e1265a7688c6f4d9a1c0bd50130f", 214 | "mirrorgitlabcontainers/gitlab-rails-ce:v12.4.1" 215 | ], 216 | "sizeBytes": 1127906476 217 | }, 218 | { 219 | "names": [ 220 | "sonarqube@sha256:7d7d88000121d368cc31d97bf2e98636cd743afb779878df41d075c16471c4e4", 221 | "sonarqube:7.4-community" 222 | ], 223 | "sizeBytes": 830430283 224 | }, 225 | { 226 | "names": [ 227 | "kubesphere/elasticsearch-oss@sha256:795da1ec4a08fd30048471f7a731700c0781234970ff5d2be64029244c9288d3", 228 | "kubesphere/elasticsearch-oss:6.7.0-1" 229 | ], 230 | "sizeBytes": 702164843 231 | }, 232 | { 233 | "names": [ 234 | "mirrorgitlabcontainers/gitlab-shell@sha256:374e5d82f137638f4c4016379656c4f2208fc04931cd92ce3c4e917cceed55e7", 235 | "mirrorgitlabcontainers/gitlab-shell:v12-3-4" 236 | ], 237 | "sizeBytes": 689626912 238 | }, 239 | { 240 | "names": [ 241 | "quay.azk8s.cn/kubernetes-ingress-controller/nginx-ingress-controller@sha256:76861d167e4e3db18f2672fd3435396aaa898ddf4d1128375d7c93b91c59f87f", 242 | "quay.azk8s.cn/kubernetes-ingress-controller/nginx-ingress-controller:0.24.1" 243 | ], 244 | "sizeBytes": 631358200 245 | }, 246 | { 247 | "names": [ 248 | "gcr.azk8s.cn/google-containers/hyperkube@sha256:c0a2b93f543177574551262ba1cf9f005fa4d2a046c731070f1d39f829d50e5f", 249 | "gcr.azk8s.cn/google-containers/hyperkube:v1.15.5" 250 | ], 251 | "sizeBytes": 593442254 252 | }, 253 | { 254 | "names": [ 255 | "jenkins/jenkins@sha256:5a1ac8381051dc430dcc90077f648ed1e1b91149b5808a8dea507639eefc563f", 256 | "jenkins/jenkins:2.176.2" 257 | ], 258 | "sizeBytes": 567041724 259 | }, 260 | { 261 | "names": [ 262 | "mirrorgitlabcontainers/gitlab-workhorse-ce@sha256:96087f030e3cf288fec7311ed6ee74a83181dd23f08d698c950831398b001e0d", 263 | "mirrorgitlabcontainers/gitlab-workhorse-ce:v12.4.1" 264 | ], 265 | "sizeBytes": 499998452 266 | }, 267 | { 268 | "names": [ 269 | "kubesphere/ks-installer@sha256:b9f240b40772a192d96c538587e85bc38470d79777146093ed2ec6b24b7bbc1a", 270 | "kubesphere/ks-installer:v2.1.0" 271 | ], 272 | "sizeBytes": 485510075 273 | }, 274 | { 275 | "names": [ 276 | "kubesphere/ks-installer@sha256:a2a652d87e2a83cb629b861a350d20184f8c30c8cf1d651b7519b92ba910e608" 277 | ], 278 | "sizeBytes": 485506488 279 | }, 280 | { 281 | "names": [ 282 | "docker.elastic.co/kibana/kibana-oss@sha256:9af7fbceb7c9a746df1f7dc79d2b3bb320f0fddf9b06a3cc12fd8f903902e731", 283 | "dockerhub.qingcloud.com/kibana/kibana-oss@sha256:9af7fbceb7c9a746df1f7dc79d2b3bb320f0fddf9b06a3cc12fd8f903902e731", 284 | "docker.elastic.co/kibana/kibana-oss:6.7.0", 285 | "dockerhub.qingcloud.com/kibana/kibana-oss:6.7.0" 286 | ], 287 | "sizeBytes": 452698702 288 | }, 289 | { 290 | "names": [ 291 | "mysql@sha256:ffa442557c7a350939d9cd531f77d6cbb98e868aeb4a328289e0e5469101c20e", 292 | "mysql:8.0.11" 293 | ], 294 | "sizeBytes": 444743757 295 | }, 296 | { 297 | "names": [ 298 | "kubesphere/jenkins-uc@sha256:1d5890eb49034bf6b1225e8e69757c2edddc2237041c6ee22a29e62cb40997f8", 299 | "kubesphere/jenkins-uc:v2.1.0" 300 | ], 301 | "sizeBytes": 418780984 302 | }, 303 | { 304 | "names": [ 305 | "istio/proxyv2@sha256:ba3471a9749893afe80f7d8f11119bf0148ffe0f4eaf3f9da66bb27076a8c2a6", 306 | "istio/proxyv2:1.3.3" 307 | ], 308 | "sizeBytes": 295718548 309 | }, 310 | { 311 | "names": [ 312 | "osixia/openldap@sha256:cb3f5fea3c3203acddc3e6b8a70642a0f994d89be3ec5f0e50621b2a9ea17a83", 313 | "osixia/openldap:1.3.0" 314 | ], 315 | "sizeBytes": 275387335 316 | }, 317 | { 318 | "names": [ 319 | "istio/galley@sha256:a5c96c260e619d6756b21638b884b41739f0bbf587b0411f26e8cfe85e18534a", 320 | "istio/galley:1.3.3" 321 | ], 322 | "sizeBytes": 270111146 323 | }, 324 | { 325 | "names": [ 326 | "jaegertracing/jaeger-operator@sha256:e0123c1f74095abc12efd8e5d115ea5b52a5219680e03de25c54ed50b0528010", 327 | "jaegertracing/jaeger-operator:1.13.1" 328 | ], 329 | "sizeBytes": 270105291 330 | }, 331 | { 332 | "names": [ 333 | "istio/pilot@sha256:a599c6c5712e266136fe58296c41b9fb9eebe462eff2bf0f02f5c0ad9caea2ea", 334 | "istio/pilot:1.3.3" 335 | ], 336 | "sizeBytes": 268607205 337 | }, 338 | { 339 | "names": [ 340 | "istio/sidecar_injector@sha256:ebd3623f456261d0343f7a51312dc1093420164e5b03e1f7a05c89654f3718a6", 341 | "istio/sidecar_injector:1.3.3" 342 | ], 343 | "sizeBytes": 256912673 344 | }, 345 | { 346 | "names": [ 347 | "grafana/grafana@sha256:aaf50da5faf2596bfb0caed81f08b5569110e7b5468b291fedad25d8cbc51f2b", 348 | "grafana/grafana:5.2.4" 349 | ], 350 | "sizeBytes": 245249907 351 | }, 352 | { 353 | "names": [ 354 | "istio/citadel@sha256:6693cf372064c5edb41462cf92e03354098689cacfb9229e93ef4b35e3f7109a", 355 | "istio/citadel:1.3.3" 356 | ], 357 | "sizeBytes": 241425010 358 | }, 359 | { 360 | "names": [ 361 | "postgres@sha256:6e1efcd656386fc0c0a9893fda0c0ec6704868fbaad5ad5be3732c4f81cf21c9", 362 | "postgres:9.6.8" 363 | ], 364 | "sizeBytes": 234295589 365 | }, 366 | { 367 | "names": [ 368 | "mirrorgitlabcontainers/gitlab-exporter@sha256:589bc9619b5510e296b65dea11494cd82abd102cdd09cec604ec8ed4dd18f3b0", 369 | "mirrorgitlabcontainers/gitlab-exporter:5.0.1" 370 | ], 371 | "sizeBytes": 220101805 372 | }, 373 | { 374 | "names": [ 375 | "goharbor/clair-photon@sha256:552085c21a422cc5ce445f4cd11775e3ffdea34ea09d1005e1812b76df9e9d1a", 376 | "goharbor/clair-photon:v2.0.9-v1.9.1" 377 | ], 378 | "sizeBytes": 165468718 379 | }, 380 | { 381 | "names": [ 382 | "quay.azk8s.cn/openebs/node-disk-manager-amd64@sha256:476aab4d4bcfa3f0eead5216cf17f7e3c52d2f80181857a47d9c5ed8921b4059", 383 | "quay.azk8s.cn/openebs/node-disk-manager-amd64:v0.4.1" 384 | ], 385 | "sizeBytes": 162565094 386 | }, 387 | { 388 | "names": [ 389 | "quay.azk8s.cn/openebs/node-disk-operator-amd64@sha256:a031f3b27fcef14df5b9c51cff93d9a4fc9de0630c4356c90c5e1a63d9426683", 390 | "quay.azk8s.cn/openebs/node-disk-operator-amd64:v0.4.1" 391 | ], 392 | "sizeBytes": 162281289 393 | }, 394 | { 395 | "names": [ 396 | "mirrorgitlabcontainers/kubectl@sha256:fa15ba466920eec245d455e9e5e679a1e62fd401106b21cf0428e360ac747cb7", 397 | "mirrorgitlabcontainers/kubectl:v1.12.10" 398 | ], 399 | "sizeBytes": 157327901 400 | }, 401 | { 402 | "names": [ 403 | "calico/node@sha256:a2782b53500c96e35299b8af729eaf39423f9ffd903d9fda675073f4a063502a", 404 | "calico/node:v3.7.3" 405 | ], 406 | "sizeBytes": 156259173 407 | }, 408 | { 409 | "names": [ 410 | "goharbor/harbor-core@sha256:6e4e9fd9af9dd934cd2c6846804a280cc22a705a87c8fe669adca1be1514aa8d", 411 | "goharbor/harbor-core:v1.9.1" 412 | ], 413 | "sizeBytes": 155419477 414 | }, 415 | { 416 | "names": [ 417 | "kubesphere/ks-devops@sha256:25e0d1b94e909299eb3b9ae4a562225e89de51e0aea58b44bac28355682ed0b8", 418 | "kubesphere/ks-devops:flyway-v2.1.0" 419 | ], 420 | "sizeBytes": 149083741 421 | }, 422 | { 423 | "names": [ 424 | "goharbor/harbor-db@sha256:6fce5c0b83f647fb13a05bba30595a1a6cda206352351454b47ffb40e0696201", 425 | "goharbor/harbor-db:v1.9.1" 426 | ], 427 | "sizeBytes": 146777706 428 | }, 429 | { 430 | "names": [ 431 | "openpitrix/openpitrix@sha256:1bc0a2fa0709f3ecd8246e19836eebca187f74843899ed6b87e2d6530e3cc5aa", 432 | "openpitrix/openpitrix:v0.4.5" 433 | ], 434 | "sizeBytes": 145053372 435 | }, 436 | { 437 | "names": [ 438 | "kubesphere/docker-elasticsearch-curator@sha256:bec03e6bc395556065100c57c562745953b272d2d6d98516309a72b4f97b57e5", 439 | "dockerhub.qingcloud.com/pires/docker-elasticsearch-curator@sha256:bec03e6bc395556065100c57c562745953b272d2d6d98516309a72b4f97b57e5", 440 | "kubesphere/docker-elasticsearch-curator:5.5.4", 441 | "dockerhub.qingcloud.com/pires/docker-elasticsearch-curator:5.5.4" 442 | ], 443 | "sizeBytes": 141725506 444 | }, 445 | { 446 | "names": [ 447 | "goharbor/harbor-jobservice@sha256:14c82514489c9bc3e9d597f37b7023c6d79250dbfcdec90cc9d96e26cc9d687d", 448 | "goharbor/harbor-jobservice:v1.9.1" 449 | ], 450 | "sizeBytes": 140885196 451 | }, 452 | { 453 | "names": [ 454 | "kubesphere/alerting-dbinit@sha256:1f447101d9aa1c2e01e34ed8f9f5a79537c2d904986565701d08f9e498d219ef", 455 | "kubesphere/alerting-dbinit:v2.1.0" 456 | ], 457 | "sizeBytes": 137663833 458 | }, 459 | { 460 | "names": [ 461 | "kubesphere/notification@sha256:48303e0b8ead5b75534e9c2dc0aecb110c6f2d6f9d5811f2bb1e7a3432dd9a7b", 462 | "kubesphere/notification:flyway_v2.1.0" 463 | ], 464 | "sizeBytes": 137651934 465 | }, 466 | { 467 | "names": [ 468 | "calico/cni@sha256:258a0cb3c25022e44ebda3606112c40865adb67b8fb7be3d119f960957301ad6", 469 | "calico/cni:v3.7.3" 470 | ], 471 | "sizeBytes": 135366007 472 | }, 473 | { 474 | "names": [ 475 | "goharbor/chartmuseum-photon@sha256:9c00a72dae0664f950d8c3a4176bbe5c0e29a3d331d2fa3faf86c9b0cef64565", 476 | "goharbor/chartmuseum-photon:v0.9.0-v1.9.1" 477 | ], 478 | "sizeBytes": 130900423 479 | }, 480 | { 481 | "names": [ 482 | "goharbor/redis-photon@sha256:ab3a6acca6a2ae994f2a94b640155d66df7b7a7acf6a6a22e9b2a9520f1a47a9", 483 | "goharbor/redis-photon:v1.9.1" 484 | ], 485 | "sizeBytes": 109603121 486 | }, 487 | { 488 | "names": [ 489 | "kubesphere/ks-controller-manager@sha256:6903e90a8a829813eb2ae720bed824f223da5ccab6f0d6efced5547da6f85f0c", 490 | "kubesphere/ks-controller-manager:v2.1.0" 491 | ], 492 | "sizeBytes": 104773250 493 | }, 494 | { 495 | "names": [ 496 | "kubesphere/prometheus@sha256:60c989c93c8097ef7719c1b3b0f4dc54ea61b5e836c222258a5d9512fb3e6181", 497 | "kubesphere/prometheus:v2.5.0" 498 | ], 499 | "sizeBytes": 99822269 500 | }, 501 | { 502 | "names": [ 503 | "goharbor/harbor-registryctl@sha256:94411f782c3e457e88b1ef0c9baf728593a84eee83faa60873b000c2d5f50739", 504 | "goharbor/harbor-registryctl:v1.9.1" 505 | ], 506 | "sizeBytes": 99625273 507 | }, 508 | { 509 | "names": [ 510 | "gcr.azk8s.cn/kubernetes-helm/tiller@sha256:c09393087c4be55023f86be979a9dfe486c728703eba996344adc9783f261baa", 511 | "gcr.azk8s.cn/kubernetes-helm/tiller:v2.14.3" 512 | ], 513 | "sizeBytes": 94194761 514 | }, 515 | { 516 | "names": [ 517 | "istio/mixer@sha256:5127f49cea52b6dcbb409fbffc64523b0d4c894d5722c9f97627e5e285a4b11d", 518 | "istio/mixer:1.3.3" 519 | ], 520 | "sizeBytes": 92748552 521 | }, 522 | { 523 | "names": [ 524 | "kubesphere/ks-apigateway@sha256:62b00bcde6253279365d48656ab9255f51769aa2b45aba4ade8ffb83ea48a6d9", 525 | "kubesphere/ks-apigateway:v2.1.0" 526 | ], 527 | "sizeBytes": 84836366 528 | }, 529 | { 530 | "names": [ 531 | "kubesphere/ks-console@sha256:7dec766d47ac92821535a55fbf63f783bb4d4ba9ac096f8643ca0fbbf52c2acc", 532 | "kubesphere/ks-console:v2.1.0" 533 | ], 534 | "sizeBytes": 82901991 535 | } 536 | ] 537 | } 538 | }, 539 | "ResponseStatus": { 540 | "code": 200, 541 | "metadata": {} 542 | }, 543 | "Rules": [ 544 | "0a14c3c7-0d42-41f1-979a-8da691bea63f" 545 | ], 546 | "SourceIPs": [ 547 | "192.168.0.20" 548 | ], 549 | "Stage": "ResponseComplete", 550 | "StageTimestamp": "2019-12-27T03:55:32.467976Z", 551 | "User": { 552 | "Extra": null, 553 | "Groups": [ 554 | "system:nodes", 555 | "system:authenticated" 556 | ], 557 | "UID": "", 558 | "Username": "system:node:ks-allinone" 559 | }, 560 | "UserAgent": "kubelet/v1.15.5 (linux/amd64) kubernetes/20c265f", 561 | "Verb": "patch" 562 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/kubesphere/event-rule-engine 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/antlr/antlr4 v0.0.0-20190819145818-b43a4c3a8015 7 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/antlr/antlr4 v0.0.0-20190819145818-b43a4c3a8015 h1:StuiJFxQUsxSCzcby6NFZRdEhPkXD5vxN7TZ4MD6T84= 2 | github.com/antlr/antlr4 v0.0.0-20190819145818-b43a4c3a8015/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y= 3 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= 4 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 5 | -------------------------------------------------------------------------------- /jar/antlr-4.7.1-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubesphere/event-rule-engine/c91b9b139a2c41e2a39e38bec4d0b86acc987596/jar/antlr-4.7.1-complete.jar -------------------------------------------------------------------------------- /visitor/eventrule.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The KubeSphere Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package visitor 18 | 19 | import ( 20 | "bytes" 21 | "errors" 22 | "fmt" 23 | "github.com/antlr/antlr4/runtime/Go/antlr" 24 | "github.com/golang/glog" 25 | "github.com/kubesphere/event-rule-engine/visitor/parser" 26 | "regexp" 27 | "strconv" 28 | "strings" 29 | ) 30 | 31 | const ( 32 | LevelInfo = 6 33 | ) 34 | 35 | const ( 36 | ArrayOperatorAny = 1 37 | ArrayOperatorAll = 2 38 | ) 39 | 40 | type Visitor struct { 41 | parser.BaseEventRuleVisitor 42 | valueStack []bool 43 | m map[string]interface{} 44 | } 45 | 46 | func NewVisitor(m map[string]interface{}) *Visitor { 47 | return &Visitor{ 48 | m: m, 49 | } 50 | } 51 | 52 | func (v *Visitor) pushValue(i bool) { 53 | v.valueStack = append(v.valueStack, i) 54 | } 55 | 56 | func (v *Visitor) popValue() bool { 57 | if len(v.valueStack) < 1 { 58 | panic("valueStack is empty unable to pop") 59 | } 60 | 61 | // Get the last value from the stack. 62 | result := v.valueStack[len(v.valueStack)-1] 63 | 64 | // Remove the last element from the stack. 65 | v.valueStack = v.valueStack[:len(v.valueStack)-1] 66 | 67 | return result 68 | } 69 | 70 | func (v *Visitor) visitRule(node antlr.RuleNode) interface{} { 71 | node.Accept(v) 72 | return nil 73 | } 74 | 75 | func (v *Visitor) VisitStart(ctx *parser.StartContext) interface{} { 76 | return v.visitRule(ctx.Expression()) 77 | } 78 | 79 | func (v *Visitor) VisitAndOr(ctx *parser.AndOrContext) interface{} { 80 | 81 | //push expression result to stack 82 | v.visitRule(ctx.Expression(0)) 83 | v.visitRule(ctx.Expression(1)) 84 | 85 | //push result to stack 86 | t := ctx.GetOp() 87 | right := v.popValue() 88 | left := v.popValue() 89 | switch t.GetTokenType() { 90 | case parser.EventRuleParserAND: 91 | v.pushValue(left && right) 92 | case parser.EventRuleParserOR: 93 | v.pushValue(left || right) 94 | default: 95 | panic("should not happen") 96 | } 97 | 98 | return nil 99 | } 100 | 101 | func (v *Visitor) VisitNot(ctx *parser.NotContext) interface{} { 102 | 103 | v.visitRule(ctx.Expression()) 104 | 105 | value := v.popValue() 106 | v.pushValue(!value) 107 | 108 | return nil 109 | } 110 | 111 | func (v *Visitor) VisitCompare(ctx *parser.CompareContext) interface{} { 112 | 113 | varName := ctx.VAR().GetText() 114 | if !strings.Contains(varName, "[") { 115 | if v.m[varName] == nil { 116 | v.pushValue(false) 117 | return nil 118 | } 119 | 120 | v.pushValue(compare(varName, v.m[varName], ctx)) 121 | return nil 122 | } 123 | 124 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 125 | return compare(varName, value, ctx) 126 | })) 127 | 128 | return nil 129 | } 130 | 131 | func compare(name string, value interface{}, ctx *parser.CompareContext) bool { 132 | 133 | if value == nil { 134 | return false 135 | } 136 | 137 | result := false 138 | if ctx.STRING() != nil { 139 | strValue := ctx.STRING().GetText() 140 | strValue = strings.TrimLeft(strValue, `"`) 141 | strValue = strings.TrimRight(strValue, `"`) 142 | 143 | switch ctx.GetOp().GetTokenType() { 144 | case parser.EventRuleParserEQU: 145 | result = fmt.Sprint(value) == strValue 146 | case parser.EventRuleParserNEQ: 147 | result = fmt.Sprint(value) != strValue 148 | case parser.EventRuleParserGT: 149 | result = fmt.Sprint(value) > strValue 150 | case parser.EventRuleParserLT: 151 | result = fmt.Sprint(value) < strValue 152 | case parser.EventRuleParserGTE: 153 | result = fmt.Sprint(value) >= strValue 154 | case parser.EventRuleParserLTE: 155 | result = fmt.Sprint(value) <= strValue 156 | } 157 | 158 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), strValue, result) 159 | } else { 160 | numValue, err := strconv.ParseFloat(ctx.NUMBER().GetText(), 64) 161 | if err != nil { 162 | panic(fmt.Errorf("%s is not number", ctx.NUMBER().GetText())) 163 | } 164 | 165 | num, err := strconv.ParseFloat(fmt.Sprint(value), 64) 166 | if err != nil { 167 | panic(fmt.Errorf("%s is not number", value)) 168 | } 169 | 170 | switch ctx.GetOp().GetTokenType() { 171 | case parser.EventRuleParserEQU: 172 | result = num == numValue 173 | case parser.EventRuleParserNEQ: 174 | result = num != numValue 175 | case parser.EventRuleParserGT: 176 | result = num > numValue 177 | case parser.EventRuleParserLT: 178 | result = num < numValue 179 | case parser.EventRuleParserGTE: 180 | result = num >= numValue 181 | case parser.EventRuleParserLTE: 182 | result = num <= numValue 183 | } 184 | 185 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), numValue, result) 186 | } 187 | 188 | return result 189 | } 190 | 191 | func (v *Visitor) VisitBoolCompare(ctx *parser.BoolCompareContext) interface{} { 192 | 193 | varName := ctx.VAR().GetText() 194 | if !strings.Contains(varName, "[") { 195 | v.pushValue(boolCompare(varName, v.m[varName], ctx)) 196 | return nil 197 | } 198 | 199 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 200 | return boolCompare(varName, value, ctx) 201 | })) 202 | 203 | return nil 204 | } 205 | 206 | func boolCompare(name string, value interface{}, ctx *parser.BoolCompareContext) bool { 207 | 208 | if value == nil { 209 | return false 210 | } 211 | 212 | boolValue, err := strconv.ParseBool(ctx.BOOLEAN().GetText()) 213 | if err != nil { 214 | panic(fmt.Errorf("%s is not bool", ctx.BOOLEAN().GetText())) 215 | } 216 | 217 | bv, err := strconv.ParseBool(fmt.Sprint(value)) 218 | if err != nil { 219 | panic(fmt.Errorf("%s is not bool", value)) 220 | } 221 | 222 | result := boolValue == bv 223 | if ctx.GetOp().GetTokenType() == parser.EventRuleLexerNEQ { 224 | result = !result 225 | } 226 | 227 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), boolValue, result) 228 | return result 229 | } 230 | 231 | func (v *Visitor) VisitContainsOrNot(ctx *parser.ContainsOrNotContext) interface{} { 232 | 233 | varName := ctx.VAR().GetText() 234 | if !strings.Contains(varName, "[") { 235 | v.pushValue(containsOrNot(varName, v.m[varName], ctx)) 236 | return nil 237 | } 238 | 239 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 240 | return containsOrNot(varName, fmt.Sprint(value), ctx) 241 | })) 242 | 243 | return nil 244 | } 245 | 246 | func containsOrNot(name string, value interface{}, ctx *parser.ContainsOrNotContext) bool { 247 | 248 | if value == nil { 249 | return false 250 | } 251 | 252 | node := ctx.STRING() 253 | var strValue string 254 | if node != nil { 255 | strValue = node.GetText() 256 | strValue = strings.TrimLeft(strValue, `"`) 257 | strValue = strings.TrimRight(strValue, `"`) 258 | } 259 | if node == nil { 260 | node = ctx.NUMBER() 261 | strValue = node.GetText() 262 | } 263 | 264 | result := strings.Contains(fmt.Sprint(value), strValue) 265 | if ctx.GetOp().GetTokenType() == parser.EventRuleParserNOTCONTAINS { 266 | result = !result 267 | } 268 | 269 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), strValue, result) 270 | return result 271 | } 272 | 273 | func (v *Visitor) VisitInOrNot(ctx *parser.InOrNotContext) interface{} { 274 | 275 | varName := ctx.VAR().GetText() 276 | if !strings.Contains(varName, "[") { 277 | v.pushValue(inOrNot(varName, v.m[varName], ctx)) 278 | return nil 279 | } 280 | 281 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 282 | return inOrNot(varName, value, ctx) 283 | })) 284 | return nil 285 | } 286 | 287 | func inOrNot(name string, value interface{}, ctx *parser.InOrNotContext) bool { 288 | 289 | if value == nil { 290 | return false 291 | } 292 | 293 | var strValues []string 294 | for _, p := range ctx.AllNUMBER() { 295 | strValue := p.GetText() 296 | strValues = append(strValues, strValue) 297 | } 298 | 299 | for _, p := range ctx.AllSTRING() { 300 | strValue := p.GetText() 301 | strValue = strings.TrimLeft(strValue, `"`) 302 | strValue = strings.TrimRight(strValue, `"`) 303 | strValues = append(strValues, strValue) 304 | } 305 | 306 | result := false 307 | for _, strValue := range strValues { 308 | if fmt.Sprint(value) == strValue { 309 | result = true 310 | break 311 | } 312 | } 313 | 314 | if ctx.GetOp().GetTokenType() == parser.EventRuleParserNOTIN { 315 | result = !result 316 | } 317 | 318 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), strValues, result) 319 | return result 320 | } 321 | 322 | func (v *Visitor) VisitRegexOrNot(ctx *parser.RegexOrNotContext) interface{} { 323 | 324 | varName := ctx.VAR().GetText() 325 | if !strings.Contains(varName, "[") { 326 | v.pushValue(regexOrNot(varName, v.m[varName], ctx)) 327 | return nil 328 | } 329 | 330 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 331 | return regexOrNot(varName, value, ctx) 332 | })) 333 | return nil 334 | } 335 | 336 | func regexOrNot(name string, value interface{}, ctx *parser.RegexOrNotContext) bool { 337 | 338 | if value == nil { 339 | return false 340 | } 341 | 342 | strValue := ctx.STRING().GetText() 343 | strValue = strings.TrimLeft(strValue, `"`) 344 | strValue = strings.TrimRight(strValue, `"`) 345 | 346 | pattern := strValue 347 | if ctx.GetOp().GetTokenType() == parser.EventRuleLexerLIKE || ctx.GetOp().GetTokenType() == parser.EventRuleLexerNOTLIKE { 348 | 349 | pattern = strings.ReplaceAll(pattern, "?", ".") 350 | 351 | regex, err := regexp.Compile("(\\*)+") 352 | if err != nil { 353 | panic(err) 354 | } 355 | pattern = regex.ReplaceAllString(pattern, "(.*)") 356 | } 357 | 358 | result, err := regexp.Match(pattern, []byte(fmt.Sprint(value))) 359 | if err != nil { 360 | panic(err) 361 | } 362 | if ctx.GetOp().GetTokenType() == parser.EventRuleLexerNOTLIKE || ctx.GetOp().GetTokenType() == parser.EventRuleLexerNOTREGEX { 363 | result = !result 364 | } 365 | 366 | glog.V(LevelInfo).Infof("visit %s(%s) %s %s, %s", name, value, ctx.GetOp().GetText(), strValue, result) 367 | return result 368 | } 369 | 370 | func (v *Visitor) VisitVariable(ctx *parser.VariableContext) interface{} { 371 | return visitVariable(ctx.VAR().GetText(), v, true) 372 | } 373 | 374 | func (v *Visitor) VisitNotVariable(ctx *parser.NotVariableContext) interface{} { 375 | return visitVariable(ctx.VAR().GetText(), v, false) 376 | } 377 | 378 | func visitVariable(varName string, v *Visitor, flag bool) error { 379 | if !strings.Contains(varName, "[") { 380 | v.pushValue(variable(varName, v, flag)) 381 | return nil 382 | } 383 | 384 | v.pushValue(arrayOperator(v, varName, -1, func(value interface{}) bool { 385 | return variable(varName, v, flag) 386 | })) 387 | 388 | return nil 389 | } 390 | 391 | func variable(varName string, v *Visitor, flag bool) bool { 392 | 393 | if v.m[varName] == nil { 394 | return false 395 | } 396 | 397 | bv, err := strconv.ParseBool(fmt.Sprint(v.m[varName])) 398 | if err != nil { 399 | panic(fmt.Errorf("%s is not bool", v.m[varName])) 400 | } 401 | return bv == flag 402 | 403 | } 404 | 405 | func (v *Visitor) VisitParenthesis(ctx *parser.ParenthesisContext) interface{} { 406 | v.visitRule(ctx.Expression()) 407 | return nil 408 | } 409 | 410 | func (v *Visitor) VisitExistsOrNot(ctx *parser.ExistsOrNotContext) interface{} { 411 | varName := ctx.VAR().GetText() 412 | if !strings.Contains(varName, "[") { 413 | v.pushValue(existsOrNot(varName, v.m[varName], ctx.GetOp().GetTokenType(), v, true)) 414 | return nil 415 | } 416 | 417 | v.pushValue(arrayOperator(v, varName, ctx.GetOp().GetTokenType(), func(value interface{}) bool { 418 | return existsOrNot(varName, value, ctx.GetOp().GetTokenType(), v, false) 419 | })) 420 | return nil 421 | } 422 | 423 | func existsOrNot(name string, value interface{}, tokenType int, v *Visitor, flag bool) bool { 424 | result := true 425 | if value == nil { 426 | result = false 427 | } 428 | 429 | if !result && flag { 430 | for k, v := range v.m { 431 | if strings.HasPrefix(k, name+".") && v != nil { 432 | result = true 433 | break 434 | } 435 | } 436 | } 437 | 438 | if tokenType == parser.EventRuleParserNOTEXISTS { 439 | result = !result 440 | } 441 | 442 | glog.V(LevelInfo).Infof("visit %s %s, %s", name, tokenType, result) 443 | return result 444 | } 445 | 446 | func CheckRule(expression string) (bool, error) { 447 | 448 | m := make(map[string]interface{}) 449 | err, _ := EventRuleEvaluate(m, expression) 450 | if err != nil { 451 | return false, err 452 | } 453 | 454 | return true, nil 455 | } 456 | 457 | func EventRuleEvaluate(m map[string]interface{}, expression string) (error, bool) { 458 | 459 | var err error 460 | res := func() bool { 461 | defer func() { 462 | if i := recover(); i != nil { 463 | err = errors.New(i.(string)) 464 | } 465 | }() 466 | 467 | is := antlr.NewInputStream(expression) 468 | // Create the Lexer 469 | lexer := parser.NewEventRuleLexer(is) 470 | tokens := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) 471 | // Create the Parser 472 | p := parser.NewEventRuleParser(tokens) 473 | v := NewVisitor(m) 474 | //Start is rule name of EventRule.g4 475 | p.Start().Accept(v) 476 | 477 | return v.popValue() 478 | }() 479 | 480 | if err != nil { 481 | return err, false 482 | } 483 | 484 | return nil, res 485 | } 486 | 487 | func arrayOperator(v *Visitor, varName string, tokenType int, match func(value interface{}) bool) bool { 488 | if strings.HasSuffix(varName, "]") && 489 | tokenType != parser.EventRuleParserNOTCONTAINS && 490 | tokenType != parser.EventRuleParserCONTAINS { 491 | panic("array only support contains or not contains method") 492 | } 493 | 494 | ss := strings.Split(varName, ".") 495 | buf := bytes.Buffer{} 496 | for i := 0; i < len(ss); i++ { 497 | s := ss[i] 498 | if !strings.Contains(s, "[") { 499 | buf.WriteString(s) 500 | buf.WriteString(".") 501 | continue 502 | } 503 | 504 | buf.WriteString(s[0:strings.Index(s, "[")]) 505 | ss = ss[i:] 506 | break 507 | } 508 | 509 | if v.m[buf.String()] == nil { 510 | return false 511 | } 512 | 513 | varValue := v.m[buf.String()] 514 | if !isArray(varValue) { 515 | panic(fmt.Errorf("%s is not array", buf.String())) 516 | } 517 | 518 | value := varValue.([]interface{}) 519 | if len(value) == 0 { 520 | return false 521 | } 522 | 523 | childValue, op, err := getChildValue(ss[0], value) 524 | if err != nil { 525 | panic(err) 526 | } 527 | 528 | if childValue == nil || len(childValue) == 0 { 529 | return false 530 | } 531 | 532 | return arrayMatch(op, childValue, ss[1:], match) 533 | } 534 | 535 | func arrayMatch(op int, value []interface{}, array []string, match func(value interface{}) bool) bool { 536 | 537 | b := false 538 | result := false 539 | for _, v := range value { 540 | if len(array) == 0 { 541 | b = match(v) 542 | } else { 543 | if !isMap(v) { 544 | panic("the value not a map") 545 | } 546 | 547 | s := array[0] 548 | key := s 549 | if strings.Contains(s, "[") { 550 | key = key[0:strings.Index(key, "[")] 551 | } 552 | 553 | subValue, ok := v.(map[string]interface{})[key] 554 | if !ok && op == ArrayOperatorAll { 555 | return false 556 | } 557 | 558 | cop := 0 559 | var childValue []interface{} 560 | if strings.Contains(s, "[") { 561 | if !isArray(subValue) { 562 | panic("the value not a array") 563 | } 564 | 565 | var err error 566 | childValue, cop, err = getChildValue(s, subValue.([]interface{})) 567 | if err != nil { 568 | panic(err) 569 | } 570 | 571 | if childValue == nil || len(childValue) == 0 { 572 | return false 573 | } 574 | } else { 575 | childValue = append(childValue, subValue) 576 | cop = ArrayOperatorAny 577 | } 578 | 579 | b = arrayMatch(cop, childValue, array[1:], match) 580 | } 581 | 582 | switch op { 583 | case ArrayOperatorAny: 584 | if b { 585 | return true 586 | } 587 | case ArrayOperatorAll: 588 | if !b { 589 | return false 590 | } 591 | result = true 592 | } 593 | } 594 | 595 | return result 596 | } 597 | 598 | func getChildValue(param string, value []interface{}) ([]interface{}, int, error) { 599 | 600 | s := param[strings.Index(param, "["):] 601 | s = strings.TrimPrefix(s, "[") 602 | s = strings.TrimSuffix(s, "]") 603 | 604 | switch s { 605 | case "*": 606 | return value, ArrayOperatorAny, nil 607 | default: 608 | if strings.Contains(s, ":") { 609 | ns := strings.Split(s, ":") 610 | start := 0 611 | if len(ns[0]) > 0 { 612 | var err error 613 | start, err = strconv.Atoi(ns[0]) 614 | if err != nil { 615 | return nil, 0, err 616 | } 617 | 618 | if start < 0 { 619 | start = 0 620 | } 621 | if start > len(value) { 622 | start = len(value) 623 | } 624 | } 625 | end := len(value) 626 | if len(ns[1]) > 0 { 627 | var err error 628 | end, err = strconv.Atoi(ns[1]) 629 | if err != nil { 630 | return nil, 0, err 631 | } 632 | 633 | if end < 0 { 634 | return nil, 0, fmt.Errorf("array out of bound end %d", end) 635 | } 636 | 637 | if end > len(value) { 638 | end = len(value) 639 | } 640 | } 641 | if start > end { 642 | return nil, 0, fmt.Errorf("wrong array range start %d, end %d", start, end) 643 | } 644 | 645 | return value[start:end], ArrayOperatorAll, nil 646 | } else { 647 | index, err := strconv.Atoi(s) 648 | if err != nil { 649 | return nil, 0, err 650 | } 651 | 652 | var cv []interface{} 653 | if index >= 0 && index < len(value) { 654 | cv = append(cv, value[index]) 655 | } 656 | 657 | return cv, ArrayOperatorAll, nil 658 | } 659 | } 660 | } 661 | 662 | func isArray(v interface{}) bool { 663 | switch v.(type) { 664 | case []interface{}: 665 | return true 666 | default: 667 | return false 668 | } 669 | } 670 | 671 | func isMap(v interface{}) bool { 672 | switch v.(type) { 673 | case map[string]interface{}: 674 | return true 675 | default: 676 | return false 677 | } 678 | } 679 | -------------------------------------------------------------------------------- /visitor/parser/EventRule.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '(' 4 | ')' 5 | 'and' 6 | 'or' 7 | null 8 | null 9 | '!=' 10 | '>' 11 | '<' 12 | '>=' 13 | '<=' 14 | 'contains' 15 | 'not contains' 16 | 'in' 17 | 'not in' 18 | 'like' 19 | 'not like' 20 | 'regex' 21 | 'not regex' 22 | 'exists' 23 | 'not exists' 24 | ',' 25 | null 26 | null 27 | null 28 | null 29 | null 30 | 31 | token symbolic names: 32 | null 33 | null 34 | null 35 | AND 36 | OR 37 | NOT 38 | EQU 39 | NEQ 40 | GT 41 | LT 42 | GTE 43 | LTE 44 | CONTAINS 45 | NOTCONTAINS 46 | IN 47 | NOTIN 48 | LIKE 49 | NOTLIKE 50 | REGEX 51 | NOTREGEX 52 | EXISTS 53 | NOTEXISTS 54 | COMMA 55 | NUMBER 56 | BOOLEAN 57 | STRING 58 | VAR 59 | WHITESPACE 60 | 61 | rule names: 62 | start 63 | expression 64 | 65 | 66 | atn: 67 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 29, 56, 4, 2, 9, 2, 4, 3, 9, 3, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 3, 32, 10, 3, 12, 3, 14, 3, 35, 11, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 46, 10, 3, 3, 3, 3, 3, 3, 3, 7, 3, 51, 10, 3, 12, 3, 14, 3, 54, 11, 3, 3, 3, 2, 3, 4, 4, 2, 4, 2, 10, 3, 2, 8, 13, 4, 2, 25, 25, 27, 27, 3, 2, 8, 9, 3, 2, 14, 15, 3, 2, 16, 17, 3, 2, 18, 21, 3, 2, 22, 23, 3, 2, 5, 6, 2, 64, 2, 6, 3, 2, 2, 2, 4, 45, 3, 2, 2, 2, 6, 7, 5, 4, 3, 2, 7, 8, 7, 2, 2, 3, 8, 3, 3, 2, 2, 2, 9, 10, 8, 3, 1, 2, 10, 11, 7, 7, 2, 2, 11, 46, 5, 4, 3, 12, 12, 13, 7, 3, 2, 2, 13, 14, 5, 4, 3, 2, 14, 15, 7, 4, 2, 2, 15, 46, 3, 2, 2, 2, 16, 17, 7, 28, 2, 2, 17, 18, 9, 2, 2, 2, 18, 46, 9, 3, 2, 2, 19, 20, 7, 28, 2, 2, 20, 21, 9, 4, 2, 2, 21, 46, 7, 26, 2, 2, 22, 23, 7, 28, 2, 2, 23, 24, 9, 5, 2, 2, 24, 46, 9, 3, 2, 2, 25, 26, 7, 28, 2, 2, 26, 27, 9, 6, 2, 2, 27, 28, 7, 3, 2, 2, 28, 33, 9, 3, 2, 2, 29, 30, 7, 24, 2, 2, 30, 32, 9, 3, 2, 2, 31, 29, 3, 2, 2, 2, 32, 35, 3, 2, 2, 2, 33, 31, 3, 2, 2, 2, 33, 34, 3, 2, 2, 2, 34, 36, 3, 2, 2, 2, 35, 33, 3, 2, 2, 2, 36, 46, 7, 4, 2, 2, 37, 38, 7, 28, 2, 2, 38, 39, 9, 7, 2, 2, 39, 46, 7, 27, 2, 2, 40, 41, 7, 28, 2, 2, 41, 46, 9, 8, 2, 2, 42, 46, 7, 28, 2, 2, 43, 44, 7, 7, 2, 2, 44, 46, 7, 28, 2, 2, 45, 9, 3, 2, 2, 2, 45, 12, 3, 2, 2, 2, 45, 16, 3, 2, 2, 2, 45, 19, 3, 2, 2, 2, 45, 22, 3, 2, 2, 2, 45, 25, 3, 2, 2, 2, 45, 37, 3, 2, 2, 2, 45, 40, 3, 2, 2, 2, 45, 42, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 46, 52, 3, 2, 2, 2, 47, 48, 12, 13, 2, 2, 48, 49, 9, 9, 2, 2, 49, 51, 5, 4, 3, 14, 50, 47, 3, 2, 2, 2, 51, 54, 3, 2, 2, 2, 52, 50, 3, 2, 2, 2, 52, 53, 3, 2, 2, 2, 53, 5, 3, 2, 2, 2, 54, 52, 3, 2, 2, 2, 5, 33, 45, 52] -------------------------------------------------------------------------------- /visitor/parser/EventRule.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | AND=3 4 | OR=4 5 | NOT=5 6 | EQU=6 7 | NEQ=7 8 | GT=8 9 | LT=9 10 | GTE=10 11 | LTE=11 12 | CONTAINS=12 13 | NOTCONTAINS=13 14 | IN=14 15 | NOTIN=15 16 | LIKE=16 17 | NOTLIKE=17 18 | REGEX=18 19 | NOTREGEX=19 20 | EXISTS=20 21 | NOTEXISTS=21 22 | COMMA=22 23 | NUMBER=23 24 | BOOLEAN=24 25 | STRING=25 26 | VAR=26 27 | WHITESPACE=27 28 | '('=1 29 | ')'=2 30 | 'and'=3 31 | 'or'=4 32 | '!='=7 33 | '>'=8 34 | '<'=9 35 | '>='=10 36 | '<='=11 37 | 'contains'=12 38 | 'not contains'=13 39 | 'in'=14 40 | 'not in'=15 41 | 'like'=16 42 | 'not like'=17 43 | 'regex'=18 44 | 'not regex'=19 45 | 'exists'=20 46 | 'not exists'=21 47 | ','=22 48 | -------------------------------------------------------------------------------- /visitor/parser/EventRuleLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '(' 4 | ')' 5 | 'and' 6 | 'or' 7 | null 8 | null 9 | '!=' 10 | '>' 11 | '<' 12 | '>=' 13 | '<=' 14 | 'contains' 15 | 'not contains' 16 | 'in' 17 | 'not in' 18 | 'like' 19 | 'not like' 20 | 'regex' 21 | 'not regex' 22 | 'exists' 23 | 'not exists' 24 | ',' 25 | null 26 | null 27 | null 28 | null 29 | null 30 | 31 | token symbolic names: 32 | null 33 | null 34 | null 35 | AND 36 | OR 37 | NOT 38 | EQU 39 | NEQ 40 | GT 41 | LT 42 | GTE 43 | LTE 44 | CONTAINS 45 | NOTCONTAINS 46 | IN 47 | NOTIN 48 | LIKE 49 | NOTLIKE 50 | REGEX 51 | NOTREGEX 52 | EXISTS 53 | NOTEXISTS 54 | COMMA 55 | NUMBER 56 | BOOLEAN 57 | STRING 58 | VAR 59 | WHITESPACE 60 | 61 | rule names: 62 | T__0 63 | T__1 64 | AND 65 | OR 66 | NOT 67 | EQU 68 | NEQ 69 | GT 70 | LT 71 | GTE 72 | LTE 73 | CONTAINS 74 | NOTCONTAINS 75 | IN 76 | NOTIN 77 | LIKE 78 | NOTLIKE 79 | REGEX 80 | NOTREGEX 81 | EXISTS 82 | NOTEXISTS 83 | COMMA 84 | NUMBER 85 | BOOLEAN 86 | STRING 87 | VAR 88 | WHITESPACE 89 | ESC 90 | 91 | channel names: 92 | DEFAULT_TOKEN_CHANNEL 93 | HIDDEN 94 | 95 | mode names: 96 | DEFAULT_MODE 97 | 98 | atn: 99 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 29, 318, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 75, 10, 6, 3, 7, 3, 7, 3, 7, 5, 7, 80, 10, 7, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 5, 24, 178, 10, 24, 3, 24, 6, 24, 181, 10, 24, 13, 24, 14, 24, 182, 3, 24, 3, 24, 6, 24, 187, 10, 24, 13, 24, 14, 24, 188, 5, 24, 191, 10, 24, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 5, 25, 220, 10, 25, 3, 26, 3, 26, 3, 26, 7, 26, 225, 10, 26, 12, 26, 14, 26, 228, 11, 26, 3, 26, 3, 26, 3, 27, 3, 27, 7, 27, 234, 10, 27, 12, 27, 14, 27, 237, 11, 27, 3, 27, 3, 27, 3, 27, 6, 27, 242, 10, 27, 13, 27, 14, 27, 243, 3, 27, 6, 27, 247, 10, 27, 13, 27, 14, 27, 248, 5, 27, 251, 10, 27, 3, 27, 3, 27, 6, 27, 255, 10, 27, 13, 27, 14, 27, 256, 5, 27, 259, 10, 27, 5, 27, 261, 10, 27, 3, 27, 5, 27, 264, 10, 27, 3, 27, 3, 27, 3, 27, 7, 27, 269, 10, 27, 12, 27, 14, 27, 272, 11, 27, 3, 27, 3, 27, 3, 27, 6, 27, 277, 10, 27, 13, 27, 14, 27, 278, 3, 27, 6, 27, 282, 10, 27, 13, 27, 14, 27, 283, 5, 27, 286, 10, 27, 3, 27, 3, 27, 6, 27, 290, 10, 27, 13, 27, 14, 27, 291, 5, 27, 294, 10, 27, 5, 27, 296, 10, 27, 3, 27, 5, 27, 299, 10, 27, 3, 27, 5, 27, 302, 10, 27, 7, 27, 304, 10, 27, 12, 27, 14, 27, 307, 11, 27, 3, 28, 3, 28, 3, 28, 3, 28, 3, 29, 3, 29, 3, 29, 3, 29, 5, 29, 317, 10, 29, 3, 226, 2, 30, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 24, 47, 25, 49, 26, 51, 27, 53, 28, 55, 29, 57, 2, 3, 2, 7, 3, 2, 47, 47, 3, 2, 50, 59, 5, 2, 67, 92, 97, 97, 99, 124, 7, 2, 47, 47, 50, 59, 67, 92, 97, 97, 99, 124, 5, 2, 11, 12, 15, 15, 34, 34, 2, 350, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 3, 59, 3, 2, 2, 2, 5, 61, 3, 2, 2, 2, 7, 63, 3, 2, 2, 2, 9, 67, 3, 2, 2, 2, 11, 74, 3, 2, 2, 2, 13, 79, 3, 2, 2, 2, 15, 81, 3, 2, 2, 2, 17, 84, 3, 2, 2, 2, 19, 86, 3, 2, 2, 2, 21, 88, 3, 2, 2, 2, 23, 91, 3, 2, 2, 2, 25, 94, 3, 2, 2, 2, 27, 103, 3, 2, 2, 2, 29, 116, 3, 2, 2, 2, 31, 119, 3, 2, 2, 2, 33, 126, 3, 2, 2, 2, 35, 131, 3, 2, 2, 2, 37, 140, 3, 2, 2, 2, 39, 146, 3, 2, 2, 2, 41, 156, 3, 2, 2, 2, 43, 163, 3, 2, 2, 2, 45, 174, 3, 2, 2, 2, 47, 177, 3, 2, 2, 2, 49, 219, 3, 2, 2, 2, 51, 221, 3, 2, 2, 2, 53, 231, 3, 2, 2, 2, 55, 308, 3, 2, 2, 2, 57, 316, 3, 2, 2, 2, 59, 60, 7, 42, 2, 2, 60, 4, 3, 2, 2, 2, 61, 62, 7, 43, 2, 2, 62, 6, 3, 2, 2, 2, 63, 64, 7, 99, 2, 2, 64, 65, 7, 112, 2, 2, 65, 66, 7, 102, 2, 2, 66, 8, 3, 2, 2, 2, 67, 68, 7, 113, 2, 2, 68, 69, 7, 116, 2, 2, 69, 10, 3, 2, 2, 2, 70, 71, 7, 112, 2, 2, 71, 72, 7, 113, 2, 2, 72, 75, 7, 118, 2, 2, 73, 75, 7, 35, 2, 2, 74, 70, 3, 2, 2, 2, 74, 73, 3, 2, 2, 2, 75, 12, 3, 2, 2, 2, 76, 80, 7, 63, 2, 2, 77, 78, 7, 63, 2, 2, 78, 80, 7, 63, 2, 2, 79, 76, 3, 2, 2, 2, 79, 77, 3, 2, 2, 2, 80, 14, 3, 2, 2, 2, 81, 82, 7, 35, 2, 2, 82, 83, 7, 63, 2, 2, 83, 16, 3, 2, 2, 2, 84, 85, 7, 64, 2, 2, 85, 18, 3, 2, 2, 2, 86, 87, 7, 62, 2, 2, 87, 20, 3, 2, 2, 2, 88, 89, 7, 64, 2, 2, 89, 90, 7, 63, 2, 2, 90, 22, 3, 2, 2, 2, 91, 92, 7, 62, 2, 2, 92, 93, 7, 63, 2, 2, 93, 24, 3, 2, 2, 2, 94, 95, 7, 101, 2, 2, 95, 96, 7, 113, 2, 2, 96, 97, 7, 112, 2, 2, 97, 98, 7, 118, 2, 2, 98, 99, 7, 99, 2, 2, 99, 100, 7, 107, 2, 2, 100, 101, 7, 112, 2, 2, 101, 102, 7, 117, 2, 2, 102, 26, 3, 2, 2, 2, 103, 104, 7, 112, 2, 2, 104, 105, 7, 113, 2, 2, 105, 106, 7, 118, 2, 2, 106, 107, 7, 34, 2, 2, 107, 108, 7, 101, 2, 2, 108, 109, 7, 113, 2, 2, 109, 110, 7, 112, 2, 2, 110, 111, 7, 118, 2, 2, 111, 112, 7, 99, 2, 2, 112, 113, 7, 107, 2, 2, 113, 114, 7, 112, 2, 2, 114, 115, 7, 117, 2, 2, 115, 28, 3, 2, 2, 2, 116, 117, 7, 107, 2, 2, 117, 118, 7, 112, 2, 2, 118, 30, 3, 2, 2, 2, 119, 120, 7, 112, 2, 2, 120, 121, 7, 113, 2, 2, 121, 122, 7, 118, 2, 2, 122, 123, 7, 34, 2, 2, 123, 124, 7, 107, 2, 2, 124, 125, 7, 112, 2, 2, 125, 32, 3, 2, 2, 2, 126, 127, 7, 110, 2, 2, 127, 128, 7, 107, 2, 2, 128, 129, 7, 109, 2, 2, 129, 130, 7, 103, 2, 2, 130, 34, 3, 2, 2, 2, 131, 132, 7, 112, 2, 2, 132, 133, 7, 113, 2, 2, 133, 134, 7, 118, 2, 2, 134, 135, 7, 34, 2, 2, 135, 136, 7, 110, 2, 2, 136, 137, 7, 107, 2, 2, 137, 138, 7, 109, 2, 2, 138, 139, 7, 103, 2, 2, 139, 36, 3, 2, 2, 2, 140, 141, 7, 116, 2, 2, 141, 142, 7, 103, 2, 2, 142, 143, 7, 105, 2, 2, 143, 144, 7, 103, 2, 2, 144, 145, 7, 122, 2, 2, 145, 38, 3, 2, 2, 2, 146, 147, 7, 112, 2, 2, 147, 148, 7, 113, 2, 2, 148, 149, 7, 118, 2, 2, 149, 150, 7, 34, 2, 2, 150, 151, 7, 116, 2, 2, 151, 152, 7, 103, 2, 2, 152, 153, 7, 105, 2, 2, 153, 154, 7, 103, 2, 2, 154, 155, 7, 122, 2, 2, 155, 40, 3, 2, 2, 2, 156, 157, 7, 103, 2, 2, 157, 158, 7, 122, 2, 2, 158, 159, 7, 107, 2, 2, 159, 160, 7, 117, 2, 2, 160, 161, 7, 118, 2, 2, 161, 162, 7, 117, 2, 2, 162, 42, 3, 2, 2, 2, 163, 164, 7, 112, 2, 2, 164, 165, 7, 113, 2, 2, 165, 166, 7, 118, 2, 2, 166, 167, 7, 34, 2, 2, 167, 168, 7, 103, 2, 2, 168, 169, 7, 122, 2, 2, 169, 170, 7, 107, 2, 2, 170, 171, 7, 117, 2, 2, 171, 172, 7, 118, 2, 2, 172, 173, 7, 117, 2, 2, 173, 44, 3, 2, 2, 2, 174, 175, 7, 46, 2, 2, 175, 46, 3, 2, 2, 2, 176, 178, 9, 2, 2, 2, 177, 176, 3, 2, 2, 2, 177, 178, 3, 2, 2, 2, 178, 180, 3, 2, 2, 2, 179, 181, 9, 3, 2, 2, 180, 179, 3, 2, 2, 2, 181, 182, 3, 2, 2, 2, 182, 180, 3, 2, 2, 2, 182, 183, 3, 2, 2, 2, 183, 190, 3, 2, 2, 2, 184, 186, 7, 48, 2, 2, 185, 187, 9, 3, 2, 2, 186, 185, 3, 2, 2, 2, 187, 188, 3, 2, 2, 2, 188, 186, 3, 2, 2, 2, 188, 189, 3, 2, 2, 2, 189, 191, 3, 2, 2, 2, 190, 184, 3, 2, 2, 2, 190, 191, 3, 2, 2, 2, 191, 48, 3, 2, 2, 2, 192, 193, 7, 86, 2, 2, 193, 194, 7, 116, 2, 2, 194, 195, 7, 119, 2, 2, 195, 220, 7, 103, 2, 2, 196, 197, 7, 86, 2, 2, 197, 198, 7, 84, 2, 2, 198, 199, 7, 87, 2, 2, 199, 220, 7, 71, 2, 2, 200, 201, 7, 118, 2, 2, 201, 202, 7, 116, 2, 2, 202, 203, 7, 119, 2, 2, 203, 220, 7, 103, 2, 2, 204, 205, 7, 72, 2, 2, 205, 206, 7, 99, 2, 2, 206, 207, 7, 110, 2, 2, 207, 208, 7, 117, 2, 2, 208, 220, 7, 103, 2, 2, 209, 210, 7, 72, 2, 2, 210, 211, 7, 67, 2, 2, 211, 212, 7, 78, 2, 2, 212, 213, 7, 85, 2, 2, 213, 220, 7, 71, 2, 2, 214, 215, 7, 104, 2, 2, 215, 216, 7, 99, 2, 2, 216, 217, 7, 110, 2, 2, 217, 218, 7, 117, 2, 2, 218, 220, 7, 103, 2, 2, 219, 192, 3, 2, 2, 2, 219, 196, 3, 2, 2, 2, 219, 200, 3, 2, 2, 2, 219, 204, 3, 2, 2, 2, 219, 209, 3, 2, 2, 2, 219, 214, 3, 2, 2, 2, 220, 50, 3, 2, 2, 2, 221, 226, 7, 36, 2, 2, 222, 225, 5, 57, 29, 2, 223, 225, 11, 2, 2, 2, 224, 222, 3, 2, 2, 2, 224, 223, 3, 2, 2, 2, 225, 228, 3, 2, 2, 2, 226, 227, 3, 2, 2, 2, 226, 224, 3, 2, 2, 2, 227, 229, 3, 2, 2, 2, 228, 226, 3, 2, 2, 2, 229, 230, 7, 36, 2, 2, 230, 52, 3, 2, 2, 2, 231, 235, 9, 4, 2, 2, 232, 234, 9, 5, 2, 2, 233, 232, 3, 2, 2, 2, 234, 237, 3, 2, 2, 2, 235, 233, 3, 2, 2, 2, 235, 236, 3, 2, 2, 2, 236, 263, 3, 2, 2, 2, 237, 235, 3, 2, 2, 2, 238, 260, 7, 93, 2, 2, 239, 261, 7, 44, 2, 2, 240, 242, 9, 3, 2, 2, 241, 240, 3, 2, 2, 2, 242, 243, 3, 2, 2, 2, 243, 241, 3, 2, 2, 2, 243, 244, 3, 2, 2, 2, 244, 261, 3, 2, 2, 2, 245, 247, 9, 3, 2, 2, 246, 245, 3, 2, 2, 2, 247, 248, 3, 2, 2, 2, 248, 246, 3, 2, 2, 2, 248, 249, 3, 2, 2, 2, 249, 251, 3, 2, 2, 2, 250, 246, 3, 2, 2, 2, 250, 251, 3, 2, 2, 2, 251, 252, 3, 2, 2, 2, 252, 258, 7, 60, 2, 2, 253, 255, 9, 3, 2, 2, 254, 253, 3, 2, 2, 2, 255, 256, 3, 2, 2, 2, 256, 254, 3, 2, 2, 2, 256, 257, 3, 2, 2, 2, 257, 259, 3, 2, 2, 2, 258, 254, 3, 2, 2, 2, 258, 259, 3, 2, 2, 2, 259, 261, 3, 2, 2, 2, 260, 239, 3, 2, 2, 2, 260, 241, 3, 2, 2, 2, 260, 250, 3, 2, 2, 2, 261, 262, 3, 2, 2, 2, 262, 264, 7, 95, 2, 2, 263, 238, 3, 2, 2, 2, 263, 264, 3, 2, 2, 2, 264, 305, 3, 2, 2, 2, 265, 266, 7, 48, 2, 2, 266, 270, 9, 4, 2, 2, 267, 269, 9, 5, 2, 2, 268, 267, 3, 2, 2, 2, 269, 272, 3, 2, 2, 2, 270, 268, 3, 2, 2, 2, 270, 271, 3, 2, 2, 2, 271, 298, 3, 2, 2, 2, 272, 270, 3, 2, 2, 2, 273, 295, 7, 93, 2, 2, 274, 296, 7, 44, 2, 2, 275, 277, 9, 3, 2, 2, 276, 275, 3, 2, 2, 2, 277, 278, 3, 2, 2, 2, 278, 276, 3, 2, 2, 2, 278, 279, 3, 2, 2, 2, 279, 296, 3, 2, 2, 2, 280, 282, 9, 3, 2, 2, 281, 280, 3, 2, 2, 2, 282, 283, 3, 2, 2, 2, 283, 281, 3, 2, 2, 2, 283, 284, 3, 2, 2, 2, 284, 286, 3, 2, 2, 2, 285, 281, 3, 2, 2, 2, 285, 286, 3, 2, 2, 2, 286, 287, 3, 2, 2, 2, 287, 293, 7, 60, 2, 2, 288, 290, 9, 3, 2, 2, 289, 288, 3, 2, 2, 2, 290, 291, 3, 2, 2, 2, 291, 289, 3, 2, 2, 2, 291, 292, 3, 2, 2, 2, 292, 294, 3, 2, 2, 2, 293, 289, 3, 2, 2, 2, 293, 294, 3, 2, 2, 2, 294, 296, 3, 2, 2, 2, 295, 274, 3, 2, 2, 2, 295, 276, 3, 2, 2, 2, 295, 285, 3, 2, 2, 2, 296, 297, 3, 2, 2, 2, 297, 299, 7, 95, 2, 2, 298, 273, 3, 2, 2, 2, 298, 299, 3, 2, 2, 2, 299, 301, 3, 2, 2, 2, 300, 302, 7, 48, 2, 2, 301, 300, 3, 2, 2, 2, 301, 302, 3, 2, 2, 2, 302, 304, 3, 2, 2, 2, 303, 265, 3, 2, 2, 2, 304, 307, 3, 2, 2, 2, 305, 303, 3, 2, 2, 2, 305, 306, 3, 2, 2, 2, 306, 54, 3, 2, 2, 2, 307, 305, 3, 2, 2, 2, 308, 309, 9, 6, 2, 2, 309, 310, 3, 2, 2, 2, 310, 311, 8, 28, 2, 2, 311, 56, 3, 2, 2, 2, 312, 313, 7, 94, 2, 2, 313, 317, 7, 36, 2, 2, 314, 315, 7, 94, 2, 2, 315, 317, 7, 94, 2, 2, 316, 312, 3, 2, 2, 2, 316, 314, 3, 2, 2, 2, 317, 58, 3, 2, 2, 2, 31, 2, 74, 79, 177, 182, 188, 190, 219, 224, 226, 235, 243, 248, 250, 256, 258, 260, 263, 270, 278, 283, 285, 291, 293, 295, 298, 301, 305, 316, 3, 8, 2, 2] -------------------------------------------------------------------------------- /visitor/parser/EventRuleLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | AND=3 4 | OR=4 5 | NOT=5 6 | EQU=6 7 | NEQ=7 8 | GT=8 9 | LT=9 10 | GTE=10 11 | LTE=11 12 | CONTAINS=12 13 | NOTCONTAINS=13 14 | IN=14 15 | NOTIN=15 16 | LIKE=16 17 | NOTLIKE=17 18 | REGEX=18 19 | NOTREGEX=19 20 | EXISTS=20 21 | NOTEXISTS=21 22 | COMMA=22 23 | NUMBER=23 24 | BOOLEAN=24 25 | STRING=25 26 | VAR=26 27 | WHITESPACE=27 28 | '('=1 29 | ')'=2 30 | 'and'=3 31 | 'or'=4 32 | '!='=7 33 | '>'=8 34 | '<'=9 35 | '>='=10 36 | '<='=11 37 | 'contains'=12 38 | 'not contains'=13 39 | 'in'=14 40 | 'not in'=15 41 | 'like'=16 42 | 'not like'=17 43 | 'regex'=18 44 | 'not regex'=19 45 | 'exists'=20 46 | 'not exists'=21 47 | ','=22 48 | -------------------------------------------------------------------------------- /visitor/parser/eventrule_base_visitor.go: -------------------------------------------------------------------------------- 1 | // Code generated from EventRule.g4 by ANTLR 4.7.1. DO NOT EDIT. 2 | 3 | package parser // EventRule 4 | 5 | import "github.com/antlr/antlr4/runtime/Go/antlr" 6 | 7 | type BaseEventRuleVisitor struct { 8 | *antlr.BaseParseTreeVisitor 9 | } 10 | 11 | func (v *BaseEventRuleVisitor) VisitStart(ctx *StartContext) interface{} { 12 | return v.VisitChildren(ctx) 13 | } 14 | 15 | func (v *BaseEventRuleVisitor) VisitInOrNot(ctx *InOrNotContext) interface{} { 16 | return v.VisitChildren(ctx) 17 | } 18 | 19 | func (v *BaseEventRuleVisitor) VisitRegexOrNot(ctx *RegexOrNotContext) interface{} { 20 | return v.VisitChildren(ctx) 21 | } 22 | 23 | func (v *BaseEventRuleVisitor) VisitNot(ctx *NotContext) interface{} { 24 | return v.VisitChildren(ctx) 25 | } 26 | 27 | func (v *BaseEventRuleVisitor) VisitParenthesis(ctx *ParenthesisContext) interface{} { 28 | return v.VisitChildren(ctx) 29 | } 30 | 31 | func (v *BaseEventRuleVisitor) VisitBoolCompare(ctx *BoolCompareContext) interface{} { 32 | return v.VisitChildren(ctx) 33 | } 34 | 35 | func (v *BaseEventRuleVisitor) VisitVariable(ctx *VariableContext) interface{} { 36 | return v.VisitChildren(ctx) 37 | } 38 | 39 | func (v *BaseEventRuleVisitor) VisitNotVariable(ctx *NotVariableContext) interface{} { 40 | return v.VisitChildren(ctx) 41 | } 42 | 43 | func (v *BaseEventRuleVisitor) VisitCompare(ctx *CompareContext) interface{} { 44 | return v.VisitChildren(ctx) 45 | } 46 | 47 | func (v *BaseEventRuleVisitor) VisitExistsOrNot(ctx *ExistsOrNotContext) interface{} { 48 | return v.VisitChildren(ctx) 49 | } 50 | 51 | func (v *BaseEventRuleVisitor) VisitAndOr(ctx *AndOrContext) interface{} { 52 | return v.VisitChildren(ctx) 53 | } 54 | 55 | func (v *BaseEventRuleVisitor) VisitContainsOrNot(ctx *ContainsOrNotContext) interface{} { 56 | return v.VisitChildren(ctx) 57 | } 58 | -------------------------------------------------------------------------------- /visitor/parser/eventrule_lexer.go: -------------------------------------------------------------------------------- 1 | // Code generated from EventRule.g4 by ANTLR 4.7.1. DO NOT EDIT. 2 | 3 | package parser 4 | 5 | import ( 6 | "fmt" 7 | "unicode" 8 | 9 | "github.com/antlr/antlr4/runtime/Go/antlr" 10 | ) 11 | 12 | // Suppress unused import error 13 | var _ = fmt.Printf 14 | var _ = unicode.IsLetter 15 | 16 | var serializedLexerAtn = []uint16{ 17 | 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 29, 318, 18 | 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 19 | 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 20 | 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 21 | 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 22 | 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 23 | 28, 4, 29, 9, 29, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 24 | 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 75, 10, 6, 3, 7, 3, 7, 3, 7, 25 | 5, 7, 80, 10, 7, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 26 | 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 27 | 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 28 | 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 29 | 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 30 | 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 31 | 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 32 | 20, 3, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 33 | 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 34 | 22, 3, 23, 3, 23, 3, 24, 5, 24, 178, 10, 24, 3, 24, 6, 24, 181, 10, 24, 35 | 13, 24, 14, 24, 182, 3, 24, 3, 24, 6, 24, 187, 10, 24, 13, 24, 14, 24, 36 | 188, 5, 24, 191, 10, 24, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 37 | 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 38 | 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 3, 25, 5, 25, 39 | 220, 10, 25, 3, 26, 3, 26, 3, 26, 7, 26, 225, 10, 26, 12, 26, 14, 26, 228, 40 | 11, 26, 3, 26, 3, 26, 3, 27, 3, 27, 7, 27, 234, 10, 27, 12, 27, 14, 27, 41 | 237, 11, 27, 3, 27, 3, 27, 3, 27, 6, 27, 242, 10, 27, 13, 27, 14, 27, 243, 42 | 3, 27, 6, 27, 247, 10, 27, 13, 27, 14, 27, 248, 5, 27, 251, 10, 27, 3, 43 | 27, 3, 27, 6, 27, 255, 10, 27, 13, 27, 14, 27, 256, 5, 27, 259, 10, 27, 44 | 5, 27, 261, 10, 27, 3, 27, 5, 27, 264, 10, 27, 3, 27, 3, 27, 3, 27, 7, 45 | 27, 269, 10, 27, 12, 27, 14, 27, 272, 11, 27, 3, 27, 3, 27, 3, 27, 6, 27, 46 | 277, 10, 27, 13, 27, 14, 27, 278, 3, 27, 6, 27, 282, 10, 27, 13, 27, 14, 47 | 27, 283, 5, 27, 286, 10, 27, 3, 27, 3, 27, 6, 27, 290, 10, 27, 13, 27, 48 | 14, 27, 291, 5, 27, 294, 10, 27, 5, 27, 296, 10, 27, 3, 27, 5, 27, 299, 49 | 10, 27, 3, 27, 5, 27, 302, 10, 27, 7, 27, 304, 10, 27, 12, 27, 14, 27, 50 | 307, 11, 27, 3, 28, 3, 28, 3, 28, 3, 28, 3, 29, 3, 29, 3, 29, 3, 29, 5, 51 | 29, 317, 10, 29, 3, 226, 2, 30, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 52 | 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 53 | 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 24, 47, 25, 49, 26, 51, 54 | 27, 53, 28, 55, 29, 57, 2, 3, 2, 7, 3, 2, 47, 47, 3, 2, 50, 59, 5, 2, 67, 55 | 92, 97, 97, 99, 124, 7, 2, 47, 47, 50, 59, 67, 92, 97, 97, 99, 124, 5, 56 | 2, 11, 12, 15, 15, 34, 34, 2, 350, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 57 | 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 58 | 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 59 | 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 60 | 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 61 | 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 62 | 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 63 | 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 3, 59, 3, 2, 2, 2, 5, 61, 3, 2, 2, 64 | 2, 7, 63, 3, 2, 2, 2, 9, 67, 3, 2, 2, 2, 11, 74, 3, 2, 2, 2, 13, 79, 3, 65 | 2, 2, 2, 15, 81, 3, 2, 2, 2, 17, 84, 3, 2, 2, 2, 19, 86, 3, 2, 2, 2, 21, 66 | 88, 3, 2, 2, 2, 23, 91, 3, 2, 2, 2, 25, 94, 3, 2, 2, 2, 27, 103, 3, 2, 67 | 2, 2, 29, 116, 3, 2, 2, 2, 31, 119, 3, 2, 2, 2, 33, 126, 3, 2, 2, 2, 35, 68 | 131, 3, 2, 2, 2, 37, 140, 3, 2, 2, 2, 39, 146, 3, 2, 2, 2, 41, 156, 3, 69 | 2, 2, 2, 43, 163, 3, 2, 2, 2, 45, 174, 3, 2, 2, 2, 47, 177, 3, 2, 2, 2, 70 | 49, 219, 3, 2, 2, 2, 51, 221, 3, 2, 2, 2, 53, 231, 3, 2, 2, 2, 55, 308, 71 | 3, 2, 2, 2, 57, 316, 3, 2, 2, 2, 59, 60, 7, 42, 2, 2, 60, 4, 3, 2, 2, 2, 72 | 61, 62, 7, 43, 2, 2, 62, 6, 3, 2, 2, 2, 63, 64, 7, 99, 2, 2, 64, 65, 7, 73 | 112, 2, 2, 65, 66, 7, 102, 2, 2, 66, 8, 3, 2, 2, 2, 67, 68, 7, 113, 2, 74 | 2, 68, 69, 7, 116, 2, 2, 69, 10, 3, 2, 2, 2, 70, 71, 7, 112, 2, 2, 71, 75 | 72, 7, 113, 2, 2, 72, 75, 7, 118, 2, 2, 73, 75, 7, 35, 2, 2, 74, 70, 3, 76 | 2, 2, 2, 74, 73, 3, 2, 2, 2, 75, 12, 3, 2, 2, 2, 76, 80, 7, 63, 2, 2, 77, 77 | 78, 7, 63, 2, 2, 78, 80, 7, 63, 2, 2, 79, 76, 3, 2, 2, 2, 79, 77, 3, 2, 78 | 2, 2, 80, 14, 3, 2, 2, 2, 81, 82, 7, 35, 2, 2, 82, 83, 7, 63, 2, 2, 83, 79 | 16, 3, 2, 2, 2, 84, 85, 7, 64, 2, 2, 85, 18, 3, 2, 2, 2, 86, 87, 7, 62, 80 | 2, 2, 87, 20, 3, 2, 2, 2, 88, 89, 7, 64, 2, 2, 89, 90, 7, 63, 2, 2, 90, 81 | 22, 3, 2, 2, 2, 91, 92, 7, 62, 2, 2, 92, 93, 7, 63, 2, 2, 93, 24, 3, 2, 82 | 2, 2, 94, 95, 7, 101, 2, 2, 95, 96, 7, 113, 2, 2, 96, 97, 7, 112, 2, 2, 83 | 97, 98, 7, 118, 2, 2, 98, 99, 7, 99, 2, 2, 99, 100, 7, 107, 2, 2, 100, 84 | 101, 7, 112, 2, 2, 101, 102, 7, 117, 2, 2, 102, 26, 3, 2, 2, 2, 103, 104, 85 | 7, 112, 2, 2, 104, 105, 7, 113, 2, 2, 105, 106, 7, 118, 2, 2, 106, 107, 86 | 7, 34, 2, 2, 107, 108, 7, 101, 2, 2, 108, 109, 7, 113, 2, 2, 109, 110, 87 | 7, 112, 2, 2, 110, 111, 7, 118, 2, 2, 111, 112, 7, 99, 2, 2, 112, 113, 88 | 7, 107, 2, 2, 113, 114, 7, 112, 2, 2, 114, 115, 7, 117, 2, 2, 115, 28, 89 | 3, 2, 2, 2, 116, 117, 7, 107, 2, 2, 117, 118, 7, 112, 2, 2, 118, 30, 3, 90 | 2, 2, 2, 119, 120, 7, 112, 2, 2, 120, 121, 7, 113, 2, 2, 121, 122, 7, 118, 91 | 2, 2, 122, 123, 7, 34, 2, 2, 123, 124, 7, 107, 2, 2, 124, 125, 7, 112, 92 | 2, 2, 125, 32, 3, 2, 2, 2, 126, 127, 7, 110, 2, 2, 127, 128, 7, 107, 2, 93 | 2, 128, 129, 7, 109, 2, 2, 129, 130, 7, 103, 2, 2, 130, 34, 3, 2, 2, 2, 94 | 131, 132, 7, 112, 2, 2, 132, 133, 7, 113, 2, 2, 133, 134, 7, 118, 2, 2, 95 | 134, 135, 7, 34, 2, 2, 135, 136, 7, 110, 2, 2, 136, 137, 7, 107, 2, 2, 96 | 137, 138, 7, 109, 2, 2, 138, 139, 7, 103, 2, 2, 139, 36, 3, 2, 2, 2, 140, 97 | 141, 7, 116, 2, 2, 141, 142, 7, 103, 2, 2, 142, 143, 7, 105, 2, 2, 143, 98 | 144, 7, 103, 2, 2, 144, 145, 7, 122, 2, 2, 145, 38, 3, 2, 2, 2, 146, 147, 99 | 7, 112, 2, 2, 147, 148, 7, 113, 2, 2, 148, 149, 7, 118, 2, 2, 149, 150, 100 | 7, 34, 2, 2, 150, 151, 7, 116, 2, 2, 151, 152, 7, 103, 2, 2, 152, 153, 101 | 7, 105, 2, 2, 153, 154, 7, 103, 2, 2, 154, 155, 7, 122, 2, 2, 155, 40, 102 | 3, 2, 2, 2, 156, 157, 7, 103, 2, 2, 157, 158, 7, 122, 2, 2, 158, 159, 7, 103 | 107, 2, 2, 159, 160, 7, 117, 2, 2, 160, 161, 7, 118, 2, 2, 161, 162, 7, 104 | 117, 2, 2, 162, 42, 3, 2, 2, 2, 163, 164, 7, 112, 2, 2, 164, 165, 7, 113, 105 | 2, 2, 165, 166, 7, 118, 2, 2, 166, 167, 7, 34, 2, 2, 167, 168, 7, 103, 106 | 2, 2, 168, 169, 7, 122, 2, 2, 169, 170, 7, 107, 2, 2, 170, 171, 7, 117, 107 | 2, 2, 171, 172, 7, 118, 2, 2, 172, 173, 7, 117, 2, 2, 173, 44, 3, 2, 2, 108 | 2, 174, 175, 7, 46, 2, 2, 175, 46, 3, 2, 2, 2, 176, 178, 9, 2, 2, 2, 177, 109 | 176, 3, 2, 2, 2, 177, 178, 3, 2, 2, 2, 178, 180, 3, 2, 2, 2, 179, 181, 110 | 9, 3, 2, 2, 180, 179, 3, 2, 2, 2, 181, 182, 3, 2, 2, 2, 182, 180, 3, 2, 111 | 2, 2, 182, 183, 3, 2, 2, 2, 183, 190, 3, 2, 2, 2, 184, 186, 7, 48, 2, 2, 112 | 185, 187, 9, 3, 2, 2, 186, 185, 3, 2, 2, 2, 187, 188, 3, 2, 2, 2, 188, 113 | 186, 3, 2, 2, 2, 188, 189, 3, 2, 2, 2, 189, 191, 3, 2, 2, 2, 190, 184, 114 | 3, 2, 2, 2, 190, 191, 3, 2, 2, 2, 191, 48, 3, 2, 2, 2, 192, 193, 7, 86, 115 | 2, 2, 193, 194, 7, 116, 2, 2, 194, 195, 7, 119, 2, 2, 195, 220, 7, 103, 116 | 2, 2, 196, 197, 7, 86, 2, 2, 197, 198, 7, 84, 2, 2, 198, 199, 7, 87, 2, 117 | 2, 199, 220, 7, 71, 2, 2, 200, 201, 7, 118, 2, 2, 201, 202, 7, 116, 2, 118 | 2, 202, 203, 7, 119, 2, 2, 203, 220, 7, 103, 2, 2, 204, 205, 7, 72, 2, 119 | 2, 205, 206, 7, 99, 2, 2, 206, 207, 7, 110, 2, 2, 207, 208, 7, 117, 2, 120 | 2, 208, 220, 7, 103, 2, 2, 209, 210, 7, 72, 2, 2, 210, 211, 7, 67, 2, 2, 121 | 211, 212, 7, 78, 2, 2, 212, 213, 7, 85, 2, 2, 213, 220, 7, 71, 2, 2, 214, 122 | 215, 7, 104, 2, 2, 215, 216, 7, 99, 2, 2, 216, 217, 7, 110, 2, 2, 217, 123 | 218, 7, 117, 2, 2, 218, 220, 7, 103, 2, 2, 219, 192, 3, 2, 2, 2, 219, 196, 124 | 3, 2, 2, 2, 219, 200, 3, 2, 2, 2, 219, 204, 3, 2, 2, 2, 219, 209, 3, 2, 125 | 2, 2, 219, 214, 3, 2, 2, 2, 220, 50, 3, 2, 2, 2, 221, 226, 7, 36, 2, 2, 126 | 222, 225, 5, 57, 29, 2, 223, 225, 11, 2, 2, 2, 224, 222, 3, 2, 2, 2, 224, 127 | 223, 3, 2, 2, 2, 225, 228, 3, 2, 2, 2, 226, 227, 3, 2, 2, 2, 226, 224, 128 | 3, 2, 2, 2, 227, 229, 3, 2, 2, 2, 228, 226, 3, 2, 2, 2, 229, 230, 7, 36, 129 | 2, 2, 230, 52, 3, 2, 2, 2, 231, 235, 9, 4, 2, 2, 232, 234, 9, 5, 2, 2, 130 | 233, 232, 3, 2, 2, 2, 234, 237, 3, 2, 2, 2, 235, 233, 3, 2, 2, 2, 235, 131 | 236, 3, 2, 2, 2, 236, 263, 3, 2, 2, 2, 237, 235, 3, 2, 2, 2, 238, 260, 132 | 7, 93, 2, 2, 239, 261, 7, 44, 2, 2, 240, 242, 9, 3, 2, 2, 241, 240, 3, 133 | 2, 2, 2, 242, 243, 3, 2, 2, 2, 243, 241, 3, 2, 2, 2, 243, 244, 3, 2, 2, 134 | 2, 244, 261, 3, 2, 2, 2, 245, 247, 9, 3, 2, 2, 246, 245, 3, 2, 2, 2, 247, 135 | 248, 3, 2, 2, 2, 248, 246, 3, 2, 2, 2, 248, 249, 3, 2, 2, 2, 249, 251, 136 | 3, 2, 2, 2, 250, 246, 3, 2, 2, 2, 250, 251, 3, 2, 2, 2, 251, 252, 3, 2, 137 | 2, 2, 252, 258, 7, 60, 2, 2, 253, 255, 9, 3, 2, 2, 254, 253, 3, 2, 2, 2, 138 | 255, 256, 3, 2, 2, 2, 256, 254, 3, 2, 2, 2, 256, 257, 3, 2, 2, 2, 257, 139 | 259, 3, 2, 2, 2, 258, 254, 3, 2, 2, 2, 258, 259, 3, 2, 2, 2, 259, 261, 140 | 3, 2, 2, 2, 260, 239, 3, 2, 2, 2, 260, 241, 3, 2, 2, 2, 260, 250, 3, 2, 141 | 2, 2, 261, 262, 3, 2, 2, 2, 262, 264, 7, 95, 2, 2, 263, 238, 3, 2, 2, 2, 142 | 263, 264, 3, 2, 2, 2, 264, 305, 3, 2, 2, 2, 265, 266, 7, 48, 2, 2, 266, 143 | 270, 9, 4, 2, 2, 267, 269, 9, 5, 2, 2, 268, 267, 3, 2, 2, 2, 269, 272, 144 | 3, 2, 2, 2, 270, 268, 3, 2, 2, 2, 270, 271, 3, 2, 2, 2, 271, 298, 3, 2, 145 | 2, 2, 272, 270, 3, 2, 2, 2, 273, 295, 7, 93, 2, 2, 274, 296, 7, 44, 2, 146 | 2, 275, 277, 9, 3, 2, 2, 276, 275, 3, 2, 2, 2, 277, 278, 3, 2, 2, 2, 278, 147 | 276, 3, 2, 2, 2, 278, 279, 3, 2, 2, 2, 279, 296, 3, 2, 2, 2, 280, 282, 148 | 9, 3, 2, 2, 281, 280, 3, 2, 2, 2, 282, 283, 3, 2, 2, 2, 283, 281, 3, 2, 149 | 2, 2, 283, 284, 3, 2, 2, 2, 284, 286, 3, 2, 2, 2, 285, 281, 3, 2, 2, 2, 150 | 285, 286, 3, 2, 2, 2, 286, 287, 3, 2, 2, 2, 287, 293, 7, 60, 2, 2, 288, 151 | 290, 9, 3, 2, 2, 289, 288, 3, 2, 2, 2, 290, 291, 3, 2, 2, 2, 291, 289, 152 | 3, 2, 2, 2, 291, 292, 3, 2, 2, 2, 292, 294, 3, 2, 2, 2, 293, 289, 3, 2, 153 | 2, 2, 293, 294, 3, 2, 2, 2, 294, 296, 3, 2, 2, 2, 295, 274, 3, 2, 2, 2, 154 | 295, 276, 3, 2, 2, 2, 295, 285, 3, 2, 2, 2, 296, 297, 3, 2, 2, 2, 297, 155 | 299, 7, 95, 2, 2, 298, 273, 3, 2, 2, 2, 298, 299, 3, 2, 2, 2, 299, 301, 156 | 3, 2, 2, 2, 300, 302, 7, 48, 2, 2, 301, 300, 3, 2, 2, 2, 301, 302, 3, 2, 157 | 2, 2, 302, 304, 3, 2, 2, 2, 303, 265, 3, 2, 2, 2, 304, 307, 3, 2, 2, 2, 158 | 305, 303, 3, 2, 2, 2, 305, 306, 3, 2, 2, 2, 306, 54, 3, 2, 2, 2, 307, 305, 159 | 3, 2, 2, 2, 308, 309, 9, 6, 2, 2, 309, 310, 3, 2, 2, 2, 310, 311, 8, 28, 160 | 2, 2, 311, 56, 3, 2, 2, 2, 312, 313, 7, 94, 2, 2, 313, 317, 7, 36, 2, 2, 161 | 314, 315, 7, 94, 2, 2, 315, 317, 7, 94, 2, 2, 316, 312, 3, 2, 2, 2, 316, 162 | 314, 3, 2, 2, 2, 317, 58, 3, 2, 2, 2, 31, 2, 74, 79, 177, 182, 188, 190, 163 | 219, 224, 226, 235, 243, 248, 250, 256, 258, 260, 263, 270, 278, 283, 285, 164 | 291, 293, 295, 298, 301, 305, 316, 3, 8, 2, 2, 165 | } 166 | 167 | var lexerDeserializer = antlr.NewATNDeserializer(nil) 168 | var lexerAtn = lexerDeserializer.DeserializeFromUInt16(serializedLexerAtn) 169 | 170 | var lexerChannelNames = []string{ 171 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN", 172 | } 173 | 174 | var lexerModeNames = []string{ 175 | "DEFAULT_MODE", 176 | } 177 | 178 | var lexerLiteralNames = []string{ 179 | "", "'('", "')'", "'and'", "'or'", "", "", "'!='", "'>'", "'<'", "'>='", 180 | "'<='", "'contains'", "'not contains'", "'in'", "'not in'", "'like'", "'not like'", 181 | "'regex'", "'not regex'", "'exists'", "'not exists'", "','", 182 | } 183 | 184 | var lexerSymbolicNames = []string{ 185 | "", "", "", "AND", "OR", "NOT", "EQU", "NEQ", "GT", "LT", "GTE", "LTE", 186 | "CONTAINS", "NOTCONTAINS", "IN", "NOTIN", "LIKE", "NOTLIKE", "REGEX", "NOTREGEX", 187 | "EXISTS", "NOTEXISTS", "COMMA", "NUMBER", "BOOLEAN", "STRING", "VAR", "WHITESPACE", 188 | } 189 | 190 | var lexerRuleNames = []string{ 191 | "T__0", "T__1", "AND", "OR", "NOT", "EQU", "NEQ", "GT", "LT", "GTE", "LTE", 192 | "CONTAINS", "NOTCONTAINS", "IN", "NOTIN", "LIKE", "NOTLIKE", "REGEX", "NOTREGEX", 193 | "EXISTS", "NOTEXISTS", "COMMA", "NUMBER", "BOOLEAN", "STRING", "VAR", "WHITESPACE", 194 | "ESC", 195 | } 196 | 197 | type EventRuleLexer struct { 198 | *antlr.BaseLexer 199 | channelNames []string 200 | modeNames []string 201 | // TODO: EOF string 202 | } 203 | 204 | var lexerDecisionToDFA = make([]*antlr.DFA, len(lexerAtn.DecisionToState)) 205 | 206 | func init() { 207 | for index, ds := range lexerAtn.DecisionToState { 208 | lexerDecisionToDFA[index] = antlr.NewDFA(ds, index) 209 | } 210 | } 211 | 212 | func NewEventRuleLexer(input antlr.CharStream) *EventRuleLexer { 213 | 214 | l := new(EventRuleLexer) 215 | 216 | l.BaseLexer = antlr.NewBaseLexer(input) 217 | l.Interpreter = antlr.NewLexerATNSimulator(l, lexerAtn, lexerDecisionToDFA, antlr.NewPredictionContextCache()) 218 | 219 | l.channelNames = lexerChannelNames 220 | l.modeNames = lexerModeNames 221 | l.RuleNames = lexerRuleNames 222 | l.LiteralNames = lexerLiteralNames 223 | l.SymbolicNames = lexerSymbolicNames 224 | l.GrammarFileName = "EventRule.g4" 225 | // TODO: l.EOF = antlr.TokenEOF 226 | 227 | return l 228 | } 229 | 230 | // EventRuleLexer tokens. 231 | const ( 232 | EventRuleLexerT__0 = 1 233 | EventRuleLexerT__1 = 2 234 | EventRuleLexerAND = 3 235 | EventRuleLexerOR = 4 236 | EventRuleLexerNOT = 5 237 | EventRuleLexerEQU = 6 238 | EventRuleLexerNEQ = 7 239 | EventRuleLexerGT = 8 240 | EventRuleLexerLT = 9 241 | EventRuleLexerGTE = 10 242 | EventRuleLexerLTE = 11 243 | EventRuleLexerCONTAINS = 12 244 | EventRuleLexerNOTCONTAINS = 13 245 | EventRuleLexerIN = 14 246 | EventRuleLexerNOTIN = 15 247 | EventRuleLexerLIKE = 16 248 | EventRuleLexerNOTLIKE = 17 249 | EventRuleLexerREGEX = 18 250 | EventRuleLexerNOTREGEX = 19 251 | EventRuleLexerEXISTS = 20 252 | EventRuleLexerNOTEXISTS = 21 253 | EventRuleLexerCOMMA = 22 254 | EventRuleLexerNUMBER = 23 255 | EventRuleLexerBOOLEAN = 24 256 | EventRuleLexerSTRING = 25 257 | EventRuleLexerVAR = 26 258 | EventRuleLexerWHITESPACE = 27 259 | ) 260 | -------------------------------------------------------------------------------- /visitor/parser/eventrule_parser.go: -------------------------------------------------------------------------------- 1 | // Code generated from EventRule.g4 by ANTLR 4.7.1. DO NOT EDIT. 2 | 3 | package parser // EventRule 4 | 5 | import ( 6 | "fmt" 7 | "reflect" 8 | "strconv" 9 | 10 | "github.com/antlr/antlr4/runtime/Go/antlr" 11 | ) 12 | 13 | // Suppress unused import errors 14 | var _ = fmt.Printf 15 | var _ = reflect.Copy 16 | var _ = strconv.Itoa 17 | 18 | var parserATN = []uint16{ 19 | 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 29, 56, 4, 20 | 2, 9, 2, 4, 3, 9, 3, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 21 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 22 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 3, 32, 10, 3, 12, 3, 14, 3, 35, 11, 3, 3, 23 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 46, 10, 3, 3, 24 | 3, 3, 3, 3, 3, 7, 3, 51, 10, 3, 12, 3, 14, 3, 54, 11, 3, 3, 3, 2, 3, 4, 25 | 4, 2, 4, 2, 10, 3, 2, 8, 13, 4, 2, 25, 25, 27, 27, 3, 2, 8, 9, 3, 2, 14, 26 | 15, 3, 2, 16, 17, 3, 2, 18, 21, 3, 2, 22, 23, 3, 2, 5, 6, 2, 64, 2, 6, 27 | 3, 2, 2, 2, 4, 45, 3, 2, 2, 2, 6, 7, 5, 4, 3, 2, 7, 8, 7, 2, 2, 3, 8, 3, 28 | 3, 2, 2, 2, 9, 10, 8, 3, 1, 2, 10, 11, 7, 7, 2, 2, 11, 46, 5, 4, 3, 12, 29 | 12, 13, 7, 3, 2, 2, 13, 14, 5, 4, 3, 2, 14, 15, 7, 4, 2, 2, 15, 46, 3, 30 | 2, 2, 2, 16, 17, 7, 28, 2, 2, 17, 18, 9, 2, 2, 2, 18, 46, 9, 3, 2, 2, 19, 31 | 20, 7, 28, 2, 2, 20, 21, 9, 4, 2, 2, 21, 46, 7, 26, 2, 2, 22, 23, 7, 28, 32 | 2, 2, 23, 24, 9, 5, 2, 2, 24, 46, 9, 3, 2, 2, 25, 26, 7, 28, 2, 2, 26, 33 | 27, 9, 6, 2, 2, 27, 28, 7, 3, 2, 2, 28, 33, 9, 3, 2, 2, 29, 30, 7, 24, 34 | 2, 2, 30, 32, 9, 3, 2, 2, 31, 29, 3, 2, 2, 2, 32, 35, 3, 2, 2, 2, 33, 31, 35 | 3, 2, 2, 2, 33, 34, 3, 2, 2, 2, 34, 36, 3, 2, 2, 2, 35, 33, 3, 2, 2, 2, 36 | 36, 46, 7, 4, 2, 2, 37, 38, 7, 28, 2, 2, 38, 39, 9, 7, 2, 2, 39, 46, 7, 37 | 27, 2, 2, 40, 41, 7, 28, 2, 2, 41, 46, 9, 8, 2, 2, 42, 46, 7, 28, 2, 2, 38 | 43, 44, 7, 7, 2, 2, 44, 46, 7, 28, 2, 2, 45, 9, 3, 2, 2, 2, 45, 12, 3, 39 | 2, 2, 2, 45, 16, 3, 2, 2, 2, 45, 19, 3, 2, 2, 2, 45, 22, 3, 2, 2, 2, 45, 40 | 25, 3, 2, 2, 2, 45, 37, 3, 2, 2, 2, 45, 40, 3, 2, 2, 2, 45, 42, 3, 2, 2, 41 | 2, 45, 43, 3, 2, 2, 2, 46, 52, 3, 2, 2, 2, 47, 48, 12, 13, 2, 2, 48, 49, 42 | 9, 9, 2, 2, 49, 51, 5, 4, 3, 14, 50, 47, 3, 2, 2, 2, 51, 54, 3, 2, 2, 2, 43 | 52, 50, 3, 2, 2, 2, 52, 53, 3, 2, 2, 2, 53, 5, 3, 2, 2, 2, 54, 52, 3, 2, 44 | 2, 2, 5, 33, 45, 52, 45 | } 46 | var deserializer = antlr.NewATNDeserializer(nil) 47 | var deserializedATN = deserializer.DeserializeFromUInt16(parserATN) 48 | 49 | var literalNames = []string{ 50 | "", "'('", "')'", "'and'", "'or'", "", "", "'!='", "'>'", "'<'", "'>='", 51 | "'<='", "'contains'", "'not contains'", "'in'", "'not in'", "'like'", "'not like'", 52 | "'regex'", "'not regex'", "'exists'", "'not exists'", "','", 53 | } 54 | var symbolicNames = []string{ 55 | "", "", "", "AND", "OR", "NOT", "EQU", "NEQ", "GT", "LT", "GTE", "LTE", 56 | "CONTAINS", "NOTCONTAINS", "IN", "NOTIN", "LIKE", "NOTLIKE", "REGEX", "NOTREGEX", 57 | "EXISTS", "NOTEXISTS", "COMMA", "NUMBER", "BOOLEAN", "STRING", "VAR", "WHITESPACE", 58 | } 59 | 60 | var ruleNames = []string{ 61 | "start", "expression", 62 | } 63 | var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState)) 64 | 65 | func init() { 66 | for index, ds := range deserializedATN.DecisionToState { 67 | decisionToDFA[index] = antlr.NewDFA(ds, index) 68 | } 69 | } 70 | 71 | type EventRuleParser struct { 72 | *antlr.BaseParser 73 | } 74 | 75 | func NewEventRuleParser(input antlr.TokenStream) *EventRuleParser { 76 | this := new(EventRuleParser) 77 | 78 | this.BaseParser = antlr.NewBaseParser(input) 79 | 80 | this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, antlr.NewPredictionContextCache()) 81 | this.RuleNames = ruleNames 82 | this.LiteralNames = literalNames 83 | this.SymbolicNames = symbolicNames 84 | this.GrammarFileName = "EventRule.g4" 85 | 86 | return this 87 | } 88 | 89 | // EventRuleParser tokens. 90 | const ( 91 | EventRuleParserEOF = antlr.TokenEOF 92 | EventRuleParserT__0 = 1 93 | EventRuleParserT__1 = 2 94 | EventRuleParserAND = 3 95 | EventRuleParserOR = 4 96 | EventRuleParserNOT = 5 97 | EventRuleParserEQU = 6 98 | EventRuleParserNEQ = 7 99 | EventRuleParserGT = 8 100 | EventRuleParserLT = 9 101 | EventRuleParserGTE = 10 102 | EventRuleParserLTE = 11 103 | EventRuleParserCONTAINS = 12 104 | EventRuleParserNOTCONTAINS = 13 105 | EventRuleParserIN = 14 106 | EventRuleParserNOTIN = 15 107 | EventRuleParserLIKE = 16 108 | EventRuleParserNOTLIKE = 17 109 | EventRuleParserREGEX = 18 110 | EventRuleParserNOTREGEX = 19 111 | EventRuleParserEXISTS = 20 112 | EventRuleParserNOTEXISTS = 21 113 | EventRuleParserCOMMA = 22 114 | EventRuleParserNUMBER = 23 115 | EventRuleParserBOOLEAN = 24 116 | EventRuleParserSTRING = 25 117 | EventRuleParserVAR = 26 118 | EventRuleParserWHITESPACE = 27 119 | ) 120 | 121 | // EventRuleParser rules. 122 | const ( 123 | EventRuleParserRULE_start = 0 124 | EventRuleParserRULE_expression = 1 125 | ) 126 | 127 | // IStartContext is an interface to support dynamic dispatch. 128 | type IStartContext interface { 129 | antlr.ParserRuleContext 130 | 131 | // GetParser returns the parser. 132 | GetParser() antlr.Parser 133 | 134 | // IsStartContext differentiates from other interfaces. 135 | IsStartContext() 136 | } 137 | 138 | type StartContext struct { 139 | *antlr.BaseParserRuleContext 140 | parser antlr.Parser 141 | } 142 | 143 | func NewEmptyStartContext() *StartContext { 144 | var p = new(StartContext) 145 | p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) 146 | p.RuleIndex = EventRuleParserRULE_start 147 | return p 148 | } 149 | 150 | func (*StartContext) IsStartContext() {} 151 | 152 | func NewStartContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StartContext { 153 | var p = new(StartContext) 154 | 155 | p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) 156 | 157 | p.parser = parser 158 | p.RuleIndex = EventRuleParserRULE_start 159 | 160 | return p 161 | } 162 | 163 | func (s *StartContext) GetParser() antlr.Parser { return s.parser } 164 | 165 | func (s *StartContext) Expression() IExpressionContext { 166 | var t = s.GetTypedRuleContext(reflect.TypeOf((*IExpressionContext)(nil)).Elem(), 0) 167 | 168 | if t == nil { 169 | return nil 170 | } 171 | 172 | return t.(IExpressionContext) 173 | } 174 | 175 | func (s *StartContext) EOF() antlr.TerminalNode { 176 | return s.GetToken(EventRuleParserEOF, 0) 177 | } 178 | 179 | func (s *StartContext) GetRuleContext() antlr.RuleContext { 180 | return s 181 | } 182 | 183 | func (s *StartContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { 184 | return antlr.TreesStringTree(s, ruleNames, recog) 185 | } 186 | 187 | func (s *StartContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 188 | switch t := visitor.(type) { 189 | case EventRuleVisitor: 190 | return t.VisitStart(s) 191 | 192 | default: 193 | return t.VisitChildren(s) 194 | } 195 | } 196 | 197 | func (p *EventRuleParser) Start() (localctx IStartContext) { 198 | localctx = NewStartContext(p, p.GetParserRuleContext(), p.GetState()) 199 | p.EnterRule(localctx, 0, EventRuleParserRULE_start) 200 | 201 | defer func() { 202 | p.ExitRule() 203 | }() 204 | 205 | defer func() { 206 | if err := recover(); err != nil { 207 | if v, ok := err.(antlr.RecognitionException); ok { 208 | localctx.SetException(v) 209 | p.GetErrorHandler().ReportError(p, v) 210 | p.GetErrorHandler().Recover(p, v) 211 | } else { 212 | panic(err) 213 | } 214 | } 215 | }() 216 | 217 | p.EnterOuterAlt(localctx, 1) 218 | { 219 | p.SetState(4) 220 | p.expression(0) 221 | } 222 | { 223 | p.SetState(5) 224 | p.Match(EventRuleParserEOF) 225 | } 226 | 227 | return localctx 228 | } 229 | 230 | // IExpressionContext is an interface to support dynamic dispatch. 231 | type IExpressionContext interface { 232 | antlr.ParserRuleContext 233 | 234 | // GetParser returns the parser. 235 | GetParser() antlr.Parser 236 | 237 | // IsExpressionContext differentiates from other interfaces. 238 | IsExpressionContext() 239 | } 240 | 241 | type ExpressionContext struct { 242 | *antlr.BaseParserRuleContext 243 | parser antlr.Parser 244 | } 245 | 246 | func NewEmptyExpressionContext() *ExpressionContext { 247 | var p = new(ExpressionContext) 248 | p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) 249 | p.RuleIndex = EventRuleParserRULE_expression 250 | return p 251 | } 252 | 253 | func (*ExpressionContext) IsExpressionContext() {} 254 | 255 | func NewExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExpressionContext { 256 | var p = new(ExpressionContext) 257 | 258 | p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) 259 | 260 | p.parser = parser 261 | p.RuleIndex = EventRuleParserRULE_expression 262 | 263 | return p 264 | } 265 | 266 | func (s *ExpressionContext) GetParser() antlr.Parser { return s.parser } 267 | 268 | func (s *ExpressionContext) CopyFrom(ctx *ExpressionContext) { 269 | s.BaseParserRuleContext.CopyFrom(ctx.BaseParserRuleContext) 270 | } 271 | 272 | func (s *ExpressionContext) GetRuleContext() antlr.RuleContext { 273 | return s 274 | } 275 | 276 | func (s *ExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { 277 | return antlr.TreesStringTree(s, ruleNames, recog) 278 | } 279 | 280 | type InOrNotContext struct { 281 | *ExpressionContext 282 | op antlr.Token 283 | } 284 | 285 | func NewInOrNotContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *InOrNotContext { 286 | var p = new(InOrNotContext) 287 | 288 | p.ExpressionContext = NewEmptyExpressionContext() 289 | p.parser = parser 290 | p.CopyFrom(ctx.(*ExpressionContext)) 291 | 292 | return p 293 | } 294 | 295 | func (s *InOrNotContext) GetOp() antlr.Token { return s.op } 296 | 297 | func (s *InOrNotContext) SetOp(v antlr.Token) { s.op = v } 298 | 299 | func (s *InOrNotContext) GetRuleContext() antlr.RuleContext { 300 | return s 301 | } 302 | 303 | func (s *InOrNotContext) VAR() antlr.TerminalNode { 304 | return s.GetToken(EventRuleParserVAR, 0) 305 | } 306 | 307 | func (s *InOrNotContext) AllNUMBER() []antlr.TerminalNode { 308 | return s.GetTokens(EventRuleParserNUMBER) 309 | } 310 | 311 | func (s *InOrNotContext) NUMBER(i int) antlr.TerminalNode { 312 | return s.GetToken(EventRuleParserNUMBER, i) 313 | } 314 | 315 | func (s *InOrNotContext) AllSTRING() []antlr.TerminalNode { 316 | return s.GetTokens(EventRuleParserSTRING) 317 | } 318 | 319 | func (s *InOrNotContext) STRING(i int) antlr.TerminalNode { 320 | return s.GetToken(EventRuleParserSTRING, i) 321 | } 322 | 323 | func (s *InOrNotContext) IN() antlr.TerminalNode { 324 | return s.GetToken(EventRuleParserIN, 0) 325 | } 326 | 327 | func (s *InOrNotContext) NOTIN() antlr.TerminalNode { 328 | return s.GetToken(EventRuleParserNOTIN, 0) 329 | } 330 | 331 | func (s *InOrNotContext) AllCOMMA() []antlr.TerminalNode { 332 | return s.GetTokens(EventRuleParserCOMMA) 333 | } 334 | 335 | func (s *InOrNotContext) COMMA(i int) antlr.TerminalNode { 336 | return s.GetToken(EventRuleParserCOMMA, i) 337 | } 338 | 339 | func (s *InOrNotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 340 | switch t := visitor.(type) { 341 | case EventRuleVisitor: 342 | return t.VisitInOrNot(s) 343 | 344 | default: 345 | return t.VisitChildren(s) 346 | } 347 | } 348 | 349 | type RegexOrNotContext struct { 350 | *ExpressionContext 351 | op antlr.Token 352 | } 353 | 354 | func NewRegexOrNotContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *RegexOrNotContext { 355 | var p = new(RegexOrNotContext) 356 | 357 | p.ExpressionContext = NewEmptyExpressionContext() 358 | p.parser = parser 359 | p.CopyFrom(ctx.(*ExpressionContext)) 360 | 361 | return p 362 | } 363 | 364 | func (s *RegexOrNotContext) GetOp() antlr.Token { return s.op } 365 | 366 | func (s *RegexOrNotContext) SetOp(v antlr.Token) { s.op = v } 367 | 368 | func (s *RegexOrNotContext) GetRuleContext() antlr.RuleContext { 369 | return s 370 | } 371 | 372 | func (s *RegexOrNotContext) VAR() antlr.TerminalNode { 373 | return s.GetToken(EventRuleParserVAR, 0) 374 | } 375 | 376 | func (s *RegexOrNotContext) STRING() antlr.TerminalNode { 377 | return s.GetToken(EventRuleParserSTRING, 0) 378 | } 379 | 380 | func (s *RegexOrNotContext) REGEX() antlr.TerminalNode { 381 | return s.GetToken(EventRuleParserREGEX, 0) 382 | } 383 | 384 | func (s *RegexOrNotContext) NOTREGEX() antlr.TerminalNode { 385 | return s.GetToken(EventRuleParserNOTREGEX, 0) 386 | } 387 | 388 | func (s *RegexOrNotContext) LIKE() antlr.TerminalNode { 389 | return s.GetToken(EventRuleParserLIKE, 0) 390 | } 391 | 392 | func (s *RegexOrNotContext) NOTLIKE() antlr.TerminalNode { 393 | return s.GetToken(EventRuleParserNOTLIKE, 0) 394 | } 395 | 396 | func (s *RegexOrNotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 397 | switch t := visitor.(type) { 398 | case EventRuleVisitor: 399 | return t.VisitRegexOrNot(s) 400 | 401 | default: 402 | return t.VisitChildren(s) 403 | } 404 | } 405 | 406 | type NotContext struct { 407 | *ExpressionContext 408 | } 409 | 410 | func NewNotContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *NotContext { 411 | var p = new(NotContext) 412 | 413 | p.ExpressionContext = NewEmptyExpressionContext() 414 | p.parser = parser 415 | p.CopyFrom(ctx.(*ExpressionContext)) 416 | 417 | return p 418 | } 419 | 420 | func (s *NotContext) GetRuleContext() antlr.RuleContext { 421 | return s 422 | } 423 | 424 | func (s *NotContext) NOT() antlr.TerminalNode { 425 | return s.GetToken(EventRuleParserNOT, 0) 426 | } 427 | 428 | func (s *NotContext) Expression() IExpressionContext { 429 | var t = s.GetTypedRuleContext(reflect.TypeOf((*IExpressionContext)(nil)).Elem(), 0) 430 | 431 | if t == nil { 432 | return nil 433 | } 434 | 435 | return t.(IExpressionContext) 436 | } 437 | 438 | func (s *NotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 439 | switch t := visitor.(type) { 440 | case EventRuleVisitor: 441 | return t.VisitNot(s) 442 | 443 | default: 444 | return t.VisitChildren(s) 445 | } 446 | } 447 | 448 | type ParenthesisContext struct { 449 | *ExpressionContext 450 | } 451 | 452 | func NewParenthesisContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ParenthesisContext { 453 | var p = new(ParenthesisContext) 454 | 455 | p.ExpressionContext = NewEmptyExpressionContext() 456 | p.parser = parser 457 | p.CopyFrom(ctx.(*ExpressionContext)) 458 | 459 | return p 460 | } 461 | 462 | func (s *ParenthesisContext) GetRuleContext() antlr.RuleContext { 463 | return s 464 | } 465 | 466 | func (s *ParenthesisContext) Expression() IExpressionContext { 467 | var t = s.GetTypedRuleContext(reflect.TypeOf((*IExpressionContext)(nil)).Elem(), 0) 468 | 469 | if t == nil { 470 | return nil 471 | } 472 | 473 | return t.(IExpressionContext) 474 | } 475 | 476 | func (s *ParenthesisContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 477 | switch t := visitor.(type) { 478 | case EventRuleVisitor: 479 | return t.VisitParenthesis(s) 480 | 481 | default: 482 | return t.VisitChildren(s) 483 | } 484 | } 485 | 486 | type BoolCompareContext struct { 487 | *ExpressionContext 488 | op antlr.Token 489 | } 490 | 491 | func NewBoolCompareContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BoolCompareContext { 492 | var p = new(BoolCompareContext) 493 | 494 | p.ExpressionContext = NewEmptyExpressionContext() 495 | p.parser = parser 496 | p.CopyFrom(ctx.(*ExpressionContext)) 497 | 498 | return p 499 | } 500 | 501 | func (s *BoolCompareContext) GetOp() antlr.Token { return s.op } 502 | 503 | func (s *BoolCompareContext) SetOp(v antlr.Token) { s.op = v } 504 | 505 | func (s *BoolCompareContext) GetRuleContext() antlr.RuleContext { 506 | return s 507 | } 508 | 509 | func (s *BoolCompareContext) VAR() antlr.TerminalNode { 510 | return s.GetToken(EventRuleParserVAR, 0) 511 | } 512 | 513 | func (s *BoolCompareContext) BOOLEAN() antlr.TerminalNode { 514 | return s.GetToken(EventRuleParserBOOLEAN, 0) 515 | } 516 | 517 | func (s *BoolCompareContext) EQU() antlr.TerminalNode { 518 | return s.GetToken(EventRuleParserEQU, 0) 519 | } 520 | 521 | func (s *BoolCompareContext) NEQ() antlr.TerminalNode { 522 | return s.GetToken(EventRuleParserNEQ, 0) 523 | } 524 | 525 | func (s *BoolCompareContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 526 | switch t := visitor.(type) { 527 | case EventRuleVisitor: 528 | return t.VisitBoolCompare(s) 529 | 530 | default: 531 | return t.VisitChildren(s) 532 | } 533 | } 534 | 535 | type VariableContext struct { 536 | *ExpressionContext 537 | } 538 | 539 | func NewVariableContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VariableContext { 540 | var p = new(VariableContext) 541 | 542 | p.ExpressionContext = NewEmptyExpressionContext() 543 | p.parser = parser 544 | p.CopyFrom(ctx.(*ExpressionContext)) 545 | 546 | return p 547 | } 548 | 549 | func (s *VariableContext) GetRuleContext() antlr.RuleContext { 550 | return s 551 | } 552 | 553 | func (s *VariableContext) VAR() antlr.TerminalNode { 554 | return s.GetToken(EventRuleParserVAR, 0) 555 | } 556 | 557 | func (s *VariableContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 558 | switch t := visitor.(type) { 559 | case EventRuleVisitor: 560 | return t.VisitVariable(s) 561 | 562 | default: 563 | return t.VisitChildren(s) 564 | } 565 | } 566 | 567 | type NotVariableContext struct { 568 | *ExpressionContext 569 | } 570 | 571 | func NewNotVariableContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *NotVariableContext { 572 | var p = new(NotVariableContext) 573 | 574 | p.ExpressionContext = NewEmptyExpressionContext() 575 | p.parser = parser 576 | p.CopyFrom(ctx.(*ExpressionContext)) 577 | 578 | return p 579 | } 580 | 581 | func (s *NotVariableContext) GetRuleContext() antlr.RuleContext { 582 | return s 583 | } 584 | 585 | func (s *NotVariableContext) NOT() antlr.TerminalNode { 586 | return s.GetToken(EventRuleParserNOT, 0) 587 | } 588 | 589 | func (s *NotVariableContext) VAR() antlr.TerminalNode { 590 | return s.GetToken(EventRuleParserVAR, 0) 591 | } 592 | 593 | func (s *NotVariableContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 594 | switch t := visitor.(type) { 595 | case EventRuleVisitor: 596 | return t.VisitNotVariable(s) 597 | 598 | default: 599 | return t.VisitChildren(s) 600 | } 601 | } 602 | 603 | type CompareContext struct { 604 | *ExpressionContext 605 | op antlr.Token 606 | } 607 | 608 | func NewCompareContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CompareContext { 609 | var p = new(CompareContext) 610 | 611 | p.ExpressionContext = NewEmptyExpressionContext() 612 | p.parser = parser 613 | p.CopyFrom(ctx.(*ExpressionContext)) 614 | 615 | return p 616 | } 617 | 618 | func (s *CompareContext) GetOp() antlr.Token { return s.op } 619 | 620 | func (s *CompareContext) SetOp(v antlr.Token) { s.op = v } 621 | 622 | func (s *CompareContext) GetRuleContext() antlr.RuleContext { 623 | return s 624 | } 625 | 626 | func (s *CompareContext) VAR() antlr.TerminalNode { 627 | return s.GetToken(EventRuleParserVAR, 0) 628 | } 629 | 630 | func (s *CompareContext) STRING() antlr.TerminalNode { 631 | return s.GetToken(EventRuleParserSTRING, 0) 632 | } 633 | 634 | func (s *CompareContext) NUMBER() antlr.TerminalNode { 635 | return s.GetToken(EventRuleParserNUMBER, 0) 636 | } 637 | 638 | func (s *CompareContext) EQU() antlr.TerminalNode { 639 | return s.GetToken(EventRuleParserEQU, 0) 640 | } 641 | 642 | func (s *CompareContext) NEQ() antlr.TerminalNode { 643 | return s.GetToken(EventRuleParserNEQ, 0) 644 | } 645 | 646 | func (s *CompareContext) GT() antlr.TerminalNode { 647 | return s.GetToken(EventRuleParserGT, 0) 648 | } 649 | 650 | func (s *CompareContext) LT() antlr.TerminalNode { 651 | return s.GetToken(EventRuleParserLT, 0) 652 | } 653 | 654 | func (s *CompareContext) GTE() antlr.TerminalNode { 655 | return s.GetToken(EventRuleParserGTE, 0) 656 | } 657 | 658 | func (s *CompareContext) LTE() antlr.TerminalNode { 659 | return s.GetToken(EventRuleParserLTE, 0) 660 | } 661 | 662 | func (s *CompareContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 663 | switch t := visitor.(type) { 664 | case EventRuleVisitor: 665 | return t.VisitCompare(s) 666 | 667 | default: 668 | return t.VisitChildren(s) 669 | } 670 | } 671 | 672 | type ExistsOrNotContext struct { 673 | *ExpressionContext 674 | op antlr.Token 675 | } 676 | 677 | func NewExistsOrNotContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ExistsOrNotContext { 678 | var p = new(ExistsOrNotContext) 679 | 680 | p.ExpressionContext = NewEmptyExpressionContext() 681 | p.parser = parser 682 | p.CopyFrom(ctx.(*ExpressionContext)) 683 | 684 | return p 685 | } 686 | 687 | func (s *ExistsOrNotContext) GetOp() antlr.Token { return s.op } 688 | 689 | func (s *ExistsOrNotContext) SetOp(v antlr.Token) { s.op = v } 690 | 691 | func (s *ExistsOrNotContext) GetRuleContext() antlr.RuleContext { 692 | return s 693 | } 694 | 695 | func (s *ExistsOrNotContext) VAR() antlr.TerminalNode { 696 | return s.GetToken(EventRuleParserVAR, 0) 697 | } 698 | 699 | func (s *ExistsOrNotContext) EXISTS() antlr.TerminalNode { 700 | return s.GetToken(EventRuleParserEXISTS, 0) 701 | } 702 | 703 | func (s *ExistsOrNotContext) NOTEXISTS() antlr.TerminalNode { 704 | return s.GetToken(EventRuleParserNOTEXISTS, 0) 705 | } 706 | 707 | func (s *ExistsOrNotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 708 | switch t := visitor.(type) { 709 | case EventRuleVisitor: 710 | return t.VisitExistsOrNot(s) 711 | 712 | default: 713 | return t.VisitChildren(s) 714 | } 715 | } 716 | 717 | type AndOrContext struct { 718 | *ExpressionContext 719 | op antlr.Token 720 | } 721 | 722 | func NewAndOrContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *AndOrContext { 723 | var p = new(AndOrContext) 724 | 725 | p.ExpressionContext = NewEmptyExpressionContext() 726 | p.parser = parser 727 | p.CopyFrom(ctx.(*ExpressionContext)) 728 | 729 | return p 730 | } 731 | 732 | func (s *AndOrContext) GetOp() antlr.Token { return s.op } 733 | 734 | func (s *AndOrContext) SetOp(v antlr.Token) { s.op = v } 735 | 736 | func (s *AndOrContext) GetRuleContext() antlr.RuleContext { 737 | return s 738 | } 739 | 740 | func (s *AndOrContext) AllExpression() []IExpressionContext { 741 | var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IExpressionContext)(nil)).Elem()) 742 | var tst = make([]IExpressionContext, len(ts)) 743 | 744 | for i, t := range ts { 745 | if t != nil { 746 | tst[i] = t.(IExpressionContext) 747 | } 748 | } 749 | 750 | return tst 751 | } 752 | 753 | func (s *AndOrContext) Expression(i int) IExpressionContext { 754 | var t = s.GetTypedRuleContext(reflect.TypeOf((*IExpressionContext)(nil)).Elem(), i) 755 | 756 | if t == nil { 757 | return nil 758 | } 759 | 760 | return t.(IExpressionContext) 761 | } 762 | 763 | func (s *AndOrContext) AND() antlr.TerminalNode { 764 | return s.GetToken(EventRuleParserAND, 0) 765 | } 766 | 767 | func (s *AndOrContext) OR() antlr.TerminalNode { 768 | return s.GetToken(EventRuleParserOR, 0) 769 | } 770 | 771 | func (s *AndOrContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 772 | switch t := visitor.(type) { 773 | case EventRuleVisitor: 774 | return t.VisitAndOr(s) 775 | 776 | default: 777 | return t.VisitChildren(s) 778 | } 779 | } 780 | 781 | type ContainsOrNotContext struct { 782 | *ExpressionContext 783 | op antlr.Token 784 | } 785 | 786 | func NewContainsOrNotContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ContainsOrNotContext { 787 | var p = new(ContainsOrNotContext) 788 | 789 | p.ExpressionContext = NewEmptyExpressionContext() 790 | p.parser = parser 791 | p.CopyFrom(ctx.(*ExpressionContext)) 792 | 793 | return p 794 | } 795 | 796 | func (s *ContainsOrNotContext) GetOp() antlr.Token { return s.op } 797 | 798 | func (s *ContainsOrNotContext) SetOp(v antlr.Token) { s.op = v } 799 | 800 | func (s *ContainsOrNotContext) GetRuleContext() antlr.RuleContext { 801 | return s 802 | } 803 | 804 | func (s *ContainsOrNotContext) VAR() antlr.TerminalNode { 805 | return s.GetToken(EventRuleParserVAR, 0) 806 | } 807 | 808 | func (s *ContainsOrNotContext) STRING() antlr.TerminalNode { 809 | return s.GetToken(EventRuleParserSTRING, 0) 810 | } 811 | 812 | func (s *ContainsOrNotContext) NUMBER() antlr.TerminalNode { 813 | return s.GetToken(EventRuleParserNUMBER, 0) 814 | } 815 | 816 | func (s *ContainsOrNotContext) CONTAINS() antlr.TerminalNode { 817 | return s.GetToken(EventRuleParserCONTAINS, 0) 818 | } 819 | 820 | func (s *ContainsOrNotContext) NOTCONTAINS() antlr.TerminalNode { 821 | return s.GetToken(EventRuleParserNOTCONTAINS, 0) 822 | } 823 | 824 | func (s *ContainsOrNotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { 825 | switch t := visitor.(type) { 826 | case EventRuleVisitor: 827 | return t.VisitContainsOrNot(s) 828 | 829 | default: 830 | return t.VisitChildren(s) 831 | } 832 | } 833 | 834 | func (p *EventRuleParser) Expression() (localctx IExpressionContext) { 835 | return p.expression(0) 836 | } 837 | 838 | func (p *EventRuleParser) expression(_p int) (localctx IExpressionContext) { 839 | var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext() 840 | _parentState := p.GetState() 841 | localctx = NewExpressionContext(p, p.GetParserRuleContext(), _parentState) 842 | var _prevctx IExpressionContext = localctx 843 | var _ antlr.ParserRuleContext = _prevctx // TODO: To prevent unused variable warning. 844 | _startState := 2 845 | p.EnterRecursionRule(localctx, 2, EventRuleParserRULE_expression, _p) 846 | var _la int 847 | 848 | defer func() { 849 | p.UnrollRecursionContexts(_parentctx) 850 | }() 851 | 852 | defer func() { 853 | if err := recover(); err != nil { 854 | if v, ok := err.(antlr.RecognitionException); ok { 855 | localctx.SetException(v) 856 | p.GetErrorHandler().ReportError(p, v) 857 | p.GetErrorHandler().Recover(p, v) 858 | } else { 859 | panic(err) 860 | } 861 | } 862 | }() 863 | 864 | var _alt int 865 | 866 | p.EnterOuterAlt(localctx, 1) 867 | p.SetState(43) 868 | p.GetErrorHandler().Sync(p) 869 | switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 1, p.GetParserRuleContext()) { 870 | case 1: 871 | localctx = NewNotContext(p, localctx) 872 | p.SetParserRuleContext(localctx) 873 | _prevctx = localctx 874 | 875 | { 876 | p.SetState(8) 877 | p.Match(EventRuleParserNOT) 878 | } 879 | { 880 | p.SetState(9) 881 | p.expression(10) 882 | } 883 | 884 | case 2: 885 | localctx = NewParenthesisContext(p, localctx) 886 | p.SetParserRuleContext(localctx) 887 | _prevctx = localctx 888 | { 889 | p.SetState(10) 890 | p.Match(EventRuleParserT__0) 891 | } 892 | { 893 | p.SetState(11) 894 | p.expression(0) 895 | } 896 | { 897 | p.SetState(12) 898 | p.Match(EventRuleParserT__1) 899 | } 900 | 901 | case 3: 902 | localctx = NewCompareContext(p, localctx) 903 | p.SetParserRuleContext(localctx) 904 | _prevctx = localctx 905 | { 906 | p.SetState(14) 907 | p.Match(EventRuleParserVAR) 908 | } 909 | { 910 | p.SetState(15) 911 | 912 | var _lt = p.GetTokenStream().LT(1) 913 | 914 | localctx.(*CompareContext).op = _lt 915 | 916 | _la = p.GetTokenStream().LA(1) 917 | 918 | if !(((_la)&-(0x1f+1)) == 0 && ((1<