More const refactorings

This commit is contained in:
Peter Boyer 2015-12-15 16:58:12 -05:00
parent 729f30768a
commit a8da94cb2e
16 changed files with 230 additions and 205 deletions

View File

@ -21,7 +21,7 @@ func NewCommonTokenFactory(copyText bool) CommonTokenFactory {
// where the input stream might not be able to provide arbitrary substrings
// of text from the input after the lexer creates a token (e.g. the
// implementation of {@link CharStream//getText} in
// {@link UnbufferedCharStream} throws an
// {@link UnbufferedCharStream} panics an
// {@link UnsupportedOperationException}). Explicitly setting the token text
// allows {@link Token//getText} to be called at any time regardless of the
// input stream implementation.

View File

@ -94,7 +94,7 @@ func (p.*Parser) reset() {
//
// @param ttype the token type to match
// @return the matched symbol
// @throws RecognitionException if the current input symbol did not match
// @panics RecognitionException if the current input symbol did not match
// {@code ttype} and the error strategy could not recover from the
// mismatched symbol
@ -126,7 +126,7 @@ func (p.*Parser) match(ttype) {
// the parse tree by calling {@link ParserRuleContext//addErrorNode}.</p>
//
// @return the matched symbol
// @throws RecognitionException if the current input symbol did not match
// @panics RecognitionException if the current input symbol did not match
// a wildcard and the error strategy could not recover from the mismatched
// symbol
@ -177,11 +177,11 @@ func (p.*Parser) getParseListeners() {
//
// @param listener the listener to add
//
// @throws nilPointerException if {@code} listener is {@code nil}
// @panics nilPointerException if {@code} listener is {@code nil}
//
func (p.*Parser) addParseListener(listener) {
if (listener == nil) {
throw "listener"
panic "listener"
}
if (p._parseListeners == nil) {
p._parseListeners = []
@ -252,13 +252,13 @@ func (p.*Parser) setTokenFactory(factory) {
// The ATN with bypass alternatives is expensive to create so we create it
// lazily.
//
// @throws UnsupportedOperationException if the current parser does not
// @panics UnsupportedOperationException if the current parser does not
// implement the {@link //getSerializedATN()} method.
//
func (p.*Parser) getATNWithBypassAlts() {
var serializedAtn = p.getSerializedATN()
if (serializedAtn == nil) {
throw "The current parser does not support an ATN with bypass alternatives."
panic "The current parser does not support an ATN with bypass alternatives."
}
var result = p.bypassAltsAtnCache[serializedAtn]
if (result == nil) {
@ -295,7 +295,7 @@ func (p.*Parser) compileParseTreePattern(pattern, patternRuleIndex, lexer) {
}
}
if (lexer == nil) {
throw "Parser can't discover a lexer to use"
panic "Parser can't discover a lexer to use"
}
var m = NewParseTreePatternMatcher(lexer, p.
return m.compile(pattern, patternRuleIndex)

View File

@ -32,7 +32,7 @@ func (this *Recognizer) removeErrorListeners() {
func (this *Recognizer) getTokenTypeMap() {
var tokenNames = this.getTokenNames()
if (tokenNames==nil) {
throw("The current recognizer does not provide a list of token names.")
panic("The current recognizer does not provide a list of token names.")
}
var result = this.tokenTypeMapCache[tokenNames]
if(result==undefined) {
@ -50,7 +50,7 @@ func (this *Recognizer) getTokenTypeMap() {
func (this *Recognizer) getRuleIndexMap() {
var ruleNames = this.getRuleNames()
if (ruleNames==nil) {
throw("The current recognizer does not provide a list of rule names.")
panic("The current recognizer does not provide a list of rule names.")
}
var result = this.ruleIndexMapCache[ruleNames]
if(result==undefined) {

View File

@ -120,14 +120,14 @@ func (this *ATN) getDecisionState( decision) {
// @param context the full parse context
// @return The set of potentially valid input symbols which could follow the
// specified state in the specified context.
// @throws IllegalArgumentException if the ATN does not contain a state with
// @panics IllegalArgumentException if the ATN does not contain a state with
// number {@code stateNumber}
var Token = require('./../Token').Token
func (this *ATN) getExpectedTokens( stateNumber, ctx ) {
if ( stateNumber < 0 || stateNumber >= this.states.length ) {
throw("Invalid state number.")
panic("Invalid state number.")
}
var s = this.states[stateNumber]
var following = this.nextTokens(s)

View File

@ -85,7 +85,7 @@ func (this *ATNConfigSet) add(config, mergeCache) {
mergeCache = nil
}
if (this.readOnly) {
throw "This set is readonly"
panic "This set is readonly"
}
if (config.semanticContext != SemanticContext.NONE) {
this.hasSemanticContext = true
@ -141,7 +141,7 @@ Object.defineProperty(ATNConfigSet.prototype, "items", {
func (this *ATNConfigSet) optimizeConfigs(interpreter) {
if (this.readOnly) {
throw "This set is readonly"
panic "This set is readonly"
}
if (this.configLookup.length == 0) {
return
@ -204,21 +204,21 @@ func (this *ATNConfigSet) isEmpty() {
func (this *ATNConfigSet) contains(item) {
if (this.configLookup == nil) {
throw "This method is not implemented for readonly sets."
panic "This method is not implemented for readonly sets."
}
return this.configLookup.contains(item)
}
func (this *ATNConfigSet) containsFast(item) {
if (this.configLookup == nil) {
throw "This method is not implemented for readonly sets."
panic "This method is not implemented for readonly sets."
}
return this.configLookup.containsFast(item)
}
func (this *ATNConfigSet) clear() {
if (this.readOnly) {
throw "This set is readonly"
panic "This set is readonly"
}
this.configs = []
this.cachedHashString = "-1"

View File

@ -110,7 +110,7 @@ func (this *ATNDeserializer) deserialize(data) {
this.readLexerActions(atn)
this.markPrecedenceDecisions(atn)
this.verifyATN(atn)
if (this.deserializationOptions.generateRuleBypassTransitions && atn.grammarType == ATNType.PARSER ) {
if (this.deserializationOptions.generateRuleBypassTransitions && atn.grammarType == ATNTypeParser ) {
this.generateRuleBypassTransitions(atn)
// re-verify after modification
this.verifyATN(atn)
@ -133,14 +133,14 @@ func (this *ATNDeserializer) reset(data) {
func (this *ATNDeserializer) checkVersion() {
var version = this.readInt()
if ( version != SERIALIZED_VERSION ) {
throw ("Could not deserialize ATN with version " + version + " (expected " + SERIALIZED_VERSION + ").")
panic ("Could not deserialize ATN with version " + version + " (expected " + SERIALIZED_VERSION + ").")
}
}
func (this *ATNDeserializer) checkUUID() {
var uuid = this.readUUID()
if (SUPPORTED_UUIDS.indexOf(uuid)<0) {
throw ("Could not deserialize ATN with UUID: " + uuid +
panic ("Could not deserialize ATN with UUID: " + uuid +
" (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID)
}
this.uuid = uuid
@ -160,7 +160,7 @@ func (this *ATNDeserializer) readStates(atn) {
for(var i=0 i<nstates i++) {
var stype = this.readInt()
// ignore bad type of states
if (stype==ATNState.INVALID_TYPE) {
if (stype==ATNStateInvalidType) {
atn.addState(nil)
continue
}
@ -169,7 +169,7 @@ func (this *ATNDeserializer) readStates(atn) {
ruleIndex = -1
}
var s = this.stateFactory(stype, ruleIndex)
if (stype == ATNState.LOOP_END) { // special case
if (stype == ATNStateLOOP_END) { // special case
var loopBackStateNumber = this.readInt()
loopBackStateNumbers.push([s, loopBackStateNumber])
} else if(s instanceof BlockStartState) {
@ -206,7 +206,7 @@ func (this *ATNDeserializer) readStates(atn) {
func (this *ATNDeserializer) readRules(atn) {
var i
var nrules = this.readInt()
if (atn.grammarType == ATNType.LEXER ) {
if (atn.grammarType == ATNTypeLexer ) {
atn.ruleToTokenType = initArray(nrules, 0)
}
atn.ruleToStartState = initArray(nrules, 0)
@ -214,7 +214,7 @@ func (this *ATNDeserializer) readRules(atn) {
var s = this.readInt()
var startState = atn.states[s]
atn.ruleToStartState[i] = startState
if ( atn.grammarType == ATNType.LEXER ) {
if ( atn.grammarType == ATNTypeLexer ) {
var tokenType = this.readInt()
if (tokenType == 0xFFFF) {
tokenType = TokenEOF
@ -300,12 +300,12 @@ func (this *ATNDeserializer) readEdges(atn, sets) {
if (state instanceof BlockStartState) {
// we need to know the end state to set its start state
if (state.endState == nil) {
throw ("IllegalState")
panic ("IllegalState")
}
// block end states can only be associated to a single block start
// state
if ( state.endState.startState != nil) {
throw ("IllegalState")
panic ("IllegalState")
}
state.endState.startState = state
}
@ -338,7 +338,7 @@ func (this *ATNDeserializer) readDecisions(atn) {
}
func (this *ATNDeserializer) readLexerActions(atn) {
if (atn.grammarType == ATNType.LEXER) {
if (atn.grammarType == ATNTypeLexer) {
var count = this.readInt()
atn.lexerActions = initArray(count, nil)
for (var i=0 i<count i++) {
@ -398,7 +398,7 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
}
}
if (excludeTransition == nil) {
throw ("Couldn't identify final state of the precedence rule prefix section.")
panic ("Couldn't identify final state of the precedence rule prefix section.")
}
} else {
endState = atn.ruleToStopState[idx]
@ -508,7 +508,7 @@ func (this *ATNDeserializer) verifyATN(atn) {
this.checkCondition(state.transitions[1].target instanceof StarBlockStartState)
this.checkCondition(state.nonGreedy)
} else {
throw("IllegalState")
panic("IllegalState")
}
} else if (state instanceof StarLoopbackState) {
this.checkCondition(state.transitions.length == 1)
@ -534,7 +534,7 @@ func (this *ATNDeserializer) checkCondition(condition, message) {
if (message == undefined || message==nil) {
message = "IllegalState"
}
throw (message)
panic (message)
}
}
@ -606,30 +606,30 @@ ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2
case Transition.WILDCARD:
return NewWildcardTransition(target)
default:
throw "The specified transition type: " + type + " is not valid."
panic "The specified transition type: " + type + " is not valid."
}
}
func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
if (this.stateFactories == nil) {
var sf = []
sf[ATNState.INVALID_TYPE] = nil
sf[ATNState.BASIC] = function() { return NewBasicState() }
sf[ATNState.RULE_START] = function() { return NewRuleStartState() }
sf[ATNState.BLOCK_START] = function() { return NewBasicBlockStartState() }
sf[ATNState.PLUS_BLOCK_START] = function() { return NewPlusBlockStartState() }
sf[ATNState.STAR_BLOCK_START] = function() { return NewStarBlockStartState() }
sf[ATNState.TOKEN_START] = function() { return NewTokensStartState() }
sf[ATNState.RULE_STOP] = function() { return NewRuleStopState() }
sf[ATNState.BLOCK_END] = function() { return NewBlockEndState() }
sf[ATNState.STAR_LOOP_BACK] = function() { return NewStarLoopbackState() }
sf[ATNState.STAR_LOOP_ENTRY] = function() { return NewStarLoopEntryState() }
sf[ATNState.PLUS_LOOP_BACK] = function() { return NewPlusLoopbackState() }
sf[ATNState.LOOP_END] = function() { return NewLoopEndState() }
sf[ATNStateInvalidType] = nil
sf[ATNStateBASIC] = function() { return NewBasicState() }
sf[ATNStateRULE_START] = function() { return NewRuleStartState() }
sf[ATNStateBLOCK_START] = function() { return NewBasicBlockStartState() }
sf[ATNStatePLUS_BLOCK_START] = function() { return NewPlusBlockStartState() }
sf[ATNStateSTAR_BLOCK_START] = function() { return NewStarBlockStartState() }
sf[ATNStateTOKEN_START] = function() { return NewTokensStartState() }
sf[ATNStateRULE_STOP] = function() { return NewRuleStopState() }
sf[ATNStateBLOCK_END] = function() { return NewBlockEndState() }
sf[ATNStateSTAR_LOOP_BACK] = function() { return NewStarLoopbackState() }
sf[ATNStateSTAR_LOOP_ENTRY] = function() { return NewStarLoopEntryState() }
sf[ATNStatePLUS_LOOP_BACK] = function() { return NewPlusLoopbackState() }
sf[ATNStateLOOP_END] = function() { return NewLoopEndState() }
this.stateFactories = sf
}
if (type>this.stateFactories.length || this.stateFactories[type] == nil) {
throw("The specified state type " + type + " is not valid.")
panic("The specified state type " + type + " is not valid.")
} else {
var s = this.stateFactories[type]()
if (s!=nil) {
@ -642,18 +642,18 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
ATNDeserializer.prototype.lexerActionFactory = function(type, data1, data2) {
if (this.actionFactories == nil) {
var af = []
af[LexerActionType.CHANNEL] = function(data1, data2) { return NewLexerChannelAction(data1) }
af[LexerActionType.CUSTOM] = function(data1, data2) { return NewLexerCustomAction(data1, data2) }
af[LexerActionType.MODE] = function(data1, data2) { return NewLexerModeAction(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 NewLexerPushModeAction(data1) }
af[LexerActionType.SKIP] = function(data1, data2) { return LexerSkipAction.INSTANCE }
af[LexerActionType.TYPE] = function(data1, data2) { return NewLexerTypeAction(data1) }
af[LexerActionTypeCHANNEL] = function(data1, data2) { return NewLexerChannelAction(data1) }
af[LexerActionTypeCUSTOM] = function(data1, data2) { return NewLexerCustomAction(data1, data2) }
af[LexerActionTypeMODE] = function(data1, data2) { return NewLexerModeAction(data1) }
af[LexerActionTypeMORE] = function(data1, data2) { return LexerMoreAction.INSTANCE }
af[LexerActionTypePOP_MODE] = function(data1, data2) { return LexerPopModeAction.INSTANCE }
af[LexerActionTypePUSH_MODE] = function(data1, data2) { return NewLexerPushModeAction(data1) }
af[LexerActionTypeSKIP] = function(data1, data2) { return LexerSkipAction.INSTANCE }
af[LexerActionTypeTYPE] = function(data1, data2) { return NewLexerTypeAction(data1) }
this.actionFactories = af
}
if (type>this.actionFactories.length || this.actionFactories[type] == nil) {
throw("The specified lexer action type " + type + " is not valid.")
panic("The specified lexer action type " + type + " is not valid.")
} else {
return this.actionFactories[type](data1, data2)
}

View File

@ -63,35 +63,56 @@ package atn
var INITIAL_NUM_TRANSITIONS = 4
type ATNState struct {
// Which ATN are we in?
this.atn = nil
this.stateNumber = ATNState.INVALID_STATE_NUMBER
this.stateType = nil
this.ruleIndex = 0 // at runtime, we don't have Rule objects
this.epsilonOnlyTransitions = false
// Track the transitions emanating from this ATN state.
this.transitions = []
// Used to cache lookahead during parsing, not used during construction
this.nextTokenWithinRule = nil
return this
// Which ATN are we in?
atn *ATN
stateNumber int
stateType int
ruleIndex int
epsilonOnlyTransitions bool
// Track the transitions emanating from this ATN state.
transitions []Transition
// Used to cache lookahead during parsing, not used during construction
nextTokenWithinRule *Token
}
// constants for serialization
ATNState.INVALID_TYPE = 0
ATNState.BASIC = 1
ATNState.RULE_START = 2
ATNState.BLOCK_START = 3
ATNState.PLUS_BLOCK_START = 4
ATNState.STAR_BLOCK_START = 5
ATNState.TOKEN_START = 6
ATNState.RULE_STOP = 7
ATNState.BLOCK_END = 8
ATNState.STAR_LOOP_BACK = 9
ATNState.STAR_LOOP_ENTRY = 10
ATNState.PLUS_LOOP_BACK = 11
ATNState.LOOP_END = 12
func NewATNState() *ATNState {
ATNState.serializationNames = [
as := new(ATNState)
// Which ATN are we in?
as.atn = nil
as.stateNumber = ATNStateINVALID_STATE_NUMBER
as.stateType = nil
as.ruleIndex = 0 // at runtime, we don't have Rule objects
as.epsilonOnlyTransitions = false
// Track the transitions emanating from this ATN state.
as.transitions = make([]Transition, 0)
// Used to cache lookahead during parsing, not used during construction
as.nextTokenWithinRule = nil
return as
}
const (
// constants for serialization
ATNStateInvalidType = 0
ATNStateBASIC = 1
ATNStateRULE_START = 2
ATNStateBLOCK_START = 3
ATNStatePLUS_BLOCK_START = 4
ATNStateSTAR_BLOCK_START = 5
ATNStateTOKEN_START = 6
ATNStateRULE_STOP = 7
ATNStateBLOCK_END = 8
ATNStateSTAR_LOOP_BACK = 9
ATNStateSTAR_LOOP_ENTRY = 10
ATNStatePLUS_LOOP_BACK = 11
ATNStateLOOP_END = 12
ATNStateINVALID_STATE_NUMBER = -1
)
var ATNState.serializationNames = [
"INVALID",
"BASIC",
"RULE_START",
@ -106,15 +127,13 @@ ATNState.serializationNames = [
"PLUS_LOOP_BACK",
"LOOP_END" ]
ATNState.INVALID_STATE_NUMBER = -1
func (this *ATNState) toString() {
return this.stateNumber
}
func (this *ATNState) equals(other) {
if (other instanceof ATNState) {
return this.stateNumber==other.stateNumber
func (this *ATNState) equals(other *ATNState) bool {
if ok := other.(ATNState); ok {
return this.stateNumber == other.stateNumber
} else {
return false
}
@ -125,11 +144,8 @@ func (this *ATNState) isNonGreedyExitState() {
}
func (this *ATNState) addTransition(trans, index) {
if(index==undefined) {
index = -1
}
if (this.transitions.length==0) {
func (this *ATNState) addTransition(trans int, index int) {
if ( len(this.transitions) == 0 ) {
this.epsilonOnlyTransitions = trans.isEpsilon
} else if(this.epsilonOnlyTransitions != trans.isEpsilon) {
this.epsilonOnlyTransitions = false
@ -142,96 +158,98 @@ func (this *ATNState) addTransition(trans, index) {
}
type BasicState struct {
}
func NewBasicState() *BasicState {
ATNState.call(this)
this.stateType = ATNState.BASIC
this.stateType = ATNStateBASIC
return this
}
BasicState.prototype = Object.create(ATNState.prototype)
BasicState.prototype.constructor = BasicState
type DecisionState struct {
}
func NewDecisionState() *DecisionState {
ATNState.call(this)
this.decision = -1
this.nonGreedy = false
return this
}
DecisionState.prototype = Object.create(ATNState.prototype)
DecisionState.prototype.constructor = DecisionState
// The start of a regular {@code (...)} block.
type BlockStartState struct {
}
func NewBlockStartState() *BlockStartState {
DecisionState.call(this)
this.endState = nil
return this
}
BlockStartState.prototype = Object.create(DecisionState.prototype)
BlockStartState.prototype.constructor = BlockStartState
type BasicBlockStartState struct {
}
func NewBasicBlockStartState() *BasicBlockStartState {
BlockStartState.call(this)
this.stateType = ATNState.BLOCK_START
this.stateType = ATNStateBLOCK_START
return this
}
BasicBlockStartState.prototype = Object.create(BlockStartState.prototype)
BasicBlockStartState.prototype.constructor = BasicBlockStartState
// Terminal node of a simple {@code (a|b|c)} block.
type BlockEndState struct {
}
func NewBlockEndState() *BlockEndState {
ATNState.call(this)
this.stateType = ATNState.BLOCK_END
this.stateType = ATNStateBLOCK_END
this.startState = nil
return this
}
BlockEndState.prototype = Object.create(ATNState.prototype)
BlockEndState.prototype.constructor = BlockEndState
// The last node in the ATN for a rule, unless that rule is the start symbol.
// In that case, there is one transition to EOF. Later, we might encode
// references to all calls to this rule to compute FOLLOW sets for
// error handling.
//
type RuleStopState struct {
}
func NewRuleStopState() *RuleStopState {
ATNState.call(this)
this.stateType = ATNState.RULE_STOP
this.stateType = ATNStateRULE_STOP
return this
}
RuleStopState.prototype = Object.create(ATNState.prototype)
RuleStopState.prototype.constructor = RuleStopState
type RuleStartState struct {
}
func NewRuleStartState() *RuleStartState {
ATNState.call(this)
this.stateType = ATNState.RULE_START
this.stateType = ATNStateRULE_START
this.stopState = nil
this.isPrecedenceRule = false
return this
}
RuleStartState.prototype = Object.create(ATNState.prototype)
RuleStartState.prototype.constructor = RuleStartState
// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions:
// one to the loop back to start of the block and one to exit.
//
type PlusLoopbackState struct {
DecisionState.call(this)
this.stateType = ATNState.PLUS_LOOP_BACK
return this
}
PlusLoopbackState.prototype = Object.create(DecisionState.prototype)
PlusLoopbackState.prototype.constructor = PlusLoopbackState
func NewPlusLoopbackState() *PlusLoopbackState {
DecisionState.call(this)
this.stateType = ATNStatePLUS_LOOP_BACK
return this
}
// Start of {@code (A|B|...)+} loop. Technically a decision state, but
// we don't use for code generation somebody might need it, so I'm defining
@ -239,72 +257,76 @@ PlusLoopbackState.prototype.constructor = PlusLoopbackState
// real decision-making note for {@code A+}.
//
type PlusBlockStartState struct {
}
func NewPlusBlockStartState() *PlusBlockStartState {
BlockStartState.call(this)
this.stateType = ATNState.PLUS_BLOCK_START
this.stateType = ATNStatePLUS_BLOCK_START
this.loopBackState = nil
return this
}
PlusBlockStartState.prototype = Object.create(BlockStartState.prototype)
PlusBlockStartState.prototype.constructor = PlusBlockStartState
// The block that begins a closure loop.
type StarBlockStartState struct {
BlockStartState.call(this)
this.stateType = ATNState.STAR_BLOCK_START
return this
}
StarBlockStartState.prototype = Object.create(BlockStartState.prototype)
StarBlockStartState.prototype.constructor = StarBlockStartState
func NewStarBlockStartState() *StarBlockStartState {
BlockStartState.call(this)
this.stateType = ATNStateSTAR_BLOCK_START
return this
}
type StarLoopbackState struct {
}
func NewStarLoopbackState() *StarLoopbackState {
ATNState.call(this)
this.stateType = ATNState.STAR_LOOP_BACK
this.stateType = ATNStateSTAR_LOOP_BACK
return this
}
StarLoopbackState.prototype = Object.create(ATNState.prototype)
StarLoopbackState.prototype.constructor = StarLoopbackState
type StarLoopEntryState struct {
}
func NewStarLoopEntryState() *StarLoopEntryState {
DecisionState.call(this)
this.stateType = ATNState.STAR_LOOP_ENTRY
this.stateType = ATNStateSTAR_LOOP_ENTRY
this.loopBackState = nil
// Indicates whether this state can benefit from a precedence DFA during SLL decision making.
this.precedenceRuleDecision = nil
return this
}
StarLoopEntryState.prototype = Object.create(DecisionState.prototype)
StarLoopEntryState.prototype.constructor = StarLoopEntryState
// Mark the end of a * or + loop.
type LoopEndState struct {
}
func NewLoopEndState() *LoopEndState {
ATNState.call(this)
this.stateType = ATNState.LOOP_END
this.stateType = ATNStateLOOP_END
this.loopBackState = nil
return this
}
LoopEndState.prototype = Object.create(ATNState.prototype)
LoopEndState.prototype.constructor = LoopEndState
// The Tokens rule start state linking to each lexer rule start state */
type TokensStartState struct {
}
func NewTokensStartState() *TokensStartState {
DecisionState.call(this)
this.stateType = ATNState.TOKEN_START
this.stateType = ATNStateTOKEN_START
return this
}
TokensStartState.prototype = Object.create(DecisionState.prototype)
TokensStartState.prototype.constructor = TokensStartState

View File

@ -6,8 +6,9 @@ type ATNType struct {
}
ATNType.LEXER = 0
ATNType.PARSER = 1
const (
ATNTypeLexer = 0
ATNTypeParser = 1
)

View File

@ -241,7 +241,7 @@ func (this *LexerATNSimulator) computeTargetState(input, s, t) {
if (reach.items.length == 0) { // we got nowhere on t from s
if (!reach.hasSemanticContext) {
// we got nowhere on t, don't throw out this knowledge it'd
// we got nowhere on t, don't panic out this knowledge it'd
// cause a failover from DFA later.
this.addDFAEdge(s, t, ATNSimulator.ERROR)
}
@ -263,7 +263,7 @@ func (this *LexerATNSimulator) failOrAccept(prevAccept, input, reach, t) {
if (t == TokenEOF && input.index == this.startIndex) {
return TokenEOF
}
throw NewLexerNoViableAltException(this.recog, input, this.startIndex, reach)
panic NewLexerNoViableAltException(this.recog, input, this.startIndex, reach)
}
}
@ -409,7 +409,7 @@ func (this *LexerATNSimulator) getEpsilonTarget(input, config, trans,
var newContext = SingletonPredictionContext.create(config.context, trans.followState.stateNumber)
cfg = NewLexerATNConfig( { state:trans.target, context:newContext}, config)
} else if (trans.serializationType == Transition.PRECEDENCE) {
throw "Precedence predicates are not supported in lexers."
panic "Precedence predicates are not supported in lexers."
} else if (trans.serializationType == Transition.PREDICATE) {
// Track traversing semantic predicates. If we traverse,
// we cannot add a DFA state for this "reach" computation

View File

@ -3,14 +3,16 @@ package atn
type LexerActionType struct {
}
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.
const (
LexerActionTypeCHANNEL = 0 //The type of a {@link LexerChannelAction} action.
LexerActionTypeCUSTOM = 1 //The type of a {@link LexerCustomAction} action.
LexerActionTypeMODE = 2 //The type of a {@link LexerModeAction} action.
LexerActionTypeMORE = 3 //The type of a {@link LexerMoreAction} action.
LexerActionTypePOP_MODE = 4 //The type of a {@link LexerPopModeAction} action.
LexerActionTypePUSH_MODE = 5 //The type of a {@link LexerPushModeAction} action.
LexerActionTypeSKIP = 6 //The type of a {@link LexerSkipAction} action.
LexerActionTypeTYPE = 7 //The type of a {@link LexerTypeAction} action.
)
func LexerAction(action) {
this.actionType = action
@ -34,7 +36,7 @@ func (this *LexerAction) equals(other) {
// <p>The {@code skip} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerSkipAction struct {
LexerAction.call(this, LexerActionType.SKIP)
LexerAction.call(this, LexerActionTypeSKIP)
return this
}
@ -55,7 +57,7 @@ func (this *LexerSkipAction) toString() {
// Implements the {@code type} lexer action by calling {@link Lexer//setType}
// with the assigned type.
func LexerTypeAction(type) {
LexerAction.call(this, LexerActionType.TYPE)
LexerAction.call(this, LexerActionTypeTYPE)
this.type = type
return this
}
@ -89,7 +91,7 @@ func (this *LexerTypeAction) toString() {
// Implements the {@code pushMode} lexer action by calling
// {@link Lexer//pushMode} with the assigned mode.
func LexerPushModeAction(mode) {
LexerAction.call(this, LexerActionType.PUSH_MODE)
LexerAction.call(this, LexerActionTypePUSH_MODE)
this.mode = mode
return this
}
@ -127,7 +129,7 @@ func (this *LexerPushModeAction) toString() {
// <p>The {@code popMode} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerPopModeAction struct {
LexerAction.call(this,LexerActionType.POP_MODE)
LexerAction.call(this,LexerActionTypePOP_MODE)
return this
}
@ -150,7 +152,7 @@ func (this *LexerPopModeAction) toString() {
// <p>The {@code more} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerMoreAction struct {
LexerAction.call(this, LexerActionType.MORE)
LexerAction.call(this, LexerActionTypeMORE)
return this
}
@ -172,7 +174,7 @@ func (this *LexerMoreAction) toString() {
// Implements the {@code mode} lexer action by calling {@link Lexer//mode} with
// the assigned mode.
func LexerModeAction(mode) {
LexerAction.call(this, LexerActionType.MODE)
LexerAction.call(this, LexerActionTypeMODE)
this.mode = mode
return this
}
@ -223,7 +225,7 @@ func (this *LexerModeAction) toString() {
// {@link Recognizer//action}.
func LexerCustomAction(ruleIndex, actionIndex) {
LexerAction.call(this, LexerActionType.CUSTOM)
LexerAction.call(this, LexerActionTypeCUSTOM)
this.ruleIndex = ruleIndex
this.actionIndex = actionIndex
this.isPositionDependent = true
@ -258,7 +260,7 @@ func (this *LexerCustomAction) equals(other) {
// Constructs a New{@code channel} action with the specified channel value.
// @param channel The channel value to pass to {@link Lexer//setChannel}.
func LexerChannelAction(channel) {
LexerAction.call(this, LexerActionType.CHANNEL)
LexerAction.call(this, LexerActionTypeCHANNEL)
this.channel = channel
return this
}

View File

@ -123,7 +123,7 @@ package atn
// When building a DFA accept state during ATN simulation, we evaluate any
// predicates and return the sole semantically valid alternative. If there is
// more than 1 alternative, we report an ambiguity. If there are 0 alternatives,
// we throw an exception. Alternatives without predicates act like they have
// we panic an exception. Alternatives without predicates act like they have
// true predicates. The simple way to think about it is to strip away all
// alternatives with false predicates and choose the minimum alternative that
// remains.</p>
@ -131,7 +131,7 @@ package atn
// <p>
// When we start in the DFA and reach an accept state that's predicated, we test
// those and return the minimum semantically viable alternative. If no
// alternatives are viable, we throw an exception.</p>
// alternatives are viable, we panic an exception.</p>
//
// <p>
// During full LL ATN simulation, closure always evaluates predicates and
@ -434,7 +434,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
if(alt!=ATN.INVALID_ALT_NUMBER) {
return alt
} else {
throw e
panic e
}
}
if(D.requiresFullContext && this.predictionMode != PredictionMode.SLL) {
@ -478,7 +478,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
input.seek(startIndex)
var alts = this.evalSemanticContext(D.predicates, outerContext, true)
if (alts.length==0) {
throw this.noViableAlt(input, outerContext, D.configs, startIndex)
panic this.noViableAlt(input, outerContext, D.configs, startIndex)
} else if (alts.length==1) {
return alts.minValue()
} else {
@ -624,7 +624,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
if(alt!=ATN.INVALID_ALT_NUMBER) {
return alt
} else {
throw e
panic e
}
}
var altSubSets = PredictionMode.getConflictingAltSubsets(reach)
@ -1048,7 +1048,7 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts, altToPred) {
//
// This method is used to improve the localization of error messages by
// choosing an alternative rather than throwing a
// choosing an alternative rather than panicing a
// {@link NoViableAltException} in particular prediction scenarios where the
// {@link //ERROR} state was reached during ATN simulation.
//
@ -1075,7 +1075,7 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts, altToPred) {
// the parser. Specifically, this could occur if the <em>only</em> configuration
// capable of successfully parsing to the end of the decision rule is
// blocked by a semantic predicate. By choosing this alternative within
// {@link //adaptivePredict} instead of throwing a
// {@link //adaptivePredict} instead of panicing a
// {@link NoViableAltException}, the resulting
// {@link FailedPredicateException} in the parser will identify the specific
// predicate which is preventing the parser from successfully parsing the
@ -1207,7 +1207,7 @@ func (this *ParserATNSimulator) closureCheckingStopState(config, configs, closur
console.log("closure(" + config.toString(this.parser,true) + ")")
console.log("configs(" + configs.toString() + ")")
if(config.reachesIntoOuterContext>50) {
throw "problem"
panic "problem"
}
}
if (config.state instanceof RuleStopState) {

View File

@ -21,7 +21,7 @@ var PrecedencePredicate = require('./SemanticContext').PrecedencePredicate
func Transition (target) {
// The target of this transition.
if (target==undefined || target==nil) {
throw "target cannot be nil."
panic "target cannot be nil."
}
this.target = target
// Are we epsilon, action, sempred?

View File

@ -39,12 +39,12 @@ func DFA(atnStartState, decision) {
// @return The start state corresponding to the specified precedence, or
// {@code nil} if no start state exists for the specified precedence.
//
// @throws IllegalStateException if this is not a precedence DFA.
// @panics IllegalStateException if this is not a precedence DFA.
// @see //isPrecedenceDfa()
func (this *DFA) getPrecedenceStartState(precedence) {
if (!(this.precedenceDfa)) {
throw ("Only precedence DFAs may contain a precedence start state.")
panic ("Only precedence DFAs may contain a precedence start state.")
}
// s0.edges is never nil for a precedence DFA
if (precedence < 0 || precedence >= this.s0.edges.length) {
@ -59,12 +59,12 @@ func (this *DFA) getPrecedenceStartState(precedence) {
// @param startState The start state corresponding to the specified
// precedence.
//
// @throws IllegalStateException if this is not a precedence DFA.
// @panics IllegalStateException if this is not a precedence DFA.
// @see //isPrecedenceDfa()
//
func (this *DFA) setPrecedenceStartState(precedence, startState) {
if (!(this.precedenceDfa)) {
throw ("Only precedence DFAs may contain a precedence start state.")
panic ("Only precedence DFAs may contain a precedence start state.")
}
if (precedence < 0) {
return

View File

@ -52,7 +52,7 @@ func (this *ConsoleErrorListener) syntaxError(recognizer, offendingSymbol, line,
func ProxyErrorListener(delegates) {
ErrorListener.call(this)
if (delegates==nil) {
throw "delegates"
panic "delegates"
}
this.delegates = delegates
return this

View File

@ -226,19 +226,19 @@ func (this *DefaultErrorStrategy) sync(recognizer) {
return
}
switch (s.stateType) {
case ATNState.BLOCK_START:
case ATNState.STAR_BLOCK_START:
case ATNState.PLUS_BLOCK_START:
case ATNState.STAR_LOOP_ENTRY:
case ATNStateBLOCK_START:
case ATNStateSTAR_BLOCK_START:
case ATNStatePLUS_BLOCK_START:
case ATNStateSTAR_LOOP_ENTRY:
// report error and recover if possible
if( this.singleTokenDeletion(recognizer) != nil) {
return
} else {
throw NewInputMismatchException(recognizer)
panic NewInputMismatchException(recognizer)
}
break
case ATNState.PLUS_LOOP_BACK:
case ATNState.STAR_LOOP_BACK:
case ATNStatePLUS_LOOP_BACK:
case ATNStateSTAR_LOOP_BACK:
this.reportUnwantedToken(recognizer)
var expecting = NewIntervalSet()
expecting.addSet(recognizer.getExpectedTokens())
@ -363,7 +363,7 @@ func (this *DefaultErrorStrategy) reportMissingToken(recognizer) {
// <p>The default implementation attempts to recover from the mismatched input
// by using single token insertion and deletion as described below. If the
// recovery attempt fails, this method throws an
// recovery attempt fails, this method panics an
// {@link InputMismatchException}.</p>
//
// <p><strong>EXTRA TOKEN</strong> (single token deletion)</p>
@ -423,8 +423,8 @@ func (this *DefaultErrorStrategy) recoverInline(recognizer) {
if (this.singleTokenInsertion(recognizer)) {
return this.getMissingSymbol(recognizer)
}
// even that didn't work must throw the exception
throw NewInputMismatchException(recognizer)
// even that didn't work must panic the exception
panic NewInputMismatchException(recognizer)
}
//
@ -633,7 +633,7 @@ func (this *DefaultErrorStrategy) escapeWSAndQuote(s) {
// In this case, for input "[]", LA(1) is ']' and in the set, so we would
// not consume anything. After printing an error, rule c would
// return normally. Rule b would not find the required '^' though.
// At this point, it gets a mismatched token error and throws an
// At this point, it gets a mismatched token error and panics an
// exception (since LA(1) is not in the viable following token
// set). The rule exception handler tries to recover, but finds
// the same recovery set and doesn't consume anything. Rule b
@ -724,7 +724,7 @@ type BailErrorStrategy struct {
BailErrorStrategy.prototype = Object.create(DefaultErrorStrategy.prototype)
BailErrorStrategy.prototype.constructor = BailErrorStrategy
// Instead of recovering from exception {@code e}, re-throw it wrapped
// Instead of recovering from exception {@code e}, re-panic it wrapped
// in a {@link ParseCancellationException} so it is not caught by the
// rule func catches. Use {@link Exception//getCause()} to get the
// original {@link RecognitionException}.
@ -735,11 +735,11 @@ func (this *BailErrorStrategy) recover(recognizer, e) {
context.exception = e
context = context.parentCtx
}
throw NewParseCancellationException(e)
panic NewParseCancellationException(e)
}
// Make sure we don't attempt to recover inline if the parser
// successfully recovers, it won't throw an exception.
// successfully recovers, it won't panic an exception.
//
func (this *BailErrorStrategy) recoverInline(recognizer) {
this.recover(recognizer, NewInputMismatchException(recognizer))

View File

@ -42,7 +42,7 @@ RecognitionException.prototype.constructor = RecognitionException
//
// Gets the set of input symbols which could potentially follow the
// previously matched symbol at the time this exception was thrown.
// previously matched symbol at the time this exception was panicn.
//
// <p>If the set of expected tokens is not known and could not be computed,
// this method returns {@code nil}.</p>