use const/let for better variable scoping
This commit is contained in:
parent
4f8527e9ee
commit
43f896d6dc
|
@ -3,72 +3,72 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
var Token = require('./../Token').Token;
|
||||
var ATN = require('./ATN');
|
||||
var ATNType = require('./ATNType');
|
||||
var ATNStates = require('./ATNState');
|
||||
var ATNState = ATNStates.ATNState;
|
||||
var BasicState = ATNStates.BasicState;
|
||||
var DecisionState = ATNStates.DecisionState;
|
||||
var BlockStartState = ATNStates.BlockStartState;
|
||||
var BlockEndState = ATNStates.BlockEndState;
|
||||
var LoopEndState = ATNStates.LoopEndState;
|
||||
var RuleStartState = ATNStates.RuleStartState;
|
||||
var RuleStopState = ATNStates.RuleStopState;
|
||||
var TokensStartState = ATNStates.TokensStartState;
|
||||
var PlusLoopbackState = ATNStates.PlusLoopbackState;
|
||||
var StarLoopbackState = ATNStates.StarLoopbackState;
|
||||
var StarLoopEntryState = ATNStates.StarLoopEntryState;
|
||||
var PlusBlockStartState = ATNStates.PlusBlockStartState;
|
||||
var StarBlockStartState = ATNStates.StarBlockStartState;
|
||||
var BasicBlockStartState = ATNStates.BasicBlockStartState;
|
||||
var Transitions = require('./Transition');
|
||||
var Transition = Transitions.Transition;
|
||||
var AtomTransition = Transitions.AtomTransition;
|
||||
var SetTransition = Transitions.SetTransition;
|
||||
var NotSetTransition = Transitions.NotSetTransition;
|
||||
var RuleTransition = Transitions.RuleTransition;
|
||||
var RangeTransition = Transitions.RangeTransition;
|
||||
var ActionTransition = Transitions.ActionTransition;
|
||||
var EpsilonTransition = Transitions.EpsilonTransition;
|
||||
var WildcardTransition = Transitions.WildcardTransition;
|
||||
var PredicateTransition = Transitions.PredicateTransition;
|
||||
var PrecedencePredicateTransition = Transitions.PrecedencePredicateTransition;
|
||||
var IntervalSet = require('./../IntervalSet').IntervalSet;
|
||||
var Interval = require('./../IntervalSet').Interval;
|
||||
var ATNDeserializationOptions = require('./ATNDeserializationOptions');
|
||||
var LexerActions = require('./LexerAction');
|
||||
var LexerActionType = LexerActions.LexerActionType;
|
||||
var LexerSkipAction = LexerActions.LexerSkipAction;
|
||||
var LexerChannelAction = LexerActions.LexerChannelAction;
|
||||
var LexerCustomAction = LexerActions.LexerCustomAction;
|
||||
var LexerMoreAction = LexerActions.LexerMoreAction;
|
||||
var LexerTypeAction = LexerActions.LexerTypeAction;
|
||||
var LexerPushModeAction = LexerActions.LexerPushModeAction;
|
||||
var LexerPopModeAction = LexerActions.LexerPopModeAction;
|
||||
var LexerModeAction = LexerActions.LexerModeAction;
|
||||
const Token = require('./../Token').Token;
|
||||
const ATN = require('./ATN');
|
||||
const ATNType = require('./ATNType');
|
||||
const ATNStates = require('./ATNState');
|
||||
const ATNState = ATNStates.ATNState;
|
||||
const BasicState = ATNStates.BasicState;
|
||||
const DecisionState = ATNStates.DecisionState;
|
||||
const BlockStartState = ATNStates.BlockStartState;
|
||||
const BlockEndState = ATNStates.BlockEndState;
|
||||
const LoopEndState = ATNStates.LoopEndState;
|
||||
const RuleStartState = ATNStates.RuleStartState;
|
||||
const RuleStopState = ATNStates.RuleStopState;
|
||||
const TokensStartState = ATNStates.TokensStartState;
|
||||
const PlusLoopbackState = ATNStates.PlusLoopbackState;
|
||||
const StarLoopbackState = ATNStates.StarLoopbackState;
|
||||
const StarLoopEntryState = ATNStates.StarLoopEntryState;
|
||||
const PlusBlockStartState = ATNStates.PlusBlockStartState;
|
||||
const StarBlockStartState = ATNStates.StarBlockStartState;
|
||||
const BasicBlockStartState = ATNStates.BasicBlockStartState;
|
||||
const Transitions = require('./Transition');
|
||||
const Transition = Transitions.Transition;
|
||||
const AtomTransition = Transitions.AtomTransition;
|
||||
const SetTransition = Transitions.SetTransition;
|
||||
const NotSetTransition = Transitions.NotSetTransition;
|
||||
const RuleTransition = Transitions.RuleTransition;
|
||||
const RangeTransition = Transitions.RangeTransition;
|
||||
const ActionTransition = Transitions.ActionTransition;
|
||||
const EpsilonTransition = Transitions.EpsilonTransition;
|
||||
const WildcardTransition = Transitions.WildcardTransition;
|
||||
const PredicateTransition = Transitions.PredicateTransition;
|
||||
const PrecedencePredicateTransition = Transitions.PrecedencePredicateTransition;
|
||||
const IntervalSet = require('./../IntervalSet').IntervalSet;
|
||||
const Interval = require('./../IntervalSet').Interval;
|
||||
const ATNDeserializationOptions = require('./ATNDeserializationOptions');
|
||||
const LexerActions = require('./LexerAction');
|
||||
const LexerActionType = LexerActions.LexerActionType;
|
||||
const LexerSkipAction = LexerActions.LexerSkipAction;
|
||||
const LexerChannelAction = LexerActions.LexerChannelAction;
|
||||
const LexerCustomAction = LexerActions.LexerCustomAction;
|
||||
const LexerMoreAction = LexerActions.LexerMoreAction;
|
||||
const LexerTypeAction = LexerActions.LexerTypeAction;
|
||||
const LexerPushModeAction = LexerActions.LexerPushModeAction;
|
||||
const LexerPopModeAction = LexerActions.LexerPopModeAction;
|
||||
const LexerModeAction = LexerActions.LexerModeAction;
|
||||
// This is the earliest supported serialized UUID.
|
||||
// stick to serialized version for now, we don't need a UUID instance
|
||||
var BASE_SERIALIZED_UUID = "AADB8D7E-AEEF-4415-AD2B-8204D6CF042E";
|
||||
const BASE_SERIALIZED_UUID = "AADB8D7E-AEEF-4415-AD2B-8204D6CF042E";
|
||||
|
||||
//
|
||||
// This UUID indicates the serialized ATN contains two sets of
|
||||
// IntervalSets, where the second set's values are encoded as
|
||||
// 32-bit integers to support the full Unicode SMP range up to U+10FFFF.
|
||||
//
|
||||
var ADDED_UNICODE_SMP = "59627784-3BE5-417A-B9EB-8131A7286089";
|
||||
const ADDED_UNICODE_SMP = "59627784-3BE5-417A-B9EB-8131A7286089";
|
||||
|
||||
// This list contains all of the currently supported UUIDs, ordered by when
|
||||
// the feature first appeared in this branch.
|
||||
var SUPPORTED_UUIDS = [ BASE_SERIALIZED_UUID, ADDED_UNICODE_SMP ];
|
||||
const SUPPORTED_UUIDS = [ BASE_SERIALIZED_UUID, ADDED_UNICODE_SMP ];
|
||||
|
||||
var SERIALIZED_VERSION = 3;
|
||||
const SERIALIZED_VERSION = 3;
|
||||
|
||||
// This is the current serialized UUID.
|
||||
var SERIALIZED_UUID = ADDED_UNICODE_SMP;
|
||||
const SERIALIZED_UUID = ADDED_UNICODE_SMP;
|
||||
|
||||
function initArray( length, value) {
|
||||
var tmp = [];
|
||||
const tmp = [];
|
||||
tmp[length-1] = value;
|
||||
return tmp.map(function(i) {return value;});
|
||||
}
|
||||
|
@ -98,11 +98,11 @@ class ATNDeserializer {
|
|||
* introduced; otherwise, {@code false}.
|
||||
*/
|
||||
isFeatureSupported(feature, actualUuid) {
|
||||
var idx1 = SUPPORTED_UUIDS.indexOf(feature);
|
||||
const idx1 = SUPPORTED_UUIDS.indexOf(feature);
|
||||
if (idx1<0) {
|
||||
return false;
|
||||
}
|
||||
var idx2 = SUPPORTED_UUIDS.indexOf(actualUuid);
|
||||
const idx2 = SUPPORTED_UUIDS.indexOf(actualUuid);
|
||||
return idx2 >= idx1;
|
||||
}
|
||||
|
||||
|
@ -110,11 +110,11 @@ class ATNDeserializer {
|
|||
this.reset(data);
|
||||
this.checkVersion();
|
||||
this.checkUUID();
|
||||
var atn = this.readATN();
|
||||
const atn = this.readATN();
|
||||
this.readStates(atn);
|
||||
this.readRules(atn);
|
||||
this.readModes(atn);
|
||||
var sets = [];
|
||||
const sets = [];
|
||||
// First, deserialize sets with 16-bit arguments <= U+FFFF.
|
||||
this.readSets(atn, sets, this.readInt.bind(this));
|
||||
// Next, if the ATN was serialized with the Unicode SMP feature,
|
||||
|
@ -136,11 +136,11 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
reset(data) {
|
||||
var adjust = function(c) {
|
||||
var v = c.charCodeAt(0);
|
||||
const adjust = function(c) {
|
||||
const v = c.charCodeAt(0);
|
||||
return v>1 ? v-2 : v + 65534;
|
||||
};
|
||||
var temp = data.split("").map(adjust);
|
||||
const temp = data.split("").map(adjust);
|
||||
// don't adjust the first value since that's the version number
|
||||
temp[0] = data.charCodeAt(0);
|
||||
this.data = temp;
|
||||
|
@ -148,14 +148,14 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
checkVersion() {
|
||||
var version = this.readInt();
|
||||
const version = this.readInt();
|
||||
if ( version !== SERIALIZED_VERSION ) {
|
||||
throw ("Could not deserialize ATN with version " + version + " (expected " + SERIALIZED_VERSION + ").");
|
||||
}
|
||||
}
|
||||
|
||||
checkUUID() {
|
||||
var uuid = this.readUUID();
|
||||
const uuid = this.readUUID();
|
||||
if (SUPPORTED_UUIDS.indexOf(uuid)<0) {
|
||||
throw ("Could not deserialize ATN with UUID: " + uuid +
|
||||
" (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID);
|
||||
|
@ -164,33 +164,33 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
readATN() {
|
||||
var grammarType = this.readInt();
|
||||
var maxTokenType = this.readInt();
|
||||
const grammarType = this.readInt();
|
||||
const maxTokenType = this.readInt();
|
||||
return new ATN(grammarType, maxTokenType);
|
||||
}
|
||||
|
||||
readStates(atn) {
|
||||
var j, pair, stateNumber;
|
||||
var loopBackStateNumbers = [];
|
||||
var endStateNumbers = [];
|
||||
var nstates = this.readInt();
|
||||
for(var i=0; i<nstates; i++) {
|
||||
var stype = this.readInt();
|
||||
let j, pair, stateNumber;
|
||||
const loopBackStateNumbers = [];
|
||||
const endStateNumbers = [];
|
||||
const nstates = this.readInt();
|
||||
for(let i=0; i<nstates; i++) {
|
||||
const stype = this.readInt();
|
||||
// ignore bad type of states
|
||||
if (stype===ATNState.INVALID_TYPE) {
|
||||
atn.addState(null);
|
||||
continue;
|
||||
}
|
||||
var ruleIndex = this.readInt();
|
||||
let ruleIndex = this.readInt();
|
||||
if (ruleIndex === 0xFFFF) {
|
||||
ruleIndex = -1;
|
||||
}
|
||||
var s = this.stateFactory(stype, ruleIndex);
|
||||
const s = this.stateFactory(stype, ruleIndex);
|
||||
if (stype === ATNState.LOOP_END) { // special case
|
||||
var loopBackStateNumber = this.readInt();
|
||||
const loopBackStateNumber = this.readInt();
|
||||
loopBackStateNumbers.push([s, loopBackStateNumber]);
|
||||
} else if(s instanceof BlockStartState) {
|
||||
var endStateNumber = this.readInt();
|
||||
const endStateNumber = this.readInt();
|
||||
endStateNumbers.push([s, endStateNumber]);
|
||||
}
|
||||
atn.addState(s);
|
||||
|
@ -207,13 +207,13 @@ class ATNDeserializer {
|
|||
pair[0].endState = atn.states[pair[1]];
|
||||
}
|
||||
|
||||
var numNonGreedyStates = this.readInt();
|
||||
let numNonGreedyStates = this.readInt();
|
||||
for (j=0; j<numNonGreedyStates; j++) {
|
||||
stateNumber = this.readInt();
|
||||
atn.states[stateNumber].nonGreedy = true;
|
||||
}
|
||||
|
||||
var numPrecedenceStates = this.readInt();
|
||||
let numPrecedenceStates = this.readInt();
|
||||
for (j=0; j<numPrecedenceStates; j++) {
|
||||
stateNumber = this.readInt();
|
||||
atn.states[stateNumber].isPrecedenceRule = true;
|
||||
|
@ -221,18 +221,17 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
readRules(atn) {
|
||||
var i;
|
||||
var nrules = this.readInt();
|
||||
let i;
|
||||
const nrules = this.readInt();
|
||||
if (atn.grammarType === ATNType.LEXER ) {
|
||||
atn.ruleToTokenType = initArray(nrules, 0);
|
||||
}
|
||||
atn.ruleToStartState = initArray(nrules, 0);
|
||||
for (i=0; i<nrules; i++) {
|
||||
var s = this.readInt();
|
||||
var startState = atn.states[s];
|
||||
atn.ruleToStartState[i] = startState;
|
||||
const s = this.readInt();
|
||||
atn.ruleToStartState[i] = atn.states[s];
|
||||
if ( atn.grammarType === ATNType.LEXER ) {
|
||||
var tokenType = this.readInt();
|
||||
let tokenType = this.readInt();
|
||||
if (tokenType === 0xFFFF) {
|
||||
tokenType = Token.EOF;
|
||||
}
|
||||
|
@ -241,7 +240,7 @@ class ATNDeserializer {
|
|||
}
|
||||
atn.ruleToStopState = initArray(nrules, 0);
|
||||
for (i=0; i<atn.states.length; i++) {
|
||||
var state = atn.states[i];
|
||||
const state = atn.states[i];
|
||||
if (!(state instanceof RuleStopState)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -251,54 +250,54 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
readModes(atn) {
|
||||
var nmodes = this.readInt();
|
||||
for (var i=0; i<nmodes; i++) {
|
||||
var s = this.readInt();
|
||||
const nmodes = this.readInt();
|
||||
for (let i=0; i<nmodes; i++) {
|
||||
let s = this.readInt();
|
||||
atn.modeToStartState.push(atn.states[s]);
|
||||
}
|
||||
}
|
||||
|
||||
readSets(atn, sets, readUnicode) {
|
||||
var m = this.readInt();
|
||||
for (var i=0; i<m; i++) {
|
||||
var iset = new IntervalSet();
|
||||
const m = this.readInt();
|
||||
for (let i=0; i<m; i++) {
|
||||
const iset = new IntervalSet();
|
||||
sets.push(iset);
|
||||
var n = this.readInt();
|
||||
var containsEof = this.readInt();
|
||||
const n = this.readInt();
|
||||
const containsEof = this.readInt();
|
||||
if (containsEof!==0) {
|
||||
iset.addOne(-1);
|
||||
}
|
||||
for (var j=0; j<n; j++) {
|
||||
var i1 = readUnicode();
|
||||
var i2 = readUnicode();
|
||||
for (let j=0; j<n; j++) {
|
||||
const i1 = readUnicode();
|
||||
const i2 = readUnicode();
|
||||
iset.addRange(i1, i2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readEdges(atn, sets) {
|
||||
var i, j, state, trans, target;
|
||||
var nedges = this.readInt();
|
||||
let i, j, state, trans, target;
|
||||
const nedges = this.readInt();
|
||||
for (i=0; i<nedges; i++) {
|
||||
var src = this.readInt();
|
||||
var trg = this.readInt();
|
||||
var ttype = this.readInt();
|
||||
var arg1 = this.readInt();
|
||||
var arg2 = this.readInt();
|
||||
var arg3 = this.readInt();
|
||||
const src = this.readInt();
|
||||
const trg = this.readInt();
|
||||
const ttype = this.readInt();
|
||||
const arg1 = this.readInt();
|
||||
const arg2 = this.readInt();
|
||||
const arg3 = this.readInt();
|
||||
trans = this.edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
|
||||
var srcState = atn.states[src];
|
||||
const srcState = atn.states[src];
|
||||
srcState.addTransition(trans);
|
||||
}
|
||||
// edges for rule stop states can be derived, so they aren't serialized
|
||||
for (i=0; i<atn.states.length; i++) {
|
||||
state = atn.states[i];
|
||||
for (j=0; j<state.transitions.length; j++) {
|
||||
var t = state.transitions[j];
|
||||
const t = state.transitions[j];
|
||||
if (!(t instanceof RuleTransition)) {
|
||||
continue;
|
||||
}
|
||||
var outermostPrecedenceReturn = -1;
|
||||
let outermostPrecedenceReturn = -1;
|
||||
if (atn.ruleToStartState[t.target.ruleIndex].isPrecedenceRule) {
|
||||
if (t.precedence === 0) {
|
||||
outermostPrecedenceReturn = t.target.ruleIndex;
|
||||
|
@ -343,10 +342,10 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
readDecisions(atn) {
|
||||
var ndecisions = this.readInt();
|
||||
for (var i=0; i<ndecisions; i++) {
|
||||
var s = this.readInt();
|
||||
var decState = atn.states[s];
|
||||
const ndecisions = this.readInt();
|
||||
for (let i=0; i<ndecisions; i++) {
|
||||
const s = this.readInt();
|
||||
const decState = atn.states[s];
|
||||
atn.decisionToState.push(decState);
|
||||
decState.decision = i;
|
||||
}
|
||||
|
@ -354,27 +353,27 @@ class ATNDeserializer {
|
|||
|
||||
readLexerActions(atn) {
|
||||
if (atn.grammarType === ATNType.LEXER) {
|
||||
var count = this.readInt();
|
||||
const count = this.readInt();
|
||||
atn.lexerActions = initArray(count, null);
|
||||
for (var i=0; i<count; i++) {
|
||||
var actionType = this.readInt();
|
||||
var data1 = this.readInt();
|
||||
for (let i=0; i<count; i++) {
|
||||
const actionType = this.readInt();
|
||||
let data1 = this.readInt();
|
||||
if (data1 === 0xFFFF) {
|
||||
data1 = -1;
|
||||
}
|
||||
var data2 = this.readInt();
|
||||
let data2 = this.readInt();
|
||||
if (data2 === 0xFFFF) {
|
||||
data2 = -1;
|
||||
}
|
||||
var lexerAction = this.lexerActionFactory(actionType, data1, data2);
|
||||
atn.lexerActions[i] = lexerAction;
|
||||
|
||||
atn.lexerActions[i] = this.lexerActionFactory(actionType, data1, data2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generateRuleBypassTransitions(atn) {
|
||||
var i;
|
||||
var count = atn.ruleToStartState.length;
|
||||
let i;
|
||||
const count = atn.ruleToStartState.length;
|
||||
for(i=0; i<count; i++) {
|
||||
atn.ruleToTokenType[i] = atn.maxTokenType + i + 1;
|
||||
}
|
||||
|
@ -384,12 +383,12 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
generateRuleBypassTransition(atn, idx) {
|
||||
var i, state;
|
||||
var bypassStart = new BasicBlockStartState();
|
||||
let i, state;
|
||||
const bypassStart = new BasicBlockStartState();
|
||||
bypassStart.ruleIndex = idx;
|
||||
atn.addState(bypassStart);
|
||||
|
||||
var bypassStop = new BlockEndState();
|
||||
const bypassStop = new BlockEndState();
|
||||
bypassStop.ruleIndex = idx;
|
||||
atn.addState(bypassStop);
|
||||
|
||||
|
@ -398,8 +397,8 @@ class ATNDeserializer {
|
|||
|
||||
bypassStop.startState = bypassStart;
|
||||
|
||||
var excludeTransition = null;
|
||||
var endState = null;
|
||||
let excludeTransition = null;
|
||||
let endState = null;
|
||||
|
||||
if (atn.ruleToStartState[idx].isPrecedenceRule) {
|
||||
// wrap from the beginning of the rule to the StarLoopEntryState
|
||||
|
@ -423,8 +422,8 @@ class ATNDeserializer {
|
|||
// target blockEnd instead
|
||||
for(i=0; i<atn.states.length; i++) {
|
||||
state = atn.states[i];
|
||||
for(var j=0; j<state.transitions.length; j++) {
|
||||
var transition = state.transitions[j];
|
||||
for(let j=0; j<state.transitions.length; j++) {
|
||||
const transition = state.transitions[j];
|
||||
if (transition === excludeTransition) {
|
||||
continue;
|
||||
}
|
||||
|
@ -436,8 +435,8 @@ class ATNDeserializer {
|
|||
|
||||
// all transitions leaving the rule start state need to leave blockStart
|
||||
// instead
|
||||
var ruleToStartState = atn.ruleToStartState[idx];
|
||||
var count = ruleToStartState.transitions.length;
|
||||
const ruleToStartState = atn.ruleToStartState[idx];
|
||||
const count = ruleToStartState.transitions.length;
|
||||
while ( count > 0) {
|
||||
bypassStart.addTransition(ruleToStartState.transitions[count-1]);
|
||||
ruleToStartState.transitions = ruleToStartState.transitions.slice(-1);
|
||||
|
@ -446,7 +445,7 @@ class ATNDeserializer {
|
|||
atn.ruleToStartState[idx].addTransition(new EpsilonTransition(bypassStart));
|
||||
bypassStop.addTransition(new EpsilonTransition(endState));
|
||||
|
||||
var matchState = new BasicState();
|
||||
const matchState = new BasicState();
|
||||
atn.addState(matchState);
|
||||
matchState.addTransition(new AtomTransition(bypassStop, atn.ruleToTokenType[idx]));
|
||||
bypassStart.addTransition(new EpsilonTransition(matchState));
|
||||
|
@ -459,7 +458,7 @@ class ATNDeserializer {
|
|||
if (!( state instanceof StarLoopEntryState)) {
|
||||
return null;
|
||||
}
|
||||
var maybeLoopEndState = state.transitions[state.transitions.length - 1].target;
|
||||
const maybeLoopEndState = state.transitions[state.transitions.length - 1].target;
|
||||
if (!( maybeLoopEndState instanceof LoopEndState)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -478,8 +477,8 @@ class ATNDeserializer {
|
|||
* @param atn The ATN.
|
||||
*/
|
||||
markPrecedenceDecisions(atn) {
|
||||
for(var i=0; i<atn.states.length; i++) {
|
||||
var state = atn.states[i];
|
||||
for(let i=0; i<atn.states.length; i++) {
|
||||
const state = atn.states[i];
|
||||
if (!( state instanceof StarLoopEntryState)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -487,7 +486,7 @@ class ATNDeserializer {
|
|||
// decision for the closure block that determines whether a
|
||||
// precedence rule should continue or complete.
|
||||
if ( atn.ruleToStartState[state.ruleIndex].isPrecedenceRule) {
|
||||
var maybeLoopEndState = state.transitions[state.transitions.length - 1].target;
|
||||
const maybeLoopEndState = state.transitions[state.transitions.length - 1].target;
|
||||
if (maybeLoopEndState instanceof LoopEndState) {
|
||||
if ( maybeLoopEndState.epsilonOnlyTransitions &&
|
||||
(maybeLoopEndState.transitions[0].target instanceof RuleStopState)) {
|
||||
|
@ -503,8 +502,8 @@ class ATNDeserializer {
|
|||
return;
|
||||
}
|
||||
// verify assumptions
|
||||
for(var i=0; i<atn.states.length; i++) {
|
||||
var state = atn.states[i];
|
||||
for(let i=0; i<atn.states.length; i++) {
|
||||
const state = atn.states[i];
|
||||
if (state === null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -556,21 +555,21 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
readInt32() {
|
||||
var low = this.readInt();
|
||||
var high = this.readInt();
|
||||
const low = this.readInt();
|
||||
const high = this.readInt();
|
||||
return low | (high << 16);
|
||||
}
|
||||
|
||||
readLong() {
|
||||
var low = this.readInt32();
|
||||
var high = this.readInt32();
|
||||
const low = this.readInt32();
|
||||
const high = this.readInt32();
|
||||
return (low & 0x00000000FFFFFFFF) | (high << 32);
|
||||
}
|
||||
|
||||
readUUID() {
|
||||
var bb = [];
|
||||
for(var i=7;i>=0;i--) {
|
||||
var int = this.readInt();
|
||||
const bb = [];
|
||||
for(let i=7;i>=0;i--) {
|
||||
const int = this.readInt();
|
||||
/* jshint bitwise: false */
|
||||
bb[(2*i)+1] = int & 0xFF;
|
||||
bb[2*i] = (int >> 8) & 0xFF;
|
||||
|
@ -586,7 +585,7 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets) {
|
||||
var target = atn.states[trg];
|
||||
const target = atn.states[trg];
|
||||
switch(type) {
|
||||
case Transition.EPSILON:
|
||||
return new EpsilonTransition(target);
|
||||
|
@ -615,26 +614,26 @@ class ATNDeserializer {
|
|||
|
||||
stateFactory(type, ruleIndex) {
|
||||
if (this.stateFactories === null) {
|
||||
var sf = [];
|
||||
const sf = [];
|
||||
sf[ATNState.INVALID_TYPE] = null;
|
||||
sf[ATNState.BASIC] = function() { return new BasicState(); };
|
||||
sf[ATNState.RULE_START] = function() { return new RuleStartState(); };
|
||||
sf[ATNState.BLOCK_START] = function() { return new BasicBlockStartState(); };
|
||||
sf[ATNState.PLUS_BLOCK_START] = function() { return new PlusBlockStartState(); };
|
||||
sf[ATNState.STAR_BLOCK_START] = function() { return new StarBlockStartState(); };
|
||||
sf[ATNState.TOKEN_START] = function() { return new TokensStartState(); };
|
||||
sf[ATNState.RULE_STOP] = function() { return new RuleStopState(); };
|
||||
sf[ATNState.BLOCK_END] = function() { return new BlockEndState(); };
|
||||
sf[ATNState.STAR_LOOP_BACK] = function() { return new StarLoopbackState(); };
|
||||
sf[ATNState.STAR_LOOP_ENTRY] = function() { return new StarLoopEntryState(); };
|
||||
sf[ATNState.PLUS_LOOP_BACK] = function() { return new PlusLoopbackState(); };
|
||||
sf[ATNState.LOOP_END] = function() { return new LoopEndState(); };
|
||||
sf[ATNState.BASIC] = () => new BasicState();
|
||||
sf[ATNState.RULE_START] = () => new RuleStartState();
|
||||
sf[ATNState.BLOCK_START] = () => new BasicBlockStartState();
|
||||
sf[ATNState.PLUS_BLOCK_START] = () => new PlusBlockStartState();
|
||||
sf[ATNState.STAR_BLOCK_START] = () => new StarBlockStartState();
|
||||
sf[ATNState.TOKEN_START] = () => new TokensStartState();
|
||||
sf[ATNState.RULE_STOP] = () => new RuleStopState();
|
||||
sf[ATNState.BLOCK_END] = () => new BlockEndState();
|
||||
sf[ATNState.STAR_LOOP_BACK] = () => new StarLoopbackState();
|
||||
sf[ATNState.STAR_LOOP_ENTRY] = () => new StarLoopEntryState();
|
||||
sf[ATNState.PLUS_LOOP_BACK] = () => new PlusLoopbackState();
|
||||
sf[ATNState.LOOP_END] = () => new LoopEndState();
|
||||
this.stateFactories = sf;
|
||||
}
|
||||
if (type>this.stateFactories.length || this.stateFactories[type] === null) {
|
||||
throw("The specified state type " + type + " is not valid.");
|
||||
} else {
|
||||
var s = this.stateFactories[type]();
|
||||
const s = this.stateFactories[type]();
|
||||
if (s!==null) {
|
||||
s.ruleIndex = ruleIndex;
|
||||
return s;
|
||||
|
@ -644,15 +643,15 @@ class ATNDeserializer {
|
|||
|
||||
lexerActionFactory(type, data1, data2) {
|
||||
if (this.actionFactories === null) {
|
||||
var af = [];
|
||||
af[LexerActionType.CHANNEL] = function(data1, data2) { return new LexerChannelAction(data1); };
|
||||
af[LexerActionType.CUSTOM] = function(data1, data2) { return new LexerCustomAction(data1, data2); };
|
||||
af[LexerActionType.MODE] = function(data1, data2) { return new LexerModeAction(data1); };
|
||||
af[LexerActionType.MORE] = function(data1, data2) { return LexerMoreAction.INSTANCE; };
|
||||
af[LexerActionType.POP_MODE] = function(data1, data2) { return LexerPopModeAction.INSTANCE; };
|
||||
af[LexerActionType.PUSH_MODE] = function(data1, data2) { return new LexerPushModeAction(data1); };
|
||||
af[LexerActionType.SKIP] = function(data1, data2) { return LexerSkipAction.INSTANCE; };
|
||||
af[LexerActionType.TYPE] = function(data1, data2) { return new LexerTypeAction(data1); };
|
||||
const af = [];
|
||||
af[LexerActionType.CHANNEL] = (data1, data2) => new LexerChannelAction(data1);
|
||||
af[LexerActionType.CUSTOM] = (data1, data2) => new LexerCustomAction(data1, data2);
|
||||
af[LexerActionType.MODE] = (data1, data2) => new LexerModeAction(data1);
|
||||
af[LexerActionType.MORE] = (data1, data2) => LexerMoreAction.INSTANCE;
|
||||
af[LexerActionType.POP_MODE] = (data1, data2) => LexerPopModeAction.INSTANCE;
|
||||
af[LexerActionType.PUSH_MODE] = (data1, data2) => new LexerPushModeAction(data1);
|
||||
af[LexerActionType.SKIP] = (data1, data2) => LexerSkipAction.INSTANCE;
|
||||
af[LexerActionType.TYPE] = (data1, data2) => new LexerTypeAction(data1);
|
||||
this.actionFactories = af;
|
||||
}
|
||||
if (type>this.actionFactories.length || this.actionFactories[type] === null) {
|
||||
|
@ -664,14 +663,14 @@ class ATNDeserializer {
|
|||
}
|
||||
|
||||
function createByteToHex() {
|
||||
var bth = [];
|
||||
for (var i = 0; i < 256; i++) {
|
||||
const bth = [];
|
||||
for (let i = 0; i < 256; i++) {
|
||||
bth[i] = (i + 0x100).toString(16).substr(1).toUpperCase();
|
||||
}
|
||||
return bth;
|
||||
}
|
||||
|
||||
var byteToHex = createByteToHex();
|
||||
const byteToHex = createByteToHex();
|
||||
|
||||
|
||||
module.exports = ATNDeserializer;
|
||||
|
|
Loading…
Reference in New Issue