Banish undefined to nil

This commit is contained in:
Peter Boyer 2015-12-16 16:08:00 -05:00
parent f9ef62e7b8
commit 2aad0fde60
13 changed files with 26 additions and 26 deletions

View File

@ -52,7 +52,7 @@ func (is *InputStream) consume() {
func (is *InputStream) LA(offset int) {
if (offset == 0) {
return 0 // undefined
return 0 // nil
}
if (offset < 0) {
offset += 1 // e.g., translate LA(-1) to use offset=0

View File

@ -19,7 +19,7 @@ import (
// Note text is not an actual field of a rule return value it is computed
// from start and stop using the input stream's toString() method. I
// could add a ctor to prc so that we can pass in and store the input
// stream, but I'm not sure we want to do that. It would seem to be undefined
// stream, but I'm not sure we want to do that. It would seem to be nil
// to get the .text property anyway if the rule matches tokens from multiple
// input streams.
//

View File

@ -66,7 +66,7 @@ func (this *Recognizer) getRuleIndexMap() {
panic("The current recognizer does not provide a list of rule names.")
}
var result = ruleIndexMapCache[ruleNames]
if(result==undefined) {
if(result==nil) {
result = ruleNames.reduce(function(o, k, i) { o[k] = i })
ruleIndexMapCache[ruleNames] = result
}
@ -75,7 +75,7 @@ func (this *Recognizer) getRuleIndexMap() {
func (this *Recognizer) getTokenType(tokenName string) int {
var ttype = this.getTokenTypeMap()[tokenName]
if (ttype !=undefined) {
if (ttype !=nil) {
return ttype
} else {
return TokenInvalidType

View File

@ -72,7 +72,7 @@ func (this *ATN) nextTokensNoContext(s) {
}
func (this *ATN) nextTokens(s, ctx) {
if ( ctx==undefined ) {
if ( ctx==nil ) {
return this.nextTokensNoContext(s)
} else {
return this.nextTokensInContext(s, ctx)

View File

@ -61,8 +61,8 @@ func ATNConfig(params, config) {
}
func (this *ATNConfig) checkContext(params, config) {
if((params.context==nil || params.context==undefined) &&
(config==nil || config.context==nil || config.context==undefined)) {
if((params.context==nil || params.context==nil) &&
(config==nil || config.context==nil || config.context==nil)) {
this.context = nil
}
}

View File

@ -44,7 +44,7 @@ func ATNConfigSet(fullCtx) {
// Indicates that this configuration set is part of a full context
// LL prediction. It will be used to determine how to merge $. With SLL
// it's a wildcard whereas it is not for LL context merge.
this.fullCtx = fullCtx == undefined ? true : fullCtx
this.fullCtx = fullCtx == nil ? true : fullCtx
// Indicates that the set of configurations is read-only. Do not
// allow any code to manipulate the set DFA states will point at
// the sets and they must not change. This does not protect the other
@ -81,7 +81,7 @@ func ATNConfigSet(fullCtx) {
// {@link //hasSemanticContext} when necessary.</p>
// /
func (this *ATNConfigSet) add(config, mergeCache) {
if (mergeCache == undefined) {
if (mergeCache == nil) {
mergeCache = nil
}
if (this.readOnly) {

View File

@ -1,7 +1,7 @@
package atn
func ATNDeserializationOptions(copyFrom) {
if(copyFrom==undefined) {
if(copyFrom==nil) {
copyFrom = nil
}
this.readOnly = false

View File

@ -65,7 +65,7 @@ func initArray( length, value) {
func ATNDeserializer (options) {
if ( options== undefined || options == nil ) {
if ( options== nil || options == nil ) {
options = ATNDeserializationOptions.defaultOptions
}
this.deserializationOptions = options
@ -531,7 +531,7 @@ func (this *ATNDeserializer) verifyATN(atn) {
func (this *ATNDeserializer) checkCondition(condition, message) {
if (!condition) {
if (message == undefined || message==nil) {
if (message == nil || message==nil) {
message = "IllegalState"
}
panic (message)

View File

@ -214,7 +214,7 @@ func (this *LexerATNSimulator) getExistingTargetState(s, t) {
}
var target = s.edges[t - LexerATNSimulator.MIN_DFA_EDGE]
if(target==undefined) {
if(target==nil) {
target = nil
}
if (this.debug && target != nil) {
@ -523,10 +523,10 @@ func (this *LexerATNSimulator) captureSimState(settings, input, dfaState) {
}
func (this *LexerATNSimulator) addDFAEdge(from_, tk, to, cfgs) {
if (to == undefined) {
if (to == nil) {
to = nil
}
if (cfgs == undefined) {
if (cfgs == nil) {
cfgs = nil
}
if (to == nil && cfgs != nil) {

View File

@ -86,9 +86,9 @@ SemanticContext.orContext = function(a, b) {
func Predicate(ruleIndex, predIndex, isCtxDependent) {
SemanticContext.call(this)
this.ruleIndex = ruleIndex == undefined ? -1 : ruleIndex
this.predIndex = predIndex == undefined ? -1 : predIndex
this.isCtxDependent = isCtxDependent == undefined ? false : isCtxDependent // e.g., $i ref in pred
this.ruleIndex = ruleIndex == nil ? -1 : ruleIndex
this.predIndex = predIndex == nil ? -1 : predIndex
this.isCtxDependent = isCtxDependent == nil ? false : isCtxDependent // e.g., $i ref in pred
return this
}
@ -128,7 +128,7 @@ func (this *Predicate) toString() string {
func PrecedencePredicate(precedence) {
SemanticContext.call(this)
this.precedence = precedence == undefined ? 0 : precedence
this.precedence = precedence == nil ? 0 : precedence
}
//PrecedencePredicate.prototype = Object.create(SemanticContext.prototype)

View File

@ -20,7 +20,7 @@ package atn
func Transition (target) {
// The target of this transition.
if (target==undefined || target==nil) {
if (target==nil || target==nil) {
panic "target cannot be nil."
}
this.target = target
@ -195,8 +195,8 @@ func ActionTransition(target, ruleIndex, actionIndex, isCtxDependent) {
Transition.call(this, target)
this.serializationType = Transition.ACTION
this.ruleIndex = ruleIndex
this.actionIndex = actionIndex==undefined ? -1 : actionIndex
this.isCtxDependent = isCtxDependent==undefined ? false : isCtxDependent // e.g., $i ref in pred
this.actionIndex = actionIndex==nil ? -1 : actionIndex
this.isCtxDependent = isCtxDependent==nil ? false : isCtxDependent // e.g., $i ref in pred
this.isEpsilon = true
return this
}
@ -218,7 +218,7 @@ func (this *ActionTransition) toString() string {
func SetTransition(target, set) {
Transition.call(this, target)
this.serializationType = Transition.SET
if (set !=undefined && set !=nil) {
if (set !=nil && set !=nil) {
this.label = set
} else {
this.label = NewIntervalSet()

View File

@ -16,7 +16,7 @@ Object.defineProperty(DFAStatesSet.prototype, "length", {
})
func DFA(atnStartState, decision) {
if (decision == undefined) {
if (decision == nil) {
decision = 0
}
// From which ATN state did we create this DFA?

View File

@ -85,7 +85,7 @@ func (this *ParseTreeVisitor) visit(ctx) {
}
func visitAtom(visitor, ctx) {
if (ctx.parser == undefined) { //is terminal
if (ctx.parser == nil) { //is terminal
return
}
@ -206,7 +206,7 @@ func NewParseTreeWalker() *ParseTreeWalker{
func (this *ParseTreeWalker) walk(listener, t) {
var errorNode = t instanceof ErrorNode ||
(t.isErrorNode != undefined && t.isErrorNode())
(t.isErrorNode != nil && t.isErrorNode())
if (errorNode) {
listener.visitErrorNode(t)
} else if _, ok := t.(TerminalNode); ok {