Initial commit with Advoware proxy

This commit is contained in:
root
2025-10-19 14:57:07 +00:00
commit 273aa8b549
45771 changed files with 5534555 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
/**
* Validates that an argument is not `null` or `undefined`.
*
* @param parameterName The name of the parameter
* @param value The argument value
*
* @throws `TypeError` if `value` is `null` or `undefined`.
*/
export declare function notNull(parameterName: string, value: any): void;

View File

@@ -0,0 +1,23 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.notNull = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:39.6568608-07:00
/**
* Validates that an argument is not `null` or `undefined`.
*
* @param parameterName The name of the parameter
* @param value The argument value
*
* @throws `TypeError` if `value` is `null` or `undefined`.
*/
function notNull(parameterName, value) {
if (value == null) {
throw new TypeError(parameterName + " cannot be null or undefined.");
}
}
exports.notNull = notNull;
//# sourceMappingURL=Args.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Args.js","sourceRoot":"","sources":["../../../src/misc/Args.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wDAAwD;AAExD;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,aAAqB,EAAE,KAAU;IACxD,IAAI,KAAK,IAAI,IAAI,EAAE;QAClB,MAAM,IAAI,SAAS,CAAC,aAAa,GAAG,+BAA+B,CAAC,CAAC;KACrE;AACF,CAAC;AAJD,0BAIC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:39.6568608-07:00\r\n\r\n/**\r\n * Validates that an argument is not `null` or `undefined`.\r\n *\r\n * @param parameterName The name of the parameter\r\n * @param value The argument value\r\n *\r\n * @throws `TypeError` if `value` is `null` or `undefined`.\r\n */\r\nexport function notNull(parameterName: string, value: any): void {\r\n\tif (value == null) {\r\n\t\tthrow new TypeError(parameterName + \" cannot be null or undefined.\");\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,20 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { EqualityComparator } from "./EqualityComparator";
import { JavaMap } from "./Stubs";
export declare class Array2DHashMap<K, V> implements JavaMap<K, V> {
private backingStore;
constructor(keyComparer: EqualityComparator<K>);
constructor(map: Array2DHashMap<K, V>);
clear(): void;
containsKey(key: K): boolean;
get(key: K): V | undefined;
get isEmpty(): boolean;
put(key: K, value: V): V | undefined;
putIfAbsent(key: K, value: V): V | undefined;
get size(): number;
hashCode(): number;
equals(o: any): boolean;
}

View File

@@ -0,0 +1,82 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Array2DHashMap = void 0;
const Array2DHashSet_1 = require("./Array2DHashSet");
class MapKeyEqualityComparator {
constructor(keyComparator) {
this.keyComparator = keyComparator;
}
hashCode(obj) {
return this.keyComparator.hashCode(obj.key);
}
equals(a, b) {
return this.keyComparator.equals(a.key, b.key);
}
}
class Array2DHashMap {
constructor(keyComparer) {
if (keyComparer instanceof Array2DHashMap) {
this.backingStore = new Array2DHashSet_1.Array2DHashSet(keyComparer.backingStore);
}
else {
this.backingStore = new Array2DHashSet_1.Array2DHashSet(new MapKeyEqualityComparator(keyComparer));
}
}
clear() {
this.backingStore.clear();
}
containsKey(key) {
return this.backingStore.contains({ key });
}
get(key) {
let bucket = this.backingStore.get({ key });
if (!bucket) {
return undefined;
}
return bucket.value;
}
get isEmpty() {
return this.backingStore.isEmpty;
}
put(key, value) {
let element = this.backingStore.get({ key, value });
let result;
if (!element) {
this.backingStore.add({ key, value });
}
else {
result = element.value;
element.value = value;
}
return result;
}
putIfAbsent(key, value) {
let element = this.backingStore.get({ key, value });
let result;
if (!element) {
this.backingStore.add({ key, value });
}
else {
result = element.value;
}
return result;
}
get size() {
return this.backingStore.size;
}
hashCode() {
return this.backingStore.hashCode();
}
equals(o) {
if (!(o instanceof Array2DHashMap)) {
return false;
}
return this.backingStore.equals(o.backingStore);
}
}
exports.Array2DHashMap = Array2DHashMap;
//# sourceMappingURL=Array2DHashMap.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { EqualityComparator } from "./EqualityComparator";
import { JavaCollection, JavaSet } from "./Stubs";
export declare class Array2DHashSet<T extends {
toString(): string;
}> implements JavaSet<T> {
protected comparator: EqualityComparator<T>;
protected buckets: Array<T[] | undefined>;
/** How many elements in set */
protected n: number;
protected threshold: number;
constructor(comparator?: EqualityComparator<T>, initialCapacity?: number);
constructor(set: Array2DHashSet<T>);
/**
* Add `o` to set if not there; return existing value if already
* there. This method performs the same operation as {@link #add} aside from
* the return value.
*/
getOrAdd(o: T): T;
protected getOrAddImpl(o: T): T;
get(o: T): T | undefined;
protected getBucket(o: T): number;
hashCode(): number;
equals(o: any): boolean;
protected expand(): void;
add(t: T): boolean;
get size(): number;
get isEmpty(): boolean;
contains(o: any): boolean;
containsFast(obj: T): boolean;
[Symbol.iterator](): IterableIterator<T>;
toArray(): T[];
containsAll(collection: JavaCollection<T>): boolean;
addAll(c: Iterable<T>): boolean;
clear(): void;
toString(): string;
toTableString(): string;
/**
* Return `o` as an instance of the element type `T`. If
* `o` is non-undefined but known to not be an instance of `T`, this
* method returns `undefined`. The base implementation does not perform any
* type checks; override this method to provide strong type checks for the
* {@link #contains} and {@link #remove} methods to ensure the arguments to
* the {@link EqualityComparator} for the set always have the expected
* types.
*
* @param o the object to try and cast to the element type of the set
* @returns `o` if it could be an instance of `T`, otherwise
* `undefined`.
*/
protected asElementType(o: any): T;
/**
* Return an array of `T[]` with length `capacity`.
*
* @param capacity the length of the array to return
* @returns the newly constructed array
*/
protected createBuckets(capacity: number): Array<T[] | undefined>;
}

View File

@@ -0,0 +1,366 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Array2DHashSet = void 0;
// ConvertTo-TS run at 2016-10-03T02:09:41.7434086-07:00
const assert = require("assert");
const DefaultEqualityComparator_1 = require("./DefaultEqualityComparator");
const Decorators_1 = require("../Decorators");
const MurmurHash_1 = require("./MurmurHash");
/** {@link Set} implementation with closed hashing (open addressing). */
// NOTE: JavaScript's Set interface has on significant different diffrence from Java's:
// e.g. the return type of add() differs!
// For this reason I've commented tweaked the implements clause
const INITAL_CAPACITY = 16; // must be power of 2
const LOAD_FACTOR = 0.75;
class Array2DHashSet {
constructor(comparatorOrSet, initialCapacity = INITAL_CAPACITY) {
/** How many elements in set */
this.n = 0;
this.threshold = Math.floor(INITAL_CAPACITY * LOAD_FACTOR); // when to expand
if (comparatorOrSet instanceof Array2DHashSet) {
this.comparator = comparatorOrSet.comparator;
this.buckets = comparatorOrSet.buckets.slice(0);
for (let i = 0; i < this.buckets.length; i++) {
let bucket = this.buckets[i];
if (bucket) {
this.buckets[i] = bucket.slice(0);
}
}
this.n = comparatorOrSet.n;
this.threshold = comparatorOrSet.threshold;
}
else {
this.comparator = comparatorOrSet || DefaultEqualityComparator_1.DefaultEqualityComparator.INSTANCE;
this.buckets = this.createBuckets(initialCapacity);
}
}
/**
* Add `o` to set if not there; return existing value if already
* there. This method performs the same operation as {@link #add} aside from
* the return value.
*/
getOrAdd(o) {
if (this.n > this.threshold) {
this.expand();
}
return this.getOrAddImpl(o);
}
getOrAddImpl(o) {
let b = this.getBucket(o);
let bucket = this.buckets[b];
// NEW BUCKET
if (!bucket) {
bucket = [o];
this.buckets[b] = bucket;
this.n++;
return o;
}
// LOOK FOR IT IN BUCKET
for (let existing of bucket) {
if (this.comparator.equals(existing, o)) {
return existing; // found existing, quit
}
}
// FULL BUCKET, expand and add to end
bucket.push(o);
this.n++;
return o;
}
get(o) {
if (o == null) {
return o;
}
let b = this.getBucket(o);
let bucket = this.buckets[b];
if (!bucket) {
// no bucket
return undefined;
}
for (let e of bucket) {
if (this.comparator.equals(e, o)) {
return e;
}
}
return undefined;
}
getBucket(o) {
let hash = this.comparator.hashCode(o);
let b = hash & (this.buckets.length - 1); // assumes len is power of 2
return b;
}
hashCode() {
let hash = MurmurHash_1.MurmurHash.initialize();
for (let bucket of this.buckets) {
if (bucket == null) {
continue;
}
for (let o of bucket) {
if (o == null) {
break;
}
hash = MurmurHash_1.MurmurHash.update(hash, this.comparator.hashCode(o));
}
}
hash = MurmurHash_1.MurmurHash.finish(hash, this.size);
return hash;
}
equals(o) {
if (o === this) {
return true;
}
if (!(o instanceof Array2DHashSet)) {
return false;
}
if (o.size !== this.size) {
return false;
}
let same = this.containsAll(o);
return same;
}
expand() {
let old = this.buckets;
let newCapacity = this.buckets.length * 2;
let newTable = this.createBuckets(newCapacity);
this.buckets = newTable;
this.threshold = Math.floor(newCapacity * LOAD_FACTOR);
// System.out.println("new size="+newCapacity+", thres="+threshold);
// rehash all existing entries
let oldSize = this.size;
for (let bucket of old) {
if (!bucket) {
continue;
}
for (let o of bucket) {
let b = this.getBucket(o);
let newBucket = this.buckets[b];
if (!newBucket) {
newBucket = [];
this.buckets[b] = newBucket;
}
newBucket.push(o);
}
}
assert(this.n === oldSize);
}
add(t) {
let existing = this.getOrAdd(t);
return existing === t;
}
get size() {
return this.n;
}
get isEmpty() {
return this.n === 0;
}
contains(o) {
return this.containsFast(this.asElementType(o));
}
containsFast(obj) {
if (obj == null) {
return false;
}
return this.get(obj) != null;
}
*[Symbol.iterator]() {
yield* this.toArray();
}
toArray() {
const a = new Array(this.size);
// Copy elements from the nested arrays into the destination array
let i = 0; // Position within destination array
for (let bucket of this.buckets) {
if (bucket == null) {
continue;
}
for (let o of bucket) {
if (o == null) {
break;
}
a[i++] = o;
}
}
return a;
}
containsAll(collection) {
if (collection instanceof Array2DHashSet) {
let s = collection;
for (let bucket of s.buckets) {
if (bucket == null) {
continue;
}
for (let o of bucket) {
if (o == null) {
break;
}
if (!this.containsFast(this.asElementType(o))) {
return false;
}
}
}
}
else {
for (let o of collection) {
if (!this.containsFast(this.asElementType(o))) {
return false;
}
}
}
return true;
}
addAll(c) {
let changed = false;
for (let o of c) {
let existing = this.getOrAdd(o);
if (existing !== o) {
changed = true;
}
}
return changed;
}
clear() {
this.buckets = this.createBuckets(INITAL_CAPACITY);
this.n = 0;
this.threshold = Math.floor(INITAL_CAPACITY * LOAD_FACTOR);
}
toString() {
if (this.size === 0) {
return "{}";
}
let buf = "{";
let first = true;
for (let bucket of this.buckets) {
if (bucket == null) {
continue;
}
for (let o of bucket) {
if (o == null) {
break;
}
if (first) {
first = false;
}
else {
buf += ", ";
}
buf += o.toString();
}
}
buf += "}";
return buf;
}
toTableString() {
let buf = "";
for (let bucket of this.buckets) {
if (bucket == null) {
buf += "null\n";
continue;
}
buf += "[";
let first = true;
for (let o of bucket) {
if (first) {
first = false;
}
else {
buf += " ";
}
if (o == null) {
buf += "_";
}
else {
buf += o.toString();
}
}
buf += "]\n";
}
return buf;
}
/**
* Return `o` as an instance of the element type `T`. If
* `o` is non-undefined but known to not be an instance of `T`, this
* method returns `undefined`. The base implementation does not perform any
* type checks; override this method to provide strong type checks for the
* {@link #contains} and {@link #remove} methods to ensure the arguments to
* the {@link EqualityComparator} for the set always have the expected
* types.
*
* @param o the object to try and cast to the element type of the set
* @returns `o` if it could be an instance of `T`, otherwise
* `undefined`.
*/
asElementType(o) {
return o;
}
/**
* Return an array of `T[]` with length `capacity`.
*
* @param capacity the length of the array to return
* @returns the newly constructed array
*/
createBuckets(capacity) {
return new Array(capacity);
}
}
__decorate([
Decorators_1.NotNull
], Array2DHashSet.prototype, "comparator", void 0);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "equals", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "add", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "size", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "isEmpty", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "contains", null);
__decorate([
__param(0, Decorators_1.Nullable)
], Array2DHashSet.prototype, "containsFast", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, Symbol.iterator, null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "toArray", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "containsAll", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "addAll", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "clear", null);
__decorate([
Decorators_1.Override
], Array2DHashSet.prototype, "toString", null);
__decorate([
Decorators_1.SuppressWarnings("unchecked")
], Array2DHashSet.prototype, "asElementType", null);
__decorate([
Decorators_1.SuppressWarnings("unchecked")
], Array2DHashSet.prototype, "createBuckets", null);
exports.Array2DHashSet = Array2DHashSet;
//# sourceMappingURL=Array2DHashSet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { EqualityComparator } from "./EqualityComparator";
import { Equatable } from "./Stubs";
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
export declare class ArrayEqualityComparator implements EqualityComparator<Equatable[]> {
static readonly INSTANCE: ArrayEqualityComparator;
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj: Equatable[]): number;
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined`, this method returns `true`. Otherwise if only
* `a` is `undefined`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a: Equatable[], b: Equatable[]): boolean;
}

View File

@@ -0,0 +1,71 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayEqualityComparator = void 0;
const Decorators_1 = require("../Decorators");
const MurmurHash_1 = require("./MurmurHash");
const ObjectEqualityComparator_1 = require("./ObjectEqualityComparator");
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
class ArrayEqualityComparator {
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj) {
if (obj == null) {
return 0;
}
return MurmurHash_1.MurmurHash.hashCode(obj, 0);
}
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined`, this method returns `true`. Otherwise if only
* `a` is `undefined`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a, b) {
if (a == null) {
return b == null;
}
else if (b == null) {
return false;
}
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (!ObjectEqualityComparator_1.ObjectEqualityComparator.INSTANCE.equals(a[i], b[i])) {
return false;
}
}
return true;
}
}
ArrayEqualityComparator.INSTANCE = new ArrayEqualityComparator();
__decorate([
Decorators_1.Override
], ArrayEqualityComparator.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], ArrayEqualityComparator.prototype, "equals", null);
exports.ArrayEqualityComparator = ArrayEqualityComparator;
//# sourceMappingURL=ArrayEqualityComparator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ArrayEqualityComparator.js","sourceRoot":"","sources":["../../../src/misc/ArrayEqualityComparator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAIH,8CAAyC;AAEzC,6CAA0C;AAC1C,yEAAsE;AAEtE;;;;;GAKG;AACH,MAAa,uBAAuB;IAGnC;;;;;OAKG;IAEI,QAAQ,CAAC,GAAgB;QAC/B,IAAI,GAAG,IAAI,IAAI,EAAE;YAChB,OAAO,CAAC,CAAC;SACT;QAED,OAAO,uBAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;;;OAQG;IAEI,MAAM,CAAC,CAAc,EAAE,CAAc;QAC3C,IAAI,CAAC,IAAI,IAAI,EAAE;YACd,OAAO,CAAC,IAAI,IAAI,CAAC;SACjB;aAAM,IAAI,CAAC,IAAI,IAAI,EAAE;YACrB,OAAO,KAAK,CAAC;SACb;QAED,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;YAC1B,OAAO,KAAK,CAAC;SACb;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClC,IAAI,CAAC,mDAAwB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC1D,OAAO,KAAK,CAAC;aACb;SACD;QAED,OAAO,IAAI,CAAC;IACb,CAAC;;AA7CsB,gCAAQ,GAA4B,IAAI,uBAAuB,EAAE,CAAC;AASzF;IADC,qBAAQ;uDAOR;AAYD;IADC,qBAAQ;qDAmBR;AA9CF,0DAgDC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-03T02:09:42.2127260-07:00\r\nimport { EqualityComparator } from \"./EqualityComparator\";\r\nimport { Override } from \"../Decorators\";\r\nimport { Equatable } from \"./Stubs\";\r\nimport { MurmurHash } from \"./MurmurHash\";\r\nimport { ObjectEqualityComparator } from \"./ObjectEqualityComparator\";\r\n\r\n/**\r\n * This default implementation of {@link EqualityComparator} uses object equality\r\n * for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class ArrayEqualityComparator implements EqualityComparator<Equatable[]> {\r\n\tpublic static readonly INSTANCE: ArrayEqualityComparator = new ArrayEqualityComparator();\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation returns\r\n\t * `obj.`{@link Object#hashCode hashCode()}.\r\n\t */\r\n\t@Override\r\n\tpublic hashCode(obj: Equatable[]): number {\r\n\t\tif (obj == null) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\treturn MurmurHash.hashCode(obj, 0);\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation relies on object equality. If both objects are\r\n\t * `undefined`, this method returns `true`. Otherwise if only\r\n\t * `a` is `undefined`, this method returns `false`. Otherwise,\r\n\t * this method returns the result of\r\n\t * `a.`{@link Object#equals equals}`(b)`.\r\n\t */\r\n\t@Override\r\n\tpublic equals(a: Equatable[], b: Equatable[]): boolean {\r\n\t\tif (a == null) {\r\n\t\t\treturn b == null;\r\n\t\t} else if (b == null) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tif (a.length !== b.length) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tfor (let i = 0; i < a.length; i++) {\r\n\t\t\tif (!ObjectEqualityComparator.INSTANCE.equals(a[i], b[i])) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n}\r\n"]}

