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,33 @@
/*!
* 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 { LexerActionExecutor } from "../atn/LexerActionExecutor";
/**
* Stores information about a {@link DFAState} which is an accept state under
* some condition. Certain settings, such as
* {@link ParserATNSimulator#getPredictionMode()}, may be used in addition to
* this information to determine whether or not a particular state is an accept
* state.
*
* @author Sam Harwell
*/
export declare class AcceptStateInfo {
private readonly _prediction;
private readonly _lexerActionExecutor?;
constructor(prediction: number);
constructor(prediction: number, lexerActionExecutor: LexerActionExecutor | undefined);
/**
* Gets the prediction made by this accept state. Note that this value
* assumes the predicates, if any, in the {@link DFAState} evaluate to
* `true`. If predicate evaluation is enabled, the final prediction of
* the accept state will be determined by the result of predicate
* evaluation.
*/
get prediction(): number;
/**
* Gets the {@link LexerActionExecutor} which can be used to execute actions
* and/or commands after the lexer matches a token.
*/
get lexerActionExecutor(): LexerActionExecutor | undefined;
}

View File

@@ -0,0 +1,41 @@
"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.AcceptStateInfo = void 0;
/**
* Stores information about a {@link DFAState} which is an accept state under
* some condition. Certain settings, such as
* {@link ParserATNSimulator#getPredictionMode()}, may be used in addition to
* this information to determine whether or not a particular state is an accept
* state.
*
* @author Sam Harwell
*/
class AcceptStateInfo {
constructor(prediction, lexerActionExecutor) {
this._prediction = prediction;
this._lexerActionExecutor = lexerActionExecutor;
}
/**
* Gets the prediction made by this accept state. Note that this value
* assumes the predicates, if any, in the {@link DFAState} evaluate to
* `true`. If predicate evaluation is enabled, the final prediction of
* the accept state will be determined by the result of predicate
* evaluation.
*/
get prediction() {
return this._prediction;
}
/**
* Gets the {@link LexerActionExecutor} which can be used to execute actions
* and/or commands after the lexer matches a token.
*/
get lexerActionExecutor() {
return this._lexerActionExecutor;
}
}
exports.AcceptStateInfo = AcceptStateInfo;
//# sourceMappingURL=AcceptStateInfo.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AcceptStateInfo.js","sourceRoot":"","sources":["../../../src/dfa/AcceptStateInfo.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH;;;;;;;;GAQG;AACH,MAAa,eAAe;IAM3B,YAAY,UAAkB,EAAE,mBAAyC;QACxE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACH,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,IAAI,mBAAmB;QACtB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IAClC,CAAC;CACD;AA7BD,0CA6BC","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:38.1172076-07:00\r\n\r\nimport { LexerActionExecutor } from \"../atn/LexerActionExecutor\";\r\n\r\n/**\r\n * Stores information about a {@link DFAState} which is an accept state under\r\n * some condition. Certain settings, such as\r\n * {@link ParserATNSimulator#getPredictionMode()}, may be used in addition to\r\n * this information to determine whether or not a particular state is an accept\r\n * state.\r\n *\r\n * @author Sam Harwell\r\n */\r\nexport class AcceptStateInfo {\r\n\tprivate readonly _prediction: number;\r\n\tprivate readonly _lexerActionExecutor?: LexerActionExecutor;\r\n\r\n\tconstructor(prediction: number);\r\n\tconstructor(prediction: number, lexerActionExecutor: LexerActionExecutor | undefined);\r\n\tconstructor(prediction: number, lexerActionExecutor?: LexerActionExecutor) {\r\n\t\tthis._prediction = prediction;\r\n\t\tthis._lexerActionExecutor = lexerActionExecutor;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the prediction made by this accept state. Note that this value\r\n\t * assumes the predicates, if any, in the {@link DFAState} evaluate to\r\n\t * `true`. If predicate evaluation is enabled, the final prediction of\r\n\t * the accept state will be determined by the result of predicate\r\n\t * evaluation.\r\n\t */\r\n\tget prediction(): number {\r\n\t\treturn this._prediction;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the {@link LexerActionExecutor} which can be used to execute actions\r\n\t * and/or commands after the lexer matches a token.\r\n\t */\r\n\tget lexerActionExecutor(): LexerActionExecutor | undefined {\r\n\t\treturn this._lexerActionExecutor;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,94 @@
/*!
* 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 { Array2DHashSet } from "../misc/Array2DHashSet";
import { ATN } from "../atn/ATN";
import { ATNState } from "../atn/ATNState";
import { DecisionState } from "../atn/DecisionState";
import { DFAState } from "./DFAState";
import { TokensStartState } from "../atn/TokensStartState";
import { Vocabulary } from "../Vocabulary";
export declare class DFA {
/**
* A set of all states in the `DFA`.
*
* Note that this collection of states holds the DFA states for both SLL and LL prediction. Only the start state
* needs to be differentiated for these cases, which is tracked by the `s0` and `s0full` fields.
*/
readonly states: Array2DHashSet<DFAState>;
s0: DFAState | undefined;
s0full: DFAState | undefined;
readonly decision: number;
/** From which ATN state did we create this DFA? */
atnStartState: ATNState;
/**
* Note: this field is accessed as `atnStartState.atn` in other targets. The TypeScript target keeps a separate copy
* to avoid a number of additional null/undefined checks each time the ATN is accessed.
*/
atn: ATN;
private nextStateNumber;
/**
* `true` if this DFA is for a precedence decision; otherwise,
* `false`. This is the backing field for {@link #isPrecedenceDfa}.
*/
private precedenceDfa;
/**
* Constructs a `DFA` instance associated with a lexer mode.
*
* The start state for a `DFA` constructed with this constructor should be a `TokensStartState`, which is the start
* state for a lexer mode. The prediction made by this DFA determines the lexer rule which matches the current
* input.
*
* @param atnStartState The start state for the mode.
*/
constructor(atnStartState: TokensStartState);
/**
* Constructs a `DFA` instance associated with a decision.
*
* @param atnStartState The decision associated with this DFA.
* @param decision The decision number.
*/
constructor(atnStartState: DecisionState, decision: number);
/**
* Gets whether this DFA is a precedence DFA. Precedence DFAs use a special
* start state {@link #s0} which is not stored in {@link #states}. The
* {@link DFAState#edges} array for this start state contains outgoing edges
* supplying individual start states corresponding to specific precedence
* values.
*
* @returns `true` if this is a precedence DFA; otherwise,
* `false`.
* @see Parser.precedence
*/
get isPrecedenceDfa(): boolean;
/**
* Get the start state for a specific precedence value.
*
* @param precedence The current precedence.
* @returns The start state corresponding to the specified precedence, or
* `undefined` if no start state exists for the specified precedence.
*
* @ if this is not a precedence DFA.
* @see `isPrecedenceDfa`
*/
getPrecedenceStartState(precedence: number, fullContext: boolean): DFAState | undefined;
/**
* Set the start state for a specific precedence value.
*
* @param precedence The current precedence.
* @param startState The start state corresponding to the specified
* precedence.
*
* @ if this is not a precedence DFA.
* @see `isPrecedenceDfa`
*/
setPrecedenceStartState(precedence: number, fullContext: boolean, startState: DFAState): void;
get isEmpty(): boolean;
get isContextSensitive(): boolean;
addState(state: DFAState): DFAState;
toString(): string;
toString(/*@NotNull*/ vocabulary: Vocabulary): string;
toString(/*@NotNull*/ vocabulary: Vocabulary, ruleNames: string[] | undefined): string;
toLexerString(): string;
}

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.
*/
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.DFA = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:38.3567094-07:00
const Array2DHashSet_1 = require("../misc/Array2DHashSet");
const ATNConfigSet_1 = require("../atn/ATNConfigSet");
const DFASerializer_1 = require("./DFASerializer");
const DFAState_1 = require("./DFAState");
const LexerDFASerializer_1 = require("./LexerDFASerializer");
const Decorators_1 = require("../Decorators");
const ObjectEqualityComparator_1 = require("../misc/ObjectEqualityComparator");
const StarLoopEntryState_1 = require("../atn/StarLoopEntryState");
const VocabularyImpl_1 = require("../VocabularyImpl");
let DFA = class DFA {
constructor(atnStartState, decision = 0) {
/**
* A set of all states in the `DFA`.
*
* Note that this collection of states holds the DFA states for both SLL and LL prediction. Only the start state
* needs to be differentiated for these cases, which is tracked by the `s0` and `s0full` fields.
*/
this.states = new Array2DHashSet_1.Array2DHashSet(ObjectEqualityComparator_1.ObjectEqualityComparator.INSTANCE);
this.nextStateNumber = 0;
if (!atnStartState.atn) {
throw new Error("The ATNState must be associated with an ATN");
}
this.atnStartState = atnStartState;
this.atn = atnStartState.atn;
this.decision = decision;
// Precedence DFAs are associated with the special precedence decision created for left-recursive rules which
// evaluate their alternatives using a precedence hierarchy. When such a decision is encountered, we mark this
// DFA instance as a precedence DFA and initialize the initial states s0 and s0full to special DFAState
// instances which use outgoing edges to link to the actual start state used for each precedence level.
let isPrecedenceDfa = false;
if (atnStartState instanceof StarLoopEntryState_1.StarLoopEntryState) {
if (atnStartState.precedenceRuleDecision) {
isPrecedenceDfa = true;
this.s0 = new DFAState_1.DFAState(new ATNConfigSet_1.ATNConfigSet());
this.s0full = new DFAState_1.DFAState(new ATNConfigSet_1.ATNConfigSet());
}
}
this.precedenceDfa = isPrecedenceDfa;
}
/**
* Gets whether this DFA is a precedence DFA. Precedence DFAs use a special
* start state {@link #s0} which is not stored in {@link #states}. The
* {@link DFAState#edges} array for this start state contains outgoing edges
* supplying individual start states corresponding to specific precedence
* values.
*
* @returns `true` if this is a precedence DFA; otherwise,
* `false`.
* @see Parser.precedence
*/
get isPrecedenceDfa() {
return this.precedenceDfa;
}
/**
* Get the start state for a specific precedence value.
*
* @param precedence The current precedence.
* @returns The start state corresponding to the specified precedence, or
* `undefined` if no start state exists for the specified precedence.
*
* @ if this is not a precedence DFA.
* @see `isPrecedenceDfa`
*/
getPrecedenceStartState(precedence, fullContext) {
if (!this.isPrecedenceDfa) {
throw new Error("Only precedence DFAs may contain a precedence start state.");
}
// s0 and s0full are never null for a precedence DFA
if (fullContext) {
return this.s0full.getTarget(precedence);
}
else {
return this.s0.getTarget(precedence);
}
}
/**
* Set the start state for a specific precedence value.
*
* @param precedence The current precedence.
* @param startState The start state corresponding to the specified
* precedence.
*
* @ if this is not a precedence DFA.
* @see `isPrecedenceDfa`
*/
setPrecedenceStartState(precedence, fullContext, startState) {
if (!this.isPrecedenceDfa) {
throw new Error("Only precedence DFAs may contain a precedence start state.");
}
if (precedence < 0) {
return;
}
if (fullContext) {
// s0full is never null for a precedence DFA
this.s0full.setTarget(precedence, startState);
}
else {
// s0 is never null for a precedence DFA
this.s0.setTarget(precedence, startState);
}
}
get isEmpty() {
if (this.isPrecedenceDfa) {
// s0 and s0full are never null for a precedence DFA
return this.s0.getEdgeMap().size === 0 && this.s0full.getEdgeMap().size === 0;
}
return this.s0 == null && this.s0full == null;
}
get isContextSensitive() {
if (this.isPrecedenceDfa) {
// s0full is never null for a precedence DFA
return this.s0full.getEdgeMap().size > 0;
}
return this.s0full != null;
}
addState(state) {
state.stateNumber = this.nextStateNumber++;
return this.states.getOrAdd(state);
}
toString(vocabulary, ruleNames) {
if (!vocabulary) {
vocabulary = VocabularyImpl_1.VocabularyImpl.EMPTY_VOCABULARY;
}
if (!this.s0) {
return "";
}
let serializer;
if (ruleNames) {
serializer = new DFASerializer_1.DFASerializer(this, vocabulary, ruleNames, this.atnStartState.atn);
}
else {
serializer = new DFASerializer_1.DFASerializer(this, vocabulary);
}
return serializer.toString();
}
toLexerString() {
if (!this.s0) {
return "";
}
let serializer = new LexerDFASerializer_1.LexerDFASerializer(this);
return serializer.toString();
}
};
__decorate([
Decorators_1.NotNull
], DFA.prototype, "states", void 0);
__decorate([
Decorators_1.NotNull
], DFA.prototype, "atnStartState", void 0);
__decorate([
Decorators_1.NotNull
], DFA.prototype, "atn", void 0);
DFA = __decorate([
__param(0, Decorators_1.NotNull)
], DFA);
exports.DFA = DFA;
//# sourceMappingURL=DFA.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
/*!
* 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 { DFA } from "./DFA";
import { DFAState } from "./DFAState";
import { Recognizer } from "../Recognizer";
import { Vocabulary } from "../Vocabulary";
/** A DFA walker that knows how to dump them to serialized strings. */
export declare class DFASerializer {
private dfa;
private vocabulary;
ruleNames?: string[];
atn?: ATN;
constructor(/*@NotNull*/ dfa: DFA, /*@NotNull*/ vocabulary: Vocabulary);
constructor(/*@NotNull*/ dfa: DFA, /*@Nullable*/ parser: Recognizer<any, any> | undefined);
constructor(/*@NotNull*/ dfa: DFA, /*@NotNull*/ vocabulary: Vocabulary, /*@Nullable*/ ruleNames: string[] | undefined, /*@Nullable*/ atn: ATN | undefined);
toString(): string;
protected getContextLabel(i: number): string;
protected getEdgeLabel(i: number): string;
getStateString(s: DFAState): string;
}

