From 586721462c0a90198b2b0119f52812857d1a2852 Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Sat, 13 Feb 2021 15:09:34 +0800 Subject: [PATCH 1/3] Fix #3078 --- runtime/JavaScript/src/antlr4/Utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/JavaScript/src/antlr4/Utils.js b/runtime/JavaScript/src/antlr4/Utils.js index 8eed91a2c2..66cf131526 100644 --- a/runtime/JavaScript/src/antlr4/Utils.js +++ b/runtime/JavaScript/src/antlr4/Utils.js @@ -4,7 +4,7 @@ */ function arrayToString(a) { - return "[" + a.join(", ") + "]"; + return Array.isArray(a) ? ("[" + a.join(", ") + "]") : "null"; } String.prototype.seed = String.prototype.seed || Math.round(Math.random() * Math.pow(2, 32)); From 26291a11d8baab70ed946b56cb151a90fc34de8d Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Sat, 13 Feb 2021 15:09:52 +0800 Subject: [PATCH 2/3] align debug output on java --- runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js b/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js index 2c4833771e..5283947515 100644 --- a/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js +++ b/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js @@ -712,7 +712,7 @@ class ParserATNSimulator extends ATNSimulator { // First figure out where we can reach on input t for (let i=0; i Date: Sat, 13 Feb 2021 15:10:17 +0800 Subject: [PATCH 3/3] fix #2007 --- .../src/antlr4/atn/SemanticContext.js | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/runtime/JavaScript/src/antlr4/atn/SemanticContext.js b/runtime/JavaScript/src/antlr4/atn/SemanticContext.js index cb54b0c0da..d1c5181c17 100644 --- a/runtime/JavaScript/src/antlr4/atn/SemanticContext.js +++ b/runtime/JavaScript/src/antlr4/atn/SemanticContext.js @@ -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.

*/ 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("||"); } }