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

antlr4-c3

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antlr4-c3 - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

lib/src/utils.d.ts

3

lib/src/ArrayType.js

@@ -13,2 +13,5 @@ "use strict";

class ArrayType extends BaseSymbol_1.BaseSymbol {
elementType;
size; // > 0 if fixed length.
referenceKind;
constructor(name, referenceKind, elemType, size = 0) {

@@ -15,0 +18,0 @@ super(name);

79

lib/src/BaseSymbol.js

@@ -8,23 +8,2 @@ "use strict";

*/
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());
});
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _BaseSymbol_parent;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -40,17 +19,20 @@ exports.BaseSymbol = void 0;

class BaseSymbol {
/** The name of the symbol or empty if anonymous. */
name;
/** Reference to the parse tree which contains this symbol. */
context;
modifiers = new Set();
visibility = types_1.MemberVisibility.Unknown;
#parent;
constructor(name = "") {
this.modifiers = new Set();
this.visibility = types_1.MemberVisibility.Unknown;
_BaseSymbol_parent.set(this, void 0);
this.name = name;
}
get parent() {
return __classPrivateFieldGet(this, _BaseSymbol_parent, "f");
return this.#parent;
}
get firstSibling() {
var _a;
if (!__classPrivateFieldGet(this, _BaseSymbol_parent, "f")) {
if (!this.#parent) {
return undefined;
}
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.firstChild;
return this.#parent?.firstChild;
}

@@ -61,9 +43,9 @@ /**

get previousSibling() {
if (!__classPrivateFieldGet(this, _BaseSymbol_parent, "f")) {
if (!this.#parent) {
return undefined;
}
if (!__classPrivateFieldGet(this, _BaseSymbol_parent, "f")) {
if (!this.#parent) {
return this;
}
return __classPrivateFieldGet(this, _BaseSymbol_parent, "f").previousSiblingOf(this);
return this.#parent.previousSiblingOf(this);
}

@@ -74,8 +56,6 @@ /**

get nextSibling() {
var _a;
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.nextSiblingOf(this);
return this.#parent?.nextSiblingOf(this);
}
get lastSibling() {
var _a;
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.lastChild;
return this.#parent?.lastChild;
}

@@ -86,4 +66,3 @@ /**

get next() {
var _a;
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.nextOf(this);
return this.#parent?.nextOf(this);
}

@@ -94,3 +73,3 @@ /**

get root() {
let run = __classPrivateFieldGet(this, _BaseSymbol_parent, "f");
let run = this.#parent;
while (run) {

@@ -111,3 +90,3 @@ if (!run.parent || this.isSymbolTable(run.parent)) {

}
let run = __classPrivateFieldGet(this, _BaseSymbol_parent, "f");
let run = this.#parent;
while (run) {

@@ -143,3 +122,3 @@ if (this.isSymbolTable(run)) {

setParent(parent) {
__classPrivateFieldSet(this, _BaseSymbol_parent, parent, "f");
this.#parent = parent;
}

@@ -150,5 +129,4 @@ /**

removeFromParent() {
var _a;
(_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.removeSymbol(this);
__classPrivateFieldSet(this, _BaseSymbol_parent, undefined, "f");
this.#parent?.removeSymbol(this);
this.#parent = undefined;
}

@@ -165,7 +143,4 @@ /**

*/
resolve(name, localOnly = false) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.resolve(name, localOnly);
});
async resolve(name, localOnly = false) {
return this.#parent?.resolve(name, localOnly);
}