View File

@@ -0,0 +1,141 @@
"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.DFASerializer = void 0;
const ATNSimulator_1 = require("../atn/ATNSimulator");
const Decorators_1 = require("../Decorators");
const PredictionContext_1 = require("../atn/PredictionContext");
const Recognizer_1 = require("../Recognizer");
const VocabularyImpl_1 = require("../VocabularyImpl");
/** A DFA walker that knows how to dump them to serialized strings. */
class DFASerializer {
constructor(dfa, vocabulary, ruleNames, atn) {
if (vocabulary instanceof Recognizer_1.Recognizer) {
ruleNames = vocabulary.ruleNames;
atn = vocabulary.atn;
vocabulary = vocabulary.vocabulary;
}
else if (!vocabulary) {
vocabulary = VocabularyImpl_1.VocabularyImpl.EMPTY_VOCABULARY;
}
this.dfa = dfa;
this.vocabulary = vocabulary;
this.ruleNames = ruleNames;
this.atn = atn;
}
toString() {
if (!this.dfa.s0) {
return "";
}
let buf = "";
if (this.dfa.states) {
let states = new Array(...this.dfa.states.toArray());
states.sort((o1, o2) => o1.stateNumber - o2.stateNumber);
for (let s of states) {
let edges = s.getEdgeMap();
let edgeKeys = [...edges.keys()].sort((a, b) => a - b);
let contextEdges = s.getContextEdgeMap();
let contextEdgeKeys = [...contextEdges.keys()].sort((a, b) => a - b);
for (let entry of edgeKeys) {
let value = edges.get(entry);
if ((value == null || value === ATNSimulator_1.ATNSimulator.ERROR) && !s.isContextSymbol(entry)) {
continue;
}
let contextSymbol = false;
buf += (this.getStateString(s)) + ("-") + (this.getEdgeLabel(entry)) + ("->");
if (s.isContextSymbol(entry)) {
buf += ("!");
contextSymbol = true;
}
let t = value;
if (t && t.stateNumber !== ATNSimulator_1.ATNSimulator.ERROR.stateNumber) {
buf += (this.getStateString(t)) + ("\n");
}
else if (contextSymbol) {
buf += ("ctx\n");
}
}
if (s.isContextSensitive) {
for (let entry of contextEdgeKeys) {
buf += (this.getStateString(s))
+ ("-")
+ (this.getContextLabel(entry))
+ ("->")
+ (this.getStateString(contextEdges.get(entry)))
+ ("\n");
}
}
}
}
let output = buf;
if (output.length === 0) {
return "";
}
//return Utils.sortLinesInString(output);
return output;
}
getContextLabel(i) {
if (i === PredictionContext_1.PredictionContext.EMPTY_FULL_STATE_KEY) {
return "ctx:EMPTY_FULL";
}
else if (i === PredictionContext_1.PredictionContext.EMPTY_LOCAL_STATE_KEY) {
return "ctx:EMPTY_LOCAL";
}
if (this.atn && i > 0 && i <= this.atn.states.length) {
let state = this.atn.states[i];
let ruleIndex = state.ruleIndex;
if (this.ruleNames && ruleIndex >= 0 && ruleIndex < this.ruleNames.length) {
return "ctx:" + String(i) + "(" + this.ruleNames[ruleIndex] + ")";
}
}
return "ctx:" + String(i);
}
getEdgeLabel(i) {
return this.vocabulary.getDisplayName(i);
}
getStateString(s) {
if (s === ATNSimulator_1.ATNSimulator.ERROR) {
return "ERROR";
}
let n = s.stateNumber;
let stateStr = "s" + n;
if (s.isAcceptState) {
if (s.predicates) {
stateStr = ":s" + n + "=>" + s.predicates;
}
else {
stateStr = ":s" + n + "=>" + s.prediction;
}
}
if (s.isContextSensitive) {
stateStr += "*";
for (let config of s.configs) {
if (config.reachesIntoOuterContext) {
stateStr += "*";
break;
}
}
}
return stateStr;
}
}
__decorate([
Decorators_1.NotNull
], DFASerializer.prototype, "dfa", void 0);
__decorate([
Decorators_1.NotNull
], DFASerializer.prototype, "vocabulary", void 0);
__decorate([
Decorators_1.Override
], DFASerializer.prototype, "toString", null);
exports.DFASerializer = DFASerializer;
//# sourceMappingURL=DFASerializer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,95 @@
/*!
* 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 { AcceptStateInfo } from "./AcceptStateInfo";
import { ATN } from "../atn/ATN";
import { ATNConfigSet } from "../atn/ATNConfigSet";
import { LexerActionExecutor } from "../atn/LexerActionExecutor";
import { SemanticContext } from "../atn/SemanticContext";
/** A DFA state represents a set of possible ATN configurations.
* As Aho, Sethi, Ullman p. 117 says "The DFA uses its state
* to keep track of all possible states the ATN can be in after
* reading each input symbol. That is to say, after reading
* input a1a2..an, the DFA is in a state that represents the
* subset T of the states of the ATN that are reachable from the
* ATN's start state along some path labeled a1a2..an."
* In conventional NFA&rarr;DFA conversion, therefore, the subset T
* would be a bitset representing the set of states the
* ATN could be in. We need to track the alt predicted by each
* state as well, however. More importantly, we need to maintain
* a stack of states, tracking the closure operations as they
* jump from rule to rule, emulating rule invocations (method calls).
* I have to add a stack to simulate the proper lookahead sequences for
* the underlying LL grammar from which the ATN was derived.
*
* I use a set of ATNConfig objects not simple states. An ATNConfig
* is both a state (ala normal conversion) and a RuleContext describing
* the chain of rules (if any) followed to arrive at that state.
*
* A DFA state may have multiple references to a particular state,
* but with different ATN contexts (with same or different alts)
* meaning that state was reached via a different set of rule invocations.
*/
export declare class DFAState {
stateNumber: number;
configs: ATNConfigSet;
/** `edges.get(symbol)` points to target of symbol.
*/
private readonly edges;
private _acceptStateInfo;
/** These keys for these edges are the top level element of the global context. */
private readonly contextEdges;
/** Symbols in this set require a global context transition before matching an input symbol. */
private contextSymbols;
/**
* This list is computed by {@link ParserATNSimulator#predicateDFAState}.
*/
predicates: DFAState.PredPrediction[] | undefined;
/**
* Constructs a new `DFAState`.
*
* @param configs The set of ATN configurations defining this state.
*/
constructor(configs: ATNConfigSet);
get isContextSensitive(): boolean;
isContextSymbol(symbol: number): boolean;
setContextSymbol(symbol: number): void;
setContextSensitive(atn: ATN): void;
get acceptStateInfo(): AcceptStateInfo | undefined;
set acceptStateInfo(acceptStateInfo: AcceptStateInfo | undefined);
get isAcceptState(): boolean;
get prediction(): number;
get lexerActionExecutor(): LexerActionExecutor | undefined;
getTarget(symbol: number): DFAState | undefined;
setTarget(symbol: number, target: DFAState): void;
getEdgeMap(): Map<number, DFAState>;
getContextTarget(invokingState: number): DFAState | undefined;
setContextTarget(invokingState: number, target: DFAState): void;
getContextEdgeMap(): Map<number, DFAState>;
hashCode(): number;
/**
* Two {@link DFAState} instances are equal if their ATN configuration sets
* are the same. This method is used to see if a state already exists.
*
* Because the number of alternatives and number of ATN configurations are
* finite, there is a finite number of DFA states that can be processed.
* This is necessary to show that the algorithm terminates.
*
* Cannot test the DFA state numbers here because in
* {@link ParserATNSimulator#addDFAState} we need to know if any other state
* exists that has this exact set of ATN configurations. The
* {@link #stateNumber} is irrelevant.
*/
equals(o: any): boolean;
toString(): string;
}
export declare namespace DFAState {
/** Map a predicate to a predicted alternative. */
class PredPrediction {
pred: SemanticContext;
alt: number;
constructor(pred: SemanticContext, alt: number);
toString(): string;
}
}