View File

@@ -0,0 +1,18 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export declare namespace Arrays {
/**
* Searches the specified array of numbers for the specified value using the binary search algorithm. The array must
* be sorted prior to making this call. If it is not sorted, the results are unspecified. If the array contains
* multiple elements with the specified value, there is no guarantee which one will be found.
*
* @returns index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The
* insertion point is defined as the point at which the key would be inserted into the array: the index of the first
* element greater than the key, or array.length if all elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if and only if the key is found.
*/
function binarySearch(array: ArrayLike<number>, key: number, fromIndex?: number, toIndex?: number): number;
function toString<T>(array: Iterable<T>): string;
}

View File

@@ -0,0 +1,69 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Arrays = void 0;
var Arrays;
(function (Arrays) {
/**
* Searches the specified array of numbers for the specified value using the binary search algorithm. The array must
* be sorted prior to making this call. If it is not sorted, the results are unspecified. If the array contains
* multiple elements with the specified value, there is no guarantee which one will be found.
*
* @returns index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The
* insertion point is defined as the point at which the key would be inserted into the array: the index of the first
* element greater than the key, or array.length if all elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if and only if the key is found.
*/
function binarySearch(array, key, fromIndex, toIndex) {
return binarySearch0(array, fromIndex !== undefined ? fromIndex : 0, toIndex !== undefined ? toIndex : array.length, key);
}
Arrays.binarySearch = binarySearch;
function binarySearch0(array, fromIndex, toIndex, key) {
let low = fromIndex;
let high = toIndex - 1;
while (low <= high) {
let mid = (low + high) >>> 1;
let midVal = array[mid];
if (midVal < key) {
low = mid + 1;
}
else if (midVal > key) {
high = mid - 1;
}
else {
// key found
return mid;
}
}
// key not found.
return -(low + 1);
}
function toString(array) {
let result = "[";
let first = true;
for (let element of array) {
if (first) {
first = false;
}
else {
result += ", ";
}
if (element === null) {
result += "null";
}
else if (element === undefined) {
result += "undefined";
}
else {
result += element;
}
}
result += "]";
return result;
}
Arrays.toString = toString;
})(Arrays = exports.Arrays || (exports.Arrays = {}));
//# sourceMappingURL=Arrays.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Arrays.js","sourceRoot":"","sources":["../../../src/misc/Arrays.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,IAAiB,MAAM,CA4DtB;AA5DD,WAAiB,MAAM;IACtB;;;;;;;;;OASG;IACH,SAAgB,YAAY,CAAC,KAAwB,EAAE,GAAW,EAAE,SAAkB,EAAE,OAAgB;QACvG,OAAO,aAAa,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3H,CAAC;IAFe,mBAAY,eAE3B,CAAA;IAED,SAAS,aAAa,CAAC,KAAwB,EAAE,SAAiB,EAAE,OAAe,EAAE,GAAW;QAC/F,IAAI,GAAG,GAAW,SAAS,CAAC;QAC5B,IAAI,IAAI,GAAW,OAAO,GAAG,CAAC,CAAC;QAE/B,OAAO,GAAG,IAAI,IAAI,EAAE;YACnB,IAAI,GAAG,GAAW,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,MAAM,GAAW,KAAK,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,MAAM,GAAG,GAAG,EAAE;gBACjB,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;aACd;iBAAM,IAAI,MAAM,GAAG,GAAG,EAAE;gBACxB,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;aACf;iBAAM;gBACN,YAAY;gBACZ,OAAO,GAAG,CAAC;aACX;SACD;QAED,iBAAiB;QACjB,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACnB,CAAC;IAED,SAAgB,QAAQ,CAAI,KAAkB;QAC7C,IAAI,MAAM,GAAG,GAAG,CAAC;QAEjB,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,KAAK,IAAI,OAAO,IAAI,KAAK,EAAE;YAC1B,IAAI,KAAK,EAAE;gBACV,KAAK,GAAG,KAAK,CAAC;aACd;iBAAM;gBACN,MAAM,IAAI,IAAI,CAAC;aACf;YAED,IAAI,OAAO,KAAK,IAAI,EAAE;gBACrB,MAAM,IAAI,MAAM,CAAC;aACjB;iBAAM,IAAI,OAAO,KAAK,SAAS,EAAE;gBACjC,MAAM,IAAI,WAAW,CAAC;aACtB;iBAAM;gBACN,MAAM,IAAI,OAAO,CAAC;aAClB;SACD;QAED,MAAM,IAAI,GAAG,CAAC;QACd,OAAO,MAAM,CAAC;IACf,CAAC;IAtBe,eAAQ,WAsBvB,CAAA;AACF,CAAC,EA5DgB,MAAM,GAAN,cAAM,KAAN,cAAM,QA4DtB","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nexport namespace Arrays {\r\n\t/**\r\n\t * Searches the specified array of numbers for the specified value using the binary search algorithm. The array must\r\n\t * be sorted prior to making this call. If it is not sorted, the results are unspecified. If the array contains\r\n\t * multiple elements with the specified value, there is no guarantee which one will be found.\r\n\t *\r\n\t * @returns index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The\r\n\t * insertion point is defined as the point at which the key would be inserted into the array: the index of the first\r\n\t * element greater than the key, or array.length if all elements in the array are less than the specified key. Note\r\n\t * that this guarantees that the return value will be >= 0 if and only if the key is found.\r\n\t */\r\n\texport function binarySearch(array: ArrayLike<number>, key: number, fromIndex?: number, toIndex?: number): number {\r\n\t\treturn binarySearch0(array, fromIndex !== undefined ? fromIndex : 0, toIndex !== undefined ? toIndex : array.length, key);\r\n\t}\r\n\r\n\tfunction binarySearch0(array: ArrayLike<number>, fromIndex: number, toIndex: number, key: number): number {\r\n\t\tlet low: number = fromIndex;\r\n\t\tlet high: number = toIndex - 1;\r\n\r\n\t\twhile (low <= high) {\r\n\t\t\tlet mid: number = (low + high) >>> 1;\r\n\t\t\tlet midVal: number = array[mid];\r\n\r\n\t\t\tif (midVal < key) {\r\n\t\t\t\tlow = mid + 1;\r\n\t\t\t} else if (midVal > key) {\r\n\t\t\t\thigh = mid - 1;\r\n\t\t\t} else {\r\n\t\t\t\t// key found\r\n\t\t\t\treturn mid;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// key not found.\r\n\t\treturn -(low + 1);\r\n\t}\r\n\r\n\texport function toString<T>(array: Iterable<T>) {\r\n\t\tlet result = \"[\";\r\n\r\n\t\tlet first = true;\r\n\t\tfor (let element of array) {\r\n\t\t\tif (first) {\r\n\t\t\t\tfirst = false;\r\n\t\t\t} else {\r\n\t\t\t\tresult += \", \";\r\n\t\t\t}\r\n\r\n\t\t\tif (element === null) {\r\n\t\t\t\tresult += \"null\";\r\n\t\t\t} else if (element === undefined) {\r\n\t\t\t\tresult += \"undefined\";\r\n\t\t\t} else {\r\n\t\t\t\tresult += element;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tresult += \"]\";\r\n\t\treturn result;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,268 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export declare class BitSet implements Iterable<number> {
private data;
/**
* Creates a new bit set. All bits are initially `false`.
*/
constructor();
/**
* Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range `0`
* through `nbits-1`. All bits are initially `false`.
*/
constructor(nbits: number);
/**
* Creates a bit set from a iterable list of numbers (including another BitSet);
*/
constructor(numbers: Iterable<number>);
/**
* Performs a logical **AND** of this target bit set with the argument bit set. This bit set is modified so that
* each bit in it has the value `true` if and only if it both initially had the value `true` and the corresponding
* bit in the bit set argument also had the value `true`.
*/
and(set: BitSet): void;
/**
* Clears all of the bits in this `BitSet` whose corresponding bit is set in the specified `BitSet`.
*/
andNot(set: BitSet): void;
/**
* Returns the number of bits set to `true` in this `BitSet`.
*/
cardinality(): number;
/**
* Sets all of the bits in this `BitSet` to `false`.
*/
clear(): void;
/**
* Sets the bit specified by the index to `false`.
*
* @param bitIndex the index of the bit to be cleared
*
* @throws RangeError if the specified index is negative
*/
clear(bitIndex: number): void;
/**
* Sets the bits from the specified `fromIndex` (inclusive) to the specified `toIndex` (exclusive) to `false`.
*
* @param fromIndex index of the first bit to be cleared
* @param toIndex index after the last bit to be cleared
*
* @throws RangeError if `fromIndex` is negative, or `toIndex` is negative, or `fromIndex` is larger than `toIndex`
*/
clear(fromIndex: number, toIndex: number): void;
/**
* Sets the bit at the specified index to the complement of its current value.
*
* @param bitIndex the index of the bit to flip
*
* @throws RangeError if the specified index is negative
*/
flip(bitIndex: number): void;
/**
* Sets each bit from the specified `fromIndex` (inclusive) to the specified `toIndex` (exclusive) to the complement
* of its current value.
*
* @param fromIndex index of the first bit to flip
* @param toIndex index after the last bit to flip
*
* @throws RangeError if `fromIndex` is negative, or `toIndex` is negative, or `fromIndex` is larger than `toIndex`
*/
flip(fromIndex: number, toIndex: number): void;
/**
* Returns the value of the bit with the specified index. The value is `true` if the bit with the index `bitIndex`
* is currently set in this `BitSet`; otherwise, the result is `false`.
*
* @param bitIndex the bit index
*
* @throws RangeError if the specified index is negative
*/
get(bitIndex: number): boolean;
/**
* Returns a new `BitSet` composed of bits from this `BitSet` from `fromIndex` (inclusive) to `toIndex` (exclusive).
*
* @param fromIndex index of the first bit to include
* @param toIndex index after the last bit to include
*
* @throws RangeError if `fromIndex` is negative, or `toIndex` is negative, or `fromIndex` is larger than `toIndex`
*/
get(fromIndex: number, toIndex: number): BitSet;
/**
* Returns true if the specified `BitSet` has any bits set to `true` that are also set to `true` in this `BitSet`.
*
* @param set `BitSet` to intersect with
*/
intersects(set: BitSet): boolean;
/**
* Returns true if this `BitSet` contains no bits that are set to `true`.
*/
get isEmpty(): boolean;
/**
* Returns the "logical size" of this `BitSet`: the index of the highest set bit in the `BitSet` plus one. Returns
* zero if the `BitSet` contains no set bits.
*/
length(): number;
/**
* Returns the index of the first bit that is set to `false` that occurs on or after the specified starting index,
* If no such bit exists then `-1` is returned.
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is negative
*/
nextClearBit(fromIndex: number): number;
/**
* Returns the index of the first bit that is set to `true` that occurs on or after the specified starting index.
* If no such bit exists then `-1` is returned.
*
* To iterate over the `true` bits in a `BitSet`, use the following loop:
*
* ```
* for (let i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
* // operate on index i here
* }
* ```
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is negative
*/
nextSetBit(fromIndex: number): number;
/**
* Performs a logical **OR** of this bit set with the bit set argument. This bit set is modified so that a bit in it
* has the value `true` if and only if it either already had the value `true` or the corresponding bit in the bit
* set argument has the value `true`.
*/
or(set: BitSet): void;
/**
* Returns the index of the nearest bit that is set to `false` that occurs on or before the specified starting
* index. If no such bit exists, or if `-1` is given as the starting index, then `-1` is returned.
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is less than `-1`
*/
previousClearBit(fromIndex: number): number;
/**
* Returns the index of the nearest bit that is set to `true` that occurs on or before the specified starting index.
* If no such bit exists, or if `-1` is given as the starting index, then `-1` is returned.
*
* To iterate over the `true` bits in a `BitSet`, use the following loop:
*
* ```
* for (let i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) {
* // operate on index i here
* }
* ```
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is less than `-1`
*/
previousSetBit(fromIndex: number): number;
/**
* Sets the bit at the specified index to `true`.
*
* @param bitIndex a bit index
*
* @throws RangeError if the specified index is negative
*/
set(bitIndex: number): void;
/**
* Sets the bit at the specified index to the specified value.
*
* @param bitIndex a bit index
* @param value a boolean value to set
*
* @throws RangeError if the specified index is negative
*/
set(bitIndex: number, value: boolean): void;
/**
* Sets the bits from the specified `fromIndex` (inclusive) to the specified `toIndex` (exclusive) to `true`.
*
* @param fromIndex index of the first bit to be set
* @param toIndex index after the last bit to be set
*
* @throws RangeError if `fromIndex` is negative, or `toIndex` is negative, or `fromIndex` is larger than `toIndex`
*/
set(fromIndex: number, toIndex: number): void;
/**
* Sets the bits from the specified `fromIndex` (inclusive) to the specified `toIndex` (exclusive) to the specified
* value.
*
* @param fromIndex index of the first bit to be set
* @param toIndex index after the last bit to be set
* @param value value to set the selected bits to
*
* @throws RangeError if `fromIndex` is negative, or `toIndex` is negative, or `fromIndex` is larger than `toIndex`
*/
set(fromIndex: number, toIndex: number, value: boolean): void;
private _setBits;
/**
* Returns the number of bits of space actually in use by this `BitSet` to represent bit values. The maximum element
* in the set is the size - 1st element.
*/
get size(): number;
/**
* Returns a new byte array containing all the bits in this bit set.
*
* More precisely, if
* `let bytes = s.toByteArray();`
* then `bytes.length === (s.length()+7)/8` and `s.get(n) === ((bytes[n/8] & (1<<(n%8))) != 0)` for all
* `n < 8 * bytes.length`.
*/
/**
* Returns a new integer array containing all the bits in this bit set.
*
* More precisely, if
* `let integers = s.toIntegerArray();`
* then `integers.length === (s.length()+31)/32` and `s.get(n) === ((integers[n/32] & (1<<(n%32))) != 0)` for all
* `n < 32 * integers.length`.
*/
hashCode(): number;
/**
* Compares this object against the specified object. The result is `true` if and only if the argument is not
* `undefined` and is a `Bitset` object that has exactly the same set of bits set to `true` as this bit set. That
* is, for every nonnegative index `k`,
*
* ```
* ((BitSet)obj).get(k) == this.get(k)
* ```
*
* must be true. The current sizes of the two bit sets are not compared.
*/
equals(obj: any): boolean;
/**
* Returns a string representation of this bit set. For every index for which this `BitSet` contains a bit in the
* set state, the decimal representation of that index is included in the result. Such indices are listed in order
* from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual
* mathematical notation for a set of integers.
*
* Example:
*
* BitSet drPepper = new BitSet();
*
* Now `drPepper.toString()` returns `"{}"`.
*
* drPepper.set(2);
*
* Now `drPepper.toString()` returns `"{2}"`.
*
* drPepper.set(4);
* drPepper.set(10);
*
* Now `drPepper.toString()` returns `"{2, 4, 10}"`.
*/
toString(): string;
/**
* Performs a logical **XOR** of this bit set with the bit set argument. This bit set is modified so that a bit in
* it has the value `true` if and only if one of the following statements holds:
*
* * The bit initially has the value `true`, and the corresponding bit in the argument has the value `false`.
* * The bit initially has the value `false`, and the corresponding bit in the argument has the value `true`.
*/
xor(set: BitSet): void;
clone(): BitSet;
[Symbol.iterator](): IterableIterator<number>;
}

