Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

antlr4

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antlr4 - npm Package Compare versions

Comparing version 4.9.1 to 4.9.2

src/test/TestIntervalSet.test.js

18

package.json
{
"name": "antlr4",
"version": "4.9.1",
"version": "4.9.2",
"description": "JavaScript runtime for ANTLR4",

@@ -20,11 +20,13 @@ "main": "src/antlr4/index.js",

"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"babel-loader": "^8.2.1",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"ini": "1.3.6"
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"babel-loader": "^8.2.2",
"ini": "1.3.6",
"jest": "^26.6.3",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"scripts": {
"build": "webpack"
"build": "webpack",
"test": "jest"
},

@@ -31,0 +33,0 @@ "engines": {

@@ -159,3 +159,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

(other instanceof LexerATNConfig &&
this.passedThroughNonGreedyDecision == other.passedThroughNonGreedyDecision &&
this.passedThroughNonGreedyDecision === other.passedThroughNonGreedyDecision &&
(this.lexerActionExecutor ? this.lexerActionExecutor.equals(other.lexerActionExecutor) : !other.lexerActionExecutor) &&

@@ -162,0 +162,0 @@ super.equals(other));

@@ -504,3 +504,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

configToAlts.hashFunction = function(cfg) { hashStuff(cfg.state.stateNumber, cfg.context); };
configToAlts.equalsFunction = function(c1, c2) { return c1.state.stateNumber==c2.state.stateNumber && c1.context.equals(c2.context);}
configToAlts.equalsFunction = function(c1, c2) { return c1.state.stateNumber === c2.state.stateNumber && c1.context.equals(c2.context);};
configs.items.map(function(cfg) {

@@ -561,4 +561,4 @@ let alts = configToAlts.get(cfg);

}
}
};
module.exports = PredictionMode;

@@ -6,3 +6,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

const {Set, Hash} = require('./../Utils');
const { Set, Hash, equalArrays } = require('./../Utils');

@@ -18,2 +18,3 @@ /**

class SemanticContext {
hashCode() {

@@ -98,2 +99,3 @@ const hash = new Hash();

class Predicate extends SemanticContext {
constructor(ruleIndex, predIndex, isCtxDependent) {

@@ -140,2 +142,3 @@ super();

class PrecedencePredicate extends SemanticContext {
constructor(precedence) {

@@ -163,3 +166,3 @@ super();

updateHashCode(hash) {
hash.update(31);
hash.update(this.precedence);
}

@@ -178,3 +181,3 @@

toString() {
return "{"+this.precedence+">=prec}?";
return "{" + this.precedence + ">=prec}?";
}

@@ -226,3 +229,3 @@

}
this.opnds = operands.values();
this.opnds = Array.from(operands.values());
}

@@ -236,3 +239,3 @@

} else {
return this.opnds === other.opnds;
return equalArrays(this.opnds, other.opnds);
}

@@ -291,7 +294,4 @@ }

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

@@ -333,3 +333,3 @@ }

}
this.opnds = operands.values();
this.opnds = Array.from(operands.values());
}

@@ -343,3 +343,3 @@

} else {
return this.opnds === other.opnds;
return equalArrays(this.opnds, other.opnds);
}

@@ -396,7 +396,4 @@ }

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

@@ -403,0 +400,0 @@ }

@@ -76,2 +76,2 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

module.exports = CharStreams
module.exports = CharStreams;

@@ -114,3 +114,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

if (this.precedenceDfa!==precedenceDfa) {
this._states = new DFAStatesSet();
this._states = new Set();
if (precedenceDfa) {

@@ -117,0 +117,0 @@ const precedenceState = new DFAState(null, new ATNConfigSet());

@@ -14,3 +14,4 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

const {PredicateTransition} = require('./../atn/Transition')
const {PredicateTransition} = require('./../atn/Transition');
const {Interval} = require('../IntervalSet').Interval;

@@ -80,5 +81,5 @@ class RecognitionException extends Error {

toString() {
let symbol = ""
let symbol = "";
if (this.startIndex >= 0 && this.startIndex < this.input.size) {
symbol = this.input.getText((this.startIndex,this.startIndex));
symbol = this.input.getText(new Interval(this.startIndex,this.startIndex));
}

@@ -85,0 +86,0 @@ return "LexerNoViableAltException" + symbol;

@@ -58,2 +58,4 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

this.lastErrorStates = null;
this.nextTokensContext = null;
this.nextTokenState = 0;
}

@@ -220,8 +222,18 @@

}
const s = recognizer._interp.atn.states[recognizer.state]
const la = recognizer.getTokenStream().LA(1)
const s = recognizer._interp.atn.states[recognizer.state];
const la = recognizer.getTokenStream().LA(1);
// try cheaper subset first; might get lucky. seems to shave a wee bit off
const nextTokens = recognizer.atn.nextTokens(s)
if (nextTokens.contains(Token.EPSILON) || nextTokens.contains(la)) {
const nextTokens = recognizer.atn.nextTokens(s);
if(nextTokens.contains(la)) {
this.nextTokensContext = null;
this.nextTokenState = ATNState.INVALID_STATE_NUMBER;
return;
} else if (nextTokens.contains(Token.EPSILON)) {
if(this.nextTokensContext === null) {
// It's possible the next token won't match information tracked
// by sync is restricted for performance.
this.nextTokensContext = recognizer._ctx;
this.nextTokensState = recognizer._stateNumber;
}
return;
}

@@ -228,0 +240,0 @@ switch (s.stateType) {

@@ -55,24 +55,24 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

addInterval(v) {
addInterval(toAdd) {
if (this.intervals === null) {
this.intervals = [];
this.intervals.push(v);
this.intervals.push(toAdd);
} else {
// find insert pos
for (let k = 0; k < this.intervals.length; k++) {
const i = this.intervals[k];
for (let pos = 0; pos < this.intervals.length; pos++) {
const existing = this.intervals[pos];
// distinct range -> insert
if (v.stop < i.start) {
this.intervals.splice(k, 0, v);
if (toAdd.stop < existing.start) {
this.intervals.splice(pos, 0, toAdd);
return;
}
// contiguous range -> adjust
else if (v.stop === i.start) {
this.intervals[k].start = v.start;
else if (toAdd.stop === existing.start) {
this.intervals[pos].start = toAdd.start;
return;
}
// overlapping range -> adjust and reduce
else if (v.start <= i.stop) {
this.intervals[k] = new Interval(Math.min(i.start, v.start), Math.max(i.stop, v.stop));
this.reduce(k);
else if (toAdd.start <= existing.stop) {
this.intervals[pos] = new Interval(Math.min(existing.start, toAdd.start), Math.max(existing.stop, toAdd.stop));
this.reduce(pos);
return;

@@ -82,3 +82,3 @@ }

// greater than any existing
this.intervals.push(v);
this.intervals.push(toAdd);
}

@@ -89,6 +89,3 @@ }

if (other.intervals !== null) {
for (let k = 0; k < other.intervals.length; k++) {
const i = other.intervals[k];
this.addInterval(new Interval(i.start, i.stop));
}
other.intervals.forEach( toAdd => this.addInterval(toAdd), this);
}

@@ -98,14 +95,14 @@ return this;

reduce(k) {
// only need to reduce if k is not the last
if (k < this.intervalslength - 1) {
const l = this.intervals[k];
const r = this.intervals[k + 1];
// if r contained in l
if (l.stop >= r.stop) {
this.intervals.pop(k + 1);
this.reduce(k);
} else if (l.stop >= r.start) {
this.intervals[k] = new Interval(l.start, r.stop);
this.intervals.pop(k + 1);
reduce(pos) {
// only need to reduce if pos is not the last
if (pos < this.intervals.length - 1) {
const current = this.intervals[pos];
const next = this.intervals[pos + 1];
// if next contained in current
if (current.stop >= next.stop) {
this.intervals.splice(pos + 1, 1);
this.reduce(pos);
} else if (current.stop >= next.start) {
this.intervals[pos] = new Interval(current.start, next.stop);
this.intervals.splice(pos + 1, 1);
}

@@ -118,5 +115,4 @@ }

result.addInterval(new Interval(start,stop+1));
for(let i=0; i<this.intervals.length; i++) {
result.removeRange(this.intervals[i]);
}
if(this.intervals !== null)
this.intervals.forEach(toRemove => result.removeRange(toRemove));
return result;

@@ -138,34 +134,34 @@ }

removeRange(v) {
if(v.start===v.stop-1) {
this.removeOne(v.start);
} else if (this.intervals!==null) {
let k = 0;
removeRange(toRemove) {
if(toRemove.start===toRemove.stop-1) {
this.removeOne(toRemove.start);
} else if (this.intervals !== null) {
let pos = 0;
for(let n=0; n<this.intervals.length; n++) {
const i = this.intervals[k];
const existing = this.intervals[pos];
// intervals are ordered
if (v.stop<=i.start) {
if (toRemove.stop<=existing.start) {
return;
}
// check for including range, split it
else if(v.start>i.start && v.stop<i.stop) {
this.intervals[k] = new Interval(i.start, v.start);
const x = new Interval(v.stop, i.stop);
this.intervals.splice(k, 0, x);
else if(toRemove.start>existing.start && toRemove.stop<existing.stop) {
this.intervals[pos] = new Interval(existing.start, toRemove.start);
const x = new Interval(toRemove.stop, existing.stop);
this.intervals.splice(pos, 0, x);
return;
}
// check for included range, remove it
else if(v.start<=i.start && v.stop>=i.stop) {
this.intervals.splice(k, 1);
k = k - 1; // need another pass
else if(toRemove.start<=existing.start && toRemove.stop>=existing.stop) {
this.intervals.splice(pos, 1);
pos = pos - 1; // need another pass
}
// check for lower boundary
else if(v.start<i.stop) {
this.intervals[k] = new Interval(i.start, v.start);
else if(toRemove.start<existing.stop) {
this.intervals[pos] = new Interval(existing.start, toRemove.start);
}
// check for upper boundary
else if(v.stop<i.stop) {
this.intervals[k] = new Interval(v.stop, i.stop);
else if(toRemove.stop<existing.stop) {
this.intervals[pos] = new Interval(toRemove.stop, existing.stop);
}
k += 1;
pos += 1;
}

@@ -175,30 +171,30 @@ }

removeOne(v) {
removeOne(value) {
if (this.intervals !== null) {
for (let k = 0; k < this.intervals.length; k++) {
const i = this.intervals[k];
// intervals is ordered
if (v < i.start) {
for (let i = 0; i < this.intervals.length; i++) {
const existing = this.intervals[i];
// intervals are ordered
if (value < existing.start) {
return;
}
// check for single value range
else if (v === i.start && v === i.stop - 1) {
this.intervals.splice(k, 1);
else if (value === existing.start && value === existing.stop - 1) {
this.intervals.splice(i, 1);
return;
}
// check for lower boundary
else if (v === i.start) {
this.intervals[k] = new Interval(i.start + 1, i.stop);
else if (value === existing.start) {
this.intervals[i] = new Interval(existing.start + 1, existing.stop);
return;
}
// check for upper boundary
else if (v === i.stop - 1) {
this.intervals[k] = new Interval(i.start, i.stop - 1);
else if (value === existing.stop - 1) {
this.intervals[i] = new Interval(existing.start, existing.stop - 1);
return;
}
// split existing range
else if (v < i.stop - 1) {
const x = new Interval(i.start, v);
i.start = v + 1;
this.intervals.splice(k, 0, x);
else if (value < existing.stop - 1) {
const replace = new Interval(existing.start, value);
existing.start = value + 1;
this.intervals.splice(i, 0, replace);
return;

@@ -228,11 +224,11 @@ }

for (let i = 0; i < this.intervals.length; i++) {
const v = this.intervals[i];
if(v.stop===v.start+1) {
if ( v.start===Token.EOF ) {
const existing = this.intervals[i];
if(existing.stop===existing.start+1) {
if ( existing.start===Token.EOF ) {
names.push("<EOF>");
} else {
names.push("'" + String.fromCharCode(v.start) + "'");
names.push("'" + String.fromCharCode(existing.start) + "'");
}
} else {
names.push("'" + String.fromCharCode(v.start) + "'..'" + String.fromCharCode(v.stop-1) + "'");
names.push("'" + String.fromCharCode(existing.start) + "'..'" + String.fromCharCode(existing.stop-1) + "'");
}

@@ -250,11 +246,11 @@ }

for (let i = 0; i < this.intervals.length; i++) {
const v = this.intervals[i];
if(v.stop===v.start+1) {
if ( v.start===Token.EOF ) {
const existing = this.intervals[i];
if(existing.stop===existing.start+1) {
if ( existing.start===Token.EOF ) {
names.push("<EOF>");
} else {
names.push(v.start.toString());
names.push(existing.start.toString());
}
} else {
names.push(v.start.toString() + ".." + (v.stop-1).toString());
names.push(existing.start.toString() + ".." + (existing.stop-1).toString());
}

@@ -272,4 +268,4 @@ }

for (let i = 0; i < this.intervals.length; i++) {
const v = this.intervals[i];
for (let j = v.start; j < v.stop; j++) {
const existing = this.intervals[i];
for (let j = existing.start; j < existing.stop; j++) {
names.push(this.elementName(literalNames, symbolicNames, j));

@@ -285,9 +281,9 @@ }

elementName(literalNames, symbolicNames, a) {
if (a === Token.EOF) {
elementName(literalNames, symbolicNames, token) {
if (token === Token.EOF) {
return "<EOF>";
} else if (a === Token.EPSILON) {
} else if (token === Token.EPSILON) {
return "<EPSILON>";
} else {
return literalNames[a] || symbolicNames[a];
return literalNames[token] || symbolicNames[token];
}

@@ -297,5 +293,3 @@ }

get length(){
let len = 0;
this.intervals.map(function(i) {len += i.length;});
return len;
return this.intervals.map( interval => interval.length ).reduce((acc, val) => acc + val);
}

@@ -302,0 +296,0 @@ }

@@ -131,14 +131,14 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

if (ctx !== PredictionContext.EMPTY) {
// run thru all possible stack tops in ctx
for(let i=0; i<ctx.length; i++) {
const returnState = this.atn.states[ctx.getReturnState(i)];
const removed = calledRuleStack.contains(returnState.ruleIndex);
try {
calledRuleStack.remove(returnState.ruleIndex);
const removed = calledRuleStack.contains(s.ruleIndex);
try {
calledRuleStack.remove(s.ruleIndex);
// run thru all possible stack tops in ctx
for (let i = 0; i < ctx.length; i++) {
const returnState = this.atn.states[ctx.getReturnState(i)];
this._LOOK(returnState, stopState, ctx.getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
} finally {
if (removed) {
calledRuleStack.add(returnState.ruleIndex);
}
}
}finally {
if (removed) {
calledRuleStack.add(s.ruleIndex);
}
}

@@ -145,0 +145,0 @@ return;

@@ -7,18 +7,20 @@ /*! https://mths.be/codepointat v0.2.0 by @mathias */

// IE 8 only supports `Object.defineProperty` on DOM elements
let result;
try {
var object = {};
var $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {}
const object = {};
const $defineProperty = Object.defineProperty;
result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {
}
return result;
}());
var codePointAt = function(position) {
const codePointAt = function(position) {
if (this == null) {
throw TypeError();
}
var string = String(this);
var size = string.length;
const string = String(this);
const size = string.length;
// `ToInteger`
var index = position ? Number(position) : 0;
if (index != index) { // better `isNaN`
let index = position ? Number(position) : 0;
if (index !== index) { // better `isNaN`
index = 0;

@@ -31,4 +33,4 @@ }

// Get the first code unit
var first = string.charCodeAt(index);
var second;
const first = string.charCodeAt(index);
let second;
if ( // check if it’s the start of a surrogate pair

@@ -35,0 +37,0 @@ first >= 0xD800 && first <= 0xDBFF && // high surrogate

/*! https://mths.be/fromcodepoint v0.2.1 by @mathias */
if (!String.fromCodePoint) {
(function() {
var defineProperty = (function() {
const defineProperty = (function() {
// IE 8 only supports `Object.defineProperty` on DOM elements
let result;
try {
var object = {};
var $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty;
const object = {};
const $defineProperty = Object.defineProperty;
result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {}
return result;
}());
var stringFromCharCode = String.fromCharCode;
var floor = Math.floor;
var fromCodePoint = function(_) {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
var lowSurrogate;
var index = -1;
var length = arguments.length;
const stringFromCharCode = String.fromCharCode;
const floor = Math.floor;
const fromCodePoint = function(_) {
const MAX_SIZE = 0x4000;
const codeUnits = [];
let highSurrogate;
let lowSurrogate;
let index = -1;
const length = arguments.length;
if (!length) {
return '';
}
var result = '';
let result = '';
while (++index < length) {
var codePoint = Number(arguments[index]);
let codePoint = Number(arguments[index]);
if (

@@ -32,3 +33,3 @@ !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`

codePoint > 0x10FFFF || // not a valid Unicode code point
floor(codePoint) != codePoint // not an integer
floor(codePoint) !== codePoint // not an integer
) {

@@ -46,3 +47,3 @@ throw RangeError('Invalid code point: ' + codePoint);

}
if (index + 1 == length || codeUnits.length > MAX_SIZE) {
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits);

@@ -49,0 +50,0 @@ codeUnits.length = 0;

@@ -18,3 +18,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

checkVersion(toolVersion) {
const runtimeVersion = "4.9.1";
const runtimeVersion = "4.9.2";
if (runtimeVersion!==toolVersion) {

@@ -21,0 +21,0 @@ console.log("ANTLR runtime and generated code versions disagree: "+runtimeVersion+"!="+toolVersion);

@@ -7,3 +7,3 @@ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.

function arrayToString(a) {
return "[" + a.join(", ") + "]";
return Array.isArray(a) ? ("[" + a.join(", ") + "]") : "null";
}

@@ -427,8 +427,8 @@

return false;
if (a == b)
if (a === b)
return true;
if (a.length != b.length)
if (a.length !== b.length)
return false;
for (let i = 0; i < a.length; i++) {
if (a[i] == b[i])
if (a[i] === b[i])
continue;

@@ -435,0 +435,0 @@ if (!a[i].equals || !a[i].equals(b[i]))

@@ -1,2 +0,2 @@

const path = require('path')
const path = require('path');

@@ -28,2 +28,2 @@ module.exports = {

}
}
};

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc