-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathPredicate.js
More file actions
46 lines (39 loc) · 1.52 KB
/
Predicate.js
File metadata and controls
46 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Copyright (c) 2012-2022 The ANTLR Project Contributors. All rights reserved.
* Use is of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
import SemanticContext from "./SemanticContext.js";
export default class Predicate extends SemanticContext {
constructor(ruleIndex, predIndex, isCtxDependent) {
super();
this.ruleIndex = ruleIndex === undefined ? -1 : ruleIndex;
this.predIndex = predIndex === undefined ? -1 : predIndex;
this.isCtxDependent = isCtxDependent === undefined ? false : isCtxDependent; // e.g., $i ref in pred
}
evaluate(parser, outerContext) {
let localctx = this.isCtxDependent ? outerContext : null;
return parser.sempred(localctx, this.ruleIndex, this.predIndex);
}
updateHashCode(hash) {
hash.update(this.ruleIndex, this.predIndex, this.isCtxDependent);
}
equals(other) {
if (this === other) {
return true;
} else if (!(other instanceof Predicate)) {
return false;
} else {
return this.ruleIndex === other.ruleIndex &&
this.predIndex === other.predIndex &&
this.isCtxDependent === other.isCtxDependent;
}
}
toString() {
return "{" + this.ruleIndex + ":" + this.predIndex + "}?";
}
}
/**
* The default {@link SemanticContext}, which is semantically equivalent to
* a predicate of the form {@code {true}?}
*/
SemanticContext.NONE = new Predicate();