View File

@@ -0,0 +1,671 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitSet = void 0;
const util = require("util");
const MurmurHash_1 = require("./MurmurHash");
/**
* Private empty array used to construct empty BitSets
*/
const EMPTY_DATA = new Uint16Array(0);
/**
* Gets the word index of the `UInt16` element in `BitSet.data` containing the bit with the specified index.
*/
function getIndex(bitNumber) {
return bitNumber >>> 4;
}
/**
* Convert a word index into the bit index of the LSB of that word
*/
function unIndex(n) {
return n * 16;
}
/**
* Get's the bit number of the least signficant bit set LSB which is set in a word non-zero word;
* Bit numbers run from LSB to MSB starting with 0.
*/
function findLSBSet(word) {
let bit = 1;
for (let i = 0; i < 16; i++) {
if ((word & bit) !== 0) {
return i;
}
bit = (bit << 1) >>> 0;
}
throw new RangeError("No specified bit found");
}
function findMSBSet(word) {
let bit = (1 << 15) >>> 0;
for (let i = 15; i >= 0; i--) {
if ((word & bit) !== 0) {
return i;
}
bit = bit >>> 1;
}
throw new RangeError("No specified bit found");
}
/**
* Gets a 16-bit mask with bit numbers fromBit to toBit (inclusive) set.
* Bit numbers run from LSB to MSB starting with 0.
*/
function bitsFor(fromBit, toBit) {
fromBit &= 0xF;
toBit &= 0xF;
if (fromBit === toBit) {
return (1 << fromBit) >>> 0;
}
return ((0xFFFF >>> (15 - toBit)) ^ (0xFFFF >>> (16 - fromBit)));
}
/**
* A lookup table for number of set bits in a 16-bit integer. This is used to quickly count the cardinality (number of unique elements) of a BitSet.
*/
const POP_CNT = new Uint8Array(65536);
for (let i = 0; i < 16; i++) {
const stride = (1 << i) >>> 0;
let index = 0;
while (index < POP_CNT.length) {
// skip the numbers where the bit isn't set
index += stride;
// increment the ones where the bit is set
for (let j = 0; j < stride; j++) {
POP_CNT[index]++;
index++;
}
}
}
class BitSet {
/*
** constructor implementation
*/
constructor(arg) {
if (!arg) {
// covering the case of unspecified and nbits===0
this.data = EMPTY_DATA;
}
else if (typeof arg === "number") {
if (arg < 0) {
throw new RangeError("nbits cannot be negative");
}
else {
this.data = new Uint16Array(getIndex(arg - 1) + 1);
}
}
else {
if (arg instanceof BitSet) {
this.data = arg.data.slice(0); // Clone the data
}
else {
let max = -1;
for (let v of arg) {
if (max < v) {
max = v;
}
}
this.data = new Uint16Array(getIndex(max - 1) + 1);
for (let v of arg) {
this.set(v);
}
}
}
}
/**
* Performs a logical **AND** of this target bit set with the argument bit set. This bit set is modified so that
* each bit in it has the value `true` if and only if it both initially had the value `true` and the corresponding
* bit in the bit set argument also had the value `true`.
*/
and(set) {
const data = this.data;
const other = set.data;
const words = Math.min(data.length, other.length);
let lastWord = -1; // Keep track of index of last non-zero word
for (let i = 0; i < words; i++) {
let value = data[i] &= other[i];
if (value !== 0) {
lastWord = i;
}
}
if (lastWord === -1) {
this.data = EMPTY_DATA;
}
if (lastWord < data.length - 1) {
this.data = data.slice(0, lastWord + 1);
}
}
/**
* Clears all of the bits in this `BitSet` whose corresponding bit is set in the specified `BitSet`.
*/
andNot(set) {
const data = this.data;
const other = set.data;
const words = Math.min(data.length, other.length);
let lastWord = -1; // Keep track of index of last non-zero word
for (let i = 0; i < words; i++) {
let value = data[i] &= (other[i] ^ 0xFFFF);
if (value !== 0) {
lastWord = i;
}
}
if (lastWord === -1) {
this.data = EMPTY_DATA;
}
if (lastWord < data.length - 1) {
this.data = data.slice(0, lastWord + 1);
}
}
/**
* Returns the number of bits set to `true` in this `BitSet`.
*/
cardinality() {
if (this.isEmpty) {
return 0;
}
const data = this.data;
const length = data.length;
let result = 0;
for (let i = 0; i < length; i++) {
result += POP_CNT[data[i]];
}
return result;
}
clear(fromIndex, toIndex) {
if (fromIndex == null) {
this.data.fill(0);
}
else if (toIndex == null) {
this.set(fromIndex, false);
}
else {
this.set(fromIndex, toIndex, false);
}
}
flip(fromIndex, toIndex) {
if (toIndex == null) {
toIndex = fromIndex;
}
if (fromIndex < 0 || toIndex < fromIndex) {
throw new RangeError();
}
let word = getIndex(fromIndex);
const lastWord = getIndex(toIndex);
if (word === lastWord) {
this.data[word] ^= bitsFor(fromIndex, toIndex);
}
else {
this.data[word++] ^= bitsFor(fromIndex, 15);
while (word < lastWord) {
this.data[word++] ^= 0xFFFF;
}
this.data[word++] ^= bitsFor(0, toIndex);
}
}
get(fromIndex, toIndex) {
if (toIndex === undefined) {
return !!(this.data[getIndex(fromIndex)] & bitsFor(fromIndex, fromIndex));
}
else {
// return a BitSet
let result = new BitSet(toIndex + 1);
for (let i = fromIndex; i <= toIndex; i++) {
result.set(i, this.get(i));
}
return result;
}
}
/**
* Returns true if the specified `BitSet` has any bits set to `true` that are also set to `true` in this `BitSet`.
*
* @param set `BitSet` to intersect with
*/
intersects(set) {
let smallerLength = Math.min(this.length(), set.length());
if (smallerLength === 0) {
return false;
}
let bound = getIndex(smallerLength - 1);
for (let i = 0; i <= bound; i++) {
if ((this.data[i] & set.data[i]) !== 0) {
return true;
}
}
return false;
}
/**
* Returns true if this `BitSet` contains no bits that are set to `true`.
*/
get isEmpty() {
return this.length() === 0;
}
/**
* Returns the "logical size" of this `BitSet`: the index of the highest set bit in the `BitSet` plus one. Returns
* zero if the `BitSet` contains no set bits.
*/
length() {
if (!this.data.length) {
return 0;
}
return this.previousSetBit(unIndex(this.data.length) - 1) + 1;
}
/**
* Returns the index of the first bit that is set to `false` that occurs on or after the specified starting index,
* If no such bit exists then `-1` is returned.
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is negative
*/
nextClearBit(fromIndex) {
if (fromIndex < 0) {
throw new RangeError("fromIndex cannot be negative");
}
const data = this.data;
const length = data.length;
let word = getIndex(fromIndex);
if (word > length) {
return -1;
}
let ignore = 0xFFFF ^ bitsFor(fromIndex, 15);
if ((data[word] | ignore) === 0xFFFF) {
word++;
ignore = 0;
for (; word < length; word++) {
if (data[word] !== 0xFFFF) {
break;
}
}
if (word === length) {
// Hit the end
return -1;
}
}
return unIndex(word) + findLSBSet((data[word] | ignore) ^ 0xFFFF);
}
/**
* Returns the index of the first bit that is set to `true` that occurs on or after the specified starting index.
* If no such bit exists then `-1` is returned.
*
* To iterate over the `true` bits in a `BitSet`, use the following loop:
*
* ```
* for (let i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
* // operate on index i here
* }
* ```
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is negative
*/
nextSetBit(fromIndex) {
if (fromIndex < 0) {
throw new RangeError("fromIndex cannot be negative");
}
const data = this.data;
const length = data.length;
let word = getIndex(fromIndex);
if (word > length) {
return -1;
}
let mask = bitsFor(fromIndex, 15);
if ((data[word] & mask) === 0) {
word++;
mask = 0xFFFF;
for (; word < length; word++) {
if (data[word] !== 0) {
break;
}
}
if (word >= length) {
return -1;
}
}
return unIndex(word) + findLSBSet(data[word] & mask);
}
/**
* Performs a logical **OR** of this bit set with the bit set argument. This bit set is modified so that a bit in it
* has the value `true` if and only if it either already had the value `true` or the corresponding bit in the bit
* set argument has the value `true`.
*/
or(set) {
const data = this.data;
const other = set.data;
const minWords = Math.min(data.length, other.length);
const words = Math.max(data.length, other.length);
const dest = data.length === words ? data : new Uint16Array(words);
let lastWord = -1;
// Or those words both sets have in common
for (let i = 0; i < minWords; i++) {
let value = dest[i] = data[i] | other[i];
if (value !== 0) {
lastWord = i;
}
}
// Copy words from larger set (if there is one)
const longer = data.length > other.length ? data : other;
for (let i = minWords; i < words; i++) {
let value = dest[i] = longer[i];
if (value !== 0) {
lastWord = i;
}
}
if (lastWord === -1) {
this.data = EMPTY_DATA;
}
else if (dest.length === lastWord + 1) {
this.data = dest;
}
else {
this.data = dest.slice(0, lastWord);
}
}
/**
* Returns the index of the nearest bit that is set to `false` that occurs on or before the specified starting
* index. If no such bit exists, or if `-1` is given as the starting index, then `-1` is returned.
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is less than `-1`
*/
previousClearBit(fromIndex) {
if (fromIndex < 0) {
throw new RangeError("fromIndex cannot be negative");
}
const data = this.data;
const length = data.length;
let word = getIndex(fromIndex);
if (word >= length) {
word = length - 1;
}
let ignore = 0xFFFF ^ bitsFor(0, fromIndex);
if ((data[word] | ignore) === 0xFFFF) {
ignore = 0;
word--;
for (; word >= 0; word--) {
if (data[word] !== 0xFFFF) {
break;
}
}
if (word < 0) {
// Hit the end
return -1;
}
}
return unIndex(word) + findMSBSet((data[word] | ignore) ^ 0xFFFF);
}
/**
* Returns the index of the nearest bit that is set to `true` that occurs on or before the specified starting index.
* If no such bit exists, or if `-1` is given as the starting index, then `-1` is returned.
*
* To iterate over the `true` bits in a `BitSet`, use the following loop:
*
* ```
* for (let i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) {
* // operate on index i here
* }
* ```
*
* @param fromIndex the index to start checking from (inclusive)
*
* @throws RangeError if the specified index is less than `-1`
*/
previousSetBit(fromIndex) {
if (fromIndex < 0) {
throw new RangeError("fromIndex cannot be negative");
}
const data = this.data;
const length = data.length;
let word = getIndex(fromIndex);
if (word >= length) {
word = length - 1;
}
let mask = bitsFor(0, fromIndex);
if ((data[word] & mask) === 0) {
word--;
mask = 0xFFFF;
for (; word >= 0; word--) {
if (data[word] !== 0) {
break;
}
}
if (word < 0) {
return -1;
}
}
return unIndex(word) + findMSBSet(data[word] & mask);
}
set(fromIndex, toIndex, value) {
if (toIndex === undefined) {
toIndex = fromIndex;
value = true;
}
else if (typeof toIndex === "boolean") {
value = toIndex;
toIndex = fromIndex;
}
if (value === undefined) {
value = true;
}
if (fromIndex < 0 || fromIndex > toIndex) {
throw new RangeError();
}
let word = getIndex(fromIndex);
let lastWord = getIndex(toIndex);
if (value && lastWord >= this.data.length) {
// Grow array "just enough" for bits we need to set
let temp = new Uint16Array(lastWord + 1);
this.data.forEach((value, index) => temp[index] = value);
this.data = temp;
}
else if (!value) {
// But there is no need to grow array to clear bits.
if (word >= this.data.length) {
// Early exit
return;
}
if (lastWord >= this.data.length) {
// Adjust work to fit array
lastWord = this.data.length - 1;
toIndex = this.data.length * 16 - 1;
}
}
if (word === lastWord) {
this._setBits(word, value, bitsFor(fromIndex, toIndex));
}
else {
this._setBits(word++, value, bitsFor(fromIndex, 15));
while (word < lastWord) {
this.data[word++] = value ? 0xFFFF : 0;
}
this._setBits(word, value, bitsFor(0, toIndex));
}
}
_setBits(word, value, mask) {
if (value) {
this.data[word] |= mask;
}
else {
this.data[word] &= 0xFFFF ^ mask;
}
}
/**
* Returns the number of bits of space actually in use by this `BitSet` to represent bit values. The maximum element
* in the set is the size - 1st element.
*/
get size() {
return this.data.byteLength * 8;
}
/**
* Returns a new byte array containing all the bits in this bit set.
*
* More precisely, if
* `let bytes = s.toByteArray();`
* then `bytes.length === (s.length()+7)/8` and `s.get(n) === ((bytes[n/8] & (1<<(n%8))) != 0)` for all
* `n < 8 * bytes.length`.
*/
// toByteArray(): Int8Array {
// throw new Error("NOT IMPLEMENTED");
// }
/**
* Returns a new integer array containing all the bits in this bit set.
*
* More precisely, if
* `let integers = s.toIntegerArray();`
* then `integers.length === (s.length()+31)/32` and `s.get(n) === ((integers[n/32] & (1<<(n%32))) != 0)` for all
* `n < 32 * integers.length`.
*/
// toIntegerArray(): Int32Array {
// throw new Error("NOT IMPLEMENTED");
// }
hashCode() {
return MurmurHash_1.MurmurHash.hashCode(this.data, 22);
}
/**
* Compares this object against the specified object. The result is `true` if and only if the argument is not
* `undefined` and is a `Bitset` object that has exactly the same set of bits set to `true` as this bit set. That
* is, for every nonnegative index `k`,
*
* ```
* ((BitSet)obj).get(k) == this.get(k)
* ```
*
* must be true. The current sizes of the two bit sets are not compared.
*/
equals(obj) {
if (obj === this) {
return true;
}
else if (!(obj instanceof BitSet)) {
return false;
}
const len = this.length();
if (len !== obj.length()) {
return false;
}
if (len === 0) {
return true;
}
let bound = getIndex(len - 1);
for (let i = 0; i <= bound; i++) {
if (this.data[i] !== obj.data[i]) {
return false;
}
}
return true;
}
/**
* Returns a string representation of this bit set. For every index for which this `BitSet` contains a bit in the
* set state, the decimal representation of that index is included in the result. Such indices are listed in order
* from lowest to highest, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual
* mathematical notation for a set of integers.
*
* Example:
*
* BitSet drPepper = new BitSet();
*
* Now `drPepper.toString()` returns `"{}"`.
*
* drPepper.set(2);
*
* Now `drPepper.toString()` returns `"{2}"`.
*
* drPepper.set(4);
* drPepper.set(10);
*
* Now `drPepper.toString()` returns `"{2, 4, 10}"`.
*/
toString() {
let result = "{";
let first = true;
for (let i = this.nextSetBit(0); i >= 0; i = this.nextSetBit(i + 1)) {
if (first) {
first = false;
}
else {
result += ", ";
}
result += i;
}
result += "}";
return result;
}
// static valueOf(bytes: Int8Array): BitSet;
// static valueOf(buffer: ArrayBuffer): BitSet;
// static valueOf(integers: Int32Array): BitSet;
// static valueOf(data: Int8Array | Int32Array | ArrayBuffer): BitSet {
// throw new Error("NOT IMPLEMENTED");
// }
/**
* Performs a logical **XOR** of this bit set with the bit set argument. This bit set is modified so that a bit in
* it has the value `true` if and only if one of the following statements holds:
*
* * The bit initially has the value `true`, and the corresponding bit in the argument has the value `false`.
* * The bit initially has the value `false`, and the corresponding bit in the argument has the value `true`.
*/
xor(set) {
const data = this.data;
const other = set.data;
const minWords = Math.min(data.length, other.length);
const words = Math.max(data.length, other.length);
const dest = data.length === words ? data : new Uint16Array(words);
let lastWord = -1;
// Xor those words both sets have in common
for (let i = 0; i < minWords; i++) {
let value = dest[i] = data[i] ^ other[i];
if (value !== 0) {
lastWord = i;
}
}
// Copy words from larger set (if there is one)
const longer = data.length > other.length ? data : other;
for (let i = minWords; i < words; i++) {
let value = dest[i] = longer[i];
if (value !== 0) {
lastWord = i;
}
}
if (lastWord === -1) {
this.data = EMPTY_DATA;
}
else if (dest.length === lastWord + 1) {
this.data = dest;
}
else {
this.data = dest.slice(0, lastWord + 1);
}
}
clone() {
return new BitSet(this);
}
[Symbol.iterator]() {
return new BitSetIterator(this.data);
}
// Overrides formatting for nodejs assert etc.
[util.inspect.custom]() {
return "BitSet " + this.toString();
}
}
exports.BitSet = BitSet;
class BitSetIterator {
constructor(data) {
this.data = data;
this.index = 0;
this.mask = 0xFFFF;
}
next() {
while (this.index < this.data.length) {
const bits = this.data[this.index] & this.mask;
if (bits !== 0) {
const bitNumber = unIndex(this.index) + findLSBSet(bits);
this.mask = bitsFor(bitNumber + 1, 15);
return { done: false, value: bitNumber };
}
this.index++;
this.mask = 0xFFFF;
}
return { done: true, value: -1 };
}
[Symbol.iterator]() { return this; }
}
//# sourceMappingURL=BitSet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export declare function isHighSurrogate(ch: number): boolean;
export declare function isLowSurrogate(ch: number): boolean;
export declare function isSupplementaryCodePoint(ch: number): boolean;

