use jsdoc and const/let

This commit is contained in:
Camilo Roca 2020-03-06 18:24:57 +01:00
parent 15720d1e33
commit 8f1b2e5eb9
1 changed files with 106 additions and 113 deletions

View File

@ -39,7 +39,8 @@ function checkParams(params, isCfg) {
}
}
function ATNConfig(params, config) {
class ATNConfig {
constructor(params, config) {
this.checkContext(params, config);
params = checkParams(params);
config = checkParams(config, true);
@ -65,32 +66,29 @@ function ATNConfig(params, config) {
this.reachesIntoOuterContext = config.reachesIntoOuterContext;
this.precedenceFilterSuppressed = config.precedenceFilterSuppressed;
return this;
}
}
ATNConfig.prototype.checkContext = function(params, config) {
checkContext(params, config) {
if((params.context===null || params.context===undefined) &&
(config===null || config.context===null || config.context===undefined)) {
this.context = null;
}
};
}
ATNConfig.prototype.hashCode = function() {
hashCode() {
var hash = new Hash();
this.updateHashCode(hash);
return hash.finish();
};
}
ATNConfig.prototype.updateHashCode = function(hash) {
updateHashCode(hash) {
hash.update(this.state.stateNumber, this.alt, this.context, this.semanticContext);
};
}
// An ATN configuration is equal to another if both have
// the same state, they predict the same alternative, and
// syntactic/semantic contexts are the same.
ATNConfig.prototype.equals = function(other) {
equals(other) {
if (this === other) {
return true;
} else if (! (other instanceof ATNConfig)) {
@ -102,17 +100,15 @@ ATNConfig.prototype.equals = function(other) {
this.semanticContext.equals(other.semanticContext) &&
this.precedenceFilterSuppressed===other.precedenceFilterSuppressed;
}
};
}
ATNConfig.prototype.hashCodeForConfigSet = function() {
hashCodeForConfigSet() {
var hash = new Hash();
hash.update(this.state.stateNumber, this.alt, this.semanticContext);
return hash.finish();
};
}
ATNConfig.prototype.equalsForConfigSet = function(other) {
equalsForConfigSet(other) {
if (this === other) {
return true;
} else if (! (other instanceof ATNConfig)) {
@ -122,10 +118,9 @@ ATNConfig.prototype.equalsForConfigSet = function(other) {
this.alt===other.alt &&
this.semanticContext.equals(other.semanticContext);
}
};
}
ATNConfig.prototype.toString = function() {
toString() {
return "(" + this.state + "," + this.alt +
(this.context!==null ? ",[" + this.context.toString() + "]" : "") +
(this.semanticContext !== SemanticContext.NONE ?
@ -134,43 +129,41 @@ ATNConfig.prototype.toString = function() {
(this.reachesIntoOuterContext>0 ?
(",up=" + this.reachesIntoOuterContext)
: "") + ")";
};
}
}
function LexerATNConfig(params, config) {
ATNConfig.call(this, params, config);
class LexerATNConfig extends ATNConfig {
constructor(params, config) {
super(params, config);
// This is the backing field for {@link //getLexerActionExecutor}.
var lexerActionExecutor = params.lexerActionExecutor || null;
this.lexerActionExecutor = lexerActionExecutor || (config!==null ? config.lexerActionExecutor : null);
this.passedThroughNonGreedyDecision = config!==null ? this.checkNonGreedyDecision(config, this.state) : false;
this.hashCodeForConfigSet = LexerATNConfig.prototype.hashCode;
this.equalsForConfigSet = LexerATNConfig.prototype.equals;
return this;
}
}
LexerATNConfig.prototype = Object.create(ATNConfig.prototype);
LexerATNConfig.prototype.constructor = LexerATNConfig;
LexerATNConfig.prototype.updateHashCode = function(hash) {
updateHashCode(hash) {
hash.update(this.state.stateNumber, this.alt, this.context, this.semanticContext, this.passedThroughNonGreedyDecision, this.lexerActionExecutor);
};
}
LexerATNConfig.prototype.equals = function(other) {
equals(other) {
return this === other ||
(other instanceof LexerATNConfig &&
this.passedThroughNonGreedyDecision == other.passedThroughNonGreedyDecision &&
(this.lexerActionExecutor ? this.lexerActionExecutor.equals(other.lexerActionExecutor) : !other.lexerActionExecutor) &&
ATNConfig.prototype.equals.call(this, other));
};
super.equals(other));
}
LexerATNConfig.prototype.hashCodeForConfigSet = LexerATNConfig.prototype.hashCode;
LexerATNConfig.prototype.equalsForConfigSet = LexerATNConfig.prototype.equals;
LexerATNConfig.prototype.checkNonGreedyDecision = function(source, target) {
checkNonGreedyDecision(source, target) {
return source.passedThroughNonGreedyDecision ||
(target instanceof DecisionState) && target.nonGreedy;
};
}
}
exports.ATNConfig = ATNConfig;
exports.LexerATNConfig = LexerATNConfig;