View File

@@ -0,0 +1,230 @@
"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.DFAState = void 0;
const ATN_1 = require("../atn/ATN");
const BitSet_1 = require("../misc/BitSet");
const MurmurHash_1 = require("../misc/MurmurHash");
const Decorators_1 = require("../Decorators");
const PredictionContext_1 = require("../atn/PredictionContext");
const assert = require("assert");
/** A DFA state represents a set of possible ATN configurations.
* As Aho, Sethi, Ullman p. 117 says "The DFA uses its state
* to keep track of all possible states the ATN can be in after
* reading each input symbol. That is to say, after reading
* input a1a2..an, the DFA is in a state that represents the
* subset T of the states of the ATN that are reachable from the
* ATN's start state along some path labeled a1a2..an."
* In conventional NFA&rarr;DFA conversion, therefore, the subset T
* would be a bitset representing the set of states the
* ATN could be in. We need to track the alt predicted by each
* state as well, however. More importantly, we need to maintain
* a stack of states, tracking the closure operations as they
* jump from rule to rule, emulating rule invocations (method calls).
* I have to add a stack to simulate the proper lookahead sequences for
* the underlying LL grammar from which the ATN was derived.
*
* I use a set of ATNConfig objects not simple states. An ATNConfig
* is both a state (ala normal conversion) and a RuleContext describing
* the chain of rules (if any) followed to arrive at that state.
*
* A DFA state may have multiple references to a particular state,
* but with different ATN contexts (with same or different alts)
* meaning that state was reached via a different set of rule invocations.
*/
class DFAState {
/**
* Constructs a new `DFAState`.
*
* @param configs The set of ATN configurations defining this state.
*/
constructor(configs) {
this.stateNumber = -1;
this.configs = configs;
this.edges = new Map();
this.contextEdges = new Map();
}
get isContextSensitive() {
return !!this.contextSymbols;
}
isContextSymbol(symbol) {
if (!this.isContextSensitive) {
return false;
}
return this.contextSymbols.get(symbol);
}
setContextSymbol(symbol) {
assert(this.isContextSensitive);
this.contextSymbols.set(symbol);
}
setContextSensitive(atn) {
assert(!this.configs.isOutermostConfigSet);
if (this.isContextSensitive) {
return;
}
if (!this.contextSymbols) {
this.contextSymbols = new BitSet_1.BitSet();
}
}
get acceptStateInfo() {
return this._acceptStateInfo;
}
set acceptStateInfo(acceptStateInfo) {
this._acceptStateInfo = acceptStateInfo;
}
get isAcceptState() {
return !!this._acceptStateInfo;
}
get prediction() {
if (!this._acceptStateInfo) {
return ATN_1.ATN.INVALID_ALT_NUMBER;
}
return this._acceptStateInfo.prediction;
}
get lexerActionExecutor() {
if (!this._acceptStateInfo) {
return undefined;
}
return this._acceptStateInfo.lexerActionExecutor;
}
getTarget(symbol) {
return this.edges.get(symbol);
}
setTarget(symbol, target) {
this.edges.set(symbol, target);
}
getEdgeMap() {
return this.edges;
}
getContextTarget(invokingState) {
if (invokingState === PredictionContext_1.PredictionContext.EMPTY_FULL_STATE_KEY) {
invokingState = -1;
}
return this.contextEdges.get(invokingState);
}
setContextTarget(invokingState, target) {
if (!this.isContextSensitive) {
throw new Error("The state is not context sensitive.");
}
if (invokingState === PredictionContext_1.PredictionContext.EMPTY_FULL_STATE_KEY) {
invokingState = -1;
}
this.contextEdges.set(invokingState, target);
}
getContextEdgeMap() {
let map = new Map(this.contextEdges);
let existing = map.get(-1);
if (existing !== undefined) {
if (map.size === 1) {
let result = new Map();
result.set(PredictionContext_1.PredictionContext.EMPTY_FULL_STATE_KEY, existing);
return result;
}
else {
map.delete(-1);
map.set(PredictionContext_1.PredictionContext.EMPTY_FULL_STATE_KEY, existing);
}
}
return map;
}
hashCode() {
let hash = MurmurHash_1.MurmurHash.initialize(7);
hash = MurmurHash_1.MurmurHash.update(hash, this.configs.hashCode());
hash = MurmurHash_1.MurmurHash.finish(hash, 1);
return hash;
}
/**
* Two {@link DFAState} instances are equal if their ATN configuration sets
* are the same. This method is used to see if a state already exists.
*
* Because the number of alternatives and number of ATN configurations are
* finite, there is a finite number of DFA states that can be processed.
* This is necessary to show that the algorithm terminates.
*
* Cannot test the DFA state numbers here because in
* {@link ParserATNSimulator#addDFAState} we need to know if any other state
* exists that has this exact set of ATN configurations. The
* {@link #stateNumber} is irrelevant.
*/
equals(o) {
// compare set of ATN configurations in this set with other
if (this === o) {
return true;
}
if (!(o instanceof DFAState)) {
return false;
}
let other = o;
let sameSet = this.configs.equals(other.configs);
// System.out.println("DFAState.equals: "+configs+(sameSet?"==":"!=")+other.configs);
return sameSet;
}
toString() {
let buf = "";
buf += (this.stateNumber) + (":") + (this.configs);
if (this.isAcceptState) {
buf += ("=>");
if (this.predicates) {
buf += this.predicates;
}
else {
buf += (this.prediction);
}
}
return buf.toString();
}
}
__decorate([
Decorators_1.NotNull
], DFAState.prototype, "configs", void 0);
__decorate([
Decorators_1.NotNull
], DFAState.prototype, "edges", void 0);
__decorate([
Decorators_1.NotNull
], DFAState.prototype, "contextEdges", void 0);
__decorate([
Decorators_1.Override
], DFAState.prototype, "hashCode", null);
__decorate([
Decorators_1.Override
], DFAState.prototype, "equals", null);
__decorate([
Decorators_1.Override
], DFAState.prototype, "toString", null);
exports.DFAState = DFAState;
(function (DFAState) {
/** Map a predicate to a predicted alternative. */
let PredPrediction = class PredPrediction {
constructor(pred, alt) {
this.alt = alt;
this.pred = pred;
}
toString() {
return "(" + this.pred + ", " + this.alt + ")";
}
};
__decorate([
Decorators_1.NotNull
], PredPrediction.prototype, "pred", void 0);
__decorate([
Decorators_1.Override
], PredPrediction.prototype, "toString", null);
PredPrediction = __decorate([
__param(0, Decorators_1.NotNull)
], PredPrediction);
DFAState.PredPrediction = PredPrediction;
})(DFAState = exports.DFAState || (exports.DFAState = {}));
//# sourceMappingURL=DFAState.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
/*!
* 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 { DFA } from "./DFA";
import { DFASerializer } from "./DFASerializer";
export declare class LexerDFASerializer extends DFASerializer {
constructor(dfa: DFA);
protected getEdgeLabel(i: number): string;
}

View File

@@ -0,0 +1,36 @@
"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.LexerDFASerializer = void 0;
const DFASerializer_1 = require("./DFASerializer");
const Decorators_1 = require("../Decorators");
const VocabularyImpl_1 = require("../VocabularyImpl");
let LexerDFASerializer = class LexerDFASerializer extends DFASerializer_1.DFASerializer {
constructor(dfa) {
super(dfa, VocabularyImpl_1.VocabularyImpl.EMPTY_VOCABULARY);
}
getEdgeLabel(i) {
return "'" + String.fromCodePoint(i) + "'";
}
};
__decorate([
Decorators_1.Override,
Decorators_1.NotNull
], LexerDFASerializer.prototype, "getEdgeLabel", null);
LexerDFASerializer = __decorate([
__param(0, Decorators_1.NotNull)
], LexerDFASerializer);
exports.LexerDFASerializer = LexerDFASerializer;
//# sourceMappingURL=LexerDFASerializer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"LexerDFASerializer.js","sourceRoot":"","sources":["../../../src/dfa/LexerDFASerializer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAKH,mDAAgD;AAChD,8CAAkD;AAClD,sDAAmD;AAEnD,IAAa,kBAAkB,GAA/B,MAAa,kBAAmB,SAAQ,6BAAa;IACpD,YAAsB,GAAQ;QAC7B,KAAK,CAAC,GAAG,EAAE,+BAAc,CAAC,gBAAgB,CAAC,CAAC;IAC7C,CAAC;IAIS,YAAY,CAAC,CAAS;QAC/B,OAAO,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAC5C,CAAC;CACD,CAAA;AAHA;IAFC,qBAAQ;IACR,oBAAO;sDAGP;AATW,kBAAkB;IAChB,WAAA,oBAAO,CAAA;GADT,kBAAkB,CAU9B;AAVY,gDAAkB","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.2167238-07:00\r\n\r\nimport { DFA } from \"./DFA\";\r\nimport { DFASerializer } from \"./DFASerializer\";\r\nimport { NotNull, Override } from \"../Decorators\";\r\nimport { VocabularyImpl } from \"../VocabularyImpl\";\r\n\r\nexport class LexerDFASerializer extends DFASerializer {\r\n\tconstructor( @NotNull dfa: DFA) {\r\n\t\tsuper(dfa, VocabularyImpl.EMPTY_VOCABULARY);\r\n\t}\r\n\r\n\t@Override\r\n\t@NotNull\r\n\tprotected getEdgeLabel(i: number): string {\r\n\t\treturn \"'\" + String.fromCodePoint(i) + \"'\";\r\n\t}\r\n}\r\n"]}

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 * from "./AcceptStateInfo";
export * from "./DFA";
export * from "./DFASerializer";
export * from "./DFAState";
export * from "./LexerDFASerializer";

View File

@@ -0,0 +1,22 @@
"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("./AcceptStateInfo"), exports);
__exportStar(require("./DFA"), exports);
__exportStar(require("./DFASerializer"), exports);
__exportStar(require("./DFAState"), exports);
__exportStar(require("./LexerDFASerializer"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dfa/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,oDAAkC;AAClC,wCAAsB;AACtB,kDAAgC;AAChC,6CAA2B;AAC3B,uDAAqC","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 \"./AcceptStateInfo\";\r\nexport * from \"./DFA\";\r\nexport * from \"./DFASerializer\";\r\nexport * from \"./DFAState\";\r\nexport * from \"./LexerDFASerializer\";\r\n"]}