View File

@@ -0,0 +1,20 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSupplementaryCodePoint = exports.isLowSurrogate = exports.isHighSurrogate = void 0;
function isHighSurrogate(ch) {
return ch >= 0xD800 && ch <= 0xDBFF;
}
exports.isHighSurrogate = isHighSurrogate;
function isLowSurrogate(ch) {
return ch >= 0xDC00 && ch <= 0xDFFF;
}
exports.isLowSurrogate = isLowSurrogate;
function isSupplementaryCodePoint(ch) {
return ch >= 0x10000;
}
exports.isSupplementaryCodePoint = isSupplementaryCodePoint;
//# sourceMappingURL=Character.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Character.js","sourceRoot":"","sources":["../../../src/misc/Character.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,SAAgB,eAAe,CAAC,EAAU;IACzC,OAAO,EAAE,IAAI,MAAM,IAAI,EAAE,IAAI,MAAM,CAAC;AACrC,CAAC;AAFD,0CAEC;AAED,SAAgB,cAAc,CAAC,EAAU;IACxC,OAAO,EAAE,IAAI,MAAM,IAAI,EAAE,IAAI,MAAM,CAAC;AACrC,CAAC;AAFD,wCAEC;AAED,SAAgB,wBAAwB,CAAC,EAAU;IAClD,OAAO,EAAE,IAAI,OAAO,CAAC;AACtB,CAAC;AAFD,4DAEC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nexport function isHighSurrogate(ch: number): boolean {\r\n\treturn ch >= 0xD800 && ch <= 0xDBFF;\r\n}\r\n\r\nexport function isLowSurrogate(ch: number): boolean {\r\n\treturn ch >= 0xDC00 && ch <= 0xDFFF;\r\n}\r\n\r\nexport function isSupplementaryCodePoint(ch: number): boolean {\r\n\treturn ch >= 0x10000;\r\n}\r\n"]}

View File

@@ -0,0 +1,31 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { EqualityComparator } from "./EqualityComparator";
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
export declare class DefaultEqualityComparator implements EqualityComparator<any> {
static readonly INSTANCE: DefaultEqualityComparator;
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj: any): number;
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined` or `null`, this method returns `true`. Otherwise if only
* `a` is `undefined` or `null`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a: any, b: any): boolean;
}

View File

@@ -0,0 +1,70 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultEqualityComparator = void 0;
const Decorators_1 = require("../Decorators");
const MurmurHash_1 = require("./MurmurHash");
const ObjectEqualityComparator_1 = require("./ObjectEqualityComparator");
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
class DefaultEqualityComparator {
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj) {
if (obj == null) {
return 0;
}
else if (typeof obj === "string" || typeof obj === "number") {
return MurmurHash_1.MurmurHash.hashCode([obj]);
}
else {
return ObjectEqualityComparator_1.ObjectEqualityComparator.INSTANCE.hashCode(obj);
}
}
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined` or `null`, this method returns `true`. Otherwise if only
* `a` is `undefined` or `null`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a, b) {
if (a == null) {
return b == null;
}
else if (typeof a === "string" || typeof a === "number") {
return a === b;
}
else {
return ObjectEqualityComparator_1.ObjectEqualityComparator.INSTANCE.equals(a, b);
}
}
}
DefaultEqualityComparator.INSTANCE = new DefaultEqualityComparator();
__decorate([
Decorators_1.Override
], DefaultEqualityComparator.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], DefaultEqualityComparator.prototype, "equals", null);
exports.DefaultEqualityComparator = DefaultEqualityComparator;
//# sourceMappingURL=DefaultEqualityComparator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"DefaultEqualityComparator.js","sourceRoot":"","sources":["../../../src/misc/DefaultEqualityComparator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAGH,8CAAyC;AAEzC,6CAA0C;AAC1C,yEAAsE;AAEtE;;;;;GAKG;AACH,MAAa,yBAAyB;IAGrC;;;;;OAKG;IAEI,QAAQ,CAAC,GAAQ;QACvB,IAAI,GAAG,IAAI,IAAI,EAAE;YAChB,OAAO,CAAC,CAAC;SACT;aAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC9D,OAAO,uBAAU,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SAClC;aAAM;YACN,OAAO,mDAAwB,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAgB,CAAC,CAAC;SACpE;IACF,CAAC;IAED;;;;;;;;OAQG;IAEI,MAAM,CAAC,CAAM,EAAE,CAAM;QAC3B,IAAI,CAAC,IAAI,IAAI,EAAE;YACd,OAAO,CAAC,IAAI,IAAI,CAAC;SACjB;aAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAC1D,OAAO,CAAC,KAAK,CAAC,CAAC;SACf;aAAM;YACN,OAAO,mDAAwB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAc,EAAE,CAAc,CAAC,CAAC;SAChF;IACF,CAAC;;AArCsB,kCAAQ,GAA8B,IAAI,yBAAyB,EAAE,CAAC;AAS7F;IADC,qBAAQ;yDASR;AAYD;IADC,qBAAQ;uDASR;AAtCF,8DAuCC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nimport { EqualityComparator } from \"./EqualityComparator\";\r\nimport { Override } from \"../Decorators\";\r\nimport { Equatable } from \"./Stubs\";\r\nimport { MurmurHash } from \"./MurmurHash\";\r\nimport { ObjectEqualityComparator } from \"./ObjectEqualityComparator\";\r\n\r\n/**\r\n * This default implementation of {@link EqualityComparator} uses object equality\r\n * for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class DefaultEqualityComparator implements EqualityComparator<any> {\r\n\tpublic static readonly INSTANCE: DefaultEqualityComparator = new DefaultEqualityComparator();\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation returns\r\n\t * `obj.`{@link Object#hashCode hashCode()}.\r\n\t */\r\n\t@Override\r\n\tpublic hashCode(obj: any): number {\r\n\t\tif (obj == null) {\r\n\t\t\treturn 0;\r\n\t\t} else if (typeof obj === \"string\" || typeof obj === \"number\") {\r\n\t\t\treturn MurmurHash.hashCode([obj]);\r\n\t\t} else {\r\n\t\t\treturn ObjectEqualityComparator.INSTANCE.hashCode(obj as Equatable);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation relies on object equality. If both objects are\r\n\t * `undefined` or `null`, this method returns `true`. Otherwise if only\r\n\t * `a` is `undefined` or `null`, this method returns `false`. Otherwise,\r\n\t * this method returns the result of\r\n\t * `a.`{@link Object#equals equals}`(b)`.\r\n\t */\r\n\t@Override\r\n\tpublic equals(a: any, b: any): boolean {\r\n\t\tif (a == null) {\r\n\t\t\treturn b == null;\r\n\t\t} else if (typeof a === \"string\" || typeof a === \"number\") {\r\n\t\t\treturn a === b;\r\n\t\t} else {\r\n\t\t\treturn ObjectEqualityComparator.INSTANCE.equals(a as Equatable, b as Equatable);\r\n\t\t}\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,29 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
/**
* This interface provides an abstract concept of object equality independent of
* {@link Object#equals} (object equality) and the `==` operator
* (reference equality). It can be used to provide algorithm-specific unordered
* comparisons without requiring changes to the object itself.
*
* @author Sam Harwell
*/
export interface EqualityComparator<T> {
/**
* This method returns a hash code for the specified object.
*
* @param obj The object.
* @returns The hash code for `obj`.
*/
hashCode(obj: T): number;
/**
* This method tests if two objects are equal.
*
* @param a The first object to compare.
* @param b The second object to compare.
* @returns `true` if `a` equals `b`, otherwise `false`.
*/
equals(a: T, b: T): boolean;
}

View File

@@ -0,0 +1,7 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=EqualityComparator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"EqualityComparator.js","sourceRoot":"","sources":["../../../src/misc/EqualityComparator.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-03T02:09:42.0574481-07:00\r\n\r\n/**\r\n * This interface provides an abstract concept of object equality independent of\r\n * {@link Object#equals} (object equality) and the `==` operator\r\n * (reference equality). It can be used to provide algorithm-specific unordered\r\n * comparisons without requiring changes to the object itself.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport interface EqualityComparator<T> {\r\n\r\n\t/**\r\n\t * This method returns a hash code for the specified object.\r\n\t *\r\n\t * @param obj The object.\r\n\t * @returns The hash code for `obj`.\r\n\t */\r\n\thashCode(obj: T): number;\r\n\r\n\t/**\r\n\t * This method tests if two objects are equal.\r\n\t *\r\n\t * @param a The first object to compare.\r\n\t * @param b The second object to compare.\r\n\t * @returns `true` if `a` equals `b`, otherwise `false`.\r\n\t */\r\n\tequals(a: T, b: T): boolean;\r\n\r\n}\r\n"]}

View File

@@ -0,0 +1,129 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
/**
* A generic set of integers.
*
* @see IntervalSet
*/
export interface IntSet {
/**
* Adds the specified value to the current set.
*
* @param el the value to add
*
* @exception IllegalStateException if the current set is read-only
*/
add(el: number): void;
/**
* Modify the current {@link IntSet} object to contain all elements that are
* present in itself, the specified `set`, or both.
*
* @param set The set to add to the current set. An `undefined` argument is
* treated as though it were an empty set.
* @returns `this` (to support chained calls)
*
* @exception IllegalStateException if the current set is read-only
*/
addAll(/*@Nullable*/ set: IntSet): IntSet;
/**
* Return a new {@link IntSet} object containing all elements that are
* present in both the current set and the specified set `a`.
*
* @param a The set to intersect with the current set.
* @returns A new {@link IntSet} instance containing the intersection of the
* current set and `a`.
*/
and(a: IntSet): IntSet;
/**
* Return a new {@link IntSet} object containing all elements that are
* present in `elements` but not present in the current set. The
* following expressions are equivalent for input non-`undefined` {@link IntSet}
* instances `x` and `y`.
*
* * `x.complement(y)`
* * `y.subtract(x)`
*
* @param elements The set to compare with the current set.
* @returns A new {@link IntSet} instance containing the elements present in
* `elements` but not present in the current set.
*/
complement(elements: IntSet): IntSet;
/**
* Return a new {@link IntSet} object containing all elements that are
* present in the current set, the specified set `a`, or both.
*
* This method is similar to {@link #addAll(IntSet)}, but returns a new
* {@link IntSet} instance instead of modifying the current set.
*
* @param a The set to union with the current set. An `undefined` argument
* is treated as though it were an empty set.
* @returns A new {@link IntSet} instance containing the union of the current
* set and `a`. The value `undefined` may be returned in place of an
* empty result set.
*/
or(/*@Nullable*/ a: IntSet): IntSet;
/**
* Return a new {@link IntSet} object containing all elements that are
* present in the current set but not present in the input set `a`.
* The following expressions are equivalent for input non-`undefined`
* {@link IntSet} instances `x` and `y`.
*
* * `y.subtract(x)`
* * `x.complement(y)`
*
* @param a The set to compare with the current set. A `undefined`
* argument is treated as though it were an empty set.
* @returns A new {@link IntSet} instance containing the elements present in
* `elements` but not present in the current set. The value
* `undefined` may be returned in place of an empty result set.
*/
subtract(/*@Nullable*/ a: IntSet): IntSet;
/**
* Return the total number of elements represented by the current set.
*
* @returns the total number of elements represented by the current set,
* regardless of the manner in which the elements are stored.
*/
readonly size: number;
/**
* Returns `true` if this set contains no elements.
*
* @returns `true` if the current set contains no elements; otherwise,
* `false`.
*/
readonly isNil: boolean;
/**
* {@inheritDoc}
*/
equals(obj: any): boolean;
/**
* Returns `true` if the set contains the specified element.
*
* @param el The element to check for.
* @returns `true` if the set contains `el`; otherwise `false`.
*/
contains(el: number): boolean;
/**
* Removes the specified value from the current set. If the current set does
* not contain the element, no changes are made.
*
* @param el the value to remove
*
* @exception IllegalStateException if the current set is read-only
*/
remove(el: number): void;
/**
* Return an array containing the elements represented by the current set. The
* array is returned in ascending numerical order.
*
* @returns An array containing all element present in the current set, sorted
* in ascending numerical order.
*/
toArray(): number[];
/**
* {@inheritDoc}
*/
toString(): string;
}

View File

@@ -0,0 +1,7 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IntSet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,69 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { JavaCollection } from "./Stubs";
/**
*
* @author Sam Harwell
*/
export declare class IntegerList {
private _data;
private _size;
constructor(arg?: number | IntegerList | Iterable<number>);
add(value: number): void;
addAll(list: number[] | IntegerList | JavaCollection<number>): void;
get(index: number): number;
contains(value: number): boolean;
set(index: number, value: number): number;
removeAt(index: number): number;
removeRange(fromIndex: number, toIndex: number): void;
get isEmpty(): boolean;
get size(): number;
trimToSize(): void;
clear(): void;
toArray(): number[];
sort(): void;
/**
* Compares the specified object with this list for equality. Returns
* `true` if and only if the specified object is also an {@link IntegerList},
* both lists have the same size, and all corresponding pairs of elements in
* the two lists are equal. In other words, two lists are defined to be
* equal if they contain the same elements in the same order.
*
* This implementation first checks if the specified object is this
* list. If so, it returns `true`; if not, it checks if the
* specified object is an {@link IntegerList}. If not, it returns `false`;
* if so, it checks the size of both lists. If the lists are not the same size,
* it returns `false`; otherwise it iterates over both lists, comparing
* corresponding pairs of elements. If any comparison returns `false`,
* this method returns `false`.
*
* @param o the object to be compared for equality with this list
* @returns `true` if the specified object is equal to this list
*/
equals(o: any): boolean;
/**
* Returns the hash code value for this list.
*
* This implementation uses exactly the code that is used to define the
* list hash function in the documentation for the {@link List#hashCode}
* method.
*
* @returns the hash code value for this list
*/
hashCode(): number;
/**
* Returns a string representation of this list.
*/
toString(): string;
binarySearch(key: number, fromIndex?: number, toIndex?: number): number;
private ensureCapacity;
/** Convert the list to a UTF-16 encoded char array. If all values are less
* than the 0xFFFF 16-bit code point limit then this is just a char array
* of 16-bit char as usual. For values in the supplementary range, encode
* them as two UTF-16 code units.
*/
toCharArray(): Uint16Array;
private charArraySize;
}

View File

