This commit is contained in:
Eric Vergnaud 2021-02-13 15:10:17 +08:00
parent 26291a11d8
commit 94f9759d14
1 changed files with 14 additions and 17 deletions

View File

@ -3,7 +3,7 @@
* can be found in the LICENSE.txt file in the project root.
*/
const {Set, Hash} = require('./../Utils');
const { Set, Hash, equalArrays } = require('./../Utils');
/**
* A tree structure used to record the semantic context in which
@ -14,6 +14,7 @@ const {Set, Hash} = require('./../Utils');
* {@link SemanticContext} within the scope of this outer class.</p>
*/
class SemanticContext {
hashCode() {
const hash = new Hash();
this.updateHashCode(hash);
@ -93,6 +94,7 @@ class SemanticContext {
class Predicate extends SemanticContext {
constructor(ruleIndex, predIndex, isCtxDependent) {
super();
this.ruleIndex = ruleIndex === undefined ? -1 : ruleIndex;
@ -134,6 +136,7 @@ SemanticContext.NONE = new Predicate();
class PrecedencePredicate extends SemanticContext {
constructor(precedence) {
super();
this.precedence = precedence === undefined ? 0 : precedence;
@ -156,7 +159,7 @@ class PrecedencePredicate extends SemanticContext {
}
updateHashCode(hash) {
hash.update(31);
hash.update(this.precedence);
}
equals(other) {
@ -170,7 +173,7 @@ class PrecedencePredicate extends SemanticContext {
}
toString() {
return "{"+this.precedence+">=prec}?";
return "{" + this.precedence + ">=prec}?";
}
static filterPrecedencePredicates(set) {
@ -217,7 +220,7 @@ class AND extends SemanticContext {
});
operands.add(reduced);
}
this.opnds = operands.values();
this.opnds = Array.from(operands.values());
}
equals(other) {
@ -226,7 +229,7 @@ class AND extends SemanticContext {
} else if (!(other instanceof AND)) {
return false;
} else {
return this.opnds === other.opnds;
return equalArrays(this.opnds, other.opnds);
}
}
@ -280,11 +283,8 @@ class AND extends SemanticContext {
}
toString() {
let s = "";
this.opnds.map(function(o) {
s += "&& " + o.toString();
});
return s.length > 3 ? s.slice(3) : s;
const s = this.opnds.map(o => o.toString());
return (s.length > 3 ? s.slice(3) : s).join("&&");
}
}
@ -321,7 +321,7 @@ class OR extends SemanticContext {
const reduced = s[s.length-1];
operands.add(reduced);
}
this.opnds = operands.values();
this.opnds = Array.from(operands.values());
}
equals(other) {
@ -330,7 +330,7 @@ class OR extends SemanticContext {
} else if (!(other instanceof OR)) {
return false;
} else {
return this.opnds === other.opnds;
return equalArrays(this.opnds, other.opnds);
}
}
@ -382,11 +382,8 @@ class OR extends SemanticContext {
}
toString() {
let s = "";
this.opnds.map(function(o) {
s += "|| " + o.toString();
});
return s.length > 3 ? s.slice(3) : s;
const s = this.opnds.map(o => o.toString());
return (s.length > 3 ? s.slice(3) : s).join("||");
}
}