diff --git a/runtime/JavaScript/src/antlr4/atn/LexerAction.js b/runtime/JavaScript/src/antlr4/atn/LexerAction.js index ad5be437f..faf2ed92b 100644 --- a/runtime/JavaScript/src/antlr4/atn/LexerAction.js +++ b/runtime/JavaScript/src/antlr4/atn/LexerAction.js @@ -1,366 +1,384 @@ -// /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ - // -function LexerActionType() { +const LexerActionType = { + // The type of a {@link LexerChannelAction} action. + CHANNEL: 0, + // The type of a {@link LexerCustomAction} action + CUSTOM: 1, + // The type of a {@link LexerModeAction} action. + MODE: 2, + //The type of a {@link LexerMoreAction} action. + MORE: 3, + //The type of a {@link LexerPopModeAction} action. + POP_MODE: 4, + //The type of a {@link LexerPushModeAction} action. + PUSH_MODE: 5, + //The type of a {@link LexerSkipAction} action. + SKIP: 6, + //The type of a {@link LexerTypeAction} action. + TYPE: 7 } -LexerActionType.CHANNEL = 0; //The type of a {@link LexerChannelAction} action. -LexerActionType.CUSTOM = 1; //The type of a {@link LexerCustomAction} action. -LexerActionType.MODE = 2; //The type of a {@link LexerModeAction} action. -LexerActionType.MORE = 3; //The type of a {@link LexerMoreAction} action. -LexerActionType.POP_MODE = 4; //The type of a {@link LexerPopModeAction} action. -LexerActionType.PUSH_MODE = 5; //The type of a {@link LexerPushModeAction} action. -LexerActionType.SKIP = 6; //The type of a {@link LexerSkipAction} action. -LexerActionType.TYPE = 7; //The type of a {@link LexerTypeAction} action. +class LexerAction { + constructor(action) { + this.actionType = action; + this.isPositionDependent = false; + } -function LexerAction(action) { - this.actionType = action; - this.isPositionDependent = false; - return this; + hashCode() { + const hash = new Hash(); + this.updateHashCode(hash); + return hash.finish() + } + + updateHashCode(hash) { + hash.update(this.actionType); + } + + equals(other) { + return this === other; + } } -LexerAction.prototype.hashCode = function() { - var hash = new Hash(); - this.updateHashCode(hash); - return hash.finish() -}; -LexerAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType); -}; +/** + * Implements the {@code skip} lexer action by calling {@link Lexer//skip}. + * + *
The {@code skip} command does not have any parameters, so this action is + * implemented as a singleton instance exposed by {@link //INSTANCE}.
+ */ +class LexerSkipAction extends LexerAction { + constructor() { + super(LexerActionType.SKIP); + } -LexerAction.prototype.equals = function(other) { - return this === other; -}; + execute(lexer) { + lexer.skip(); + } - - -// -// Implements the {@code skip} lexer action by calling {@link Lexer//skip}. -// -//The {@code skip} command does not have any parameters, so this action is -// implemented as a singleton instance exposed by {@link //INSTANCE}.
-function LexerSkipAction() { - LexerAction.call(this, LexerActionType.SKIP); - return this; + toString() { + return "skip"; + } } -LexerSkipAction.prototype = Object.create(LexerAction.prototype); -LexerSkipAction.prototype.constructor = LexerSkipAction; - // Provides a singleton instance of this parameterless lexer action. LexerSkipAction.INSTANCE = new LexerSkipAction(); -LexerSkipAction.prototype.execute = function(lexer) { - lexer.skip(); -}; - -LexerSkipAction.prototype.toString = function() { - return "skip"; -}; - -// Implements the {@code type} lexer action by calling {@link Lexer//setType} -// with the assigned type. -function LexerTypeAction(type) { - LexerAction.call(this, LexerActionType.TYPE); - this.type = type; - return this; -} - -LexerTypeAction.prototype = Object.create(LexerAction.prototype); -LexerTypeAction.prototype.constructor = LexerTypeAction; - -LexerTypeAction.prototype.execute = function(lexer) { - lexer.type = this.type; -}; - -LexerTypeAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.type); -}; - - -LexerTypeAction.prototype.equals = function(other) { - if(this === other) { - return true; - } else if (! (other instanceof LexerTypeAction)) { - return false; - } else { - return this.type === other.type; +/** + * Implements the {@code type} lexer action by calling {@link Lexer//setType} + * with the assigned type + */ +class LexerTypeAction extends LexerAction { + constructor(type) { + super(LexerActionType.TYPE); + this.type = type; } -}; -LexerTypeAction.prototype.toString = function() { - return "type(" + this.type + ")"; -}; - -// Implements the {@code pushMode} lexer action by calling -// {@link Lexer//pushMode} with the assigned mode. -function LexerPushModeAction(mode) { - LexerAction.call(this, LexerActionType.PUSH_MODE); - this.mode = mode; - return this; -} - -LexerPushModeAction.prototype = Object.create(LexerAction.prototype); -LexerPushModeAction.prototype.constructor = LexerPushModeAction; - -//This action is implemented by calling {@link Lexer//pushMode} with the -// value provided by {@link //getMode}.
-LexerPushModeAction.prototype.execute = function(lexer) { - lexer.pushMode(this.mode); -}; - -LexerPushModeAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.mode); -}; - -LexerPushModeAction.prototype.equals = function(other) { - if (this === other) { - return true; - } else if (! (other instanceof LexerPushModeAction)) { - return false; - } else { - return this.mode === other.mode; + execute(lexer) { + lexer.type = this.type; } -}; -LexerPushModeAction.prototype.toString = function() { - return "pushMode(" + this.mode + ")"; -}; + updateHashCode(hash) { + hash.update(this.actionType, this.type); + } + equals(other) { + if(this === other) { + return true; + } else if (! (other instanceof LexerTypeAction)) { + return false; + } else { + return this.type === other.type; + } + } -// Implements the {@code popMode} lexer action by calling {@link Lexer//popMode}. -// -//The {@code popMode} command does not have any parameters, so this action is -// implemented as a singleton instance exposed by {@link //INSTANCE}.
-function LexerPopModeAction() { - LexerAction.call(this,LexerActionType.POP_MODE); - return this; + toString() { + return "type(" + this.type + ")"; + } } -LexerPopModeAction.prototype = Object.create(LexerAction.prototype); -LexerPopModeAction.prototype.constructor = LexerPopModeAction; + +/** + * Implements the {@code pushMode} lexer action by calling + * {@link Lexer//pushMode} with the assigned mode + */ +class LexerPushModeAction extends LexerAction { + constructor(mode) { + super(LexerActionType.PUSH_MODE); + this.mode = mode; + } + + /** + *This action is implemented by calling {@link Lexer//pushMode} with the + * value provided by {@link //getMode}.
+ */ + execute(lexer) { + lexer.pushMode(this.mode); + } + + updateHashCode(hash) { + hash.update(this.actionType, this.mode); + } + + equals(other) { + if (this === other) { + return true; + } else if (! (other instanceof LexerPushModeAction)) { + return false; + } else { + return this.mode === other.mode; + } + } + + toString() { + return "pushMode(" + this.mode + ")"; + } +} + +/** + * Implements the {@code popMode} lexer action by calling {@link Lexer//popMode}. + * + *The {@code popMode} command does not have any parameters, so this action is + * implemented as a singleton instance exposed by {@link //INSTANCE}.
+ */ +class LexerPopModeAction extends LexerAction { + constructor() { + super(LexerActionType.POP_MODE); + } + + /** + *This action is implemented by calling {@link Lexer//popMode}.
+ */ + execute(lexer) { + lexer.popMode(); + } + + toString() { + return "popMode"; + } +} LexerPopModeAction.INSTANCE = new LexerPopModeAction(); -//This action is implemented by calling {@link Lexer//popMode}.
-LexerPopModeAction.prototype.execute = function(lexer) { - lexer.popMode(); -}; +/** + * Implements the {@code more} lexer action by calling {@link Lexer//more}. + * + *The {@code more} command does not have any parameters, so this action is + * implemented as a singleton instance exposed by {@link //INSTANCE}.
+ */ +class LexerMoreAction extends LexerAction { + constructor() { + super(LexerActionType.MORE); + } -LexerPopModeAction.prototype.toString = function() { - return "popMode"; -}; + /** + *This action is implemented by calling {@link Lexer//popMode}.
+ */ + execute(lexer) { + lexer.more(); + } -// Implements the {@code more} lexer action by calling {@link Lexer//more}. -// -//The {@code more} command does not have any parameters, so this action is -// implemented as a singleton instance exposed by {@link //INSTANCE}.
-function LexerMoreAction() { - LexerAction.call(this, LexerActionType.MORE); - return this; + toString() { + return "more"; + } } -LexerMoreAction.prototype = Object.create(LexerAction.prototype); -LexerMoreAction.prototype.constructor = LexerMoreAction; - LexerMoreAction.INSTANCE = new LexerMoreAction(); -//This action is implemented by calling {@link Lexer//popMode}.
-LexerMoreAction.prototype.execute = function(lexer) { - lexer.more(); -}; -LexerMoreAction.prototype.toString = function() { - return "more"; -}; +/** + * Implements the {@code mode} lexer action by calling {@link Lexer//mode} with + * the assigned mode + */ +class LexerModeAction extends LexerAction { + constructor(mode) { + super(LexerActionType.MODE); + this.mode = mode; + } + /** + *This action is implemented by calling {@link Lexer//mode} with the + * value provided by {@link //getMode}.
+ */ + execute(lexer) { + lexer.mode(this.mode); + } -// Implements the {@code mode} lexer action by calling {@link Lexer//mode} with -// the assigned mode. -function LexerModeAction(mode) { - LexerAction.call(this, LexerActionType.MODE); - this.mode = mode; - return this; + updateHashCode(hash) { + hash.update(this.actionType, this.mode); + } + + equals(other) { + if (this === other) { + return true; + } else if (! (other instanceof LexerModeAction)) { + return false; + } else { + return this.mode === other.mode; + } + } + + toString() { + return "mode(" + this.mode + ")"; + } } -LexerModeAction.prototype = Object.create(LexerAction.prototype); -LexerModeAction.prototype.constructor = LexerModeAction; - -//This action is implemented by calling {@link Lexer//mode} with the -// value provided by {@link //getMode}.
-LexerModeAction.prototype.execute = function(lexer) { - lexer.mode(this.mode); -}; - -LexerModeAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.mode); -}; - -LexerModeAction.prototype.equals = function(other) { - if (this === other) { - return true; - } else if (! (other instanceof LexerModeAction)) { - return false; - } else { - return this.mode === other.mode; +/** + * Executes a custom lexer action by calling {@link Recognizer//action} with the + * rule and action indexes assigned to the custom action. The implementation of + * a custom action is added to the generated code for the lexer in an override + * of {@link Recognizer//action} when the grammar is compiled. + * + *This class may represent embedded actions created with the {...}
+ * syntax in ANTLR 4, as well as actions created for lexer commands where the
+ * command argument could not be evaluated when the grammar was compiled.
Custom actions are implemented by calling {@link Lexer//action} with the + * appropriate rule and action indexes.
+ */ + execute(lexer) { + lexer.action(null, this.ruleIndex, this.actionIndex); + } -// Executes a custom lexer action by calling {@link Recognizer//action} with the -// rule and action indexes assigned to the custom action. The implementation of -// a custom action is added to the generated code for the lexer in an override -// of {@link Recognizer//action} when the grammar is compiled. -// -//This class may represent embedded actions created with the {...}
-// syntax in ANTLR 4, as well as actions created for lexer commands where the
-// command argument could not be evaluated when the grammar was compiled.
Custom actions are implemented by calling {@link Lexer//action} with the -// appropriate rule and action indexes.
-LexerCustomAction.prototype.execute = function(lexer) { - lexer.action(null, this.ruleIndex, this.actionIndex); -}; - -LexerCustomAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.ruleIndex, this.actionIndex); -}; - -LexerCustomAction.prototype.equals = function(other) { - if (this === other) { - return true; - } else if (! (other instanceof LexerCustomAction)) { - return false; - } else { - return this.ruleIndex === other.ruleIndex && this.actionIndex === other.actionIndex; +/** + * Implements the {@code channel} lexer action by calling + * {@link Lexer//setChannel} with the assigned channel. + * Constructs a new {@code channel} action with the specified channel value. + * @param channel The channel value to pass to {@link Lexer//setChannel} + */ +class LexerChannelAction extends LexerAction { + constructor(channel) { + super(LexerActionType.CHANNEL); + this.channel = channel; } -}; -// Implements the {@code channel} lexer action by calling -// {@link Lexer//setChannel} with the assigned channel. -// Constructs a new {@code channel} action with the specified channel value. -// @param channel The channel value to pass to {@link Lexer//setChannel}. -function LexerChannelAction(channel) { - LexerAction.call(this, LexerActionType.CHANNEL); - this.channel = channel; - return this; + /** + *This action is implemented by calling {@link Lexer//setChannel} with the + * value provided by {@link //getChannel}.
+ */ + execute(lexer) { + lexer._channel = this.channel; + } + + updateHashCode(hash) { + hash.update(this.actionType, this.channel); + } + + equals(other) { + if (this === other) { + return true; + } else if (! (other instanceof LexerChannelAction)) { + return false; + } else { + return this.channel === other.channel; + } + } + + toString() { + return "channel(" + this.channel + ")"; + } } -LexerChannelAction.prototype = Object.create(LexerAction.prototype); -LexerChannelAction.prototype.constructor = LexerChannelAction; -//This action is implemented by calling {@link Lexer//setChannel} with the -// value provided by {@link //getChannel}.
-LexerChannelAction.prototype.execute = function(lexer) { - lexer._channel = this.channel; -}; - -LexerChannelAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.channel); -}; - -LexerChannelAction.prototype.equals = function(other) { - if (this === other) { - return true; - } else if (! (other instanceof LexerChannelAction)) { - return false; - } else { - return this.channel === other.channel; +/** + * This implementation of {@link LexerAction} is used for tracking input offsets + * for position-dependent actions within a {@link LexerActionExecutor}. + * + *This action is not serialized as part of the ATN, and is only required for + * position-dependent lexer actions which appear at a location other than the + * end of a rule. For more information about DFA optimizations employed for + * lexer actions, see {@link LexerActionExecutor//append} and + * {@link LexerActionExecutor//fixOffsetBeforeMatch}.
+ * + * Constructs a new indexed custom action by associating a character offset + * with a {@link LexerAction}. + * + *Note: This class is only required for lexer actions for which + * {@link LexerAction//isPositionDependent} returns {@code true}.
+ * + * @param offset The offset into the input {@link CharStream}, relative to + * the token start index, at which the specified lexer action should be + * executed. + * @param action The lexer action to execute at a particular offset in the + * input {@link CharStream}. + */ +class LexerIndexedCustomAction extends LexerAction { + constructor(offset, action) { + super(action.actionType); + this.offset = offset; + this.action = action; + this.isPositionDependent = true; } -}; -LexerChannelAction.prototype.toString = function() { - return "channel(" + this.channel + ")"; -}; + /** + *This method calls {@link //execute} on the result of {@link //getAction} + * using the provided {@code lexer}.
+ */ + execute(lexer) { + // assume the input stream position was properly set by the calling code + this.action.execute(lexer); + } -// This implementation of {@link LexerAction} is used for tracking input offsets -// for position-dependent actions within a {@link LexerActionExecutor}. -// -//This action is not serialized as part of the ATN, and is only required for -// position-dependent lexer actions which appear at a location other than the -// end of a rule. For more information about DFA optimizations employed for -// lexer actions, see {@link LexerActionExecutor//append} and -// {@link LexerActionExecutor//fixOffsetBeforeMatch}.
+ updateHashCode(hash) { + hash.update(this.actionType, this.offset, this.action); + } -// Constructs a new indexed custom action by associating a character offset -// with a {@link LexerAction}. -// -//Note: This class is only required for lexer actions for which -// {@link LexerAction//isPositionDependent} returns {@code true}.
-// -// @param offset The offset into the input {@link CharStream}, relative to -// the token start index, at which the specified lexer action should be -// executed. -// @param action The lexer action to execute at a particular offset in the -// input {@link CharStream}. -function LexerIndexedCustomAction(offset, action) { - LexerAction.call(this, action.actionType); - this.offset = offset; - this.action = action; - this.isPositionDependent = true; - return this; + equals(other) { + if (this === other) { + return true; + } else if (! (other instanceof LexerIndexedCustomAction)) { + return false; + } else { + return this.offset === other.offset && this.action === other.action; + } + } } -LexerIndexedCustomAction.prototype = Object.create(LexerAction.prototype); -LexerIndexedCustomAction.prototype.constructor = LexerIndexedCustomAction; - -//This method calls {@link //execute} on the result of {@link //getAction} -// using the provided {@code lexer}.
-LexerIndexedCustomAction.prototype.execute = function(lexer) { - // assume the input stream position was properly set by the calling code - this.action.execute(lexer); -}; - -LexerIndexedCustomAction.prototype.updateHashCode = function(hash) { - hash.update(this.actionType, this.offset, this.action); -}; - -LexerIndexedCustomAction.prototype.equals = function(other) { - if (this === other) { - return true; - } else if (! (other instanceof LexerIndexedCustomAction)) { - return false; - } else { - return this.offset === other.offset && this.action === other.action; - } -}; - - -exports.LexerActionType = LexerActionType; -exports.LexerSkipAction = LexerSkipAction; -exports.LexerChannelAction = LexerChannelAction; -exports.LexerCustomAction = LexerCustomAction; -exports.LexerIndexedCustomAction = LexerIndexedCustomAction; -exports.LexerMoreAction = LexerMoreAction; -exports.LexerTypeAction = LexerTypeAction; -exports.LexerPushModeAction = LexerPushModeAction; -exports.LexerPopModeAction = LexerPopModeAction; -exports.LexerModeAction = LexerModeAction; \ No newline at end of file +module.exports = { + LexerActionType, + LexerSkipAction, + LexerChannelAction, + LexerCustomAction, + LexerIndexedCustomAction, + LexerMoreAction, + LexerTypeAction, + LexerPushModeAction, + LexerPopModeAction, + LexerModeAction +}