@@ -0,0 +1,293 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntegerList = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:40.5099429-07:00
const Arrays_1 = require("./Arrays");
const Decorators_1 = require("../Decorators");
const EMPTY_DATA = new Int32Array(0);
const INITIAL_SIZE = 4;
const MAX_ARRAY_SIZE = (((1 << 31) >>> 0) - 1) - 8;
/**
*
* @author Sam Harwell
*/
class IntegerList {
constructor(arg) {
if (!arg) {
this._data = EMPTY_DATA;
this._size = 0;
}
else if (arg instanceof IntegerList) {
this._data = arg._data.slice(0);
this._size = arg._size;
}
else if (typeof arg === "number") {
if (arg === 0) {
this._data = EMPTY_DATA;
this._size = 0;
}
else {
this._data = new Int32Array(arg);
this._size = 0;
}
}
else {
// arg is Iterable<number>
this._data = EMPTY_DATA;
this._size = 0;
for (let value of arg) {
this.add(value);
}
}
}
add(value) {
if (this._data.length === this._size) {
this.ensureCapacity(this._size + 1);
}
this._data[this._size] = value;
this._size++;
}
addAll(list) {
if (Array.isArray(list)) {
this.ensureCapacity(this._size + list.length);
this._data.subarray(this._size, this._size + list.length).set(list);
this._size += list.length;
}
else if (list instanceof IntegerList) {
this.ensureCapacity(this._size + list._size);
this._data.subarray(this._size, this._size + list.size).set(list._data);
this._size += list._size;
}
else {
// list is JavaCollection<number>
this.ensureCapacity(this._size + list.size);
let current = 0;
for (let xi of list) {
this._data[this._size + current] = xi;
current++;
}
this._size += list.size;
}
}
get(index) {
if (index < 0 || index >= this._size) {
throw RangeError();
}
return this._data[index];
}
contains(value) {
for (let i = 0; i < this._size; i++) {
if (this._data[i] === value) {
return true;
}
}
return false;
}
set(index, value) {
if (index < 0 || index >= this._size) {
throw RangeError();
}
let previous = this._data[index];
this._data[index] = value;
return previous;
}
removeAt(index) {
let value = this.get(index);
this._data.copyWithin(index, index + 1, this._size);
this._data[this._size - 1] = 0;
this._size--;
return value;
}
removeRange(fromIndex, toIndex) {
if (fromIndex < 0 || toIndex < 0 || fromIndex > this._size || toIndex > this._size) {
throw RangeError();
}
if (fromIndex > toIndex) {
throw RangeError();
}
this._data.copyWithin(toIndex, fromIndex, this._size);
this._data.fill(0, this._size - (toIndex - fromIndex), this._size);
this._size -= (toIndex - fromIndex);
}
get isEmpty() {
return this._size === 0;
}
get size() {
return this._size;
}
trimToSize() {
if (this._data.length === this._size) {
return;
}
this._data = this._data.slice(0, this._size);
}
clear() {
this._data.fill(0, 0, this._size);
this._size = 0;
}
toArray() {
if (this._size === 0) {
return [];
}
return Array.from(this._data.subarray(0, this._size));
}
sort() {
this._data.subarray(0, this._size).sort();
}
/**
* Compares the specified object with this list for equality. Returns
* `true` if and only if the specified object is also an {@link IntegerList},
* both lists have the same size, and all corresponding pairs of elements in
* the two lists are equal. In other words, two lists are defined to be
* equal if they contain the same elements in the same order.
*
* This implementation first checks if the specified object is this
* list. If so, it returns `true`; if not, it checks if the
* specified object is an {@link IntegerList}. If not, it returns `false`;
* if so, it checks the size of both lists. If the lists are not the same size,
* it returns `false`; otherwise it iterates over both lists, comparing
* corresponding pairs of elements. If any comparison returns `false`,
* this method returns `false`.
*
* @param o the object to be compared for equality with this list
* @returns `true` if the specified object is equal to this list
*/
equals(o) {
if (o === this) {
return true;
}
if (!(o instanceof IntegerList)) {
return false;
}
if (this._size !== o._size) {
return false;
}
for (let i = 0; i < this._size; i++) {
if (this._data[i] !== o._data[i]) {
return false;
}
}
return true;
}
/**
* Returns the hash code value for this list.
*
* This implementation uses exactly the code that is used to define the
* list hash function in the documentation for the {@link List#hashCode}
* method.
*
* @returns the hash code value for this list
*/
hashCode() {
let hashCode = 1;
for (let i = 0; i < this._size; i++) {
hashCode = 31 * hashCode + this._data[i];
}
return hashCode;
}
/**
* Returns a string representation of this list.
*/
toString() {
return this._data.toString();
}
binarySearch(key, fromIndex, toIndex) {
if (fromIndex === undefined) {
fromIndex = 0;
}
if (toIndex === undefined) {
toIndex = this._size;
}
if (fromIndex < 0 || toIndex < 0 || fromIndex > this._size || toIndex > this._size) {
throw new RangeError();
}
if (fromIndex > toIndex) {
throw new RangeError();
}
return Arrays_1.Arrays.binarySearch(this._data, key, fromIndex, toIndex);
}
ensureCapacity(capacity) {
if (capacity < 0 || capacity > MAX_ARRAY_SIZE) {
throw new RangeError();
}
let newLength;
if (this._data.length === 0) {
newLength = INITIAL_SIZE;
}
else {
newLength = this._data.length;
}
while (newLength < capacity) {
newLength = newLength * 2;
if (newLength < 0 || newLength > MAX_ARRAY_SIZE) {
newLength = MAX_ARRAY_SIZE;
}
}
let tmp = new Int32Array(newLength);
tmp.set(this._data);
this._data = tmp;
}
/** Convert the list to a UTF-16 encoded char array. If all values are less
* than the 0xFFFF 16-bit code point limit then this is just a char array
* of 16-bit char as usual. For values in the supplementary range, encode
* them as two UTF-16 code units.
*/
toCharArray() {
// Optimize for the common case (all data values are < 0xFFFF) to avoid an extra scan
let resultArray = new Uint16Array(this._size);
let resultIdx = 0;
let calculatedPreciseResultSize = false;
for (let i = 0; i < this._size; i++) {
let codePoint = this._data[i];
if (codePoint >= 0 && codePoint < 0x10000) {
resultArray[resultIdx] = codePoint;
resultIdx++;
continue;
}
// Calculate the precise result size if we encounter a code point > 0xFFFF
if (!calculatedPreciseResultSize) {
let newResultArray = new Uint16Array(this.charArraySize());
newResultArray.set(resultArray, 0);
resultArray = newResultArray;
calculatedPreciseResultSize = true;
}
// This will throw RangeError if the code point is not a valid Unicode code point
let pair = String.fromCodePoint(codePoint);
resultArray[resultIdx] = pair.charCodeAt(0);
resultArray[resultIdx + 1] = pair.charCodeAt(1);
resultIdx += 2;
}
return resultArray;
}
charArraySize() {
let result = 0;
for (let i = 0; i < this._size; i++) {
result += this._data[i] >= 0x10000 ? 2 : 1;
}
return result;
}
}
__decorate([
Decorators_1.NotNull
], IntegerList.prototype, "_data", void 0);
__decorate([
Decorators_1.Override
], IntegerList.prototype, "equals", null);
__decorate([
Decorators_1.Override
], IntegerList.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], IntegerList.prototype, "toString", null);
exports.IntegerList = IntegerList;
//# sourceMappingURL=IntegerList.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { IntegerList } from "./IntegerList";
/**
*
* @author Sam Harwell
*/
export declare class IntegerStack extends IntegerList {
constructor(arg?: number | IntegerStack);
push(value: number): void;
pop(): number;
peek(): number;
}

View File

@@ -0,0 +1,29 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntegerStack = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:40.6647101-07:00
const IntegerList_1 = require("./IntegerList");
/**
*
* @author Sam Harwell
*/
class IntegerStack extends IntegerList_1.IntegerList {
constructor(arg) {
super(arg);
}
push(value) {
this.add(value);
}
pop() {
return this.removeAt(this.size - 1);
}
peek() {
return this.get(this.size - 1);
}
}
exports.IntegerStack = IntegerStack;
//# sourceMappingURL=IntegerStack.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"IntegerStack.js","sourceRoot":"","sources":["../../../src/misc/IntegerStack.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wDAAwD;AAExD,+CAA4C;AAE5C;;;GAGG;AACH,MAAa,YAAa,SAAQ,yBAAW;IAE5C,YAAY,GAA2B;QACtC,KAAK,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;IAEM,IAAI,CAAC,KAAa;QACxB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAEM,GAAG;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC;IAEM,IAAI;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAChC,CAAC;CAED;AAlBD,oCAkBC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:40.6647101-07:00\r\n\r\nimport { IntegerList } from \"./IntegerList\";\r\n\r\n/**\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class IntegerStack extends IntegerList {\r\n\r\n\tconstructor(arg?: number | IntegerStack) {\r\n\t\tsuper(arg);\r\n\t}\r\n\r\n\tpublic push(value: number): void {\r\n\t\tthis.add(value);\r\n\t}\r\n\r\n\tpublic pop(): number {\r\n\t\treturn this.removeAt(this.size - 1);\r\n\t}\r\n\r\n\tpublic peek(): number {\r\n\t\treturn this.get(this.size - 1);\r\n\t}\r\n\r\n}\r\n"]}

View File

@@ -0,0 +1,39 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { ATN } from "../atn/ATN";
import { Vocabulary } from "../Vocabulary";
export declare namespace InterpreterDataReader {
/**
* The structure of the data file is very simple. Everything is line based with empty lines
* separating the different parts. For lexers the layout is:
* token literal names:
* ...
*
* token symbolic names:
* ...
*
* rule names:
* ...
*
* channel names:
* ...
*
* mode names:
* ...
*
* atn:
* <a single line with comma separated int values> enclosed in a pair of squared brackets.
*
* Data for a parser does not contain channel and mode names.
*/
function parseFile(fileName: string): Promise<InterpreterDataReader.InterpreterData>;
class InterpreterData {
atn?: ATN;
vocabulary: Vocabulary;
ruleNames: string[];
channels?: string[];
modes?: string[];
}
}

View File

@@ -0,0 +1,176 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InterpreterDataReader = void 0;
const fs = require("fs");
const util = require("util");
const VocabularyImpl_1 = require("../VocabularyImpl");
const ATNDeserializer_1 = require("../atn/ATNDeserializer");
function splitToLines(buffer) {
let lines = [];
let index = 0;
while (index < buffer.length) {
let lineStart = index;
let lineEndLF = buffer.indexOf("\n".charCodeAt(0), index);
let lineEndCR = buffer.indexOf("\r".charCodeAt(0), index);
let lineEnd;
if (lineEndCR >= 0 && (lineEndCR < lineEndLF || lineEndLF === -1)) {
lineEnd = lineEndCR;
}
else if (lineEndLF >= 0) {
lineEnd = lineEndLF;
}
else {
lineEnd = buffer.length;
}
lines.push(buffer.toString("utf-8", lineStart, lineEnd));
if (lineEnd === lineEndCR && lineEnd + 1 === lineEndLF) {
index = lineEnd + 2;
}
else {
index = lineEnd + 1;
}
}
return lines;
}
// A class to read plain text interpreter data produced by ANTLR.
var InterpreterDataReader;
(function (InterpreterDataReader) {
/**
* The structure of the data file is very simple. Everything is line based with empty lines
* separating the different parts. For lexers the layout is:
* token literal names:
* ...
*
* token symbolic names:
* ...
*
* rule names:
* ...
*
* channel names:
* ...
*
* mode names:
* ...
*
* atn:
* <a single line with comma separated int values> enclosed in a pair of squared brackets.
*
* Data for a parser does not contain channel and mode names.
*/
function parseFile(fileName) {
return __awaiter(this, void 0, void 0, function* () {
let result = new InterpreterDataReader.InterpreterData();
let input = yield util.promisify(fs.readFile)(fileName);
let lines = splitToLines(input);
try {
let line;
let lineIndex = 0;
let literalNames = [];
let symbolicNames = [];
line = lines[lineIndex++];
if (line !== "token literal names:") {
throw new RangeError("Unexpected data entry");
}
for (line = lines[lineIndex++]; line !== undefined; line = lines[lineIndex++]) {
if (line.length === 0) {
break;
}
literalNames.push(line === "null" ? "" : line);
}
line = lines[lineIndex++];
if (line !== "token symbolic names:") {
throw new RangeError("Unexpected data entry");
}
for (line = lines[lineIndex++]; line !== undefined; line = lines[lineIndex++]) {
if (line.length === 0) {
break;
}
symbolicNames.push(line === "null" ? "" : line);
}
let displayNames = [];
result.vocabulary = new VocabularyImpl_1.VocabularyImpl(literalNames, symbolicNames, displayNames);
line = lines[lineIndex++];
if (line !== "rule names:") {
throw new RangeError("Unexpected data entry");
}
for (line = lines[lineIndex++]; line !== undefined; line = lines[lineIndex++]) {
if (line.length === 0) {
break;
}
result.ruleNames.push(line);
}
line = lines[lineIndex++];
if (line === "channel names:") { // Additional lexer data.
result.channels = [];
for (line = lines[lineIndex++]; line !== undefined; line = lines[lineIndex++]) {
if (line.length === 0) {
break;
}
result.channels.push(line);
}
line = lines[lineIndex++];
if (line !== "mode names:") {
throw new RangeError("Unexpected data entry");
}
result.modes = [];
for (line = lines[lineIndex++]; line !== undefined; line = lines[lineIndex++]) {
if (line.length === 0) {
break;
}
result.modes.push(line);
}
}
line = lines[lineIndex++];
if (line !== "atn:") {
throw new RangeError("Unexpected data entry");
}
line = lines[lineIndex++];
let elements = line.split(",");
let serializedATN = new Uint16Array(elements.length);
for (let i = 0; i < elements.length; ++i) {
let value;
let element = elements[i];
if (element.startsWith("[")) {
value = parseInt(element.substring(1).trim(), 10);
}
else if (element.endsWith("]")) {
value = parseInt(element.substring(0, element.length - 1).trim(), 10);
}
else {
value = parseInt(element.trim(), 10);
}
serializedATN[i] = value;
}
let deserializer = new ATNDeserializer_1.ATNDeserializer();
result.atn = deserializer.deserialize(serializedATN);
}
catch (e) {
// We just swallow the error and return empty objects instead.
}
return result;
});
}
InterpreterDataReader.parseFile = parseFile;
class InterpreterData {
constructor() {
this.vocabulary = VocabularyImpl_1.VocabularyImpl.EMPTY_VOCABULARY;
this.ruleNames = [];
}
}
InterpreterDataReader.InterpreterData = InterpreterData;
})(InterpreterDataReader = exports.InterpreterDataReader || (exports.InterpreterDataReader = {}));
//# sourceMappingURL=InterpreterDataReader.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Equatable } from "./Stubs";
/** An immutable inclusive interval a..b */
export declare class Interval implements Equatable {
a: number;
b: number;
private static _INVALID;
static get INVALID(): Interval;
private static readonly cache;
/**
* @param a The start of the interval
* @param b The end of the interval (inclusive)
*/
constructor(a: number, b: number);
/** Interval objects are used readonly so share all with the
* same single value a==b up to some max size. Use an array as a perfect hash.
* Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new
* Interval object with a..a in it. On Java.g4, 218623 IntervalSets
* have a..a (set with 1 element).
*/
static of(a: number, b: number): Interval;
/** return number of elements between a and b inclusively. x..x is length 1.
* if b &lt; a, then length is 0. 9..10 has length 2.
*/
get length(): number;
equals(o: any): boolean;
hashCode(): number;
/** Does this start completely before other? Disjoint */
startsBeforeDisjoint(other: Interval): boolean;
/** Does this start at or before other? Nondisjoint */
startsBeforeNonDisjoint(other: Interval): boolean;
/** Does this.a start after other.b? May or may not be disjoint */
startsAfter(other: Interval): boolean;
/** Does this start completely after other? Disjoint */
startsAfterDisjoint(other: Interval): boolean;
/** Does this start after other? NonDisjoint */
startsAfterNonDisjoint(other: Interval): boolean;
/** Are both ranges disjoint? I.e., no overlap? */
disjoint(other: Interval): boolean;
/** Are two intervals adjacent such as 0..41 and 42..42? */
adjacent(other: Interval): boolean;
properlyContains(other: Interval): boolean;
/** Return the interval computed from combining this and other */
union(other: Interval): Interval;
/** Return the interval in common between this and o */
intersection(other: Interval): Interval;
/** Return the interval with elements from `this` not in `other`;
* `other` must not be totally enclosed (properly contained)
* within `this`, which would result in two disjoint intervals
* instead of the single one returned by this method.
*/
differenceNotProperlyContained(other: Interval): Interval | undefined;
toString(): string;
}

View File

