Comparing version 2.2.1 to 2.2.2
@@ -59,2 +59,4 @@ ANTLR4-C3 Project Contributors Certification of Origin and Rights | ||
2020/08/06, tamcgoey, Thomas McGoey-Smith, thomas@sourdough.dev | ||
2020/11/24, alessiostalla, Alessio Stalla, alessiostalla@gmail.com | ||
2020/11/24, alessiostalla, Alessio Stalla, alessiostalla@gmail.com | ||
2022/11/08, XenoAmess, Jin Xu, xenoamess@gmail.com | ||
2023/03/04, br0nstein, Aaron Braunstein, aa(last name)@gmail.com |
"use strict"; | ||
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]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
import { Parser, ParserRuleContext } from "antlr4ts"; | ||
export declare type TokenList = number[]; | ||
export declare type RuleList = number[]; | ||
export type TokenList = number[]; | ||
export type RuleList = number[]; | ||
export interface CandidateRule { | ||
@@ -12,3 +12,3 @@ startTokenIndex: number; | ||
} | ||
export declare type RuleWithStartTokenList = RuleWithStartToken[]; | ||
export type RuleWithStartTokenList = RuleWithStartToken[]; | ||
export declare class CandidatesCollection { | ||
@@ -15,0 +15,0 @@ tokens: Map<number, TokenList>; |
@@ -166,21 +166,22 @@ "use strict"; | ||
determineFollowSets(start, stop) { | ||
const result = []; | ||
const sets = []; | ||
const stateStack = []; | ||
const ruleStack = []; | ||
this.collectFollowSets(start, stop, result, stateStack, ruleStack); | ||
return result; | ||
const isExhaustive = this.collectFollowSets(start, stop, sets, stateStack, ruleStack); | ||
const combined = new IntervalSet_1.IntervalSet(); | ||
for (const set of sets) { | ||
combined.addAll(set.intervals); | ||
} | ||
return { sets, isExhaustive, combined }; | ||
} | ||
collectFollowSets(s, stopState, followSets, stateStack, ruleStack) { | ||
if (stateStack.find((x) => x === s)) { | ||
return; | ||
return true; | ||
} | ||
stateStack.push(s); | ||
if (s === stopState || s.stateType === atn_1.ATNStateType.RULE_STOP) { | ||
const set = new FollowSetWithPath(); | ||
set.intervals = IntervalSet_1.IntervalSet.of(antlr4ts_1.Token.EPSILON); | ||
set.path = ruleStack.slice(); | ||
followSets.push(set); | ||
stateStack.pop(); | ||
return; | ||
return false; | ||
} | ||
let isExhaustive = true; | ||
for (const transition of s.getTransitions()) { | ||
@@ -193,12 +194,18 @@ if (transition.serializationType === 3) { | ||
ruleStack.push(ruleTransition.target.ruleIndex); | ||
this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
const ruleFollowSetsIsExhaustive = this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
ruleStack.pop(); | ||
if (!ruleFollowSetsIsExhaustive) { | ||
const nextStateFollowSetsIsExhaustive = this.collectFollowSets(ruleTransition.followState, stopState, followSets, stateStack, ruleStack); | ||
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive); | ||
} | ||
} | ||
else if (transition.serializationType === 4) { | ||
if (this.checkPredicate(transition)) { | ||
this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
const nextStateFollowSetsIsExhaustive = this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive); | ||
} | ||
} | ||
else if (transition.isEpsilon) { | ||
this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
const nextStateFollowSetsIsExhaustive = this.collectFollowSets(transition.target, stopState, followSets, stateStack, ruleStack); | ||
isExhaustive && (isExhaustive = nextStateFollowSetsIsExhaustive); | ||
} | ||
@@ -226,2 +233,3 @@ else if (transition.serializationType === 9) { | ||
stateStack.pop(); | ||
return isExhaustive; | ||
} | ||
@@ -250,11 +258,5 @@ processRule(startState, tokenListIndex, callStack, precedence, indentation) { | ||
if (!followSets) { | ||
followSets = new FollowSetsHolder(); | ||
const stop = this.atn.ruleToStopState[startState.ruleIndex]; | ||
followSets = this.determineFollowSets(startState, stop); | ||
setsPerState.set(startState.stateNumber, followSets); | ||
const stop = this.atn.ruleToStopState[startState.ruleIndex]; | ||
followSets.sets = this.determineFollowSets(startState, stop); | ||
const combined = new IntervalSet_1.IntervalSet(); | ||
for (const set of followSets.sets) { | ||
combined.addAll(set.intervals); | ||
} | ||
followSets.combined = combined; | ||
} | ||
@@ -297,2 +299,5 @@ const startTokenIndex = this.tokens[tokenListIndex].tokenIndex; | ||
} | ||
if (!followSets.isExhaustive) { | ||
result.add(tokenListIndex); | ||
} | ||
callStack.pop(); | ||
@@ -303,3 +308,3 @@ return result; | ||
const currentSymbol = this.tokens[tokenListIndex].type; | ||
if (!followSets.combined.contains(antlr4ts_1.Token.EPSILON) && !followSets.combined.contains(currentSymbol)) { | ||
if (followSets.isExhaustive && !followSets.combined.contains(currentSymbol)) { | ||
callStack.pop(); | ||
@@ -306,0 +311,0 @@ return result; |
@@ -24,11 +24,15 @@ import { ParseTree } from "antlr4ts/tree/ParseTree"; | ||
export declare enum TypeKind { | ||
Integer = 0, | ||
Float = 1, | ||
String = 2, | ||
Boolean = 3, | ||
Date = 4, | ||
Class = 5, | ||
Interface = 6, | ||
Array = 7, | ||
Alias = 8 | ||
Unknown = 0, | ||
Integer = 1, | ||
Float = 2, | ||
Number = 3, | ||
String = 4, | ||
Char = 5, | ||
Boolean = 6, | ||
Class = 7, | ||
Interface = 8, | ||
Array = 9, | ||
Map = 10, | ||
Enum = 11, | ||
Alias = 12 | ||
} | ||
@@ -55,7 +59,6 @@ export declare enum ReferenceKind { | ||
static readonly boolType: FundamentalType; | ||
static readonly dateType: FundamentalType; | ||
name: string; | ||
private typeKind; | ||
private referenceKind; | ||
constructor(name: string, typeKind: TypeKind, referenceKind: ReferenceKind); | ||
constructor(name: string, typeKind?: TypeKind, referenceKind?: ReferenceKind); | ||
get baseTypes(): Type[]; | ||
@@ -100,3 +103,3 @@ get kind(): TypeKind; | ||
export declare class ScopedSymbol extends Symbol { | ||
private _children; | ||
private childSymbols; | ||
constructor(name?: string); | ||
@@ -142,3 +145,3 @@ get directScopes(): Promise<ScopedSymbol[]>; | ||
export declare class RoutineSymbol extends ScopedSymbol { | ||
private returnType?; | ||
returnType?: Type; | ||
constructor(name: string, returnType: Type); | ||
@@ -145,0 +148,0 @@ getVariables(localOnly?: boolean): Promise<VariableSymbol[]>; |
@@ -39,11 +39,15 @@ "use strict"; | ||
(function (TypeKind) { | ||
TypeKind[TypeKind["Integer"] = 0] = "Integer"; | ||
TypeKind[TypeKind["Float"] = 1] = "Float"; | ||
TypeKind[TypeKind["String"] = 2] = "String"; | ||
TypeKind[TypeKind["Boolean"] = 3] = "Boolean"; | ||
TypeKind[TypeKind["Date"] = 4] = "Date"; | ||
TypeKind[TypeKind["Class"] = 5] = "Class"; | ||
TypeKind[TypeKind["Interface"] = 6] = "Interface"; | ||
TypeKind[TypeKind["Array"] = 7] = "Array"; | ||
TypeKind[TypeKind["Alias"] = 8] = "Alias"; | ||
TypeKind[TypeKind["Unknown"] = 0] = "Unknown"; | ||
TypeKind[TypeKind["Integer"] = 1] = "Integer"; | ||
TypeKind[TypeKind["Float"] = 2] = "Float"; | ||
TypeKind[TypeKind["Number"] = 3] = "Number"; | ||
TypeKind[TypeKind["String"] = 4] = "String"; | ||
TypeKind[TypeKind["Char"] = 5] = "Char"; | ||
TypeKind[TypeKind["Boolean"] = 6] = "Boolean"; | ||
TypeKind[TypeKind["Class"] = 7] = "Class"; | ||
TypeKind[TypeKind["Interface"] = 8] = "Interface"; | ||
TypeKind[TypeKind["Array"] = 9] = "Array"; | ||
TypeKind[TypeKind["Map"] = 10] = "Map"; | ||
TypeKind[TypeKind["Enum"] = 11] = "Enum"; | ||
TypeKind[TypeKind["Alias"] = 12] = "Alias"; | ||
})(TypeKind = exports.TypeKind || (exports.TypeKind = {})); | ||
@@ -58,3 +62,3 @@ var ReferenceKind; | ||
class FundamentalType { | ||
constructor(name, typeKind, referenceKind) { | ||
constructor(name, typeKind = TypeKind.Unknown, referenceKind = ReferenceKind.Irrelevant) { | ||
this.name = name; | ||
@@ -79,3 +83,2 @@ this.typeKind = typeKind; | ||
FundamentalType.boolType = new FundamentalType("bool", TypeKind.Boolean, ReferenceKind.Instance); | ||
FundamentalType.dateType = new FundamentalType("date", TypeKind.Date, ReferenceKind.Instance); | ||
class Symbol { | ||
@@ -220,5 +223,11 @@ constructor(name = "") { | ||
} | ||
get baseTypes() { return [this.targetType]; } | ||
get kind() { return TypeKind.Alias; } | ||
get reference() { return ReferenceKind.Irrelevant; } | ||
get baseTypes() { | ||
return [this.targetType]; | ||
} | ||
get kind() { | ||
return TypeKind.Alias; | ||
} | ||
get reference() { | ||
return ReferenceKind.Irrelevant; | ||
} | ||
} | ||
@@ -229,3 +238,3 @@ exports.TypeAlias = TypeAlias; | ||
super(name); | ||
this._children = []; | ||
this.childSymbols = []; | ||
} | ||
@@ -236,3 +245,3 @@ get directScopes() { | ||
get children() { | ||
return this._children; | ||
return this.childSymbols; | ||
} | ||
@@ -252,3 +261,3 @@ get firstChild() { | ||
clear() { | ||
this._children = []; | ||
this.childSymbols = []; | ||
} | ||
@@ -480,3 +489,3 @@ addSymbol(symbol) { | ||
if (index === -1 || index >= this.children.length - 1) { | ||
return; | ||
return undefined; | ||
} | ||
@@ -488,3 +497,3 @@ return this.children[index + 1]; | ||
if (index < 1) { | ||
return; | ||
return undefined; | ||
} | ||
@@ -495,3 +504,3 @@ return this.children[index - 1]; | ||
if (!(child.parent instanceof ScopedSymbol)) { | ||
return; | ||
return undefined; | ||
} | ||
@@ -717,2 +726,3 @@ if (child.parent !== this) { | ||
} | ||
return undefined; | ||
}; | ||
@@ -731,6 +741,7 @@ let symbols = yield this.getAllSymbols(Symbol); | ||
if (result) { | ||
result; | ||
return result; | ||
} | ||
} | ||
} | ||
return undefined; | ||
}); | ||
@@ -751,2 +762,3 @@ } | ||
} | ||
return undefined; | ||
}; | ||
@@ -765,6 +777,7 @@ let symbols = this.getAllSymbolsSync(Symbol); | ||
if (result) { | ||
result; | ||
return result; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
@@ -771,0 +784,0 @@ resolve(name, localOnly = false) { |
{ | ||
"name": "antlr4-c3", | ||
"version": "2.2.1", | ||
"description": "A code completion core implementation for ANTLR4 based parsers", | ||
"main": "out/index.js", | ||
"typings": "out/index.d.ts", | ||
"scripts": { | ||
"prepublishOnly": "npm run test", | ||
"test": "tsc --version && npm run generate && tsc && npm run eslint && mocha out/test", | ||
"generate": "antlr4ts test/CPP14.g4 test/Expr.g4 -no-listener -no-visitor -o test/generated -Xexact-output-dir", | ||
"eslint": "eslint ." | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mike-lischke/antlr4-c3" | ||
}, | ||
"keywords": [ | ||
"ANTLR4", | ||
"code completion", | ||
"auto completion", | ||
"grammar", | ||
"parser" | ||
], | ||
"dependencies": { | ||
"antlr4ts": "^0.5.0-alpha.4" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.3.0", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^17.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.8.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^5.8.0", | ||
"@typescript-eslint/parser": "^5.8.0", | ||
"antlr4ts-cli": "^0.5.0-alpha.4", | ||
"chai": "^4.3.4", | ||
"eslint": "^8.5.0", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-jsdoc": "^37.4.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"mocha": "^9.1.3", | ||
"path": "^0.12.7", | ||
"tslint": "^6.1.3", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
}, | ||
"author": "Mike Lischke", | ||
"license": "MIT" | ||
"name": "antlr4-c3", | ||
"version": "2.2.2", | ||
"description": "A code completion core implementation for ANTLR4 based parsers", | ||
"author": "Mike Lischke", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mike-lischke/antlr4-c3" | ||
}, | ||
"keywords": [ | ||
"ANTLR4", | ||
"code completion", | ||
"auto completion", | ||
"grammar", | ||
"parser" | ||
], | ||
"scripts": { | ||
"prepublishOnly": "npm run test", | ||
"test": "tsc --version && npm run generate && tsc && npm run eslint && mocha out/test", | ||
"generate": "antlr4ts test/CPP14.g4 test/Expr.g4 test/Whitebox.g4 -no-listener -no-visitor -o test/generated -Xexact-output-dir", | ||
"eslint": "eslint ." | ||
}, | ||
"dependencies": { | ||
"antlr4ts": "0.5.0-alpha.4" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "4.3.4", | ||
"@types/mocha": "10.0.1", | ||
"@types/node": "18.14.0", | ||
"@typescript-eslint/eslint-plugin": "5.53.0", | ||
"@typescript-eslint/parser": "5.53.0", | ||
"antlr4ts-cli": "0.5.0-alpha.4", | ||
"chai": "4.3.7", | ||
"eslint": "8.34.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-jsdoc": "40.0.0", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-prefer-arrow": "1.2.3", | ||
"eslint-plugin-promise": "6.1.1", | ||
"mocha": "10.2.0", | ||
"tslint": "6.1.3", | ||
"ts-node": "10.9.1", | ||
"typescript": "4.9.5" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
![](https://img.shields.io/github/license/mike-lischke/antlr4-c3?style=for-the-badge) | ||
![](https://img.shields.io/npm/dw/antlr4-c3?style=for-the-badge) | ||
[![Build & Test](https://github.com/mike-lischke/antlr4-c3/actions/workflows/nodejs.yml/badge.svg?branch=master)](https://github.com/mike-lischke/antlr4-c3/actions/workflows/nodejs.yml)[![Downloads](https://img.shields.io/npm/dw/antlr4-c3?color=blue)](https://www.npmjs.com/package/antlr4-c3) | ||
# antlr4-c3 The ANTLR4 Code Completion Core | ||
@@ -8,3 +8,3 @@ | ||
The original implementation is provided as a node module, and is written in TypeScript. A port to Java is available under `ports/java`. Implementations under the `ports` folder might not be up to date compared to the Typescript version. | ||
The original implementation is provided as a node module (works in both, Node.js and browsers), and is written in TypeScript. A port to Java is available under `ports/java`. Implementations under the `ports` folder might not be up to date compared to the Typescript version. | ||
@@ -218,2 +218,7 @@ # Abstract | ||
### 2.2.2 | ||
- Some improvements in the symbol table implementation. | ||
- Updated dependencies. | ||
- PR #76 (fixes bug #23) Account for empty and fully-optional-body rules when collecting tokens, thanks to Aaron Braunstein. | ||
### 2.2.1 | ||
@@ -220,0 +225,0 @@ Reverted changes from `any` to `unknown` for `SymbolTable.addNewSymbolOfType`. It works in the tests, but is not accepted by consumers of the node module. |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223404
17
1584
277
+ Addedantlr4ts@0.5.0-alpha.4(transitive)
- Removedantlr4ts@0.5.0-dev(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsource-map-support@0.5.21(transitive)
Updatedantlr4ts@0.5.0-alpha.4