!== -> !=

This commit is contained in:
Peter Boyer 2015-12-15 15:55:04 -05:00
parent 8a00cbd485
commit f12eaef24f
27 changed files with 194 additions and 195 deletions

View File

@ -48,9 +48,9 @@ func (this *CommonTokenFactory) create(source, type, text, channel, start, stop,
var t = new CommonToken(source, type, channel, start, stop) var t = new CommonToken(source, type, channel, start, stop)
t.line = line t.line = line
t.column = column t.column = column
if (text !==nil) { if (text !=nil) {
t.text = text t.text = text
} else if (this.copyText && source[1] !==nil) { } else if (this.copyText && source[1] !=nil) {
t.text = source[1].getText(start,stop) t.text = source[1].getText(start,stop)
} }
return t return t

View File

@ -88,7 +88,7 @@ LL1func (this *Analyzer) LOOK(s, stopState, ctx) {
var r = new IntervalSet() var r = new IntervalSet()
var seeThruPreds = true // ignore preds get all lookahead var seeThruPreds = true // ignore preds get all lookahead
ctx = ctx || nil ctx = ctx || nil
var lookContext = ctx!==nil ? predictionContextFromRuleContext(s.atn, ctx) : nil var lookContext = ctx!=nil ? predictionContextFromRuleContext(s.atn, ctx) : nil
this._LOOK(s, stopState, lookContext, r, new Set(), new BitSet(), seeThruPreds, true) this._LOOK(s, stopState, lookContext, r, new Set(), new BitSet(), seeThruPreds, true)
return r return r
} }
@ -146,7 +146,7 @@ LL1func (this *Analyzer) _LOOK(s, stopState , ctx, look, lookBusy, calledRuleSta
look.addOne(Token.EOF) look.addOne(Token.EOF)
return return
} }
if (ctx !== PredictionContext.EMPTY) { if (ctx != PredictionContext.EMPTY) {
// run thru all possible stack tops in ctx // run thru all possible stack tops in ctx
for(var i=0 i<ctx.length i++) { for(var i=0 i<ctx.length i++) {
var returnState = this.atn.states[ctx.getReturnState(i)] var returnState = this.atn.states[ctx.getReturnState(i)]
@ -188,7 +188,7 @@ LL1func (this *Analyzer) _LOOK(s, stopState , ctx, look, lookBusy, calledRuleSta
look.addRange( Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType ) look.addRange( Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType )
} else { } else {
var set = t.label var set = t.label
if (set !== nil) { if (set != nil) {
if (t instanceof NotSetTransition) { if (t instanceof NotSetTransition) {
set = set.complement(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType) set = set.complement(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType)
} }

View File

@ -67,7 +67,7 @@ Parser.bypassAltsAtnCache = {}
// reset the parser's state// // reset the parser's state//
func (p.*Parser) reset() { func (p.*Parser) reset() {
if (p._input !== nil) { if (p._input != nil) {
p._input.seek(0) p._input.seek(0)
} }
p._errHandler.reset(p. p._errHandler.reset(p.
@ -76,7 +76,7 @@ func (p.*Parser) reset() {
p.setTrace(false) p.setTrace(false)
p._precedenceStack = [] p._precedenceStack = []
p._precedenceStack.push(0) p._precedenceStack.push(0)
if (p._interp !== nil) { if (p._interp != nil) {
p._interp.reset() p._interp.reset()
} }
} }
@ -197,7 +197,7 @@ func (p.*Parser) addParseListener(listener) {
// @param listener the listener to remove // @param listener the listener to remove
// //
func (p.*Parser) removeParseListener(listener) { func (p.*Parser) removeParseListener(listener) {
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
var idx = p._parseListeners.indexOf(listener) var idx = p._parseListeners.indexOf(listener)
if (idx >= 0) { if (idx >= 0) {
p._parseListeners.splice(idx, 1) p._parseListeners.splice(idx, 1)
@ -215,7 +215,7 @@ func (p.*Parser) removeParseListeners() {
// Notify any parse listeners of an enter rule event. // Notify any parse listeners of an enter rule event.
func (p.*Parser) triggerEnterRuleEvent() { func (p.*Parser) triggerEnterRuleEvent() {
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
var ctx = p._ctx var ctx = p._ctx
p._parseListeners.map(function(listener) { p._parseListeners.map(function(listener) {
listener.enterEveryRule(ctx) listener.enterEveryRule(ctx)
@ -230,7 +230,7 @@ func (p.*Parser) triggerEnterRuleEvent() {
// @see //addParseListener // @see //addParseListener
// //
func (p.*Parser) triggerExitRuleEvent() { func (p.*Parser) triggerExitRuleEvent() {
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
// reverse order walk of listeners // reverse order walk of listeners
var ctx = p._ctx var ctx = p._ctx
p._parseListeners.slice(0).reverse().map(function(listener) { p._parseListeners.slice(0).reverse().map(function(listener) {
@ -287,7 +287,7 @@ var Lexer = require('./Lexer').Lexer
func (p.*Parser) compileParseTreePattern(pattern, patternRuleIndex, lexer) { func (p.*Parser) compileParseTreePattern(pattern, patternRuleIndex, lexer) {
lexer = lexer || nil lexer = lexer || nil
if (lexer == nil) { if (lexer == nil) {
if (p.getTokenStream() !== nil) { if (p.getTokenStream() != nil) {
var tokenSource = p.getTokenStream().tokenSource var tokenSource = p.getTokenStream().tokenSource
if (tokenSource instanceof Lexer) { if (tokenSource instanceof Lexer) {
lexer = tokenSource lexer = tokenSource
@ -363,10 +363,10 @@ func (p.*Parser) notifyErrorListeners(msg, offendingToken, err) {
// //
func (p.*Parser) consume() { func (p.*Parser) consume() {
var o = p.getCurrentToken() var o = p.getCurrentToken()
if (o.type !== Token.EOF) { if (o.type != Token.EOF) {
p.getInputStream().consume() p.getInputStream().consume()
} }
var hasListener = p._parseListeners !== nil && p._parseListeners.length > 0 var hasListener = p._parseListeners != nil && p._parseListeners.length > 0
if (p.buildParseTrees || hasListener) { if (p.buildParseTrees || hasListener) {
var node var node
if (p._errHandler.inErrorRecoveryMode(p.) { if (p._errHandler.inErrorRecoveryMode(p.) {
@ -386,7 +386,7 @@ func (p.*Parser) consume() {
func (p.*Parser) addContextToParseTree() { func (p.*Parser) addContextToParseTree() {
// add current context to parent if we have a parent // add current context to parent if we have a parent
if (p._ctx.parentCtx !== nil) { if (p._ctx.parentCtx != nil) {
p._ctx.parentCtx.addChild(p._ctx) p._ctx.parentCtx.addChild(p._ctx)
} }
} }
@ -401,7 +401,7 @@ func (p.*Parser) enterRule(localctx, state, ruleIndex) {
if (p.buildParseTrees) { if (p.buildParseTrees) {
p.addContextToParseTree() p.addContextToParseTree()
} }
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
p.triggerEnterRuleEvent() p.triggerEnterRuleEvent()
} }
} }
@ -409,7 +409,7 @@ func (p.*Parser) enterRule(localctx, state, ruleIndex) {
func (p.*Parser) exitRule() { func (p.*Parser) exitRule() {
p._ctx.stop = p._input.LT(-1) p._ctx.stop = p._input.LT(-1)
// trigger event on _ctx, before it reverts to parent // trigger event on _ctx, before it reverts to parent
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
p.triggerExitRuleEvent() p.triggerExitRuleEvent()
} }
p.state = p._ctx.invokingState p.state = p._ctx.invokingState
@ -419,8 +419,8 @@ func (p.*Parser) exitRule() {
func (p.*Parser) enterOuterAlt(localctx, altNum) { func (p.*Parser) enterOuterAlt(localctx, altNum) {
// if we have new localctx, make sure we replace existing ctx // if we have new localctx, make sure we replace existing ctx
// that is previous child of parse tree // that is previous child of parse tree
if (p.buildParseTrees && p._ctx !== localctx) { if (p.buildParseTrees && p._ctx != localctx) {
if (p._ctx.parentCtx !== nil) { if (p._ctx.parentCtx != nil) {
p._ctx.parentCtx.removeLastChild() p._ctx.parentCtx.removeLastChild()
p._ctx.parentCtx.addChild(localctx) p._ctx.parentCtx.addChild(localctx)
} }
@ -447,7 +447,7 @@ func (p.*Parser) enterRecursionRule(localctx, state, ruleIndex,
p._precedenceStack.push(precedence) p._precedenceStack.push(precedence)
p._ctx = localctx p._ctx = localctx
p._ctx.start = p._input.LT(1) p._ctx.start = p._input.LT(1)
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
p.triggerEnterRuleEvent() // simulates rule entry for p.triggerEnterRuleEvent() // simulates rule entry for
// left-recursive rules // left-recursive rules
} }
@ -467,7 +467,7 @@ func (p.*Parser) pushNewRecursionContext(localctx, state, ruleIndex) {
if (p.buildParseTrees) { if (p.buildParseTrees) {
p._ctx.addChild(previous) p._ctx.addChild(previous)
} }
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
p.triggerEnterRuleEvent() // simulates rule entry for p.triggerEnterRuleEvent() // simulates rule entry for
// left-recursive rules // left-recursive rules
} }
@ -478,8 +478,8 @@ func (p.*Parser) unrollRecursionContexts(parentCtx) {
p._ctx.stop = p._input.LT(-1) p._ctx.stop = p._input.LT(-1)
var retCtx = p._ctx // save current ctx (return value) var retCtx = p._ctx // save current ctx (return value)
// unroll so _ctx is as it was before call to recursive method // unroll so _ctx is as it was before call to recursive method
if (p._parseListeners !== nil) { if (p._parseListeners != nil) {
while (p._ctx !== parentCtx) { while (p._ctx != parentCtx) {
p.triggerExitRuleEvent() p.triggerExitRuleEvent()
p._ctx = p._ctx.parentCtx p._ctx = p._ctx.parentCtx
} }
@ -488,7 +488,7 @@ func (p.*Parser) unrollRecursionContexts(parentCtx) {
} }
// hook into tree // hook into tree
retCtx.parentCtx = parentCtx retCtx.parentCtx = parentCtx
if (p.buildParseTrees && parentCtx !== nil) { if (p.buildParseTrees && parentCtx != nil) {
// add return ctx into invoking rule's tree // add return ctx into invoking rule's tree
parentCtx.addChild(retCtx) parentCtx.addChild(retCtx)
} }
@ -496,7 +496,7 @@ func (p.*Parser) unrollRecursionContexts(parentCtx) {
func (p.*Parser) getInvokingContext(ruleIndex) { func (p.*Parser) getInvokingContext(ruleIndex) {
var ctx = p._ctx var ctx = p._ctx
while (ctx !== nil) { while (ctx != nil) {
if (ctx.ruleIndex == ruleIndex) { if (ctx.ruleIndex == ruleIndex) {
return ctx return ctx
} }
@ -539,7 +539,7 @@ func (p.*Parser) isExpectedToken(symbol) {
if (!following.contains(Token.EPSILON)) { if (!following.contains(Token.EPSILON)) {
return false return false
} }
while (ctx !== nil && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) { while (ctx != nil && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) {
var invokingState = atn.states[ctx.invokingState] var invokingState = atn.states[ctx.invokingState]
var rt = invokingState.transitions[0] var rt = invokingState.transitions[0]
following = atn.nextTokens(rt.followState) following = atn.nextTokens(rt.followState)
@ -574,7 +574,7 @@ func (p.*Parser) getExpectedTokensWithinCurrentRule() {
// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.// // Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.//
func (p.*Parser) getRuleIndex(ruleName) { func (p.*Parser) getRuleIndex(ruleName) {
var ruleIndex = p.getRuleIndexMap()[ruleName] var ruleIndex = p.getRuleIndexMap()[ruleName]
if (ruleIndex !== nil) { if (ruleIndex != nil) {
return ruleIndex return ruleIndex
} else { } else {
return -1 return -1
@ -594,7 +594,7 @@ func (p.*Parser) getRuleInvocationStack(p) {
p = p._ctx p = p._ctx
} }
var stack = [] var stack = []
while (p !== nil) { while (p != nil) {
// compute what follows who invoked us // compute what follows who invoked us
var ruleIndex = p.ruleIndex var ruleIndex = p.ruleIndex
if (ruleIndex < 0) { if (ruleIndex < 0) {
@ -646,7 +646,7 @@ func (p.*Parser) setTrace(trace) {
p.removeParseListener(p._tracer) p.removeParseListener(p._tracer)
p._tracer = nil p._tracer = nil
} else { } else {
if (p._tracer !== nil) { if (p._tracer != nil) {
p.removeParseListener(p._tracer) p.removeParseListener(p._tracer)
} }
p._tracer = new TraceListener(p. p._tracer = new TraceListener(p.

View File

@ -84,7 +84,7 @@ func (this *ParserRuleContext) addChild(child) {
// generic ruleContext object. // generic ruleContext object.
// / // /
func (this *ParserRuleContext) removeLastChild() { func (this *ParserRuleContext) removeLastChild() {
if (this.children !== nil) { if (this.children != nil) {
this.children.pop() this.children.pop()
} }
} }

View File

@ -84,7 +84,7 @@ func (this *PredictionContextCache) add(ctx) {
return PredictionContext.EMPTY return PredictionContext.EMPTY
} }
var existing = this.cache[ctx] || nil var existing = this.cache[ctx] || nil
if (existing !== nil) { if (existing != nil) {
return existing return existing
} }
this.cache[ctx] = ctx this.cache[ctx] = ctx
@ -102,7 +102,7 @@ Object.defineProperty(PredictionContextCache.prototype, "length", {
}) })
func SingletonPredictionContext(parent, returnState) { func SingletonPredictionContext(parent, returnState) {
var hashString = parent !== nil ? calculateHashString(parent, returnState) var hashString = parent != nil ? calculateHashString(parent, returnState)
: calculateEmptyHashString() : calculateEmptyHashString()
PredictionContext.call(this, hashString) PredictionContext.call(this, hashString)
this.parentCtx = parent this.parentCtx = parent
@ -140,10 +140,10 @@ func (this *SingletonPredictionContext) equals(other) {
return true return true
} else if (!(other instanceof SingletonPredictionContext)) { } else if (!(other instanceof SingletonPredictionContext)) {
return false return false
} else if (this.hashString() !== other.hashString()) { } else if (this.hashString() != other.hashString()) {
return false // can't be same if hash is different return false // can't be same if hash is different
} else { } else {
if(this.returnState !== other.returnState) if(this.returnState != other.returnState)
return false return false
else if(this.parentCtx==nil) else if(this.parentCtx==nil)
return other.parentCtx==nil return other.parentCtx==nil
@ -239,7 +239,7 @@ func (this *ArrayPredictionContext) equals(other) {
return true return true
} else if (!(other instanceof ArrayPredictionContext)) { } else if (!(other instanceof ArrayPredictionContext)) {
return false return false
} else if (this.hashString !== other.hashString()) { } else if (this.hashString != other.hashString()) {
return false // can't be same if hash is different return false // can't be same if hash is different
} else { } else {
return this.returnStates == other.returnStates && return this.returnStates == other.returnStates &&
@ -261,7 +261,7 @@ func (this *ArrayPredictionContext) toString() {
continue continue
} }
s = s + this.returnStates[i] s = s + this.returnStates[i]
if (this.parents[i] !== nil) { if (this.parents[i] != nil) {
s = s + " " + this.parents[i] s = s + " " + this.parents[i]
} else { } else {
s = s + "nil" s = s + "nil"
@ -361,20 +361,20 @@ func merge(a, b, rootIsWildcard, mergeCache) {
// @param mergeCache // @param mergeCache
// / // /
func mergeSingletons(a, b, rootIsWildcard, mergeCache) { func mergeSingletons(a, b, rootIsWildcard, mergeCache) {
if (mergeCache !== nil) { if (mergeCache != nil) {
var previous = mergeCache.get(a, b) var previous = mergeCache.get(a, b)
if (previous !== nil) { if (previous != nil) {
return previous return previous
} }
previous = mergeCache.get(b, a) previous = mergeCache.get(b, a)
if (previous !== nil) { if (previous != nil) {
return previous return previous
} }
} }
var rootMerge = mergeRoot(a, b, rootIsWildcard) var rootMerge = mergeRoot(a, b, rootIsWildcard)
if (rootMerge !== nil) { if (rootMerge != nil) {
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, rootMerge) mergeCache.set(a, b, rootMerge)
} }
return rootMerge return rootMerge
@ -394,19 +394,19 @@ func mergeSingletons(a, b, rootIsWildcard, mergeCache) {
// of those graphs. dup a, a' points at merged array // of those graphs. dup a, a' points at merged array
// new joined parent so create new singleton pointing to it, a' // new joined parent so create new singleton pointing to it, a'
var spc = SingletonPredictionContext.create(parent, a.returnState) var spc = SingletonPredictionContext.create(parent, a.returnState)
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, spc) mergeCache.set(a, b, spc)
} }
return spc return spc
} else { // a != b payloads differ } else { // a != b payloads differ
// see if we can collapse parents due to $+x parents if local ctx // see if we can collapse parents due to $+x parents if local ctx
var singleParent = nil var singleParent = nil
if (a == b || (a.parentCtx !== nil && a.parentCtx == b.parentCtx)) { // ax + if (a == b || (a.parentCtx != nil && a.parentCtx == b.parentCtx)) { // ax +
// bx = // bx =
// [a,b]x // [a,b]x
singleParent = a.parentCtx singleParent = a.parentCtx
} }
if (singleParent !== nil) { // parents are same if (singleParent != nil) { // parents are same
// sort payloads and use same parent // sort payloads and use same parent
var payloads = [ a.returnState, b.returnState ] var payloads = [ a.returnState, b.returnState ]
if (a.returnState > b.returnState) { if (a.returnState > b.returnState) {
@ -415,7 +415,7 @@ func mergeSingletons(a, b, rootIsWildcard, mergeCache) {
} }
var parents = [ singleParent, singleParent ] var parents = [ singleParent, singleParent ]
var apc = new ArrayPredictionContext(parents, payloads) var apc = new ArrayPredictionContext(parents, payloads)
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, apc) mergeCache.set(a, b, apc)
} }
return apc return apc
@ -431,7 +431,7 @@ func mergeSingletons(a, b, rootIsWildcard, mergeCache) {
parents = [ b.parentCtx, a.parentCtx ] parents = [ b.parentCtx, a.parentCtx ]
} }
var a_ = new ArrayPredictionContext(parents, payloads) var a_ = new ArrayPredictionContext(parents, payloads)
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, a_) mergeCache.set(a, b, a_)
} }
return a_ return a_
@ -522,13 +522,13 @@ func mergeRoot(a, b, rootIsWildcard) {
// <embed src="images/ArrayMerge_EqualTop.svg" type="image/svg+xml"/></p> // <embed src="images/ArrayMerge_EqualTop.svg" type="image/svg+xml"/></p>
// / // /
func mergeArrays(a, b, rootIsWildcard, mergeCache) { func mergeArrays(a, b, rootIsWildcard, mergeCache) {
if (mergeCache !== nil) { if (mergeCache != nil) {
var previous = mergeCache.get(a, b) var previous = mergeCache.get(a, b)
if (previous !== nil) { if (previous != nil) {
return previous return previous
} }
previous = mergeCache.get(b, a) previous = mergeCache.get(b, a)
if (previous !== nil) { if (previous != nil) {
return previous return previous
} }
} }
@ -549,7 +549,7 @@ func mergeArrays(a, b, rootIsWildcard, mergeCache) {
// $+$ = $ // $+$ = $
var bothDollars = payload == PredictionContext.EMPTY_RETURN_STATE && var bothDollars = payload == PredictionContext.EMPTY_RETURN_STATE &&
a_parent == nil && b_parent == nil a_parent == nil && b_parent == nil
var ax_ax = (a_parent !== nil && b_parent !== nil && a_parent == b_parent) // ax+ax var ax_ax = (a_parent != nil && b_parent != nil && a_parent == b_parent) // ax+ax
// -> // ->
// ax // ax
if (bothDollars || ax_ax) { if (bothDollars || ax_ax) {
@ -592,7 +592,7 @@ func mergeArrays(a, b, rootIsWildcard, mergeCache) {
if (k == 1) { // for just one merged element, return singleton top if (k == 1) { // for just one merged element, return singleton top
var a_ = SingletonPredictionContext.create(mergedParents[0], var a_ = SingletonPredictionContext.create(mergedParents[0],
mergedReturnStates[0]) mergedReturnStates[0])
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, a_) mergeCache.set(a, b, a_)
} }
return a_ return a_
@ -606,20 +606,20 @@ func mergeArrays(a, b, rootIsWildcard, mergeCache) {
// if we created same array as a or b, return that instead // if we created same array as a or b, return that instead
// TODO: track whether this is possible above during merge sort for speed // TODO: track whether this is possible above during merge sort for speed
if (M == a) { if (M == a) {
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, a) mergeCache.set(a, b, a)
} }
return a return a
} }
if (M == b) { if (M == b) {
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, b) mergeCache.set(a, b, b)
} }
return b return b
} }
combineCommonParents(mergedParents) combineCommonParents(mergedParents)
if (mergeCache !== nil) { if (mergeCache != nil) {
mergeCache.set(a, b, M) mergeCache.set(a, b, M)
} }
return M return M
@ -648,11 +648,11 @@ func getCachedPredictionContext(context, contextCache, visited) {
return context return context
} }
var existing = visited[context] || nil var existing = visited[context] || nil
if (existing !== nil) { if (existing != nil) {
return existing return existing
} }
existing = contextCache.get(context) existing = contextCache.get(context)
if (existing !== nil) { if (existing != nil) {
visited[context] = existing visited[context] = existing
return existing return existing
} }
@ -660,7 +660,7 @@ func getCachedPredictionContext(context, contextCache, visited) {
var parents = [] var parents = []
for (var i = 0 i < parents.length i++) { for (var i = 0 i < parents.length i++) {
var parent = getCachedPredictionContext(context.getParent(i), contextCache, visited) var parent = getCachedPredictionContext(context.getParent(i), contextCache, visited)
if (changed || parent !== context.getParent(i)) { if (changed || parent != context.getParent(i)) {
if (!changed) { if (!changed) {
parents = [] parents = []
for (var j = 0 j < context.length j++) { for (var j = 0 j < context.length j++) {
@ -701,7 +701,7 @@ func getAllContextNodes(context, nodes, visited) {
visited = {} visited = {}
return getAllContextNodes(context, nodes, visited) return getAllContextNodes(context, nodes, visited)
} else { } else {
if (context == nil || visited[context] !== nil) { if (context == nil || visited[context] != nil) {
return nodes return nodes
} }
visited[context] = context visited[context] = context

View File

@ -14,10 +14,9 @@ type Recognizer struct {
Recognizer.tokenTypeMapCache = {} Recognizer.tokenTypeMapCache = {}
Recognizer.ruleIndexMapCache = {} Recognizer.ruleIndexMapCache = {}
func (this *Recognizer) checkVersion(toolVersion) { func (this *Recognizer) checkVersion(toolVersion) {
var runtimeVersion = "4.5.1" var runtimeVersion = "4.5.1"
if (runtimeVersion!==toolVersion) { if (runtimeVersion!=toolVersion) {
console.log("ANTLR runtime and generated code versions disagree: "+runtimeVersion+"!="+toolVersion) console.log("ANTLR runtime and generated code versions disagree: "+runtimeVersion+"!="+toolVersion)
} }
} }
@ -63,7 +62,7 @@ func (this *Recognizer) getRuleIndexMap() {
func (this *Recognizer) getTokenType(tokenName) { func (this *Recognizer) getTokenType(tokenName) {
var ttype = this.getTokenTypeMap()[tokenName] var ttype = this.getTokenTypeMap()[tokenName]
if (ttype !==undefined) { if (ttype !=undefined) {
return ttype return ttype
} else { } else {
return Token.INVALID_TYPE return Token.INVALID_TYPE

View File

@ -41,7 +41,7 @@ RuleContext.prototype.constructor = RuleContext
func (this *RuleContext) depth() { func (this *RuleContext) depth() {
var n = 0 var n = 0
var p = this var p = this
while (p !== nil) { while (p != nil) {
p = p.parentCtx p = p.parentCtx
n += 1 n += 1
} }
@ -115,7 +115,7 @@ func (this *RuleContext) toString(ruleNames, stop) {
stop = stop || nil stop = stop || nil
var p = this var p = this
var s = "[" var s = "["
while (p !== nil && p !== stop) { while (p != nil && p != stop) {
if (ruleNames == nil) { if (ruleNames == nil) {
if (!p.isEmpty()) { if (!p.isEmpty()) {
s += p.invokingState s += p.invokingState
@ -126,7 +126,7 @@ func (this *RuleContext) toString(ruleNames, stop) {
: "" + ri : "" + ri
s += ruleName s += ruleName
} }
if (p.parentCtx !== nil && (ruleNames !== nil || !p.parentCtx.isEmpty())) { if (p.parentCtx != nil && (ruleNames != nil || !p.parentCtx.isEmpty())) {
s += " " s += " "
} }
p = p.parentCtx p = p.parentCtx

View File

@ -65,13 +65,13 @@ func (this *Token) getInputStream() {
func CommonToken(source, type, channel, start, stop) { func CommonToken(source, type, channel, start, stop) {
Token.call(this) Token.call(this)
this.source = source !== undefined ? source : CommonToken.EMPTY_SOURCE this.source = source != undefined ? source : CommonToken.EMPTY_SOURCE
this.type = type !== undefined ? type : nil this.type = type != undefined ? type : nil
this.channel = channel !== undefined ? channel : Token.DEFAULT_CHANNEL this.channel = channel != undefined ? channel : Token.DEFAULT_CHANNEL
this.start = start !== undefined ? start : -1 this.start = start != undefined ? start : -1
this.stop = stop !== undefined ? stop : -1 this.stop = stop != undefined ? stop : -1
this.tokenIndex = -1 this.tokenIndex = -1
if (this.source[0] !== nil) { if (this.source[0] != nil) {
this.line = source[0].line this.line = source[0].line
this.column = source[0].column this.column = source[0].column
} else { } else {
@ -111,7 +111,7 @@ func (this *CommonToken) clone() {
Object.defineProperty(CommonToken.prototype, "text", { Object.defineProperty(CommonToken.prototype, "text", {
get : function() { get : function() {
if (this._text !== nil) { if (this._text != nil) {
return this._text return this._text
} }
var input = this.getInputStream() var input = this.getInputStream()
@ -132,7 +132,7 @@ Object.defineProperty(CommonToken.prototype, "text", {
func (this *CommonToken) toString() { func (this *CommonToken) toString() {
var txt = this.text var txt = this.text
if (txt !== nil) { if (txt != nil) {
txt = txt.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t") txt = txt.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")
} else { } else {
txt = "<no text>" txt = "<no text>"

View File

@ -63,7 +63,7 @@ func (this *ATN) nextTokensInContext(s, ctx) {
// staying in same rule. {@link Token//EPSILON} is in set if we reach end of // staying in same rule. {@link Token//EPSILON} is in set if we reach end of
// rule. // rule.
func (this *ATN) nextTokensNoContext(s) { func (this *ATN) nextTokensNoContext(s) {
if (s.nextTokenWithinRule !== nil ) { if (s.nextTokenWithinRule != nil ) {
return s.nextTokenWithinRule return s.nextTokenWithinRule
} }
s.nextTokenWithinRule = this.nextTokensInContext(s, nil) s.nextTokenWithinRule = this.nextTokensInContext(s, nil)
@ -80,7 +80,7 @@ func (this *ATN) nextTokens(s, ctx) {
} }
func (this *ATN) addState( state) { func (this *ATN) addState( state) {
if ( state !== nil ) { if ( state != nil ) {
state.atn = this state.atn = this
state.stateNumber = this.states.length state.stateNumber = this.states.length
} }
@ -137,7 +137,7 @@ func (this *ATN) getExpectedTokens( stateNumber, ctx ) {
var expected = new IntervalSet() var expected = new IntervalSet()
expected.addSet(following) expected.addSet(following)
expected.removeOne(Token.EPSILON) expected.removeOne(Token.EPSILON)
while (ctx !== nil && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) { while (ctx != nil && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) {
var invokingState = this.states[ctx.invokingState] var invokingState = this.states[ctx.invokingState]
var rt = invokingState.transitions[0] var rt = invokingState.transitions[0]
following = this.nextTokens(rt.followState) following = this.nextTokens(rt.followState)

View File

@ -37,15 +37,15 @@ func ATNConfig(params, config) {
params = checkParams(params) params = checkParams(params)
config = checkParams(config, true) config = checkParams(config, true)
// The ATN state associated with this configuration/// // The ATN state associated with this configuration///
this.state = params.state!==nil ? params.state : config.state this.state = params.state!=nil ? params.state : config.state
// What alt (or lexer rule) is predicted by this configuration/// // What alt (or lexer rule) is predicted by this configuration///
this.alt = params.alt!==nil ? params.alt : config.alt this.alt = params.alt!=nil ? params.alt : config.alt
// The stack of invoking states leading to the rule/states associated // The stack of invoking states leading to the rule/states associated
// with this config. We track only those contexts pushed during // with this config. We track only those contexts pushed during
// execution of the ATN simulator. // execution of the ATN simulator.
this.context = params.context!==nil ? params.context : config.context this.context = params.context!=nil ? params.context : config.context
this.semanticContext = params.semanticContext!==nil ? params.semanticContext : this.semanticContext = params.semanticContext!=nil ? params.semanticContext :
(config.semanticContext!==nil ? config.semanticContext : SemanticContext.NONE) (config.semanticContext!=nil ? config.semanticContext : SemanticContext.NONE)
// We cannot execute predicates dependent upon local context unless // We cannot execute predicates dependent upon local context unless
// we know for sure we are in the correct context. Because there is // we know for sure we are in the correct context. Because there is
// no way to do this efficiently, we simply cannot evaluate // no way to do this efficiently, we simply cannot evaluate
@ -97,8 +97,8 @@ func (this *ATNConfig) hashString() {
func (this *ATNConfig) toString() { func (this *ATNConfig) toString() {
return "(" + this.state + "," + this.alt + return "(" + this.state + "," + this.alt +
(this.context!==nil ? ",[" + this.context.toString() + "]" : "") + (this.context!=nil ? ",[" + this.context.toString() + "]" : "") +
(this.semanticContext !== SemanticContext.NONE ? (this.semanticContext != SemanticContext.NONE ?
("," + this.semanticContext.toString()) ("," + this.semanticContext.toString())
: "") + : "") +
(this.reachesIntoOuterContext>0 ? (this.reachesIntoOuterContext>0 ?
@ -112,8 +112,8 @@ func LexerATNConfig(params, config) {
// This is the backing field for {@link //getLexerActionExecutor}. // This is the backing field for {@link //getLexerActionExecutor}.
var lexerActionExecutor = params.lexerActionExecutor || nil var lexerActionExecutor = params.lexerActionExecutor || nil
this.lexerActionExecutor = lexerActionExecutor || (config!==nil ? config.lexerActionExecutor : nil) this.lexerActionExecutor = lexerActionExecutor || (config!=nil ? config.lexerActionExecutor : nil)
this.passedThroughNonGreedyDecision = config!==nil ? this.checkNonGreedyDecision(config, this.state) : false this.passedThroughNonGreedyDecision = config!=nil ? this.checkNonGreedyDecision(config, this.state) : false
return this return this
} }
@ -131,7 +131,7 @@ func (this *LexerATNConfig) equals(other) {
return true return true
} else if (!(other instanceof LexerATNConfig)) { } else if (!(other instanceof LexerATNConfig)) {
return false return false
} else if (this.passedThroughNonGreedyDecision !== other.passedThroughNonGreedyDecision) { } else if (this.passedThroughNonGreedyDecision != other.passedThroughNonGreedyDecision) {
return false return false
} else if (this.lexerActionExecutor ? } else if (this.lexerActionExecutor ?
!this.lexerActionExecutor.equals(other.lexerActionExecutor) !this.lexerActionExecutor.equals(other.lexerActionExecutor)

View File

@ -87,7 +87,7 @@ func (this *ATNConfigSet) add(config, mergeCache) {
if (this.readOnly) { if (this.readOnly) {
throw "This set is readonly" throw "This set is readonly"
} }
if (config.semanticContext !== SemanticContext.NONE) { if (config.semanticContext != SemanticContext.NONE) {
this.hasSemanticContext = true this.hasSemanticContext = true
} }
if (config.reachesIntoOuterContext > 0) { if (config.reachesIntoOuterContext > 0) {
@ -126,7 +126,7 @@ func (this *ATNConfigSet) getPredicates() {
var preds = [] var preds = []
for (var i = 0 i < this.configs.length i++) { for (var i = 0 i < this.configs.length i++) {
var c = this.configs[i].semanticContext var c = this.configs[i].semanticContext
if (c !== SemanticContext.NONE) { if (c != SemanticContext.NONE) {
preds.push(c.semanticContext) preds.push(c.semanticContext)
} }
} }
@ -165,7 +165,7 @@ func (this *ATNConfigSet) equals(other) {
} else if (!(other instanceof ATNConfigSet)) { } else if (!(other instanceof ATNConfigSet)) {
return false return false
} }
return this.configs !== nil && this.configs.equals(other.configs) && return this.configs != nil && this.configs.equals(other.configs) &&
this.fullCtx == other.fullCtx && this.fullCtx == other.fullCtx &&
this.uniqueAlt == other.uniqueAlt && this.uniqueAlt == other.uniqueAlt &&
this.conflictingAlts == other.conflictingAlts && this.conflictingAlts == other.conflictingAlts &&
@ -235,8 +235,8 @@ func (this *ATNConfigSet) setReadonly(readOnly) {
func (this *ATNConfigSet) toString() { func (this *ATNConfigSet) toString() {
return Utils.arrayToString(this.configs) + return Utils.arrayToString(this.configs) +
(this.hasSemanticContext ? ",hasSemanticContext=" + this.hasSemanticContext : "") + (this.hasSemanticContext ? ",hasSemanticContext=" + this.hasSemanticContext : "") +
(this.uniqueAlt !== ATN.INVALID_ALT_NUMBER ? ",uniqueAlt=" + this.uniqueAlt : "") + (this.uniqueAlt != ATN.INVALID_ALT_NUMBER ? ",uniqueAlt=" + this.uniqueAlt : "") +
(this.conflictingAlts !== nil ? ",conflictingAlts=" + this.conflictingAlts : "") + (this.conflictingAlts != nil ? ",conflictingAlts=" + this.conflictingAlts : "") +
(this.dipsIntoOuterContext ? ",dipsIntoOuterContext" : "") (this.dipsIntoOuterContext ? ",dipsIntoOuterContext" : "")
} }

View File

@ -132,7 +132,7 @@ func (this *ATNDeserializer) reset(data) {
func (this *ATNDeserializer) checkVersion() { func (this *ATNDeserializer) checkVersion() {
var version = this.readInt() var version = this.readInt()
if ( version !== SERIALIZED_VERSION ) { if ( version != SERIALIZED_VERSION ) {
throw ("Could not deserialize ATN with version " + version + " (expected " + SERIALIZED_VERSION + ").") throw ("Could not deserialize ATN with version " + version + " (expected " + SERIALIZED_VERSION + ").")
} }
} }
@ -249,7 +249,7 @@ func (this *ATNDeserializer) readSets(atn) {
sets.push(iset) sets.push(iset)
var n = this.readInt() var n = this.readInt()
var containsEof = this.readInt() var containsEof = this.readInt()
if (containsEof!==0) { if (containsEof!=0) {
iset.addOne(-1) iset.addOne(-1)
} }
for (var j=0 j<n j++) { for (var j=0 j<n j++) {
@ -304,7 +304,7 @@ func (this *ATNDeserializer) readEdges(atn, sets) {
} }
// block end states can only be associated to a single block start // block end states can only be associated to a single block start
// state // state
if ( state.endState.startState !== nil) { if ( state.endState.startState != nil) {
throw ("IllegalState") throw ("IllegalState")
} }
state.endState.startState = state state.endState.startState = state
@ -438,7 +438,7 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
} }
func (this *ATNDeserializer) stateIsEndStateFor(state, idx) { func (this *ATNDeserializer) stateIsEndStateFor(state, idx) {
if ( state.ruleIndex !== idx) { if ( state.ruleIndex != idx) {
return nil return nil
} }
if (!( state instanceof StarLoopEntryState)) { if (!( state instanceof StarLoopEntryState)) {
@ -497,9 +497,9 @@ func (this *ATNDeserializer) verifyATN(atn) {
} }
this.checkCondition(state.epsilonOnlyTransitions || state.transitions.length <= 1) this.checkCondition(state.epsilonOnlyTransitions || state.transitions.length <= 1)
if (state instanceof PlusBlockStartState) { if (state instanceof PlusBlockStartState) {
this.checkCondition(state.loopBackState !== nil) this.checkCondition(state.loopBackState != nil)
} else if (state instanceof StarLoopEntryState) { } else if (state instanceof StarLoopEntryState) {
this.checkCondition(state.loopBackState !== nil) this.checkCondition(state.loopBackState != nil)
this.checkCondition(state.transitions.length == 2) this.checkCondition(state.transitions.length == 2)
if (state.transitions[0].target instanceof StarBlockStartState) { if (state.transitions[0].target instanceof StarBlockStartState) {
this.checkCondition(state.transitions[1].target instanceof LoopEndState) this.checkCondition(state.transitions[1].target instanceof LoopEndState)
@ -514,13 +514,13 @@ func (this *ATNDeserializer) verifyATN(atn) {
this.checkCondition(state.transitions.length == 1) this.checkCondition(state.transitions.length == 1)
this.checkCondition(state.transitions[0].target instanceof StarLoopEntryState) this.checkCondition(state.transitions[0].target instanceof StarLoopEntryState)
} else if (state instanceof LoopEndState) { } else if (state instanceof LoopEndState) {
this.checkCondition(state.loopBackState !== nil) this.checkCondition(state.loopBackState != nil)
} else if (state instanceof RuleStartState) { } else if (state instanceof RuleStartState) {
this.checkCondition(state.stopState !== nil) this.checkCondition(state.stopState != nil)
} else if (state instanceof BlockStartState) { } else if (state instanceof BlockStartState) {
this.checkCondition(state.endState !== nil) this.checkCondition(state.endState != nil)
} else if (state instanceof BlockEndState) { } else if (state instanceof BlockEndState) {
this.checkCondition(state.startState !== nil) this.checkCondition(state.startState != nil)
} else if (state instanceof DecisionState) { } else if (state instanceof DecisionState) {
this.checkCondition(state.transitions.length <= 1 || state.decision >= 0) this.checkCondition(state.transitions.length <= 1 || state.decision >= 0)
} else { } else {
@ -588,17 +588,17 @@ ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2
case Transition.EPSILON: case Transition.EPSILON:
return new EpsilonTransition(target) return new EpsilonTransition(target)
case Transition.RANGE: case Transition.RANGE:
return arg3 !== 0 ? new RangeTransition(target, Token.EOF, arg2) : new RangeTransition(target, arg1, arg2) return arg3 != 0 ? new RangeTransition(target, Token.EOF, arg2) : new RangeTransition(target, arg1, arg2)
case Transition.RULE: case Transition.RULE:
return new RuleTransition(atn.states[arg1], arg2, arg3, target) return new RuleTransition(atn.states[arg1], arg2, arg3, target)
case Transition.PREDICATE: case Transition.PREDICATE:
return new PredicateTransition(target, arg1, arg2, arg3 !== 0) return new PredicateTransition(target, arg1, arg2, arg3 != 0)
case Transition.PRECEDENCE: case Transition.PRECEDENCE:
return new PrecedencePredicateTransition(target, arg1) return new PrecedencePredicateTransition(target, arg1)
case Transition.ATOM: case Transition.ATOM:
return arg3 !== 0 ? new AtomTransition(target, Token.EOF) : new AtomTransition(target, arg1) return arg3 != 0 ? new AtomTransition(target, Token.EOF) : new AtomTransition(target, arg1)
case Transition.ACTION: case Transition.ACTION:
return new ActionTransition(target, arg1, arg2, arg3 !== 0) return new ActionTransition(target, arg1, arg2, arg3 != 0)
case Transition.SET: case Transition.SET:
return new SetTransition(target, sets[arg1]) return new SetTransition(target, sets[arg1])
case Transition.NOT_SET: case Transition.NOT_SET:
@ -632,7 +632,7 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
throw("The specified state type " + type + " is not valid.") throw("The specified state type " + type + " is not valid.")
} else { } else {
var s = this.stateFactories[type]() var s = this.stateFactories[type]()
if (s!==nil) { if (s!=nil) {
s.ruleIndex = ruleIndex s.ruleIndex = ruleIndex
return s return s
} }

View File

@ -131,7 +131,7 @@ func (this *ATNState) addTransition(trans, index) {
} }
if (this.transitions.length==0) { if (this.transitions.length==0) {
this.epsilonOnlyTransitions = trans.isEpsilon this.epsilonOnlyTransitions = trans.isEpsilon
} else if(this.epsilonOnlyTransitions !== trans.isEpsilon) { } else if(this.epsilonOnlyTransitions != trans.isEpsilon) {
this.epsilonOnlyTransitions = false this.epsilonOnlyTransitions = false
} }
if (index==-1) { if (index==-1) {

View File

@ -184,7 +184,7 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
// capturing the accept state so the input index, line, and char // capturing the accept state so the input index, line, and char
// position accurately reflect the state of the interpreter at the // position accurately reflect the state of the interpreter at the
// end of the token. // end of the token.
if (t !== Token.EOF) { if (t != Token.EOF) {
this.consume(input) this.consume(input)
} }
if (target.isAcceptState) { if (target.isAcceptState) {
@ -217,7 +217,7 @@ func (this *LexerATNSimulator) getExistingTargetState(s, t) {
if(target==undefined) { if(target==undefined) {
target = nil target = nil
} }
if (this.debug && target !== nil) { if (this.debug && target != nil) {
console.log("reuse state " + s.stateNumber + " edge to " + target.stateNumber) console.log("reuse state " + s.stateNumber + " edge to " + target.stateNumber)
} }
return target return target
@ -253,7 +253,7 @@ func (this *LexerATNSimulator) computeTargetState(input, s, t) {
} }
func (this *LexerATNSimulator) failOrAccept(prevAccept, input, reach, t) { func (this *LexerATNSimulator) failOrAccept(prevAccept, input, reach, t) {
if (this.prevAccept.dfaState !== nil) { if (this.prevAccept.dfaState != nil) {
var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
this.accept(input, lexerActionExecutor, this.startIndex, this.accept(input, lexerActionExecutor, this.startIndex,
prevAccept.index, prevAccept.line, prevAccept.column) prevAccept.index, prevAccept.line, prevAccept.column)
@ -288,9 +288,9 @@ func (this *LexerATNSimulator) getReachableConfigSet(input, closure,
for (var j = 0 j < cfg.state.transitions.length j++) { for (var j = 0 j < cfg.state.transitions.length j++) {
var trans = cfg.state.transitions[j] // for each transition var trans = cfg.state.transitions[j] // for each transition
var target = this.getReachableTarget(trans, t) var target = this.getReachableTarget(trans, t)
if (target !== nil) { if (target != nil) {
var lexerActionExecutor = cfg.lexerActionExecutor var lexerActionExecutor = cfg.lexerActionExecutor
if (lexerActionExecutor !== nil) { if (lexerActionExecutor != nil) {
lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index - this.startIndex) lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index - this.startIndex)
} }
var treatEofAsEpsilon = (t == Token.EOF) var treatEofAsEpsilon = (t == Token.EOF)
@ -315,7 +315,7 @@ func (this *LexerATNSimulator) accept(input, lexerActionExecutor,
input.seek(index) input.seek(index)
this.line = line this.line = line
this.column = charPos this.column = charPos
if (lexerActionExecutor !== nil && this.recog !== nil) { if (lexerActionExecutor != nil && this.recog != nil) {
lexerActionExecutor.execute(this.recog, input, startIndex) lexerActionExecutor.execute(this.recog, input, startIndex)
} }
} }
@ -355,7 +355,7 @@ func (this *LexerATNSimulator) closure(input, config, configs,
} }
if (config.state instanceof RuleStopState) { if (config.state instanceof RuleStopState) {
if (this.debug) { if (this.debug) {
if (this.recog !== nil) { if (this.recog != nil) {
console.log("closure at %s rule stop %s\n", this.recog.getRuleNames()[config.state.ruleIndex], config) console.log("closure at %s rule stop %s\n", this.recog.getRuleNames()[config.state.ruleIndex], config)
} else { } else {
console.log("closure at rule stop %s\n", config) console.log("closure at rule stop %s\n", config)
@ -370,9 +370,9 @@ func (this *LexerATNSimulator) closure(input, config, configs,
currentAltReachedAcceptState = true currentAltReachedAcceptState = true
} }
} }
if (config.context !== nil && !config.context.isEmpty()) { if (config.context != nil && !config.context.isEmpty()) {
for (var i = 0 i < config.context.length i++) { for (var i = 0 i < config.context.length i++) {
if (config.context.getReturnState(i) !== PredictionContext.EMPTY_RETURN_STATE) { if (config.context.getReturnState(i) != PredictionContext.EMPTY_RETURN_STATE) {
var newContext = config.context.getParent(i) // "pop" return state var newContext = config.context.getParent(i) // "pop" return state
var returnState = this.atn.states[config.context.getReturnState(i)] var returnState = this.atn.states[config.context.getReturnState(i)]
cfg = new LexerATNConfig({ state:returnState, context:newContext }, config) cfg = new LexerATNConfig({ state:returnState, context:newContext }, config)
@ -393,7 +393,7 @@ func (this *LexerATNSimulator) closure(input, config, configs,
for (var j = 0 j < config.state.transitions.length j++) { for (var j = 0 j < config.state.transitions.length j++) {
var trans = config.state.transitions[j] var trans = config.state.transitions[j]
cfg = this.getEpsilonTarget(input, config, trans, configs, speculative, treatEofAsEpsilon) cfg = this.getEpsilonTarget(input, config, trans, configs, speculative, treatEofAsEpsilon)
if (cfg !== nil) { if (cfg != nil) {
currentAltReachedAcceptState = this.closure(input, cfg, configs, currentAltReachedAcceptState = this.closure(input, cfg, configs,
currentAltReachedAcceptState, speculative, treatEofAsEpsilon) currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
} }
@ -529,7 +529,7 @@ func (this *LexerATNSimulator) addDFAEdge(from_, tk, to, cfgs) {
if (cfgs == undefined) { if (cfgs == undefined) {
cfgs = nil cfgs = nil
} }
if (to == nil && cfgs !== nil) { if (to == nil && cfgs != nil) {
// leading to this call, ATNConfigSet.hasSemanticContext is used as a // leading to this call, ATNConfigSet.hasSemanticContext is used as a
// marker indicating dynamic predicate evaluation makes this edge // marker indicating dynamic predicate evaluation makes this edge
// dependent on the specific input sequence, so the static edge in the // dependent on the specific input sequence, so the static edge in the
@ -581,7 +581,7 @@ func (this *LexerATNSimulator) addDFAState(configs) {
break break
} }
} }
if (firstConfigWithRuleStopState !== nil) { if (firstConfigWithRuleStopState != nil) {
proposed.isAcceptState = true proposed.isAcceptState = true
proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor
proposed.prediction = this.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex] proposed.prediction = this.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex]
@ -589,7 +589,7 @@ func (this *LexerATNSimulator) addDFAState(configs) {
var hash = proposed.hashString() var hash = proposed.hashString()
var dfa = this.decisionToDFA[this.mode] var dfa = this.decisionToDFA[this.mode]
var existing = dfa.states[hash] || nil var existing = dfa.states[hash] || nil
if (existing!==nil) { if (existing!=nil) {
return existing return existing
} }
var newState = proposed var newState = proposed

View File

@ -114,7 +114,7 @@ func (this *LexerActionExecutor) execute(lexer, input, startIndex) {
var offset = lexerAction.offset var offset = lexerAction.offset
input.seek(startIndex + offset) input.seek(startIndex + offset)
lexerAction = lexerAction.action lexerAction = lexerAction.action
requiresSeek = (startIndex + offset) !== stopIndex requiresSeek = (startIndex + offset) != stopIndex
} else if (lexerAction.isPositionDependent) { } else if (lexerAction.isPositionDependent) {
input.seek(stopIndex) input.seek(stopIndex)
requiresSeek = false requiresSeek = false

View File

@ -431,21 +431,21 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
var e = this.noViableAlt(input, outerContext, previousD.configs, startIndex) var e = this.noViableAlt(input, outerContext, previousD.configs, startIndex)
input.seek(startIndex) input.seek(startIndex)
alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configs, outerContext) alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configs, outerContext)
if(alt!==ATN.INVALID_ALT_NUMBER) { if(alt!=ATN.INVALID_ALT_NUMBER) {
return alt return alt
} else { } else {
throw e throw e
} }
} }
if(D.requiresFullContext && this.predictionMode !== PredictionMode.SLL) { if(D.requiresFullContext && this.predictionMode != PredictionMode.SLL) {
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error) // IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
var conflictingAlts = nil var conflictingAlts = nil
if (D.predicates!==nil) { if (D.predicates!=nil) {
if (this.debug) { if (this.debug) {
console.log("DFA state has preds in DFA sim LL failover") console.log("DFA state has preds in DFA sim LL failover")
} }
var conflictIndex = input.index var conflictIndex = input.index
if(conflictIndex !== startIndex) { if(conflictIndex != startIndex) {
input.seek(startIndex) input.seek(startIndex)
} }
conflictingAlts = this.evalSemanticContext(D.predicates, outerContext, true) conflictingAlts = this.evalSemanticContext(D.predicates, outerContext, true)
@ -455,7 +455,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
} }
return conflictingAlts.minValue() return conflictingAlts.minValue()
} }
if (conflictIndex !== startIndex) { if (conflictIndex != startIndex) {
// restore the index so reporting the fallback to full // restore the index so reporting the fallback to full
// context occurs with the index at the correct spot // context occurs with the index at the correct spot
input.seek(conflictIndex) input.seek(conflictIndex)
@ -489,7 +489,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
} }
previousD = D previousD = D
if (t !== Token.EOF) { if (t != Token.EOF) {
input.consume() input.consume()
t = input.LA(1) t = input.LA(1)
} }
@ -547,7 +547,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
PredictionMode.allSubsetsConflict(altSubSets) + ", conflictingAlts=" + PredictionMode.allSubsetsConflict(altSubSets) + ", conflictingAlts=" +
this.getConflictingAlts(reach)) this.getConflictingAlts(reach))
} }
if (predictedAlt!==ATN.INVALID_ALT_NUMBER) { if (predictedAlt!=ATN.INVALID_ALT_NUMBER) {
// NO CONFLICT, UNIQUELY PREDICTED ALT // NO CONFLICT, UNIQUELY PREDICTED ALT
D.isAcceptState = true D.isAcceptState = true
D.configs.uniqueAlt = predictedAlt D.configs.uniqueAlt = predictedAlt
@ -562,7 +562,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
} }
if (D.isAcceptState && D.configs.hasSemanticContext) { if (D.isAcceptState && D.configs.hasSemanticContext) {
this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision)) this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision))
if( D.predicates!==nil) { if( D.predicates!=nil) {
D.prediction = ATN.INVALID_ALT_NUMBER D.prediction = ATN.INVALID_ALT_NUMBER
} }
} }
@ -579,7 +579,7 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState, decisionState) {
// pairs if preds found for conflicting alts // pairs if preds found for conflicting alts
var altsToCollectPredsFrom = this.getConflictingAltsOrUniqueAlt(dfaState.configs) var altsToCollectPredsFrom = this.getConflictingAltsOrUniqueAlt(dfaState.configs)
var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts) var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts)
if (altToPred!==nil) { if (altToPred!=nil) {
dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred) dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred)
dfaState.prediction = ATN.INVALID_ALT_NUMBER // make sure we use preds dfaState.prediction = ATN.INVALID_ALT_NUMBER // make sure we use preds
} else { } else {
@ -621,7 +621,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
var e = this.noViableAlt(input, outerContext, previous, startIndex) var e = this.noViableAlt(input, outerContext, previous, startIndex)
input.seek(startIndex) input.seek(startIndex)
var alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext) var alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext)
if(alt!==ATN.INVALID_ALT_NUMBER) { if(alt!=ATN.INVALID_ALT_NUMBER) {
return alt return alt
} else { } else {
throw e throw e
@ -635,12 +635,12 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
} }
reach.uniqueAlt = this.getUniqueAlt(reach) reach.uniqueAlt = this.getUniqueAlt(reach)
// unique prediction? // unique prediction?
if(reach.uniqueAlt!==ATN.INVALID_ALT_NUMBER) { if(reach.uniqueAlt!=ATN.INVALID_ALT_NUMBER) {
predictedAlt = reach.uniqueAlt predictedAlt = reach.uniqueAlt
break break
} else if (this.predictionMode !== PredictionMode.LL_EXACT_AMBIG_DETECTION) { } else if (this.predictionMode != PredictionMode.LL_EXACT_AMBIG_DETECTION) {
predictedAlt = PredictionMode.resolvesToJustOneViableAlt(altSubSets) predictedAlt = PredictionMode.resolvesToJustOneViableAlt(altSubSets)
if(predictedAlt !== ATN.INVALID_ALT_NUMBER) { if(predictedAlt != ATN.INVALID_ALT_NUMBER) {
break break
} }
} else { } else {
@ -656,7 +656,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
// So, keep going. // So, keep going.
} }
previous = reach previous = reach
if( t !== Token.EOF) { if( t != Token.EOF) {
input.consume() input.consume()
t = input.LA(1) t = input.LA(1)
} }
@ -664,7 +664,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
// If the configuration set uniquely predicts an alternative, // If the configuration set uniquely predicts an alternative,
// without conflict, then we know that it's a full LL decision // without conflict, then we know that it's a full LL decision
// not SLL. // not SLL.
if (reach.uniqueAlt !== ATN.INVALID_ALT_NUMBER ) { if (reach.uniqueAlt != ATN.INVALID_ALT_NUMBER ) {
this.reportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.index) this.reportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.index)
return predictedAlt return predictedAlt
} }
@ -742,7 +742,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
for(var j=0j<c.state.transitions.lengthj++) { for(var j=0j<c.state.transitions.lengthj++) {
var trans = c.state.transitions[j] var trans = c.state.transitions[j]
var target = this.getReachableTarget(trans, t) var target = this.getReachableTarget(trans, t)
if (target!==nil) { if (target!=nil) {
var cfg = new ATNConfig({state:target}, c) var cfg = new ATNConfig({state:target}, c)
intermediate.add(cfg, this.mergeCache) intermediate.add(cfg, this.mergeCache)
if(this.debug) { if(this.debug) {
@ -763,14 +763,14 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
// condition is not true when one or more configurations have been // condition is not true when one or more configurations have been
// withheld in skippedStopStates, or when the current symbol is EOF. // withheld in skippedStopStates, or when the current symbol is EOF.
// //
if (skippedStopStates==nil && t!==Token.EOF) { if (skippedStopStates==nil && t!=Token.EOF) {
if (intermediate.items.length==1) { if (intermediate.items.length==1) {
// Don't pursue the closure if there is just one state. // Don't pursue the closure if there is just one state.
// It can only have one alternative just add to result // It can only have one alternative just add to result
// Also don't pursue the closure if there is unique alternative // Also don't pursue the closure if there is unique alternative
// among the configurations. // among the configurations.
reach = intermediate reach = intermediate
} else if (this.getUniqueAlt(intermediate)!==ATN.INVALID_ALT_NUMBER) { } else if (this.getUniqueAlt(intermediate)!=ATN.INVALID_ALT_NUMBER) {
// Also don't pursue the closure if there is unique alternative // Also don't pursue the closure if there is unique alternative
// among the configurations. // among the configurations.
reach = intermediate reach = intermediate
@ -807,7 +807,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
// //
reach = this.removeAllConfigsNotInRuleStopState(reach, reach == intermediate) reach = this.removeAllConfigsNotInRuleStopState(reach, reach == intermediate)
} }
// If skippedStopStates!==nil, then it contains at least one // If skippedStopStates!=nil, then it contains at least one
// configuration. For full-context reach operations, these // configuration. For full-context reach operations, these
// configurations reached the end of the start rule, in which case we // configurations reached the end of the start rule, in which case we
// only add them back to reach if no configuration during the current // only add them back to reach if no configuration during the current
@ -815,7 +815,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
// chooses an alternative matching the longest overall sequence when // chooses an alternative matching the longest overall sequence when
// multiple alternatives are viable. // multiple alternatives are viable.
// //
if (skippedStopStates!==nil && ( (! fullCtx) || (! PredictionMode.hasConfigInRuleStopState(reach)))) { if (skippedStopStates!=nil && ( (! fullCtx) || (! PredictionMode.hasConfigInRuleStopState(reach)))) {
for (var l=0 l<skippedStopStates.lengthl++) { for (var l=0 l<skippedStopStates.lengthl++) {
reach.add(skippedStopStates[l], this.mergeCache) reach.add(skippedStopStates[l], this.mergeCache)
} }
@ -944,7 +944,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs) {
for(var i=0 i<configs.items.length i++) { for(var i=0 i<configs.items.length i++) {
config = configs.items[i] config = configs.items[i]
// handle alt 1 first // handle alt 1 first
if (config.alt !== 1) { if (config.alt != 1) {
continue continue
} }
var updatedContext = config.semanticContext.evalPrecedence(this.parser, this._outerContext) var updatedContext = config.semanticContext.evalPrecedence(this.parser, this._outerContext)
@ -953,7 +953,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs) {
continue continue
} }
statesFromAlt1[config.state.stateNumber] = config.context statesFromAlt1[config.state.stateNumber] = config.context
if (updatedContext !== config.semanticContext) { if (updatedContext != config.semanticContext) {
configSet.add(new ATNConfig({semanticContext:updatedContext}, config), this.mergeCache) configSet.add(new ATNConfig({semanticContext:updatedContext}, config), this.mergeCache)
} else { } else {
configSet.add(config, this.mergeCache) configSet.add(config, this.mergeCache)
@ -970,7 +970,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs) {
// (basically a graph subtraction algorithm). // (basically a graph subtraction algorithm).
if (!config.precedenceFilterSuppressed) { if (!config.precedenceFilterSuppressed) {
var context = statesFromAlt1[config.state.stateNumber] || nil var context = statesFromAlt1[config.state.stateNumber] || nil
if (context!==nil && context.equals(config.context)) { if (context!=nil && context.equals(config.context)) {
// eliminated // eliminated
continue continue
} }
@ -1013,7 +1013,7 @@ func (this *ParserATNSimulator) getPredsForAmbigAlts(ambigAlts, configs, nalts)
var pred = altToPred[i] || nil var pred = altToPred[i] || nil
if (pred==nil) { if (pred==nil) {
altToPred[i] = SemanticContext.NONE altToPred[i] = SemanticContext.NONE
} else if (pred !== SemanticContext.NONE) { } else if (pred != SemanticContext.NONE) {
nPredAlts += 1 nPredAlts += 1
} }
} }
@ -1033,10 +1033,10 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts, altToPred) {
for (var i=1 i<altToPred.lengthi++) { for (var i=1 i<altToPred.lengthi++) {
var pred = altToPred[i] var pred = altToPred[i]
// unpredicated is indicated by SemanticContext.NONE // unpredicated is indicated by SemanticContext.NONE
if( ambigAlts!==nil && ambigAlts.contains( i )) { if( ambigAlts!=nil && ambigAlts.contains( i )) {
pairs.push(new PredPrediction(pred, i)) pairs.push(new PredPrediction(pred, i))
} }
if (pred !== SemanticContext.NONE) { if (pred != SemanticContext.NONE) {
containsPredicate = true containsPredicate = true
} }
} }
@ -1097,13 +1097,13 @@ func (this *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEn
var semValidConfigs = cfgs[0] var semValidConfigs = cfgs[0]
var semInvalidConfigs = cfgs[1] var semInvalidConfigs = cfgs[1]
var alt = this.getAltThatFinishedDecisionEntryRule(semValidConfigs) var alt = this.getAltThatFinishedDecisionEntryRule(semValidConfigs)
if (alt!==ATN.INVALID_ALT_NUMBER) { // semantically/syntactically viable path exists if (alt!=ATN.INVALID_ALT_NUMBER) { // semantically/syntactically viable path exists
return alt return alt
} }
// Is there a syntactically valid path with a failed pred? // Is there a syntactically valid path with a failed pred?
if (semInvalidConfigs.items.length>0) { if (semInvalidConfigs.items.length>0) {
alt = this.getAltThatFinishedDecisionEntryRule(semInvalidConfigs) alt = this.getAltThatFinishedDecisionEntryRule(semInvalidConfigs)
if (alt!==ATN.INVALID_ALT_NUMBER) { // syntactically viable path exists if (alt!=ATN.INVALID_ALT_NUMBER) { // syntactically viable path exists
return alt return alt
} }
} }
@ -1140,7 +1140,7 @@ func (this *ParserATNSimulator) splitAccordingToSemanticValidity( configs, outer
var failed = new ATNConfigSet(configs.fullCtx) var failed = new ATNConfigSet(configs.fullCtx)
for(var i=0i<configs.items.length i++) { for(var i=0i<configs.items.length i++) {
var c = configs.items[i] var c = configs.items[i]
if (c.semanticContext !== SemanticContext.NONE) { if (c.semanticContext != SemanticContext.NONE) {
var predicateEvaluationResult = c.semanticContext.evaluate(this.parser, outerContext) var predicateEvaluationResult = c.semanticContext.evaluate(this.parser, outerContext)
if (predicateEvaluationResult) { if (predicateEvaluationResult) {
succeeded.add(c) succeeded.add(c)
@ -1267,8 +1267,8 @@ func (this *ParserATNSimulator) closure_(config, configs, closureBusy, collectPr
var t = p.transitions[i] var t = p.transitions[i]
var continueCollecting = collectPredicates && !(t instanceof ActionTransition) var continueCollecting = collectPredicates && !(t instanceof ActionTransition)
var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon) var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
if (c!==nil) { if (c!=nil) {
if (!t.isEpsilon && closureBusy.add(c)!==c){ if (!t.isEpsilon && closureBusy.add(c)!=c){
// avoid infinite recursion for EOF* and EOF+ // avoid infinite recursion for EOF* and EOF+
continue continue
} }
@ -1280,12 +1280,12 @@ func (this *ParserATNSimulator) closure_(config, configs, closureBusy, collectPr
// come in handy and we avoid evaluating context dependent // come in handy and we avoid evaluating context dependent
// preds if this is > 0. // preds if this is > 0.
if (closureBusy.add(c)!==c) { if (closureBusy.add(c)!=c) {
// avoid infinite recursion for right-recursive rules // avoid infinite recursion for right-recursive rules
continue continue
} }
if (this._dfa !== nil && this._dfa.precedenceDfa) { if (this._dfa != nil && this._dfa.precedenceDfa) {
if (t.outermostPrecedenceReturn == this._dfa.atnStartState.ruleIndex) { if (t.outermostPrecedenceReturn == this._dfa.atnStartState.ruleIndex) {
c.precedenceFilterSuppressed = true c.precedenceFilterSuppressed = true
} }
@ -1309,7 +1309,7 @@ func (this *ParserATNSimulator) closure_(config, configs, closureBusy, collectPr
} }
func (this *ParserATNSimulator) getRuleName( index) { func (this *ParserATNSimulator) getRuleName( index) {
if (this.parser!==nil && index>=0) { if (this.parser!=nil && index>=0) {
return this.parser.ruleNames[index] return this.parser.ruleNames[index]
} else { } else {
return "<rule " + index + ">" return "<rule " + index + ">"
@ -1355,7 +1355,7 @@ func (this *ParserATNSimulator) precedenceTransition(config, pt, collectPredica
if (this.debug) { if (this.debug) {
console.log("PRED (collectPredicates=" + collectPredicates + ") " + console.log("PRED (collectPredicates=" + collectPredicates + ") " +
pt.precedence + ">=_p, ctx dependent=true") pt.precedence + ">=_p, ctx dependent=true")
if (this.parser!==nil) { if (this.parser!=nil) {
console.log("context surrounding pred is " + Utils.arrayToString(this.parser.getRuleInvocationStack())) console.log("context surrounding pred is " + Utils.arrayToString(this.parser.getRuleInvocationStack()))
} }
} }
@ -1390,7 +1390,7 @@ func (this *ParserATNSimulator) predTransition(config, pt, collectPredicates, in
if (this.debug) { if (this.debug) {
console.log("PRED (collectPredicates=" + collectPredicates + ") " + pt.ruleIndex + console.log("PRED (collectPredicates=" + collectPredicates + ") " + pt.ruleIndex +
":" + pt.predIndex + ", ctx dependent=" + pt.isCtxDependent) ":" + pt.predIndex + ", ctx dependent=" + pt.isCtxDependent)
if (this.parser!==nil) { if (this.parser!=nil) {
console.log("context surrounding pred is " + Utils.arrayToString(this.parser.getRuleInvocationStack())) console.log("context surrounding pred is " + Utils.arrayToString(this.parser.getRuleInvocationStack()))
} }
} }
@ -1473,7 +1473,7 @@ func (this *ParserATNSimulator) getConflictingAlts(configs) {
func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs) { func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs) {
var conflictingAlts = nil var conflictingAlts = nil
if (configs.uniqueAlt!== ATN.INVALID_ALT_NUMBER) { if (configs.uniqueAlt!= ATN.INVALID_ALT_NUMBER) {
conflictingAlts = new BitSet() conflictingAlts = new BitSet()
conflictingAlts.add(configs.uniqueAlt) conflictingAlts.add(configs.uniqueAlt)
} else { } else {
@ -1486,7 +1486,7 @@ func (this *ParserATNSimulator) getTokenName( t) {
if (t==Token.EOF) { if (t==Token.EOF) {
return "EOF" return "EOF"
} }
if( this.parser!==nil && this.parser.literalNames!==nil) { if( this.parser!=nil && this.parser.literalNames!=nil) {
if (t >= this.parser.literalNames.length) { if (t >= this.parser.literalNames.length) {
console.log("" + t + " ttype out of range: " + this.parser.literalNames) console.log("" + t + " ttype out of range: " + this.parser.literalNames)
console.log("" + this.parser.getInputStream().getTokens()) console.log("" + this.parser.getInputStream().getTokens())
@ -1534,7 +1534,7 @@ func (this *ParserATNSimulator) getUniqueAlt(configs) {
var c = configs.items[i] var c = configs.items[i]
if (alt == ATN.INVALID_ALT_NUMBER) { if (alt == ATN.INVALID_ALT_NUMBER) {
alt = c.alt // found first alt alt = c.alt // found first alt
} else if( c.alt!==alt) { } else if( c.alt!=alt) {
return ATN.INVALID_ALT_NUMBER return ATN.INVALID_ALT_NUMBER
} }
} }
@ -1604,7 +1604,7 @@ func (this *ParserATNSimulator) addDFAState(dfa, D) {
} }
var hash = D.hashString() var hash = D.hashString()
var existing = dfa.states[hash] || nil var existing = dfa.states[hash] || nil
if(existing!==nil) { if(existing!=nil) {
return existing return existing
} }
D.stateNumber = dfa.states.length D.stateNumber = dfa.states.length
@ -1625,7 +1625,7 @@ func (this *ParserATNSimulator) reportAttemptingFullContext(dfa, conflictingAlts
console.log("reportAttemptingFullContext decision=" + dfa.decision + ":" + configs + console.log("reportAttemptingFullContext decision=" + dfa.decision + ":" + configs +
", input=" + this.parser.getTokenStream().getText(interval)) ", input=" + this.parser.getTokenStream().getText(interval))
} }
if (this.parser!==nil) { if (this.parser!=nil) {
this.parser.getErrorListenerDispatch().reportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs) this.parser.getErrorListenerDispatch().reportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs)
} }
} }
@ -1636,7 +1636,7 @@ func (this *ParserATNSimulator) reportContextSensitivity(dfa, prediction, config
console.log("reportContextSensitivity decision=" + dfa.decision + ":" + configs + console.log("reportContextSensitivity decision=" + dfa.decision + ":" + configs +
", input=" + this.parser.getTokenStream().getText(interval)) ", input=" + this.parser.getTokenStream().getText(interval))
} }
if (this.parser!==nil) { if (this.parser!=nil) {
this.parser.getErrorListenerDispatch().reportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs) this.parser.getErrorListenerDispatch().reportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs)
} }
} }
@ -1649,7 +1649,7 @@ func (this *ParserATNSimulator) reportAmbiguity(dfa, D, startIndex, stopIndex,
console.log("reportAmbiguity " + ambigAlts + ":" + configs + console.log("reportAmbiguity " + ambigAlts + ":" + configs +
", input=" + this.parser.getTokenStream().getText(interval)) ", input=" + this.parser.getTokenStream().getText(interval))
} }
if (this.parser!==nil) { if (this.parser!=nil) {
this.parser.getErrorListenerDispatch().reportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs) this.parser.getErrorListenerDispatch().reportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
} }
} }

View File

@ -440,7 +440,7 @@ PredictionMode.allSubsetsEqual = function(altsets) {
var alts = altsets[i] var alts = altsets[i]
if (first == nil) { if (first == nil) {
first = alts first = alts
} else if (alts!==first) { } else if (alts!=first) {
return false return false
} }
} }
@ -499,7 +499,7 @@ PredictionMode.getConflictingAltSubsets = function(configs) {
} }
var values = [] var values = []
for(var k in configToAlts) { for(var k in configToAlts) {
if(k.indexOf("key_")!==0) { if(k.indexOf("key_")!=0) {
continue continue
} }
values.push(configToAlts[k]) values.push(configToAlts[k])
@ -545,7 +545,7 @@ PredictionMode.getSingleViableAlt = function(altsets) {
var minAlt = alts.minValue() var minAlt = alts.minValue()
if(result==nil) { if(result==nil) {
result = minAlt result = minAlt
} else if(result!==minAlt) { // more than 1 viable alt } else if(result!=minAlt) { // more than 1 viable alt
return ATN.INVALID_ALT_NUMBER return ATN.INVALID_ALT_NUMBER
} }
} }

View File

@ -254,11 +254,11 @@ func (this *AND) evalPrecedence(parser, outerContext) {
for (var i = 0 i < this.opnds.length i++) { for (var i = 0 i < this.opnds.length i++) {
var context = this.opnds[i] var context = this.opnds[i]
var evaluated = context.evalPrecedence(parser, outerContext) var evaluated = context.evalPrecedence(parser, outerContext)
differs |= (evaluated !== context) differs |= (evaluated != context)
if (evaluated == nil) { if (evaluated == nil) {
// The AND context is false if any element is false // The AND context is false if any element is false
return nil return nil
} else if (evaluated !== SemanticContext.NONE) { } else if (evaluated != SemanticContext.NONE) {
// Reduce the result by skipping true elements // Reduce the result by skipping true elements
operands.push(evaluated) operands.push(evaluated)
} }
@ -356,11 +356,11 @@ func (this *OR) evalPrecedence(parser, outerContext) {
for (var i = 0 i < this.opnds.length i++) { for (var i = 0 i < this.opnds.length i++) {
var context = this.opnds[i] var context = this.opnds[i]
var evaluated = context.evalPrecedence(parser, outerContext) var evaluated = context.evalPrecedence(parser, outerContext)
differs |= (evaluated !== context) differs |= (evaluated != context)
if (evaluated == SemanticContext.NONE) { if (evaluated == SemanticContext.NONE) {
// The OR context is true if any element is true // The OR context is true if any element is true
return SemanticContext.NONE return SemanticContext.NONE
} else if (evaluated !== nil) { } else if (evaluated != nil) {
// Reduce the result by skipping false elements // Reduce the result by skipping false elements
operands.push(evaluated) operands.push(evaluated)
} }

View File

@ -218,7 +218,7 @@ func (this *ActionTransition) toString() {
func SetTransition(target, set) { func SetTransition(target, set) {
Transition.call(this, target) Transition.call(this, target)
this.serializationType = Transition.SET this.serializationType = Transition.SET
if (set !==undefined && set !==nil) { if (set !=undefined && set !=nil) {
this.label = set this.label = set
} else { } else {
this.label = new IntervalSet() this.label = new IntervalSet()

View File

@ -94,7 +94,7 @@ func (this *DFA) setPrecedenceStartState(precedence, startState) {
// {@code false} // {@code false}
func (this *DFA) setPrecedenceDfa(precedenceDfa) { func (this *DFA) setPrecedenceDfa(precedenceDfa) {
if (this.precedenceDfa!==precedenceDfa) { if (this.precedenceDfa!=precedenceDfa) {
this._states = new DFAStatesSet() this._states = new DFAStatesSet()
if (precedenceDfa) { if (precedenceDfa) {
var precedenceState = new DFAState(new ATNConfigSet()) var precedenceState = new DFAState(new ATNConfigSet())

View File

@ -18,11 +18,11 @@ func (this *DFASerializer) toString() {
var states = this.dfa.sortedStates() var states = this.dfa.sortedStates()
for(var i=0i<states.lengthi++) { for(var i=0i<states.lengthi++) {
var s = states[i] var s = states[i]
if(s.edges!==nil) { if(s.edges!=nil) {
var n = s.edges.length var n = s.edges.length
for(var j=0j<nj++) { for(var j=0j<nj++) {
var t = s.edges[j] || nil var t = s.edges[j] || nil
if(t!==nil && t.stateNumber !== 0x7FFFFFFF) { if(t!=nil && t.stateNumber != 0x7FFFFFFF) {
buf = buf.concat(this.getStateString(s)) buf = buf.concat(this.getStateString(s))
buf = buf.concat("-") buf = buf.concat("-")
buf = buf.concat(this.getEdgeLabel(j)) buf = buf.concat(this.getEdgeLabel(j))
@ -39,7 +39,7 @@ func (this *DFASerializer) toString() {
func (this *DFASerializer) getEdgeLabel(i) { func (this *DFASerializer) getEdgeLabel(i) {
if (i==0) { if (i==0) {
return "EOF" return "EOF"
} else if(this.literalNames !==nil || this.symbolicNames!==nil) { } else if(this.literalNames !=nil || this.symbolicNames!=nil) {
return this.literalNames[i-1] || this.symbolicNames[i-1] return this.literalNames[i-1] || this.symbolicNames[i-1]
} else { } else {
return String.fromCharCode(i-1) return String.fromCharCode(i-1)
@ -49,7 +49,7 @@ func (this *DFASerializer) getEdgeLabel(i) {
func (this *DFASerializer) getStateString(s) { func (this *DFASerializer) getStateString(s) {
var baseStateStr = ( s.isAcceptState ? ":" : "") + "s" + s.stateNumber + ( s.requiresFullContext ? "^" : "") var baseStateStr = ( s.isAcceptState ? ":" : "") + "s" + s.stateNumber + ( s.requiresFullContext ? "^" : "")
if(s.isAcceptState) { if(s.isAcceptState) {
if (s.predicates !== nil) { if (s.predicates != nil) {
return baseStateStr + "=>" + s.predicates.toString() return baseStateStr + "=>" + s.predicates.toString()
} else { } else {
return baseStateStr + "=>" + s.prediction.toString() return baseStateStr + "=>" + s.prediction.toString()

View File

@ -85,7 +85,7 @@ func DFAState(stateNumber, configs) {
// DFA state. // DFA state.
func (this *DFAState) getAltSet() { func (this *DFAState) getAltSet() {
var alts = new Set() var alts = new Set()
if (this.configs !== nil) { if (this.configs != nil) {
for (var i = 0 i < this.configs.length i++) { for (var i = 0 i < this.configs.length i++) {
var c = this.configs[i] var c = this.configs[i]
alts.add(c.alt) alts.add(c.alt)
@ -127,7 +127,7 @@ func (this *DFAState) toString() {
func (this *DFAState) hashString() { func (this *DFAState) hashString() {
return "" + this.configs + return "" + this.configs +
(this.isAcceptState ? (this.isAcceptState ?
"=>" + (this.predicates !== nil ? "=>" + (this.predicates != nil ?
this.predicates : this.predicates :
this.prediction) : this.prediction) :
"") "")

View File

@ -93,7 +93,7 @@ func (this *DiagnosticErrorListener) getDecisionDescription(recognizer, dfa) {
// returns the set of alternatives represented in {@code configs}. // returns the set of alternatives represented in {@code configs}.
// //
func (this *DiagnosticErrorListener) getConflictingAlts(reportedAlts, configs) { func (this *DiagnosticErrorListener) getConflictingAlts(reportedAlts, configs) {
if (reportedAlts !== nil) { if (reportedAlts != nil) {
return reportedAlts return reportedAlts
} }
var result = new BitSet() var result = new BitSet()

View File

@ -149,7 +149,7 @@ func (this *DefaultErrorStrategy) reportError(recognizer, e) {
// //
func (this *DefaultErrorStrategy) recover(recognizer, e) { func (this *DefaultErrorStrategy) recover(recognizer, e) {
if (this.lastErrorIndex==recognizer.getInputStream().index && if (this.lastErrorIndex==recognizer.getInputStream().index &&
this.lastErrorStates !== nil && this.lastErrorStates.indexOf(recognizer.state)>=0) { this.lastErrorStates != nil && this.lastErrorStates.indexOf(recognizer.state)>=0) {
// uh oh, another error at same token index and previously-visited // uh oh, another error at same token index and previously-visited
// state in ATN must be a case where LT(1) is in the recovery // state in ATN must be a case where LT(1) is in the recovery
// token set so nothing got consumed. Consume a single token // token set so nothing got consumed. Consume a single token
@ -231,7 +231,7 @@ func (this *DefaultErrorStrategy) sync(recognizer) {
case ATNState.PLUS_BLOCK_START: case ATNState.PLUS_BLOCK_START:
case ATNState.STAR_LOOP_ENTRY: case ATNState.STAR_LOOP_ENTRY:
// report error and recover if possible // report error and recover if possible
if( this.singleTokenDeletion(recognizer) !== nil) { if( this.singleTokenDeletion(recognizer) != nil) {
return return
} else { } else {
throw new InputMismatchException(recognizer) throw new InputMismatchException(recognizer)
@ -261,7 +261,7 @@ func (this *DefaultErrorStrategy) sync(recognizer) {
func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer, e) { func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer, e) {
var tokens = recognizer.getTokenStream() var tokens = recognizer.getTokenStream()
var input var input
if(tokens !== nil) { if(tokens != nil) {
if (e.startToken.type==Token.EOF) { if (e.startToken.type==Token.EOF) {
input = "<EOF>" input = "<EOF>"
} else { } else {
@ -413,7 +413,7 @@ func (this *DefaultErrorStrategy) reportMissingToken(recognizer) {
func (this *DefaultErrorStrategy) recoverInline(recognizer) { func (this *DefaultErrorStrategy) recoverInline(recognizer) {
// SINGLE TOKEN DELETION // SINGLE TOKEN DELETION
var matchedSymbol = this.singleTokenDeletion(recognizer) var matchedSymbol = this.singleTokenDeletion(recognizer)
if (matchedSymbol !== nil) { if (matchedSymbol != nil) {
// we have deleted the extra token. // we have deleted the extra token.
// now, move past ttype token as if all were ok // now, move past ttype token as if all were ok
recognizer.consume() recognizer.consume()
@ -529,7 +529,7 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer) {
} }
var current = currentSymbol var current = currentSymbol
var lookback = recognizer.getTokenStream().LT(-1) var lookback = recognizer.getTokenStream().LT(-1)
if (current.type==Token.EOF && lookback !== nil) { if (current.type==Token.EOF && lookback != nil) {
current = lookback current = lookback
} }
return recognizer.getTokenFactory().create(current.source, return recognizer.getTokenFactory().create(current.source,
@ -667,7 +667,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer) {
var atn = recognizer._interp.atn var atn = recognizer._interp.atn
var ctx = recognizer._ctx var ctx = recognizer._ctx
var recoverSet = new IntervalSet() var recoverSet = new IntervalSet()
while (ctx !== nil && ctx.invokingState>=0) { while (ctx != nil && ctx.invokingState>=0) {
// compute what follows who invoked us // compute what follows who invoked us
var invokingState = atn.states[ctx.invokingState] var invokingState = atn.states[ctx.invokingState]
var rt = invokingState.transitions[0] var rt = invokingState.transitions[0]
@ -682,7 +682,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer) {
// Consume tokens until one matches the given token set.// // Consume tokens until one matches the given token set.//
func (this *DefaultErrorStrategy) consumeUntil(recognizer, set) { func (this *DefaultErrorStrategy) consumeUntil(recognizer, set) {
var ttype = recognizer.getTokenStream().LA(1) var ttype = recognizer.getTokenStream().LA(1)
while( ttype !== Token.EOF && !set.contains(ttype)) { while( ttype != Token.EOF && !set.contains(ttype)) {
recognizer.consume() recognizer.consume()
ttype = recognizer.getTokenStream().LA(1) ttype = recognizer.getTokenStream().LA(1)
} }
@ -731,7 +731,7 @@ BailErrorStrategy.prototype.constructor = BailErrorStrategy
// //
func (this *BailErrorStrategy) recover(recognizer, e) { func (this *BailErrorStrategy) recover(recognizer, e) {
var context = recognizer._ctx var context = recognizer._ctx
while (context !== nil) { while (context != nil) {
context.exception = e context.exception = e
context = context.parentCtx context = context.parentCtx
} }

View File

@ -29,7 +29,7 @@ func RecognitionException(params) {
// {@link DecisionState} number. For others, it is the state whose outgoing // {@link DecisionState} number. For others, it is the state whose outgoing
// edge we couldn't match. // edge we couldn't match.
this.offendingState = -1 this.offendingState = -1
if (this.recognizer!==nil) { if (this.recognizer!=nil) {
this.offendingState = this.recognizer.state this.offendingState = this.recognizer.state
} }
return this return this
@ -51,7 +51,7 @@ RecognitionException.prototype.constructor = RecognitionException
// state in the ATN, or {@code nil} if the information is not available. // state in the ATN, or {@code nil} if the information is not available.
// / // /
func (this *RecognitionException) getExpectedTokens() { func (this *RecognitionException) getExpectedTokens() {
if (this.recognizer!==nil) { if (this.recognizer!=nil) {
return this.recognizer.atn.getExpectedTokens(this.offendingState, this.ctx) return this.recognizer.atn.getExpectedTokens(this.offendingState, this.ctx)
} else { } else {
return nil return nil
@ -142,7 +142,7 @@ FailedPredicateException.prototype = Object.create(RecognitionException.prototyp
FailedPredicateException.prototype.constructor = FailedPredicateException FailedPredicateException.prototype.constructor = FailedPredicateException
func (this *FailedPredicateException) formatMessage(predicate, message) { func (this *FailedPredicateException) formatMessage(predicate, message) {
if (message !==nil) { if (message !=nil) {
return message return message
} else { } else {
return "failed predicate: {" + predicate + "}?" return "failed predicate: {" + predicate + "}?"

View File

@ -179,7 +179,7 @@ type ParseTreeWalker struct {
func (this *ParseTreeWalker) walk(listener, t) { func (this *ParseTreeWalker) walk(listener, t) {
var errorNode = t instanceof ErrorNode || var errorNode = t instanceof ErrorNode ||
(t.isErrorNode !== undefined && t.isErrorNode()) (t.isErrorNode != undefined && t.isErrorNode())
if (errorNode) { if (errorNode) {
listener.visitErrorNode(t) listener.visitErrorNode(t)
} else if (t instanceof TerminalNode) { } else if (t instanceof TerminalNode) {

View File

@ -17,7 +17,7 @@ type Trees struct {
Trees.toStringTree = function(tree, ruleNames, recog) { Trees.toStringTree = function(tree, ruleNames, recog) {
ruleNames = ruleNames || nil ruleNames = ruleNames || nil
recog = recog || nil recog = recog || nil
if(recog!==nil) { if(recog!=nil) {
ruleNames = recog.ruleNames ruleNames = recog.ruleNames
} }
var s = Trees.getNodeText(tree, ruleNames) var s = Trees.getNodeText(tree, ruleNames)
@ -42,16 +42,16 @@ Trees.toStringTree = function(tree, ruleNames, recog) {
Trees.getNodeText = function(t, ruleNames, recog) { Trees.getNodeText = function(t, ruleNames, recog) {
ruleNames = ruleNames || nil ruleNames = ruleNames || nil
recog = recog || nil recog = recog || nil
if(recog!==nil) { if(recog!=nil) {
ruleNames = recog.ruleNames ruleNames = recog.ruleNames
} }
if(ruleNames!==nil) { if(ruleNames!=nil) {
if (t instanceof RuleNode) { if (t instanceof RuleNode) {
return ruleNames[t.getRuleContext().ruleIndex] return ruleNames[t.getRuleContext().ruleIndex]
} else if ( t instanceof ErrorNode) { } else if ( t instanceof ErrorNode) {
return t.toString() return t.toString()
} else if(t instanceof TerminalNode) { } else if(t instanceof TerminalNode) {
if(t.symbol!==nil) { if(t.symbol!=nil) {
return t.symbol.text return t.symbol.text
} }
} }
@ -80,7 +80,7 @@ Trees.getChildren = function(t) {
Trees.getAncestors = function(t) { Trees.getAncestors = function(t) {
var ancestors = [] var ancestors = []
t = t.getParent() t = t.getParent()
while(t!==nil) { while(t!=nil) {
ancestors = [t].concat(ancestors) ancestors = [t].concat(ancestors)
t = t.getParent() t = t.getParent()
} }