@@ -0,0 +1,142 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interval = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:40.7402214-07:00
const Decorators_1 = require("../Decorators");
const INTERVAL_POOL_MAX_VALUE = 1000;
/** An immutable inclusive interval a..b */
class Interval {
/**
* @param a The start of the interval
* @param b The end of the interval (inclusive)
*/
constructor(a, b) {
this.a = a;
this.b = b;
}
static get INVALID() {
return Interval._INVALID;
}
/** Interval objects are used readonly so share all with the
* same single value a==b up to some max size. Use an array as a perfect hash.
* Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new
* Interval object with a..a in it. On Java.g4, 218623 IntervalSets
* have a..a (set with 1 element).
*/
static of(a, b) {
// cache just a..a
if (a !== b || a < 0 || a > INTERVAL_POOL_MAX_VALUE) {
return new Interval(a, b);
}
if (Interval.cache[a] == null) {
Interval.cache[a] = new Interval(a, a);
}
return Interval.cache[a];
}
/** return number of elements between a and b inclusively. x..x is length 1.
* if b &lt; a, then length is 0. 9..10 has length 2.
*/
get length() {
if (this.b < this.a) {
return 0;
}
return this.b - this.a + 1;
}
equals(o) {
if (o === this) {
return true;
}
else if (!(o instanceof Interval)) {
return false;
}
return this.a === o.a && this.b === o.b;
}
hashCode() {
let hash = 23;
hash = hash * 31 + this.a;
hash = hash * 31 + this.b;
return hash;
}
/** Does this start completely before other? Disjoint */
startsBeforeDisjoint(other) {
return this.a < other.a && this.b < other.a;
}
/** Does this start at or before other? Nondisjoint */
startsBeforeNonDisjoint(other) {
return this.a <= other.a && this.b >= other.a;
}
/** Does this.a start after other.b? May or may not be disjoint */
startsAfter(other) {
return this.a > other.a;
}
/** Does this start completely after other? Disjoint */
startsAfterDisjoint(other) {
return this.a > other.b;
}
/** Does this start after other? NonDisjoint */
startsAfterNonDisjoint(other) {
return this.a > other.a && this.a <= other.b; // this.b>=other.b implied
}
/** Are both ranges disjoint? I.e., no overlap? */
disjoint(other) {
return this.startsBeforeDisjoint(other) || this.startsAfterDisjoint(other);
}
/** Are two intervals adjacent such as 0..41 and 42..42? */
adjacent(other) {
return this.a === other.b + 1 || this.b === other.a - 1;
}
properlyContains(other) {
return other.a >= this.a && other.b <= this.b;
}
/** Return the interval computed from combining this and other */
union(other) {
return Interval.of(Math.min(this.a, other.a), Math.max(this.b, other.b));
}
/** Return the interval in common between this and o */
intersection(other) {
return Interval.of(Math.max(this.a, other.a), Math.min(this.b, other.b));
}
/** Return the interval with elements from `this` not in `other`;
* `other` must not be totally enclosed (properly contained)
* within `this`, which would result in two disjoint intervals
* instead of the single one returned by this method.
*/
differenceNotProperlyContained(other) {
let diff;
if (other.startsBeforeNonDisjoint(this)) {
// other.a to left of this.a (or same)
diff = Interval.of(Math.max(this.a, other.b + 1), this.b);
}
else if (other.startsAfterNonDisjoint(this)) {
// other.a to right of this.a
diff = Interval.of(this.a, other.a - 1);
}
return diff;
}
toString() {
return this.a + ".." + this.b;
}
}
Interval._INVALID = new Interval(-1, -2);
Interval.cache = new Array(INTERVAL_POOL_MAX_VALUE + 1);
__decorate([
Decorators_1.Override
], Interval.prototype, "equals", null);
__decorate([
Decorators_1.Override
], Interval.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], Interval.prototype, "toString", null);
exports.Interval = Interval;
//# sourceMappingURL=Interval.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,96 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { IntegerList } from "./IntegerList";
import { Interval } from "./Interval";
import { IntSet } from "./IntSet";
import { Vocabulary } from "../Vocabulary";
/**
* This class implements the {@link IntSet} backed by a sorted array of
* non-overlapping intervals. It is particularly efficient for representing
* large collections of numbers, where the majority of elements appear as part
* of a sequential range of numbers that are all part of the set. For example,
* the set { 1, 2, 3, 4, 7, 8 } may be represented as { [1, 4], [7, 8] }.
*
* This class is able to represent sets containing any combination of values in
* the range {@link Integer#MIN_VALUE} to {@link Integer#MAX_VALUE}
* (inclusive).
*/
export declare class IntervalSet implements IntSet {
private static _COMPLETE_CHAR_SET;
static get COMPLETE_CHAR_SET(): IntervalSet;
private static _EMPTY_SET;
static get EMPTY_SET(): IntervalSet;
/** The list of sorted, disjoint intervals. */
private _intervals;
private readonly;
constructor(intervals?: Interval[]);
/**
* Create a set with all ints within range [a..b] (inclusive). If b is omitted, the set contains the single element
* a.
*/
static of(a: number, b?: number): IntervalSet;
clear(): void;
/** Add interval; i.e., add all integers from a to b to set.
* If b&lt;a, do nothing.
* Keep list in sorted order (by left range value).
* If overlap, combine ranges. For example,
* If this is {1..5, 10..20}, adding 6..7 yields
* {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
*/
add(a: number, b?: number): void;
protected addRange(addition: Interval): void;
/** combine all sets in the array returned the or'd value */
static or(sets: IntervalSet[]): IntervalSet;
addAll(set: IntSet): IntervalSet;
complementRange(minElement: number, maxElement: number): IntervalSet;
/** {@inheritDoc} */
complement(vocabulary: IntSet): IntervalSet;
subtract(a: IntSet): IntervalSet;
/**
* Compute the set difference between two interval sets. The specific
* operation is `left - right`.
*/
static subtract(left: IntervalSet, right: IntervalSet): IntervalSet;
or(a: IntSet): IntervalSet;
/** {@inheritDoc} */
and(other: IntSet): IntervalSet;
/** {@inheritDoc} */
contains(el: number): boolean;
/** {@inheritDoc} */
get isNil(): boolean;
/**
* Returns the maximum value contained in the set if not isNil.
*
* @return the maximum value contained in the set.
* @throws RangeError if set is empty
*/
get maxElement(): number;
/**
* Returns the minimum value contained in the set if not isNil.
*
* @return the minimum value contained in the set.
* @throws RangeError if set is empty
*/
get minElement(): number;
/** Return a list of Interval objects. */
get intervals(): Interval[];
hashCode(): number;
/** Are two IntervalSets equal? Because all intervals are sorted
* and disjoint, equals is a simple linear walk over both lists
* to make sure they are the same. Interval.equals() is used
* by the List.equals() method to check the ranges.
*/
equals(o: any): boolean;
toString(elemAreChar?: boolean): string;
toStringVocabulary(vocabulary: Vocabulary): string;
protected elementName(vocabulary: Vocabulary, a: number): string;
get size(): number;
toIntegerList(): IntegerList;
toSet(): Set<number>;
toArray(): number[];
remove(el: number): void;
get isReadonly(): boolean;
setReadonly(readonly: boolean): void;
}

View File

@@ -0,0 +1,645 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntervalSet = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:40.8683480-07:00
const ArrayEqualityComparator_1 = require("./ArrayEqualityComparator");
const IntegerList_1 = require("./IntegerList");
const Interval_1 = require("./Interval");
const Lexer_1 = require("../Lexer");
const MurmurHash_1 = require("./MurmurHash");
const Decorators_1 = require("../Decorators");
const Token_1 = require("../Token");
/**
* This class implements the {@link IntSet} backed by a sorted array of
* non-overlapping intervals. It is particularly efficient for representing
* large collections of numbers, where the majority of elements appear as part
* of a sequential range of numbers that are all part of the set. For example,
* the set { 1, 2, 3, 4, 7, 8 } may be represented as { [1, 4], [7, 8] }.
*
* This class is able to represent sets containing any combination of values in
* the range {@link Integer#MIN_VALUE} to {@link Integer#MAX_VALUE}
* (inclusive).
*/
class IntervalSet {
constructor(intervals) {
this.readonly = false;
if (intervals != null) {
this._intervals = intervals.slice(0);
}
else {
this._intervals = [];
}
}
static get COMPLETE_CHAR_SET() {
if (IntervalSet._COMPLETE_CHAR_SET === undefined) {
IntervalSet._COMPLETE_CHAR_SET = IntervalSet.of(Lexer_1.Lexer.MIN_CHAR_VALUE, Lexer_1.Lexer.MAX_CHAR_VALUE);
IntervalSet._COMPLETE_CHAR_SET.setReadonly(true);
}
return IntervalSet._COMPLETE_CHAR_SET;
}
static get EMPTY_SET() {
if (IntervalSet._EMPTY_SET == null) {
IntervalSet._EMPTY_SET = new IntervalSet();
IntervalSet._EMPTY_SET.setReadonly(true);
}
return IntervalSet._EMPTY_SET;
}
/**
* Create a set with all ints within range [a..b] (inclusive). If b is omitted, the set contains the single element
* a.
*/
static of(a, b = a) {
let s = new IntervalSet();
s.add(a, b);
return s;
}
clear() {
if (this.readonly) {
throw new Error("can't alter readonly IntervalSet");
}
this._intervals.length = 0;
}
/** Add interval; i.e., add all integers from a to b to set.
* If b&lt;a, do nothing.
* Keep list in sorted order (by left range value).
* If overlap, combine ranges. For example,
* If this is {1..5, 10..20}, adding 6..7 yields
* {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
*/
add(a, b = a) {
this.addRange(Interval_1.Interval.of(a, b));
}
// copy on write so we can cache a..a intervals and sets of that
addRange(addition) {
if (this.readonly) {
throw new Error("can't alter readonly IntervalSet");
}
//System.out.println("add "+addition+" to "+intervals.toString());
if (addition.b < addition.a) {
return;
}
// find position in list
// Use iterators as we modify list in place
for (let i = 0; i < this._intervals.length; i++) {
let r = this._intervals[i];
if (addition.equals(r)) {
return;
}
if (addition.adjacent(r) || !addition.disjoint(r)) {
// next to each other, make a single larger interval
let bigger = addition.union(r);
this._intervals[i] = bigger;
// make sure we didn't just create an interval that
// should be merged with next interval in list
while (i < this._intervals.length - 1) {
i++;
let next = this._intervals[i];
if (!bigger.adjacent(next) && bigger.disjoint(next)) {
break;
}
// if we bump up against or overlap next, merge
// remove this one
this._intervals.splice(i, 1);
i--;
// move backwards to what we just set
this._intervals[i] = bigger.union(next);
// set to 3 merged ones
}
// first call to next after previous duplicates the result
return;
}
if (addition.startsBeforeDisjoint(r)) {
// insert before r
this._intervals.splice(i, 0, addition);
return;
}
// if disjoint and after r, a future iteration will handle it
}
// ok, must be after last interval (and disjoint from last interval)
// just add it
this._intervals.push(addition);
}
/** combine all sets in the array returned the or'd value */
static or(sets) {
let r = new IntervalSet();
for (let s of sets) {
r.addAll(s);
}
return r;
}
addAll(set) {
if (set == null) {
return this;
}
if (set instanceof IntervalSet) {
let other = set;
// walk set and add each interval
let n = other._intervals.length;
for (let i = 0; i < n; i++) {
let I = other._intervals[i];
this.add(I.a, I.b);
}
}
else {
for (let value of set.toArray()) {
this.add(value);
}
}
return this;
}
complementRange(minElement, maxElement) {
return this.complement(IntervalSet.of(minElement, maxElement));
}
/** {@inheritDoc} */
complement(vocabulary) {
if (vocabulary.isNil) {
// nothing in common with null set
return IntervalSet.EMPTY_SET;
}
let vocabularyIS;
if (vocabulary instanceof IntervalSet) {
vocabularyIS = vocabulary;
}
else {
vocabularyIS = new IntervalSet();
vocabularyIS.addAll(vocabulary);
}
return vocabularyIS.subtract(this);
}
subtract(a) {
if (a == null || a.isNil) {
return new IntervalSet(this._intervals);
}
if (a instanceof IntervalSet) {
return IntervalSet.subtract(this, a);
}
let other = new IntervalSet();
other.addAll(a);
return IntervalSet.subtract(this, other);
}
/**
* Compute the set difference between two interval sets. The specific
* operation is `left - right`.
*/
static subtract(left, right) {
if (left.isNil) {
return new IntervalSet();
}
let result = new IntervalSet(left._intervals);
if (right.isNil) {
// right set has no elements; just return the copy of the current set
return result;
}
let resultI = 0;
let rightI = 0;
while (resultI < result._intervals.length && rightI < right._intervals.length) {
let resultInterval = result._intervals[resultI];
let rightInterval = right._intervals[rightI];
// operation: (resultInterval - rightInterval) and update indexes
if (rightInterval.b < resultInterval.a) {
rightI++;
continue;
}
if (rightInterval.a > resultInterval.b) {
resultI++;
continue;
}
let beforeCurrent;
let afterCurrent;
if (rightInterval.a > resultInterval.a) {
beforeCurrent = new Interval_1.Interval(resultInterval.a, rightInterval.a - 1);
}
if (rightInterval.b < resultInterval.b) {
afterCurrent = new Interval_1.Interval(rightInterval.b + 1, resultInterval.b);
}
if (beforeCurrent) {
if (afterCurrent) {
// split the current interval into two
result._intervals[resultI] = beforeCurrent;
result._intervals.splice(resultI + 1, 0, afterCurrent);
resultI++;
rightI++;
continue;
}
else {
// replace the current interval
result._intervals[resultI] = beforeCurrent;
resultI++;
continue;
}
}
else {
if (afterCurrent) {
// replace the current interval
result._intervals[resultI] = afterCurrent;
rightI++;
continue;
}
else {
// remove the current interval (thus no need to increment resultI)
result._intervals.splice(resultI, 1);
continue;
}
}
}
// If rightI reached right.intervals.size, no more intervals to subtract from result.
// If resultI reached result.intervals.size, we would be subtracting from an empty set.
// Either way, we are done.
return result;
}
or(a) {
let o = new IntervalSet();
o.addAll(this);
o.addAll(a);
return o;
}
/** {@inheritDoc} */
and(other) {
if (other.isNil) { //|| !(other instanceof IntervalSet) ) {
// nothing in common with null set
return new IntervalSet();
}
let myIntervals = this._intervals;
let theirIntervals = other._intervals;
let intersection;
let mySize = myIntervals.length;
let theirSize = theirIntervals.length;
let i = 0;
let j = 0;
// iterate down both interval lists looking for nondisjoint intervals
while (i < mySize && j < theirSize) {
let mine = myIntervals[i];
let theirs = theirIntervals[j];
//System.out.println("mine="+mine+" and theirs="+theirs);
if (mine.startsBeforeDisjoint(theirs)) {
// move this iterator looking for interval that might overlap
i++;
}
else if (theirs.startsBeforeDisjoint(mine)) {
// move other iterator looking for interval that might overlap
j++;
}
else if (mine.properlyContains(theirs)) {
// overlap, add intersection, get next theirs
if (!intersection) {
intersection = new IntervalSet();
}
intersection.addRange(mine.intersection(theirs));
j++;
}
else if (theirs.properlyContains(mine)) {
// overlap, add intersection, get next mine
if (!intersection) {
intersection = new IntervalSet();
}
intersection.addRange(mine.intersection(theirs));
i++;
}
else if (!mine.disjoint(theirs)) {
// overlap, add intersection
if (!intersection) {
intersection = new IntervalSet();
}
intersection.addRange(mine.intersection(theirs));
// Move the iterator of lower range [a..b], but not
// the upper range as it may contain elements that will collide
// with the next iterator. So, if mine=[0..115] and
// theirs=[115..200], then intersection is 115 and move mine
// but not theirs as theirs may collide with the next range
// in thisIter.
// move both iterators to next ranges
if (mine.startsAfterNonDisjoint(theirs)) {
j++;
}
else if (theirs.startsAfterNonDisjoint(mine)) {
i++;
}
}
}
if (!intersection) {
return new IntervalSet();
}
return intersection;
}
/** {@inheritDoc} */
contains(el) {
let n = this._intervals.length;
let l = 0;
let r = n - 1;
// Binary search for the element in the (sorted, disjoint) array of intervals.
while (l <= r) {
let m = (l + r) >> 1;
let I = this._intervals[m];
let a = I.a;
let b = I.b;
if (b < el) {
l = m + 1;
}
else if (a > el) {
r = m - 1;
}
else {
// el >= a && el <= b
return true;
}
}
return false;
}
/** {@inheritDoc} */
get isNil() {
return this._intervals == null || this._intervals.length === 0;
}
/**
* Returns the maximum value contained in the set if not isNil.
*
* @return the maximum value contained in the set.
* @throws RangeError if set is empty
*/
get maxElement() {
if (this.isNil) {
throw new RangeError("set is empty");
}
let last = this._intervals[this._intervals.length - 1];
return last.b;
}
/**
* Returns the minimum value contained in the set if not isNil.
*
* @return the minimum value contained in the set.
* @throws RangeError if set is empty
*/
get minElement() {
if (this.isNil) {
throw new RangeError("set is empty");
}
return this._intervals[0].a;
}
/** Return a list of Interval objects. */
get intervals() {
return this._intervals;
}
hashCode() {
let hash = MurmurHash_1.MurmurHash.initialize();
for (let I of this._intervals) {
hash = MurmurHash_1.MurmurHash.update(hash, I.a);
hash = MurmurHash_1.MurmurHash.update(hash, I.b);
}
hash = MurmurHash_1.MurmurHash.finish(hash, this._intervals.length * 2);
return hash;
}
/** Are two IntervalSets equal? Because all intervals are sorted
* and disjoint, equals is a simple linear walk over both lists
* to make sure they are the same. Interval.equals() is used
* by the List.equals() method to check the ranges.
*/
equals(o) {
if (o == null || !(o instanceof IntervalSet)) {
return false;
}
return ArrayEqualityComparator_1.ArrayEqualityComparator.INSTANCE.equals(this._intervals, o._intervals);
}
toString(elemAreChar = false) {
let buf = "";
if (this._intervals == null || this._intervals.length === 0) {
return "{}";
}
if (this.size > 1) {
buf += "{";
}
let first = true;
for (let I of this._intervals) {
if (first) {
first = false;
}
else {
buf += ", ";
}
let a = I.a;
let b = I.b;
if (a === b) {
if (a === Token_1.Token.EOF) {
buf += "<EOF>";
}
else if (elemAreChar) {
buf += "'" + String.fromCodePoint(a) + "'";
}
else {
buf += a;
}
}
else {
if (elemAreChar) {
buf += "'" + String.fromCodePoint(a) + "'..'" + String.fromCodePoint(b) + "'";
}
else {
buf += a + ".." + b;
}
}
}
if (this.size > 1) {
buf += "}";
}
return buf;
}
toStringVocabulary(vocabulary) {
if (this._intervals == null || this._intervals.length === 0) {
return "{}";
}
let buf = "";
if (this.size > 1) {
buf += "{";
}
let first = true;
for (let I of this._intervals) {
if (first) {
first = false;
}
else {
buf += ", ";
}
let a = I.a;
let b = I.b;
if (a === b) {
buf += this.elementName(vocabulary, a);
}
else {
for (let i = a; i <= b; i++) {
if (i > a) {
buf += ", ";
}
buf += this.elementName(vocabulary, i);
}
}
}
if (this.size > 1) {
buf += "}";
}
return buf;
}
elementName(vocabulary, a) {
if (a === Token_1.Token.EOF) {
return "<EOF>";
}
else if (a === Token_1.Token.EPSILON) {
return "<EPSILON>";
}
else {
return vocabulary.getDisplayName(a);
}
}
get size() {
let n = 0;
let numIntervals = this._intervals.length;
if (numIntervals === 1) {
let firstInterval = this._intervals[0];
return firstInterval.b - firstInterval.a + 1;
}
for (let i = 0; i < numIntervals; i++) {
let I = this._intervals[i];
n += (I.b - I.a + 1);
}
return n;
}
toIntegerList() {
let values = new IntegerList_1.IntegerList(this.size);
let n = this._intervals.length;
for (let i = 0; i < n; i++) {
let I = this._intervals[i];
let a = I.a;
let b = I.b;
for (let v = a; v <= b; v++) {
values.add(v);
}
}
return values;
}
toSet() {
let s = new Set();
for (let I of this._intervals) {
let a = I.a;
let b = I.b;
for (let v = a; v <= b; v++) {
s.add(v);
}
}
return s;
}
toArray() {
let values = new Array();
let n = this._intervals.length;
for (let i = 0; i < n; i++) {
let I = this._intervals[i];
let a = I.a;
let b = I.b;
for (let v = a; v <= b; v++) {
values.push(v);
}
}
return values;
}
remove(el) {
if (this.readonly) {
throw new Error("can't alter readonly IntervalSet");
}
let n = this._intervals.length;
for (let i = 0; i < n; i++) {
let I = this._intervals[i];
let a = I.a;
let b = I.b;
if (el < a) {
break; // list is sorted and el is before this interval; not here
}
// if whole interval x..x, rm
if (el === a && el === b) {
this._intervals.splice(i, 1);
break;
}
// if on left edge x..b, adjust left
if (el === a) {
this._intervals[i] = Interval_1.Interval.of(I.a + 1, I.b);
break;
}
// if on right edge a..x, adjust right
if (el === b) {
this._intervals[i] = Interval_1.Interval.of(I.a, I.b - 1);
break;
}
// if in middle a..x..b, split interval
if (el > a && el < b) { // found in this interval
let oldb = I.b;
this._intervals[i] = Interval_1.Interval.of(I.a, el - 1); // [a..x-1]
this.add(el + 1, oldb); // add [x+1..b]
}
}
}
get isReadonly() {
return this.readonly;
}
setReadonly(readonly) {
if (this.readonly && !readonly) {
throw new Error("can't alter readonly IntervalSet");
}
this.readonly = readonly;
}
}
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "addAll", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "complement", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "subtract", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "or", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "and", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "contains", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "isNil", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "equals", null);
__decorate([
__param(0, Decorators_1.NotNull)
], IntervalSet.prototype, "toStringVocabulary", null);
__decorate([
Decorators_1.NotNull,
__param(0, Decorators_1.NotNull)
], IntervalSet.prototype, "elementName", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "size", null);
__decorate([
Decorators_1.Override
], IntervalSet.prototype, "remove", null);
__decorate([
Decorators_1.NotNull
], IntervalSet, "of", null);
__decorate([
Decorators_1.NotNull
], IntervalSet, "subtract", null);
exports.IntervalSet = IntervalSet;
//# sourceMappingURL=IntervalSet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export declare class MultiMap<K, V> extends Map<K, V[]> {
constructor();
map(key: K, value: V): void;
getPairs(): Array<[K, V]>;
}