@@ -183,4 +158,3 @@ /**

resolveSync(name, localOnly = false) {
var _a;
return (_a = __classPrivateFieldGet(this, _BaseSymbol_parent, "f")) === null || _a === void 0 ? void 0 : _a.resolveSync(name, localOnly);
return this.#parent?.resolveSync(name, localOnly);
}

@@ -193,3 +167,3 @@ /**

getParentOfType(t) {
let run = __classPrivateFieldGet(this, _BaseSymbol_parent, "f");
let run = this.#parent;
while (run) {

@@ -218,3 +192,3 @@ if (run instanceof t) {

let result = this.name.length === 0 ? "<anonymous>" : this.name;
let run = __classPrivateFieldGet(this, _BaseSymbol_parent, "f");
let run = this.#parent;
while (run) {

@@ -243,3 +217,2 @@ if (includeAnonymous || run.name.length > 0) {

exports.BaseSymbol = BaseSymbol;
_BaseSymbol_parent = new WeakMap();
//# sourceMappingURL=BaseSymbol.js.map

@@ -16,6 +16,12 @@ "use strict";

class ClassSymbol extends ScopedSymbol_1.ScopedSymbol {
isStruct = false;
reference = types_1.ReferenceKind.Irrelevant;
/** Usually only one member, unless the language supports multiple inheritance (like C++). */
// eslint-disable-next-line no-use-before-define
extends;
/** Typescript allows a class to implement a class, not only interfaces. */
// eslint-disable-next-line no-use-before-define
implements;
constructor(name, ext, impl) {
super(name);
this.isStruct = false;
this.reference = types_1.ReferenceKind.Irrelevant;
this.extends = ext;

@@ -22,0 +28,0 @@ this.implements = impl;

import { Parser, ParserRuleContext } from "antlr4ts";
export type TokenList = number[];
export type RuleList = number[];
export interface CandidateRule {
export interface ICandidateRule {
startTokenIndex: number;
ruleList: RuleList;
}
export interface RuleWithStartToken {
export interface IRuleWithStartToken {
startTokenIndex: number;
ruleIndex: number;
}
export type RuleWithStartTokenList = RuleWithStartToken[];
export type RuleWithStartTokenList = IRuleWithStartToken[];
/**
* All the candidates which have been found. Tokens and rules are separated.
* Token entries include a list of tokens that directly follow them (see also the "following" member in the
* FollowSetWithPath class).
* Rule entries include the index of the starting token within the evaluated rule, along with a call stack of rules
* found during evaluation.
*/
export declare class CandidatesCollection {
tokens: Map<number, TokenList>;
rules: Map<number, CandidateRule>;
rules: Map<number, ICandidateRule>;
}
/** The main class for doing the collection process. */
export declare class CodeCompletionCore {
private static followSetsByATN;
private static atnStateTypeMap;
/** Not dependent on showDebugOutput. Prints the collected rules + tokens to terminal. */
showResult: boolean;
/** Enables printing ATN state info to terminal. */
showDebugOutput: boolean;
/** Only relevant when showDebugOutput is true. Enables transition printing for a state. */
debugOutputWithTransitions: boolean;
/** Also depends on showDebugOutput. Enables call stack printing for each rule recursion. */
showRuleStack: boolean;
/**
* Tailoring of the result:
* Tokens which should not appear in the candidates set.
*/
ignoredTokens: Set<number>;
/**
* Rules which replace any candidate token they contain.
* This allows to return descriptive rules (e.g. className, instead of ID/identifier).
*/
preferredRules: Set<number>;
/**
* Specify if preferred rules should translated top-down (higher index rule returns first) or
* bottom-up (lower index rule returns first).
*/
translateRulesTopDown: boolean;

@@ -35,3 +59,8 @@ private parser;

private statesProcessed;
/**
* A mapping of rule index + token stream position to end token positions.
* A rule which has been visited before with the same input position will always produce the same output positions.
*/
private shortcutMap;
/** The collected candidates (rules and tokens). */
private candidates;

@@ -38,0 +67,0 @@ constructor(parser: Parser);

@@ -14,53 +14,96 @@ "use strict";

const IntervalSet_1 = require("antlr4ts/misc/IntervalSet");
// All the candidates which have been found. Tokens and rules are separated.
// Token entries include a list of tokens that directly follow them (see also the "following" member in the
// FollowSetWithPath class).
// Rule entries include the index of the starting token within the evaluated rule, along with a call stack of rules
// found during evaluation.
const utils_1 = require("./utils");
/**
* All the candidates which have been found. Tokens and rules are separated.
* Token entries include a list of tokens that directly follow them (see also the "following" member in the
* FollowSetWithPath class).
* Rule entries include the index of the starting token within the evaluated rule, along with a call stack of rules
* found during evaluation.
*/
class CandidatesCollection {
constructor() {
this.tokens = new Map();
this.rules = new Map();
}
tokens = new Map();
rules = new Map();
}
exports.CandidatesCollection = CandidatesCollection;
// A record for a follow set along with the path at which this set was found.
// If there is only a single symbol in the interval set then we also collect and store tokens which follow
// this symbol directly in its rule (i.e. there is no intermediate rule transition). Only single label transitions
// are considered. This is useful if you have a chain of tokens which can be suggested as a whole, because there is
// a fixed sequence in the grammar.
/**
* A record for a follow set along with the path at which this set was found.
* If there is only a single symbol in the interval set then we also collect and store tokens which follow
* this symbol directly in its rule (i.e. there is no intermediate rule transition). Only single label transitions
* are considered. This is useful if you have a chain of tokens which can be suggested as a whole, because there is
* a fixed sequence in the grammar.
*/
class FollowSetWithPath {
constructor() {
this.path = [];
this.following = [];
}
intervals;
path = [];
following = [];
}
// A list of follow sets (for a given state number) + all of them combined for quick hit tests + whether they are
// exhaustive (false if subsequent yet-unprocessed rules could add further tokens to the follow set, true otherwise).
// This data is static in nature (because the used ATN states are part of a static struct: the ATN).
// Hence it can be shared between all C3 instances, however it depends on the actual parser class (type).
/**
* A list of follow sets (for a given state number) + all of them combined for quick hit tests + whether they are
* exhaustive (false if subsequent yet-unprocessed rules could add further tokens to the follow set, true otherwise).
* This data is static in nature (because the used ATN states are part of a static struct: the ATN).
* Hence it can be shared between all C3 instances, however it depends on the actual parser class (type).
*/
class FollowSetsHolder {
sets;
combined;
isExhaustive;
}
// The main class for doing the collection process.
/** The main class for doing the collection process. */
class CodeCompletionCore {
static followSetsByATN = new Map();
static atnStateTypeMap = [
"invalid",
"basic",
"rule start",
"block start",
"plus block start",
"star block start",
"token start",
"rule stop",
"block end",
"star loop back",
"star loop entry",
"plus loop back",
"loop end",
];
// Debugging options. Print human readable ATN state and other info.
/** Not dependent on showDebugOutput. Prints the collected rules + tokens to terminal. */
showResult = false;
/** Enables printing ATN state info to terminal. */
showDebugOutput = false;
/** Only relevant when showDebugOutput is true. Enables transition printing for a state. */
debugOutputWithTransitions = false;
/** Also depends on showDebugOutput. Enables call stack printing for each rule recursion. */
showRuleStack = false;
/**
* Tailoring of the result:
* Tokens which should not appear in the candidates set.
*/
ignoredTokens;
/**
* Rules which replace any candidate token they contain.
* This allows to return descriptive rules (e.g. className, instead of ID/identifier).
*/
preferredRules;
/**
* Specify if preferred rules should translated top-down (higher index rule returns first) or
* bottom-up (lower index rule returns first).
*/
translateRulesTopDown = false;
parser;
atn;
vocabulary;
ruleNames;
tokens;
precedenceStack;
tokenStartIndex = 0;
statesProcessed = 0;
/**
* A mapping of rule index + token stream position to end token positions.
* A rule which has been visited before with the same input position will always produce the same output positions.
*/
shortcutMap = new Map();
/** The collected candidates (rules and tokens). */
candidates = new CandidatesCollection();
constructor(parser) {
// Debugging options. Print human readable ATN state and other info.
// Not dependent on showDebugOutput. Prints the collected rules + tokens to terminal.
this.showResult = false;
// Enables printing ATN state info to terminal.
this.showDebugOutput = false;
// Only relevant when showDebugOutput is true. Enables transition printing for a state.
this.debugOutputWithTransitions = false;
// Also depends on showDebugOutput. Enables call stack printing for each rule recursion.
this.showRuleStack = false;
// Specify if preferred rules should translated top-down (higher index rule returns first) or
// bottom-up (lower index rule returns first).
this.translateRulesTopDown = false;
this.tokenStartIndex = 0;
this.statesProcessed = 0;
// A mapping of rule index + token stream position to end token positions.
// A rule which has been visited before with the same input position will always produce the same output positions.
this.shortcutMap = new Map();
// The collected candidates (rules and tokens).
this.candidates = new CandidatesCollection();
this.parser = parser;

@@ -191,3 +234,3 @@ this.atn = parser.atn;

// but only if there isn't already an entry like that.
const path = ruleWithStartTokenList.slice(0, i).map(({ ruleIndex: candidate }) => candidate);
const path = ruleWithStartTokenList.slice(0, i).map(({ ruleIndex: candidate }) => { return candidate; });
let addNew = true;

@@ -199,3 +242,3 @@ for (const rule of this.candidates.rules) {

// Found an entry for this rule. Same path? If so don't add a new (duplicate) entry.
if (path.every((v, j) => v === rule[1].ruleList[j])) {
if (path.every((v, j) => { return v === rule[1].ruleList[j]; })) {
addNew = false;

@@ -282,3 +325,3 @@ break;

collectFollowSets(s, stopState, followSets, stateStack, ruleStack) {
if (stateStack.find((x) => x === s)) {
if (stateStack.find((x) => { return x === s; })) {
return true;

@@ -305,3 +348,3 @@ }

const nextStateFollowSetsIsExhaustive = this.collectFollowSets(ruleTransition.followState, stopState, followSets, stateStack, ruleStack);
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive);
isExhaustive &&= nextStateFollowSetsIsExhaustive;
}

@@ -312,3 +355,3 @@ }

const nextStateFollowSetsIsExhaustive = this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack);
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive);
isExhaustive &&= nextStateFollowSetsIsExhaustive;
}

@@ -318,3 +361,3 @@ }

const nextStateFollowSetsIsExhaustive = this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack);
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive);
isExhaustive &&= nextStateFollowSetsIsExhaustive;
}

@@ -408,7 +451,9 @@ else if (transition.serializationType === 9 /* TransitionType.WILDCARD */) {

const fullPath = callStack.slice();
// Rules derived from our followSet will always start at the same token as our current rule
const followSetPath = set.path.map((path) => ({
startTokenIndex,
ruleIndex: path,
}));
// Rules derived from our followSet will always start at the same token as our current rule.
const followSetPath = set.path.map((path) => {
return {
startTokenIndex,
ruleIndex: path,
};
});
fullPath.push(...followSetPath);

@@ -550,3 +595,3 @@ if (!this.translateStackToRuleIndex(fullPath)) {

const list = set.toArray();
const addFollowing = list.length === 1;
const hasTokenSequence = list.length === 1;
for (const symbol of list) {

@@ -557,7 +602,10 @@ if (!this.ignoredTokens.has(symbol)) {

}
if (addFollowing) {
this.candidates.tokens.set(symbol, this.getFollowingTokens(transition));
const followingTokens = hasTokenSequence
? this.getFollowingTokens(transition)
: [];
if (!this.candidates.tokens.has(symbol)) {
this.candidates.tokens.set(symbol, followingTokens);
}
else {
this.candidates.tokens.set(symbol, []);
this.candidates.tokens.set(symbol, (0, utils_1.longestCommonPrefix)(followingTokens, this.candidates.tokens.get(symbol)));
}

@@ -644,19 +692,3 @@ }

}
CodeCompletionCore.followSetsByATN = new Map();
CodeCompletionCore.atnStateTypeMap = [
"invalid",
"basic",
"rule start",
"block start",
"plus block start",
"star block start",
"token start",
"rule stop",
"block end",
"star loop back",
"star loop entry",
"plus loop back",
"loop end",
];
exports.CodeCompletionCore = CodeCompletionCore;
//# sourceMappingURL=CodeCompletionCore.js.map

@@ -13,4 +13,6 @@ "use strict";

class FieldSymbol extends VariableSymbol_1.VariableSymbol {
setter;
getter;
}
exports.FieldSymbol = FieldSymbol;
//# sourceMappingURL=FieldSymbol.js.map

@@ -13,2 +13,9 @@ "use strict";

class FundamentalType {
static integerType = new FundamentalType("int", types_1.TypeKind.Integer, types_1.ReferenceKind.Instance);
static floatType = new FundamentalType("float", types_1.TypeKind.Float, types_1.ReferenceKind.Instance);
static stringType = new FundamentalType("string", types_1.TypeKind.String, types_1.ReferenceKind.Instance);
static boolType = new FundamentalType("bool", types_1.TypeKind.Boolean, types_1.ReferenceKind.Instance);
name;
typeKind;
referenceKind;
constructor(name, typeKind = types_1.TypeKind.Unknown, referenceKind = types_1.ReferenceKind.Irrelevant) {

@@ -29,7 +36,3 @@ this.name = name;

}
FundamentalType.integerType = new FundamentalType("int", types_1.TypeKind.Integer, types_1.ReferenceKind.Instance);
FundamentalType.floatType = new FundamentalType("float", types_1.TypeKind.Float, types_1.ReferenceKind.Instance);
FundamentalType.stringType = new FundamentalType("string", types_1.TypeKind.String, types_1.ReferenceKind.Instance);
FundamentalType.boolType = new FundamentalType("bool", types_1.TypeKind.Boolean, types_1.ReferenceKind.Instance);
exports.FundamentalType = FundamentalType;
//# sourceMappingURL=FundamentalType.js.map

@@ -15,5 +15,8 @@ "use strict";

class InterfaceSymbol extends ScopedSymbol_1.ScopedSymbol {
reference = types_1.ReferenceKind.Irrelevant;
/** Typescript allows an interface to extend a class, not only interfaces. */
// eslint-disable-next-line no-use-before-define
extends;
constructor(name, ext) {
super(name);
this.reference = types_1.ReferenceKind.Irrelevant;
this.extends = ext;

@@ -20,0 +23,0 @@ }

@@ -12,2 +12,3 @@ "use strict";

class LiteralSymbol extends TypedSymbol_1.TypedSymbol {
value;
constructor(name, value, type) {

@@ -14,0 +15,0 @@ super(name, type);

@@ -21,11 +21,8 @@ "use strict";

MethodFlags[MethodFlags["Explicit"] = 16] = "Explicit";
})(MethodFlags = exports.MethodFlags || (exports.MethodFlags = {}));
})(MethodFlags || (exports.MethodFlags = MethodFlags = {}));
/** A function which belongs to a class or other outer container structure. */
class MethodSymbol extends RoutineSymbol_1.RoutineSymbol {
constructor() {
super(...arguments);
this.methodFlags = MethodFlags.None;
}
methodFlags = MethodFlags.None;
}
exports.MethodSymbol = MethodSymbol;
//# sourceMappingURL=MethodSymbol.js.map

@@ -12,2 +12,4 @@ "use strict";

class NamespaceSymbol extends ScopedSymbol_1.ScopedSymbol {
inline;
attributes;
constructor(name, inline = false, attributes = []) {

@@ -14,0 +16,0 @@ super(name);

@@ -15,2 +15,3 @@ "use strict";

class RoutineSymbol extends ScopedSymbol_1.ScopedSymbol {
returnType; // Can be null if result is void.
constructor(name, returnType) {

@@ -17,0 +18,0 @@ super(name);

@@ -8,23 +8,2 @@ "use strict";

*/
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());
});
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _ScopedSymbol_children, _ScopedSymbol_names;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -36,8 +15,8 @@ exports.ScopedSymbol = void 0;

class ScopedSymbol extends BaseSymbol_1.BaseSymbol {
/** All child symbols in definition order. */
#children = [];
// All used child names. Used to detect name collisions.
#names = new Map();
constructor(name = "") {
super(name);
/** All child symbols in definition order. */
_ScopedSymbol_children.set(this, []);
// All used child names. Used to detect name collisions.
_ScopedSymbol_names.set(this, new Map());
}

@@ -51,7 +30,7 @@ /**

get children() {
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f");
return this.#children;
}
get firstChild() {
if (__classPrivateFieldGet(this, _ScopedSymbol_children, "f").length > 0) {
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f")[0];
if (this.#children.length > 0) {
return this.#children[0];
}

@@ -61,4 +40,4 @@ return undefined;

get lastChild() {
if (__classPrivateFieldGet(this, _ScopedSymbol_children, "f").length > 0) {
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f")[__classPrivateFieldGet(this, _ScopedSymbol_children, "f").length - 1];
if (this.#children.length > 0) {
return this.#children[this.#children.length - 1];
}

@@ -68,4 +47,4 @@ return undefined;

clear() {
__classPrivateFieldSet(this, _ScopedSymbol_children, [], "f");
__classPrivateFieldGet(this, _ScopedSymbol_names, "f").clear();
this.#children = [];
this.#names.clear();
}

@@ -79,18 +58,17 @@ /**

addSymbol(symbol) {
var _a, _b;
symbol.removeFromParent();
// Check for duplicates first.
const symbolTable = this.symbolTable;
const count = __classPrivateFieldGet(this, _ScopedSymbol_names, "f").get(symbol.name);
const count = this.#names.get(symbol.name);
if (!symbolTable || !symbolTable.options.allowDuplicateSymbols) {
if (count !== undefined) {
throw new DuplicateSymbolError_1.DuplicateSymbolError("Attempt to add duplicate symbol '" + ((_a = symbol.name) !== null && _a !== void 0 ? _a : "<anonymous>") +
throw new DuplicateSymbolError_1.DuplicateSymbolError("Attempt to add duplicate symbol '" + (symbol.name ?? "<anonymous>") +
"'");
}
else {
__classPrivateFieldGet(this, _ScopedSymbol_names, "f").set(symbol.name, 1);
this.#names.set(symbol.name, 1);
}
const index = __classPrivateFieldGet(this, _ScopedSymbol_children, "f").indexOf(symbol);
const index = this.#children.indexOf(symbol);
if (index > -1) {
throw new DuplicateSymbolError_1.DuplicateSymbolError("Attempt to add duplicate symbol '" + ((_b = symbol.name) !== null && _b !== void 0 ? _b : "<anonymous>") +
throw new DuplicateSymbolError_1.DuplicateSymbolError("Attempt to add duplicate symbol '" + (symbol.name ?? "<anonymous>") +
"'");

@@ -100,19 +78,19 @@ }

else {
__classPrivateFieldGet(this, _ScopedSymbol_names, "f").set(symbol.name, count === undefined ? 1 : count + 1);
this.#names.set(symbol.name, count === undefined ? 1 : count + 1);
}
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").push(symbol);
this.#children.push(symbol);
symbol.setParent(this);
}
removeSymbol(symbol) {
const index = __classPrivateFieldGet(this, _ScopedSymbol_children, "f").indexOf(symbol);
const index = this.#children.indexOf(symbol);
if (index > -1) {
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").splice(index, 1);
this.#children.splice(index, 1);
symbol.setParent(undefined);
const count = __classPrivateFieldGet(this, _ScopedSymbol_names, "f").get(symbol.name);
const count = this.#names.get(symbol.name);
if (count !== undefined) {
if (count === 1) {
__classPrivateFieldGet(this, _ScopedSymbol_names, "f").delete(symbol.name);
this.#names.delete(symbol.name);
}
else {
__classPrivateFieldGet(this, _ScopedSymbol_names, "f").set(symbol.name, count - 1);
this.#names.set(symbol.name, count - 1);
}

@@ -129,20 +107,18 @@ }

*/
getNestedSymbolsOfType(t) {
return __awaiter(this, void 0, void 0, function* () {
const result = [];
const childPromises = [];
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").forEach((child) => {
if (child instanceof t) {
result.push(child);
}
if (child instanceof ScopedSymbol) {
childPromises.push(child.getNestedSymbolsOfType(t));
}
});
const childSymbols = yield Promise.all(childPromises);
childSymbols.forEach((entry) => {
result.push(...entry);
});
return result;
async getNestedSymbolsOfType(t) {
const result = [];
const childPromises = [];
this.#children.forEach((child) => {
if (child instanceof t) {
result.push(child);
}
if (child instanceof ScopedSymbol) {
childPromises.push(child.getNestedSymbolsOfType(t));
}
});
const childSymbols = await Promise.all(childPromises);
childSymbols.forEach((entry) => {
result.push(...entry);
});
return result;
}

@@ -158,3 +134,3 @@ /**

const result = [];
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").forEach((child) => {
this.#children.forEach((child) => {
if (child instanceof t) {

@@ -174,20 +150,18 @@ result.push(child);

*/
getAllNestedSymbols(name) {
return __awaiter(this, void 0, void 0, function* () {
const result = [];
const childPromises = [];
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").forEach((child) => {
if (!name || child.name === name) {
result.push(child);
}
if (child instanceof ScopedSymbol) {
childPromises.push(child.getAllNestedSymbols(name));
}
});
const childSymbols = yield Promise.all(childPromises);
childSymbols.forEach((entry) => {
result.push(...entry);
});
return result;
async getAllNestedSymbols(name) {
const result = [];
const childPromises = [];
this.#children.forEach((child) => {
if (!name || child.name === name) {
result.push(child);
}
if (child instanceof ScopedSymbol) {
childPromises.push(child.getAllNestedSymbols(name));
}
});
const childSymbols = await Promise.all(childPromises);
childSymbols.forEach((entry) => {
result.push(...entry);
});
return result;
}

@@ -201,3 +175,3 @@ /**

const result = [];
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").forEach((child) => {
this.#children.forEach((child) => {
if (!name || child.name === name) {

@@ -220,3 +194,3 @@ result.push(child);

const result = [];
__classPrivateFieldGet(this, _ScopedSymbol_children, "f").forEach((child) => {
this.#children.forEach((child) => {
if (child instanceof t) {

@@ -239,24 +213,22 @@ result.push(child);

*/
getAllSymbols(t, localOnly = false) {
return __awaiter(this, void 0, void 0, function* () {
const result = [];
// Special handling for namespaces, which act like grouping symbols in this scope,
// so we show them as available in this scope.
for (const child of __classPrivateFieldGet(this, _ScopedSymbol_children, "f")) {
if (child instanceof t) {
result.push(child);
}
if (this.isNamespace(child)) {
const childSymbols = yield child.getAllSymbols(t, true);
result.push(...childSymbols);
}
async getAllSymbols(t, localOnly = false) {
const result = [];
// Special handling for namespaces, which act like grouping symbols in this scope,
// so we show them as available in this scope.
for (const child of this.#children) {
if (child instanceof t) {
result.push(child);
}
if (!localOnly) {
if (this.parent) {
const childSymbols = yield this.getAllSymbols(t, true);
result.push(...childSymbols);
}
if (this.isNamespace(child)) {
const childSymbols = await child.getAllSymbols(t, true);
result.push(...childSymbols);
}
return result;
});
}
if (!localOnly) {
if (this.parent) {
const childSymbols = await this.getAllSymbols(t, true);
result.push(...childSymbols);
}
}
return result;
}

@@ -277,3 +249,3 @@ /**

// so we show them as available in this scope.
for (const child of __classPrivateFieldGet(this, _ScopedSymbol_children, "f")) {
for (const child of this.#children) {
if (child instanceof t) {

@@ -303,20 +275,18 @@ result.push(child);

*/
resolve(name, localOnly = false) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
for (const child of __classPrivateFieldGet(this, _ScopedSymbol_children, "f")) {
if (child.name === name) {
resolve(child);
return;
}
async resolve(name, localOnly = false) {
return new Promise((resolve, reject) => {
for (const child of this.#children) {
if (child.name === name) {
resolve(child);
return;
}
// Nothing found locally. Let the parent continue.
if (!localOnly) {
if (this.parent) {
resolve(this.parent.resolve(name, false));
return;
}
}
// Nothing found locally. Let the parent continue.
if (!localOnly) {
if (this.parent) {
resolve(this.parent.resolve(name, false));
return;
}
resolve(undefined);
});
}
resolve(undefined);
});

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

resolveSync(name, localOnly = false) {
for (const child of __classPrivateFieldGet(this, _ScopedSymbol_children, "f")) {
for (const child of this.#children) {
if (child.name === name) {

@@ -381,3 +351,3 @@ return child;

indexOfChild(child) {
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f").findIndex((value, index) => { return value === child; });
return this.#children.findIndex((value, index) => { return value === child; });
}

@@ -391,6 +361,6 @@ /**

const index = this.indexOfChild(child);
if (index === -1 || index >= __classPrivateFieldGet(this, _ScopedSymbol_children, "f").length - 1) {
if (index === -1 || index >= this.#children.length - 1) {
return undefined;
}
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f")[index + 1];
return this.#children[index + 1];
}

@@ -407,3 +377,3 @@ /**

}
return __classPrivateFieldGet(this, _ScopedSymbol_children, "f")[index - 1];
return this.#children[index - 1];
}

@@ -437,3 +407,2 @@ /**

exports.ScopedSymbol = ScopedSymbol;
_ScopedSymbol_children = new WeakMap(), _ScopedSymbol_names = new WeakMap();
//# sourceMappingURL=ScopedSymbol.js.map

@@ -8,11 +8,2 @@ "use strict";

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

@@ -25,7 +16,8 @@ exports.SymbolTable = void 0;

class SymbolTable extends ScopedSymbol_1.ScopedSymbol {
options;
/** Other symbol information available to this instance. */
dependencies = new Set();
constructor(name, options) {
super(name);
this.options = options;
/** Other symbol information available to this instance. */
this.dependencies = new Set();
}

@@ -62,17 +54,15 @@ get info() {

}
addNewNamespaceFromPath(parent, path, delimiter = ".") {
return __awaiter(this, void 0, void 0, function* () {
const parts = path.split(delimiter);
let i = 0;
let currentParent = (parent === undefined) ? this : parent;
while (i < parts.length - 1) {
let namespace = yield currentParent.resolve(parts[i], true);
if (namespace === undefined) {
namespace = this.addNewSymbolOfType(NamespaceSymbol_1.NamespaceSymbol, currentParent, parts[i]);
}
currentParent = namespace;
++i;
async addNewNamespaceFromPath(parent, path, delimiter = ".") {
const parts = path.split(delimiter);
let i = 0;
let currentParent = (parent === undefined) ? this : parent;
while (i < parts.length - 1) {
let namespace = await currentParent.resolve(parts[i], true);
if (namespace === undefined) {
namespace = this.addNewSymbolOfType(NamespaceSymbol_1.NamespaceSymbol, currentParent, parts[i]);
}
return this.addNewSymbolOfType(NamespaceSymbol_1.NamespaceSymbol, currentParent, parts[parts.length - 1]);
});
currentParent = namespace;
++i;
}
return this.addNewSymbolOfType(NamespaceSymbol_1.NamespaceSymbol, currentParent, parts[parts.length - 1]);
}

@@ -93,18 +83,13 @@ addNewNamespaceFromPathSync(parent, path, delimiter = ".") {

}
getAllSymbols(t, localOnly = false) {
const _super = Object.create(null, {
getAllSymbols: { get: () => super.getAllSymbols }
});
return __awaiter(this, void 0, void 0, function* () {
const result = yield _super.getAllSymbols.call(this, t, localOnly);
if (!localOnly) {
const dependencyResults = yield Promise.all([...this.dependencies].map((dependency) => {
return (dependency.getAllSymbols(t, localOnly));
}));
dependencyResults.forEach((value) => {
result.push(...value);
});
}
return result;
});
async getAllSymbols(t, localOnly = false) {
const result = await super.getAllSymbols(t, localOnly);
if (!localOnly) {
const dependencyResults = await Promise.all([...this.dependencies].map((dependency) => {
return (dependency.getAllSymbols(t, localOnly));
}));
dependencyResults.forEach((value) => {
result.push(...value);
});
}
return result;
}

@@ -120,26 +105,33 @@ getAllSymbolsSync(t, localOnly = false) {

}
symbolWithContext(context) {
return __awaiter(this, void 0, void 0, function* () {
/**
* Local function to find a symbol recursively.
*
* @param symbol The symbol to search through.
*
* @returns The symbol with the given context, if found.
*/
const findRecursive = (symbol) => {
if (symbol.context === context) {
return symbol;
}
if (symbol instanceof ScopedSymbol_1.ScopedSymbol) {
for (const child of symbol.children) {
const result = findRecursive(child);
if (result) {
return result;
}
async symbolWithContext(context) {
/**
* Local function to find a symbol recursively.
*
* @param symbol The symbol to search through.
*
* @returns The symbol with the given context, if found.
*/
const findRecursive = (symbol) => {
if (symbol.context === context) {
return symbol;
}
if (symbol instanceof ScopedSymbol_1.ScopedSymbol) {
for (const child of symbol.children) {
const result = findRecursive(child);
if (result) {
return result;
}
}
return undefined;
};
let symbols = yield this.getAllSymbols(BaseSymbol_1.BaseSymbol);
}
return undefined;
};
let symbols = await this.getAllSymbols(BaseSymbol_1.BaseSymbol);
for (const symbol of symbols) {
const result = findRecursive(symbol);
if (result) {
return result;
}
}
for (const dependency of this.dependencies) {
symbols = await dependency.getAllSymbols(BaseSymbol_1.BaseSymbol);
for (const symbol of symbols) {

@@ -151,13 +143,4 @@ const result = findRecursive(symbol);

}
for (const dependency of this.dependencies) {
symbols = yield dependency.getAllSymbols(BaseSymbol_1.BaseSymbol);
for (const symbol of symbols) {
const result = findRecursive(symbol);
if (result) {
return result;
}
}
}
return undefined;
});
}
return undefined;
}

@@ -204,18 +187,13 @@ symbolWithContextSync(context) {

}
resolve(name, localOnly = false) {
const _super = Object.create(null, {
resolve: { get: () => super.resolve }
});
return __awaiter(this, void 0, void 0, function* () {
let result = yield _super.resolve.call(this, name, localOnly);
if (!result && !localOnly) {
for (const dependency of this.dependencies) {
result = yield dependency.resolve(name, false);
if (result) {
return result;
}
async resolve(name, localOnly = false) {
let result = await super.resolve(name, localOnly);
if (!result && !localOnly) {
for (const dependency of this.dependencies) {
result = await dependency.resolve(name, false);
if (result) {
return result;
}
}
return result;
});
}
return result;
}

@@ -222,0 +200,0 @@ resolveSync(name, localOnly = false) {

@@ -14,2 +14,3 @@ "use strict";

class TypeAlias extends BaseSymbol_1.BaseSymbol {
targetType;
constructor(name, target) {

@@ -16,0 +17,0 @@ super(name);

@@ -13,2 +13,3 @@ "use strict";

class TypedSymbol extends BaseSymbol_1.BaseSymbol {
type;
constructor(name, type) {

@@ -15,0 +16,0 @@ super(name);

@@ -30,3 +30,3 @@ "use strict";

MemberVisibility[MemberVisibility["Library"] = 6] = "Library";
})(MemberVisibility = exports.MemberVisibility || (exports.MemberVisibility = {}));
})(MemberVisibility || (exports.MemberVisibility = MemberVisibility = {}));
/** The modifier of a symbol member. */

@@ -43,3 +43,3 @@ var Modifier;

Modifier[Modifier["Overwritten"] = 7] = "Overwritten";
})(Modifier = exports.Modifier || (exports.Modifier = {}));
})(Modifier || (exports.Modifier = Modifier = {}));
/** Rough categorization of a type. */

@@ -61,3 +61,3 @@ var TypeKind;

TypeKind[TypeKind["Alias"] = 12] = "Alias";
})(TypeKind = exports.TypeKind || (exports.TypeKind = {}));
})(TypeKind || (exports.TypeKind = TypeKind = {}));
/** Describes a reference to a type. */

@@ -73,3 +73,3 @@ var ReferenceKind;

ReferenceKind[ReferenceKind["Instance"] = 3] = "Instance";
})(ReferenceKind = exports.ReferenceKind || (exports.ReferenceKind = {}));
})(ReferenceKind || (exports.ReferenceKind = ReferenceKind = {}));
//# sourceMappingURL=types.js.map

@@ -12,2 +12,3 @@ "use strict";

class VariableSymbol extends TypedSymbol_1.TypedSymbol {
value;
constructor(name, value, type) {

@@ -14,0 +15,0 @@ super(name, type);

{
"name": "antlr4-c3",
"version": "3.0.1",
"version": "3.1.0",
"description": "A code completion core implementation for ANTLR4 based parsers",

@@ -18,3 +18,4 @@ "author": "Mike Lischke",

],
"main": "./lib/index",
"type": "commonjs",
"main": "./lib/index.js",
"scripts": {

@@ -33,17 +34,17 @@ "build": "tsc",

"devDependencies": {
"@types/jest": "29.4.0",
"@types/node": "18.15.0",
"@types/jest": "29.5.3",
"@types/node": "20.4.8",
"@types/unicode-properties": "1.3.0",
"@typescript-eslint/eslint-plugin": "5.54.1",
"@typescript-eslint/parser": "5.54.1",
"@typescript-eslint/eslint-plugin": "6.3.0",
"@typescript-eslint/parser": "6.3.0",
"antlr4ts-cli": "0.5.0-alpha.4",
"eslint": "8.36.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "40.0.1",
"eslint": "8.46.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-jsdoc": "46.4.6",
"eslint-plugin-prefer-arrow": "1.2.3",
"jest": "29.5.0",
"ts-jest": "29.0.5",
"jest": "29.6.2",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.0.2"
"typescript": "5.1.6"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc