Merge pull request #1012 from ericvergnaud/lexer-bug-in-javascript-runtime

Lexer bug in javascript runtime
This commit is contained in:
Terence Parr 2015-10-09 10:23:13 -07:00
commit 8abc1106f7
8 changed files with 21 additions and 13 deletions

5
.gitignore vendored
View File

@ -13,6 +13,11 @@ user.build.properties
# Python
*.pyc
# CSharp
bin/
obj/
*.userprefs
# NetBeans user configuration files
nbactions*.xml
/nbproject/private/

View File

@ -408,6 +408,7 @@ Parser.prototype.consume = function() {
} else {
node = this._ctx.addTokenNode(o);
}
node.invokingState = this.state;
if (hasListener) {
this._parseListeners.map(function(listener) {
listener.visitTerminal(node);

View File

@ -78,7 +78,7 @@ ATN.prototype.nextTokensNoContext = function(s) {
return s.nextTokenWithinRule;
}
s.nextTokenWithinRule = this.nextTokensInContext(s, null);
s.nextTokenWithinRule.readonly = true;
s.nextTokenWithinRule.readOnly = true;
return s.nextTokenWithinRule;
};

View File

@ -162,7 +162,9 @@ LexerATNConfig.prototype.equals = function(other) {
return false;
} else if (this.passedThroughNonGreedyDecision !== other.passedThroughNonGreedyDecision) {
return false;
} else if (this.lexerActionExecutor !== other.lexerActionExecutor) {
} else if (this.lexerActionExecutor ?
!this.lexerActionExecutor.equals(other.lexerActionExecutor)
: !other.lexerActionExecutor) {
return false;
} else {
return ATNConfig.prototype.equals.call(this, other);

View File

@ -78,7 +78,7 @@ function ATNConfigSet(fullCtx) {
// the sets and they must not change. This does not protect the other
// fields; in particular, conflictingAlts is set after
// we've made this readonly.
this.readonly = false;
this.readOnly = false;
// Track the elements as they are added to the set; supports get(i)///
this.configs = [];
@ -112,7 +112,7 @@ ATNConfigSet.prototype.add = function(config, mergeCache) {
if (mergeCache === undefined) {
mergeCache = null;
}
if (this.readonly) {
if (this.readOnly) {
throw "This set is readonly";
}
if (config.semanticContext !== SemanticContext.NONE) {
@ -168,7 +168,7 @@ Object.defineProperty(ATNConfigSet.prototype, "items", {
});
ATNConfigSet.prototype.optimizeConfigs = function(interpreter) {
if (this.readonly) {
if (this.readOnly) {
throw "This set is readonly";
}
if (this.configLookup.length === 0) {
@ -202,7 +202,7 @@ ATNConfigSet.prototype.equals = function(other) {
};
ATNConfigSet.prototype.hashString = function() {
if (this.readonly) {
if (this.readOnly) {
if (this.cachedHashString === "-1") {
this.cachedHashString = this.hashConfigs();
}
@ -245,7 +245,7 @@ ATNConfigSet.prototype.containsFast = function(item) {
};
ATNConfigSet.prototype.clear = function() {
if (this.readonly) {
if (this.readOnly) {
throw "This set is readonly";
}
this.configs = [];
@ -253,9 +253,9 @@ ATNConfigSet.prototype.clear = function() {
this.configLookup = new Set();
};
ATNConfigSet.prototype.setReadonly = function(readonly) {
this.readonly = readonly;
if (readonly) {
ATNConfigSet.prototype.setReadonly = function(readOnly) {
this.readOnly = readOnly;
if (readOnly) {
this.configLookup = null; // can't mod, no need for lookup cache
}
};

View File

@ -1637,7 +1637,7 @@ ParserATNSimulator.prototype.addDFAState = function(dfa, D) {
return existing;
}
D.stateNumber = dfa.states.length;
if (! D.configs.readonly) {
if (! D.configs.readOnly) {
D.configs.optimizeConfigs(this);
D.configs.setReadonly(true);
}

View File

@ -140,7 +140,7 @@ class LexerATNConfig(ATNConfig):
return False
if self.passedThroughNonGreedyDecision != other.passedThroughNonGreedyDecision:
return False
if self.lexerActionExecutor is not other.lexerActionExecutor:
if not(self.lexerActionExecutor==other.lexerActionExecutor):
return False
return super(LexerATNConfig, self).__eq__(other)

View File

@ -146,7 +146,7 @@ class LexerATNConfig(ATNConfig):
return False
if self.passedThroughNonGreedyDecision != other.passedThroughNonGreedyDecision:
return False
if self.lexerActionExecutor is not other.lexerActionExecutor:
if not(self.lexerActionExecutor == other.lexerActionExecutor):
return False
return super().__eq__(other)