View File

@@ -0,0 +1,32 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiMap = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:42.1346951-07:00
class MultiMap extends Map {
constructor() {
super();
}
map(key, value) {
let elementsForKey = super.get(key);
if (!elementsForKey) {
elementsForKey = [];
super.set(key, elementsForKey);
}
elementsForKey.push(value);
}
getPairs() {
let pairs = [];
this.forEach((values, key) => {
values.forEach((v) => {
pairs.push([key, v]);
});
});
return pairs;
}
}
exports.MultiMap = MultiMap;
//# sourceMappingURL=MultiMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"MultiMap.js","sourceRoot":"","sources":["../../../src/misc/MultiMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wDAAwD;AAExD,MAAa,QAAe,SAAQ,GAAW;IAC9C;QACC,KAAK,EAAE,CAAC;IACT,CAAC;IAEM,GAAG,CAAC,GAAM,EAAE,KAAQ;QAC1B,IAAI,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,cAAc,EAAE;YACpB,cAAc,GAAG,EAAS,CAAC;YAC3B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SAC/B;QACD,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,QAAQ;QACd,IAAI,KAAK,GAAkB,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,GAAM,EAAE,EAAE;YACpC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACpB,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAvBD,4BAuBC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:42.1346951-07:00\r\n\r\nexport class MultiMap<K, V> extends Map<K, V[]> {\r\n\tconstructor() {\r\n\t\tsuper();\r\n\t}\r\n\r\n\tpublic map(key: K, value: V): void {\r\n\t\tlet elementsForKey = super.get(key);\r\n\t\tif (!elementsForKey) {\r\n\t\t\telementsForKey = [] as V[];\r\n\t\t\tsuper.set(key, elementsForKey);\r\n\t\t}\r\n\t\telementsForKey.push(value);\r\n\t}\r\n\r\n\tpublic getPairs(): Array<[K, V]> {\r\n\t\tlet pairs: Array<[K, V]> = [];\r\n\t\tthis.forEach((values: V[], key: K) => {\r\n\t\t\tvalues.forEach((v) => {\r\n\t\t\t\tpairs.push([key, v]);\r\n\t\t\t});\r\n\t\t});\r\n\t\treturn pairs;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,45 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Equatable } from "./Stubs";
/**
*
* @author Sam Harwell
*/
export declare namespace MurmurHash {
/**
* Initialize the hash using the specified `seed`.
*
* @param seed the seed (optional)
* @returns the intermediate hash value
*/
function initialize(seed?: number): number;
/**
* Update the intermediate hash value for the next input `value`.
*
* @param hash the intermediate hash value
* @param value the value to add to the current hash
* @returns the updated intermediate hash value
*/
function update(hash: number, value: number | string | Equatable | null | undefined): number;
/**
* Apply the final computation steps to the intermediate value `hash`
* to form the final result of the MurmurHash 3 hash function.
*
* @param hash the intermediate hash value
* @param numberOfWords the number of integer values added to the hash
* @returns the final hash result
*/
function finish(hash: number, numberOfWords: number): number;
/**
* Utility function to compute the hash code of an array using the
* MurmurHash algorithm.
*
* @param <T> the array element type
* @param data the array data
* @param seed the seed for the MurmurHash algorithm
* @returns the hash code of the data
*/
function hashCode<T extends number | string | Equatable>(data: Iterable<T>, seed?: number): number;
}

View File

@@ -0,0 +1,114 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MurmurHash = void 0;
/**
*
* @author Sam Harwell
*/
var MurmurHash;
(function (MurmurHash) {
const DEFAULT_SEED = 0;
/**
* Initialize the hash using the specified `seed`.
*
* @param seed the seed (optional)
* @returns the intermediate hash value
*/
function initialize(seed = DEFAULT_SEED) {
return seed;
}
MurmurHash.initialize = initialize;
/**
* Update the intermediate hash value for the next input `value`.
*
* @param hash the intermediate hash value
* @param value the value to add to the current hash
* @returns the updated intermediate hash value
*/
function update(hash, value) {
const c1 = 0xCC9E2D51;
const c2 = 0x1B873593;
const r1 = 15;
const r2 = 13;
const m = 5;
const n = 0xE6546B64;
if (value == null) {
value = 0;
}
else if (typeof value === "string") {
value = hashString(value);
}
else if (typeof value === "object") {
value = value.hashCode();
}
let k = value;
k = Math.imul(k, c1);
k = (k << r1) | (k >>> (32 - r1));
k = Math.imul(k, c2);
hash = hash ^ k;
hash = (hash << r2) | (hash >>> (32 - r2));
hash = Math.imul(hash, m) + n;
return hash & 0xFFFFFFFF;
}
MurmurHash.update = update;
/**
* Apply the final computation steps to the intermediate value `hash`
* to form the final result of the MurmurHash 3 hash function.
*
* @param hash the intermediate hash value
* @param numberOfWords the number of integer values added to the hash
* @returns the final hash result
*/
function finish(hash, numberOfWords) {
hash = hash ^ (numberOfWords * 4);
hash = hash ^ (hash >>> 16);
hash = Math.imul(hash, 0x85EBCA6B);
hash = hash ^ (hash >>> 13);
hash = Math.imul(hash, 0xC2B2AE35);
hash = hash ^ (hash >>> 16);
return hash;
}
MurmurHash.finish = finish;
/**
* Utility function to compute the hash code of an array using the
* MurmurHash algorithm.
*
* @param <T> the array element type
* @param data the array data
* @param seed the seed for the MurmurHash algorithm
* @returns the hash code of the data
*/
function hashCode(data, seed = DEFAULT_SEED) {
let hash = initialize(seed);
let length = 0;
for (let value of data) {
hash = update(hash, value);
length++;
}
hash = finish(hash, length);
return hash;
}
MurmurHash.hashCode = hashCode;
/**
* Function to hash a string. Based on the implementation found here:
* http://stackoverflow.com/a/7616484
*/
function hashString(str) {
let len = str.length;
if (len === 0) {
return 0;
}
let hash = 0;
for (let i = 0; i < len; i++) {
let c = str.charCodeAt(i);
hash = (((hash << 5) >>> 0) - hash) + c;
hash |= 0;
}
return hash;
}
})(MurmurHash = exports.MurmurHash || (exports.MurmurHash = {}));
//# sourceMappingURL=MurmurHash.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { EqualityComparator } from "./EqualityComparator";
import { Equatable } from "./Stubs";
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
export declare class ObjectEqualityComparator implements EqualityComparator<Equatable | null | undefined> {
static readonly INSTANCE: ObjectEqualityComparator;
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj: Equatable | null | undefined): number;
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined` or `null`, this method returns `true`. Otherwise if only
* `a` is `undefined` or `null`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a: Equatable | null | undefined, b: Equatable | null | undefined): boolean;
}

View File

@@ -0,0 +1,58 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectEqualityComparator = void 0;
const Decorators_1 = require("../Decorators");
/**
* This default implementation of {@link EqualityComparator} uses object equality
* for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
*
* @author Sam Harwell
*/
class ObjectEqualityComparator {
/**
* {@inheritDoc}
*
* This implementation returns
* `obj.`{@link Object#hashCode hashCode()}.
*/
hashCode(obj) {
if (obj == null) {
return 0;
}
return obj.hashCode();
}
/**
* {@inheritDoc}
*
* This implementation relies on object equality. If both objects are
* `undefined` or `null`, this method returns `true`. Otherwise if only
* `a` is `undefined` or `null`, this method returns `false`. Otherwise,
* this method returns the result of
* `a.`{@link Object#equals equals}`(b)`.
*/
equals(a, b) {
if (a == null) {
return b == null;
}
return a.equals(b);
}
}
ObjectEqualityComparator.INSTANCE = new ObjectEqualityComparator();
__decorate([
Decorators_1.Override
], ObjectEqualityComparator.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], ObjectEqualityComparator.prototype, "equals", null);
exports.ObjectEqualityComparator = ObjectEqualityComparator;
//# sourceMappingURL=ObjectEqualityComparator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ObjectEqualityComparator.js","sourceRoot":"","sources":["../../../src/misc/ObjectEqualityComparator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAIH,8CAAyC;AAGzC;;;;;GAKG;AACH,MAAa,wBAAwB;IAGpC;;;;;OAKG;IAEI,QAAQ,CAAC,GAAiC;QAChD,IAAI,GAAG,IAAI,IAAI,EAAE;YAChB,OAAO,CAAC,CAAC;SACT;QAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IAEI,MAAM,CAAC,CAA+B,EAAE,CAA+B;QAC7E,IAAI,CAAC,IAAI,IAAI,EAAE;YACd,OAAO,CAAC,IAAI,IAAI,CAAC;SACjB;QAED,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;;AAjCsB,iCAAQ,GAA6B,IAAI,wBAAwB,EAAE,CAAC;AAS3F;IADC,qBAAQ;wDAOR;AAYD;IADC,qBAAQ;sDAOR;AAlCF,4DAoCC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-03T02:09:42.2127260-07:00\r\nimport { EqualityComparator } from \"./EqualityComparator\";\r\nimport { Override } from \"../Decorators\";\r\nimport { Equatable } from \"./Stubs\";\r\n\r\n/**\r\n * This default implementation of {@link EqualityComparator} uses object equality\r\n * for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class ObjectEqualityComparator implements EqualityComparator<Equatable | null | undefined> {\r\n\tpublic static readonly INSTANCE: ObjectEqualityComparator = new ObjectEqualityComparator();\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation returns\r\n\t * `obj.`{@link Object#hashCode hashCode()}.\r\n\t */\r\n\t@Override\r\n\tpublic hashCode(obj: Equatable | null | undefined): number {\r\n\t\tif (obj == null) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\treturn obj.hashCode();\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * This implementation relies on object equality. If both objects are\r\n\t * `undefined` or `null`, this method returns `true`. Otherwise if only\r\n\t * `a` is `undefined` or `null`, this method returns `false`. Otherwise,\r\n\t * this method returns the result of\r\n\t * `a.`{@link Object#equals equals}`(b)`.\r\n\t */\r\n\t@Override\r\n\tpublic equals(a: Equatable | null | undefined, b: Equatable | null | undefined): boolean {\r\n\t\tif (a == null) {\r\n\t\t\treturn b == null;\r\n\t\t}\r\n\r\n\t\treturn a.equals(b);\r\n\t}\r\n\r\n}\r\n"]}

View File

@@ -0,0 +1,18 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
/**
* This exception is thrown to cancel a parsing operation. This exception does
* not extend {@link RecognitionException}, allowing it to bypass the standard
* error recovery mechanisms. {@link BailErrorStrategy} throws this exception in
* response to a parse error.
*
* @author Sam Harwell
*/
export declare class ParseCancellationException extends Error {
cause: Error;
readonly stack?: string;
constructor(cause: Error);
getCause(): Error;
}

View File

@@ -0,0 +1,28 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseCancellationException = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:42.5447085-07:00
/**
* This exception is thrown to cancel a parsing operation. This exception does
* not extend {@link RecognitionException}, allowing it to bypass the standard
* error recovery mechanisms. {@link BailErrorStrategy} throws this exception in
* response to a parse error.
*
* @author Sam Harwell
*/
class ParseCancellationException extends Error {
constructor(cause) {
super(cause.message);
this.cause = cause;
this.stack = cause.stack;
}
getCause() {
return this.cause;
}
}
exports.ParseCancellationException = ParseCancellationException;
//# sourceMappingURL=ParseCancellationException.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ParseCancellationException.js","sourceRoot":"","sources":["../../../src/misc/ParseCancellationException.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wDAAwD;AAExD;;;;;;;GAOG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAIpD,YAAmB,KAAY;QAC9B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QADH,UAAK,GAAL,KAAK,CAAO;QAE9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1B,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAZD,gEAYC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:42.5447085-07:00\r\n\r\n/**\r\n * This exception is thrown to cancel a parsing operation. This exception does\r\n * not extend {@link RecognitionException}, allowing it to bypass the standard\r\n * error recovery mechanisms. {@link BailErrorStrategy} throws this exception in\r\n * response to a parse error.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class ParseCancellationException extends Error {\r\n\t// private static serialVersionUID: number = -3529552099366979683L;\r\n\tpublic readonly stack?: string;\r\n\r\n\tconstructor(public cause: Error) {\r\n\t\tsuper(cause.message);\r\n\t\tthis.stack = cause.stack;\r\n\t}\r\n\r\n\tpublic getCause(): Error {\r\n\t\treturn this.cause;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,31 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export interface Equatable {
equals(other: any): boolean;
hashCode(): number;
}
export interface Comparable<T> {
compareTo(o: T): number;
}
export interface JavaCollection<E> extends Iterable<E>, Equatable {
add(e: E): boolean;
addAll(collection: Iterable<E>): boolean;
clear(): void;
contains(o: any): boolean;
containsAll(collection: Iterable<any>): boolean;
readonly isEmpty: boolean;
readonly size: number;
toArray(): E[];
}
export interface JavaSet<E> extends JavaCollection<E> {
}
export interface JavaMap<K, V> extends Equatable {
clear(): void;
containsKey(key: K): boolean;
get(key: K): V | undefined;
readonly isEmpty: boolean;
put(key: K, value: V): V | undefined;
readonly size: number;
}

View File

@@ -0,0 +1,7 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Stubs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Stubs.js","sourceRoot":"","sources":["../../../src/misc/Stubs.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nexport interface Equatable {\r\n\tequals(other: any): boolean;\r\n\thashCode(): number;\r\n}\r\n\r\nexport interface Comparable<T> {\r\n\tcompareTo(o: T): number;\r\n}\r\n\r\n// This has been tweaked to fore implemenations to support either Java or JavaScript collections passed in...\r\n\r\nexport interface JavaCollection<E> extends Iterable<E>, Equatable {\r\n\tadd(e: E): boolean;\r\n\taddAll(collection: Iterable<E>): boolean;\r\n\tclear(): void;\r\n\tcontains(o: any): boolean; // Shouldn't argument be restricted to E?\r\n\tcontainsAll(collection: Iterable<any>): boolean; // Shouldn't argument be restricted to Collection<E>?\r\n\treadonly isEmpty: boolean;\r\n\treadonly size: number;\r\n\ttoArray(): E[];\r\n}\r\n\r\nexport interface JavaSet<E> extends JavaCollection<E> {\r\n\t// Seems like Java's Set doesn't really seem to extend Java's Collection with anything...\r\n\r\n\t// add(e:E): boolean;\r\n\t// addAll(collection:Iterable<E>): boolean;\r\n\t// clear(): void;\r\n\t// contains(o:any): boolean; // Shouldn't argument be restricted to E?\r\n\t// containsAll(collection: Iterable<any>) // Shouldn't argument be restricted to E?\r\n\t// readonly isEmpty: boolean;\r\n\t// readonly size: number;\r\n\t// toArray(): E[];\r\n}\r\n\r\nexport interface JavaMap<K, V> extends Equatable {\r\n\tclear(): void;\r\n\tcontainsKey(key: K): boolean;\r\n\tget(key: K): V | undefined;\r\n\treadonly isEmpty: boolean;\r\n\tput(key: K, value: V): V | undefined;\r\n\treadonly size: number;\r\n}\r\n"]}

View File

@@ -0,0 +1,13 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Equatable } from "./Stubs";
export declare class UUID implements Equatable {
private readonly data;
constructor(mostSigBits: number, moreSigBits: number, lessSigBits: number, leastSigBits: number);
static fromString(data: string): UUID;
hashCode(): number;
equals(obj: any): boolean;
toString(): string;
}

View File

@@ -0,0 +1,53 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.UUID = void 0;
const MurmurHash_1 = require("./MurmurHash");
class UUID {
constructor(mostSigBits, moreSigBits, lessSigBits, leastSigBits) {
this.data = new Uint32Array(4);
this.data[0] = mostSigBits;
this.data[1] = moreSigBits;
this.data[2] = lessSigBits;
this.data[3] = leastSigBits;
}
static fromString(data) {
if (!/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/.test(data)) {
throw new Error("Incorrectly formatted UUID");
}
let segments = data.split("-");
let mostSigBits = parseInt(segments[0], 16);
let moreSigBits = ((parseInt(segments[1], 16) << 16) >>> 0) + parseInt(segments[2], 16);
let lessSigBits = ((parseInt(segments[3], 16) << 16) >>> 0) + parseInt(segments[4].substr(0, 4), 16);
let leastSigBits = parseInt(segments[4].substr(-8), 16);
return new UUID(mostSigBits, moreSigBits, lessSigBits, leastSigBits);
}
hashCode() {
return MurmurHash_1.MurmurHash.hashCode([this.data[0], this.data[1], this.data[2], this.data[3]]);
}
equals(obj) {
if (obj === this) {
return true;
}
else if (!(obj instanceof UUID)) {
return false;
}
return this.data[0] === obj.data[0]
&& this.data[1] === obj.data[1]
&& this.data[2] === obj.data[2]
&& this.data[3] === obj.data[3];
}
toString() {
return ("00000000" + this.data[0].toString(16)).substr(-8)
+ "-" + ("0000" + (this.data[1] >>> 16).toString(16)).substr(-4)
+ "-" + ("0000" + this.data[1].toString(16)).substr(-4)
+ "-" + ("0000" + (this.data[2] >>> 16).toString(16)).substr(-4)
+ "-" + ("0000" + this.data[2].toString(16)).substr(-4)
+ ("00000000" + this.data[3].toString(16)).substr(-8);
}
}
exports.UUID = UUID;
//# sourceMappingURL=UUID.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Equatable } from "./Stubs";
import { IntegerList } from "./IntegerList";
export declare function escapeWhitespace(s: string, escapeSpaces: boolean): string;
export declare function join(collection: Iterable<any>, separator: string): string;
export declare function equals(x: Equatable | undefined, y: Equatable | undefined): boolean;
/** Convert array of strings to string&rarr;index map. Useful for
* converting rulenames to name&rarr;ruleindex map.
*/
export declare function toMap(keys: string[]): Map<string, number>;
export declare function toCharArray(str: string): Uint16Array;
export declare function toCharArray(data: IntegerList): Uint16Array;

View File

@@ -0,0 +1,174 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCharArray = exports.toMap = exports.equals = exports.join = exports.escapeWhitespace = void 0;
function escapeWhitespace(s, escapeSpaces) {
return escapeSpaces ? s.replace(/ /, "\u00B7") : s
.replace(/\t/, "\\t")
.replace(/\n/, "\\n")
.replace(/\r/, "\\r");
}
exports.escapeWhitespace = escapeWhitespace;
// Seriously: why isn't this built in to java? ugh!
function join(collection, separator) {
let buf = "";
let first = true;
for (let current of collection) {
if (first) {
first = false;
}
else {
buf += separator;
}
buf += current;
}
return buf;
}
exports.join = join;
function equals(x, y) {
if (x === y) {
return true;
}
if (x === undefined || y === undefined) {
return false;
}
return x.equals(y);
}
exports.equals = equals;
// export function numNonnull(data: any[]): number {
// let n: number = 0;
// if ( data == null ) return n;
// for (let o of data) {
// if ( o!=null ) n++;
// }
// return n;
// }
// export function removeAllElements<T>(data: Collection<T>, value: T): void {
// if ( data==null ) return;
// while ( data.contains(value) ) data.remove(value);
// }
// export function writeFile(@NotNull file: File, @NotNull content: Uint8Array): void {
// let fos: FileOutputStream = new FileOutputStream(file);
// try {
// fos.write(content);
// } finally {
// fos.close();
// }
// }
// export function writeFile(@NotNull fileName: string, @NotNull content: string): void {
// writeFile(fileName, content, null);
// }
// export function writeFile(@NotNull fileName: string, @NotNull content: string, @Nullable encoding: string): void {
// let f: File = new File(fileName);
// let fos: FileOutputStream = new FileOutputStream(f);
// let osw: OutputStreamWriter;
// if (encoding != null) {
// osw = new OutputStreamWriter(fos, encoding);
// }
// else {
// osw = new OutputStreamWriter(fos);
// }
// try {
// osw.write(content);
// }
// finally {
// osw.close();
// }
// }
// @NotNull
// export function readFile(@NotNull fileName: string): char[] {
// return readFile(fileName, null);
// }
// @NotNull
// export function readFile(@NotNull fileName: string, @Nullable encoding: string): char[] {
// let f: File = new File(fileName);
// let size: number = (int)f.length();
// let isr: InputStreamReader;
// let fis: FileInputStream = new FileInputStream(fileName);
// if ( encoding!=null ) {
// isr = new InputStreamReader(fis, encoding);
// }
// else {
// isr = new InputStreamReader(fis);
// }
// let data: char[] = null;
// try {
// data = new char[size];
// let n: number = isr.read(data);
// if (n < data.length) {
// data = Arrays.copyOf(data, n);
// }
// }
// finally {
// isr.close();
// }
// return data;
// }
// export function removeAll<T>(@NotNull predicate: List<T> list,@NotNull Predicate<? super T>): void {
// let j: number = 0;
// for (let i = 0; i < list.size; i++) {
// let item: T = list.get(i);
// if (!predicate.eval(item)) {
// if (j != i) {
// list.set(j, item);
// }
// j++;
// }
// }
// if (j < list.size) {
// list.subList(j, list.size).clear();
// }
// }
// export function removeAll<T>(@NotNull predicate: Iterable<T> iterable,@NotNull Predicate<? super T>): void {
// if (iterable instanceof List<?>) {
// removeAll((List<T>)iterable, predicate);
// return;
// }
// for (Iterator<T> iterator = iterable.iterator(); iterator.hasNext(); ) {
// let item: T = iterator.next();
// if (predicate.eval(item)) {
// iterator.remove();
// }
// }
// }
/** Convert array of strings to string&rarr;index map. Useful for
* converting rulenames to name&rarr;ruleindex map.
*/
function toMap(keys) {
let m = new Map();
for (let i = 0; i < keys.length; i++) {
m.set(keys[i], i);
}
return m;
}
exports.toMap = toMap;
function toCharArray(str) {
if (typeof str === "string") {
let result = new Uint16Array(str.length);
for (let i = 0; i < str.length; i++) {
result[i] = str.charCodeAt(i);
}
return result;
}
else {
return str.toCharArray();
}
}
exports.toCharArray = toCharArray;
// /**
// * @since 4.5
// */
// @NotNull
// export function toSet(@NotNull bits: BitSet): IntervalSet {
// let s: IntervalSet = new IntervalSet();
// let i: number = bits.nextSetBit(0);
// while ( i >= 0 ) {
// s.add(i);
// i = bits.nextSetBit(i+1);
// }
// return s;
// }
//# sourceMappingURL=Utils.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,25 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export * from "./Array2DHashMap";
export * from "./ArrayEqualityComparator";
export * from "./Args";
export * from "./Array2DHashSet";
export * from "./Arrays";
export * from "./BitSet";
export * from "./Character";
export * from "./DefaultEqualityComparator";
export * from "./EqualityComparator";
export * from "./IntegerList";
export * from "./IntegerStack";
export * from "./InterpreterDataReader";
export * from "./Interval";
export * from "./IntervalSet";
export * from "./IntSet";
export * from "./MultiMap";
export * from "./MurmurHash";
export * from "./ObjectEqualityComparator";
export * from "./ParseCancellationException";
export * from "./Utils";
export * from "./UUID";

View File

@@ -0,0 +1,44 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./Array2DHashMap"), exports);
__exportStar(require("./ArrayEqualityComparator"), exports);
__exportStar(require("./Args"), exports);
__exportStar(require("./Array2DHashSet"), exports);
__exportStar(require("./Arrays"), exports);
__exportStar(require("./BitSet"), exports);
__exportStar(require("./Character"), exports);
__exportStar(require("./DefaultEqualityComparator"), exports);
// export * from "./DoubleKeyMap";
__exportStar(require("./EqualityComparator"), exports);
// export * from "./FlexibleHashMap";
__exportStar(require("./IntegerList"), exports);
__exportStar(require("./IntegerStack"), exports);
__exportStar(require("./InterpreterDataReader"), exports);
__exportStar(require("./Interval"), exports);
__exportStar(require("./IntervalSet"), exports);
__exportStar(require("./IntSet"), exports);
// export * from "./LogManager";
__exportStar(require("./MultiMap"), exports);
__exportStar(require("./MurmurHash"), exports);
__exportStar(require("./ObjectEqualityComparator"), exports);
// export * from "./OrderedHashSet";
__exportStar(require("./ParseCancellationException"), exports);
// export * from "./RuleDependencyChecker";
// export * from "./RuleDependencyProcessor";
__exportStar(require("./Utils"), exports);
__exportStar(require("./UUID"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/misc/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,mDAAiC;AACjC,4DAA0C;AAC1C,yCAAuB;AACvB,mDAAiC;AACjC,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,8DAA4C;AAC5C,kCAAkC;AAClC,uDAAqC;AACrC,qCAAqC;AACrC,gDAA8B;AAC9B,iDAA+B;AAC/B,0DAAwC;AACxC,6CAA2B;AAC3B,gDAA8B;AAC9B,2CAAyB;AACzB,gCAAgC;AAChC,6CAA2B;AAC3B,+CAA6B;AAC7B,6DAA2C;AAC3C,oCAAoC;AACpC,+DAA6C;AAC7C,2CAA2C;AAC3C,6CAA6C;AAC7C,0CAAwB;AACxB,yCAAuB","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nexport * from \"./Array2DHashMap\";\r\nexport * from \"./ArrayEqualityComparator\";\r\nexport * from \"./Args\";\r\nexport * from \"./Array2DHashSet\";\r\nexport * from \"./Arrays\";\r\nexport * from \"./BitSet\";\r\nexport * from \"./Character\";\r\nexport * from \"./DefaultEqualityComparator\";\r\n// export * from \"./DoubleKeyMap\";\r\nexport * from \"./EqualityComparator\";\r\n// export * from \"./FlexibleHashMap\";\r\nexport * from \"./IntegerList\";\r\nexport * from \"./IntegerStack\";\r\nexport * from \"./InterpreterDataReader\";\r\nexport * from \"./Interval\";\r\nexport * from \"./IntervalSet\";\r\nexport * from \"./IntSet\";\r\n// export * from \"./LogManager\";\r\nexport * from \"./MultiMap\";\r\nexport * from \"./MurmurHash\";\r\nexport * from \"./ObjectEqualityComparator\";\r\n// export * from \"./OrderedHashSet\";\r\nexport * from \"./ParseCancellationException\";\r\n// export * from \"./RuleDependencyChecker\";\r\n// export * from \"./RuleDependencyProcessor\";\r\nexport * from \"./Utils\";\r\nexport * from \"./UUID\";\r\n"]}