More minor fixes

This commit is contained in:
Peter Boyer 2015-12-26 10:32:02 -06:00
parent a2e6ee7570
commit 4ffb3f81b6
10 changed files with 44 additions and 40 deletions

View File

@ -151,7 +151,7 @@ func (this *ATNConfig) equals(other interface{}) bool {
} }
func (this *ATNConfig) shortHashString() string { func (this *ATNConfig) shortHashString() string {
return "" + strconv.Itoa(this.state.GetStateNumber()) + "/" + strconv.Itoa(this.alt) + "/" + this.semanticContext.String() return strconv.Itoa(this.state.GetStateNumber()) + "/" + strconv.Itoa(this.alt) + "/" + this.semanticContext.String()
} }
func (this *ATNConfig) hashString() string { func (this *ATNConfig) hashString() string {
@ -163,7 +163,7 @@ func (this *ATNConfig) hashString() string {
c = this.context.hashString() c = this.context.hashString()
} }
return "" + strconv.Itoa(this.state.GetStateNumber()) + "/" + strconv.Itoa(this.alt) + "/" + c + "/" + this.semanticContext.String() return strconv.Itoa(this.state.GetStateNumber()) + "/" + strconv.Itoa(this.alt) + "/" + c + "/" + this.semanticContext.String()
} }
func (this *ATNConfig) String() string { func (this *ATNConfig) String() string {
@ -175,7 +175,7 @@ func (this *ATNConfig) String() string {
var b string var b string
if this.semanticContext != SemanticContextNONE { if this.semanticContext != SemanticContextNONE {
b = ("," + fmt.Sprint(this.semanticContext)) b = "," + fmt.Sprint(this.semanticContext)
} }
var c string var c string
@ -186,6 +186,10 @@ func (this *ATNConfig) String() string {
return "(" + fmt.Sprint(this.state) + "," + strconv.Itoa(this.alt) + a + b + c + ")" return "(" + fmt.Sprint(this.state) + "," + strconv.Itoa(this.alt) + a + b + c + ")"
} }
type LexerATNConfig struct { type LexerATNConfig struct {
*ATNConfig *ATNConfig
@ -265,7 +269,7 @@ func (this *LexerATNConfig) hashString() string {
f = "0" f = "0"
} }
return "" + strconv.Itoa(this.state.GetStateNumber()) + strconv.Itoa(this.alt) + fmt.Sprint(this.context) + return strconv.Itoa(this.state.GetStateNumber()) + strconv.Itoa(this.alt) + fmt.Sprint(this.context) +
fmt.Sprint(this.semanticContext) + f + fmt.Sprint(this.lexerActionExecutor) fmt.Sprint(this.semanticContext) + f + fmt.Sprint(this.lexerActionExecutor)
} }

View File

@ -15,6 +15,10 @@ func hashATNConfig(c interface{}) string {
} }
func equalATNConfigs(a, b interface{}) bool { func equalATNConfigs(a, b interface{}) bool {
fmt.Println("compare")
fmt.Println(a)
if a == b { if a == b {
return true return true
} }
@ -30,10 +34,11 @@ func equalATNConfigs(a, b interface{}) bool {
} }
return ai.GetState().GetStateNumber() == bi.GetState().GetStateNumber() && return ai.GetState().GetStateNumber() == bi.GetState().GetStateNumber() &&
ai.GetAlt() == bi.GetAlt() && ai.GetAlt() == bi.GetAlt() &&
ai.GetSemanticContext().equals(bi.GetSemanticContext()) ai.GetSemanticContext().equals(bi.GetSemanticContext())
} }
type ATNConfigSet struct { type ATNConfigSet struct {
readOnly bool readOnly bool
fullCtx bool fullCtx bool
@ -102,6 +107,8 @@ func NewATNConfigSet(fullCtx bool) *ATNConfigSet {
// / // /
func (this *ATNConfigSet) add(config IATNConfig, mergeCache *DoubleDict) bool { func (this *ATNConfigSet) add(config IATNConfig, mergeCache *DoubleDict) bool {
// fmt.Println("DEBUG = Adding config : " + config.String())
if this.readOnly { if this.readOnly {
panic("This set is readonly") panic("This set is readonly")
} }

View File

@ -7,7 +7,7 @@ import (
// //
// This implementation of {@link ANTLRErrorListener} can be used to identify // This implementation of {@link ANTLRErrorListener} can be used to identify
// certain potential correctness and performance problems in grammars. "Reports" // certain potential correctness and performance problems in grammars. "Reports"
// are made by calling {@link Parser//notifyErrorListeners} with the appropriate // are made by calling {@link Parser//NotifyErrorListeners} with the appropriate
// message. // message.
// //
// <ul> // <ul>
@ -48,7 +48,7 @@ func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer *Parser, dfa *DF
this.getConflictingAlts(ambigAlts, configs).String() + this.getConflictingAlts(ambigAlts, configs).String() +
", input='" + ", input='" +
recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'" recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'"
recognizer.notifyErrorListeners(msg, nil, nil) recognizer.NotifyErrorListeners(msg, nil, nil)
} }
func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) { func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
@ -57,7 +57,7 @@ func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Par
this.getDecisionDescription(recognizer, dfa) + this.getDecisionDescription(recognizer, dfa) +
", input='" + ", input='" +
recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'" recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'"
recognizer.notifyErrorListeners(msg, nil, nil) recognizer.NotifyErrorListeners(msg, nil, nil)
} }
func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) { func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
@ -65,7 +65,7 @@ func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *Parser
this.getDecisionDescription(recognizer, dfa) + this.getDecisionDescription(recognizer, dfa) +
", input='" + ", input='" +
recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'" recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'"
recognizer.notifyErrorListeners(msg, nil, nil) recognizer.NotifyErrorListeners(msg, nil, nil)
} }
func (this *DiagnosticErrorListener) getDecisionDescription(recognizer *Parser, dfa *DFA) string { func (this *DiagnosticErrorListener) getDecisionDescription(recognizer *Parser, dfa *DFA) string {

View File

@ -61,7 +61,7 @@ var ConsoleErrorListenerINSTANCE = NewConsoleErrorListener()
// </pre> // </pre>
// //
func (this *ConsoleErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) { func (this *ConsoleErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
fmt.Errorf("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg) fmt.Println("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg)
} }
type ProxyErrorListener struct { type ProxyErrorListener struct {

View File

@ -106,7 +106,7 @@ func (this *DefaultErrorStrategy) ReportMatch(recognizer IParser) {
// {@link //ReportInputMisMatch}</li> // {@link //ReportInputMisMatch}</li>
// <li>{@link FailedPredicateException}: Dispatches the call to // <li>{@link FailedPredicateException}: Dispatches the call to
// {@link //ReportFailedPredicate}</li> // {@link //ReportFailedPredicate}</li>
// <li>All other types: calls {@link Parser//notifyErrorListeners} to Report // <li>All other types: calls {@link Parser//NotifyErrorListeners} to Report
// the exception</li> // the exception</li>
// </ul> // </ul>
// //
@ -122,7 +122,7 @@ func (this *DefaultErrorStrategy) ReportError(recognizer IParser, e IRecognition
default: default:
fmt.Println("unknown recognition error type: " + reflect.TypeOf(e).Name()) fmt.Println("unknown recognition error type: " + reflect.TypeOf(e).Name())
// fmt.Println(e.stack) // fmt.Println(e.stack)
recognizer.notifyErrorListeners(e.GetMessage(), e.GetOffendingToken(), e) recognizer.NotifyErrorListeners(e.GetMessage(), e.GetOffendingToken(), e)
case *NoViableAltException: case *NoViableAltException:
this.ReportNoViableAlternative(recognizer, t) this.ReportNoViableAlternative(recognizer, t)
case *InputMisMatchException: case *InputMisMatchException:
@ -264,7 +264,7 @@ func (this *DefaultErrorStrategy) ReportNoViableAlternative(recognizer IParser,
input = "<unknown input>" input = "<unknown input>"
} }
var msg = "no viable alternative at input " + this.escapeWSAndQuote(input) var msg = "no viable alternative at input " + this.escapeWSAndQuote(input)
recognizer.notifyErrorListeners(msg, e.offendingToken, e) recognizer.NotifyErrorListeners(msg, e.offendingToken, e)
} }
// //
@ -279,7 +279,7 @@ func (this *DefaultErrorStrategy) ReportNoViableAlternative(recognizer IParser,
func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer IParser, e *InputMisMatchException) { func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer IParser, e *InputMisMatchException) {
var msg = "misMatched input " + this.GetTokenErrorDisplay(e.offendingToken) + var msg = "misMatched input " + this.GetTokenErrorDisplay(e.offendingToken) +
" expecting " + e.getExpectedTokens().StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) " expecting " + e.getExpectedTokens().StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
recognizer.notifyErrorListeners(msg, e.offendingToken, e) recognizer.NotifyErrorListeners(msg, e.offendingToken, e)
} }
// //
@ -294,7 +294,7 @@ func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer IParser, e *Inp
func (this *DefaultErrorStrategy) ReportFailedPredicate(recognizer IParser, e *FailedPredicateException) { func (this *DefaultErrorStrategy) ReportFailedPredicate(recognizer IParser, e *FailedPredicateException) {
var ruleName = recognizer.GetRuleNames()[recognizer.GetParserRuleContext().GetRuleIndex()] var ruleName = recognizer.GetRuleNames()[recognizer.GetParserRuleContext().GetRuleIndex()]
var msg = "rule " + ruleName + " " + e.message var msg = "rule " + ruleName + " " + e.message
recognizer.notifyErrorListeners(msg, e.offendingToken, e) recognizer.NotifyErrorListeners(msg, e.offendingToken, e)
} }
// This method is called to Report a syntax error which requires the removal // This method is called to Report a syntax error which requires the removal
@ -310,7 +310,7 @@ func (this *DefaultErrorStrategy) ReportFailedPredicate(recognizer IParser, e *F
// <p>The default implementation simply returns if the handler is already in // <p>The default implementation simply returns if the handler is already in
// error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to // error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to
// enter error recovery mode, followed by calling // enter error recovery mode, followed by calling
// {@link Parser//notifyErrorListeners}.</p> // {@link Parser//NotifyErrorListeners}.</p>
// //
// @param recognizer the parser instance // @param recognizer the parser instance
// //
@ -324,7 +324,7 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer IParser) {
var expecting = this.getExpectedTokens(recognizer) var expecting = this.getExpectedTokens(recognizer)
var msg = "extraneous input " + tokenName + " expecting " + var msg = "extraneous input " + tokenName + " expecting " +
expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
recognizer.notifyErrorListeners(msg, t, nil) recognizer.NotifyErrorListeners(msg, t, nil)
} }
// This method is called to Report a syntax error which requires the // This method is called to Report a syntax error which requires the
@ -339,7 +339,7 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer IParser) {
// <p>The default implementation simply returns if the handler is already in // <p>The default implementation simply returns if the handler is already in
// error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to // error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to
// enter error recovery mode, followed by calling // enter error recovery mode, followed by calling
// {@link Parser//notifyErrorListeners}.</p> // {@link Parser//NotifyErrorListeners}.</p>
// //
// @param recognizer the parser instance // @param recognizer the parser instance
// //
@ -352,7 +352,7 @@ func (this *DefaultErrorStrategy) ReportMissingToken(recognizer IParser) {
var expecting = this.getExpectedTokens(recognizer) var expecting = this.getExpectedTokens(recognizer)
var msg = "missing " + expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) + var msg = "missing " + expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) +
" at " + this.GetTokenErrorDisplay(t) " at " + this.GetTokenErrorDisplay(t)
recognizer.notifyErrorListeners(msg, t, nil) recognizer.NotifyErrorListeners(msg, t, nil)
} }
// <p>The default implementation attempts to recover from the misMatched input // <p>The default implementation attempts to recover from the misMatched input

View File

@ -14,7 +14,7 @@ type IParser interface {
GetInputStream() IntStream GetInputStream() IntStream
getCurrentToken() *Token getCurrentToken() *Token
getExpectedTokens() *IntervalSet getExpectedTokens() *IntervalSet
notifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException) NotifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException)
isExpectedToken(symbol int) bool isExpectedToken(symbol int) bool
getPrecedence() int getPrecedence() int
getRuleInvocationStack(IParserRuleContext) []string getRuleInvocationStack(IParserRuleContext) []string
@ -68,7 +68,7 @@ func NewParser(input TokenStream) *Parser {
// events during the parse. // events during the parse.
p._parseListeners = nil p._parseListeners = nil
// The number of syntax errors Reported during parsing. p.value is // The number of syntax errors Reported during parsing. p.value is
// incremented each time {@link //notifyErrorListeners} is called. // incremented each time {@link //NotifyErrorListeners} is called.
p._SyntaxErrors = 0 p._SyntaxErrors = 0
p.setInputStream(input) p.setInputStream(input)
@ -389,7 +389,7 @@ func (p *Parser) getCurrentToken() *Token {
return p._input.LT(1) return p._input.LT(1)
} }
func (p *Parser) notifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException) { func (p *Parser) NotifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException) {
if offendingToken == nil { if offendingToken == nil {
offendingToken = p.getCurrentToken() offendingToken = p.getCurrentToken()
} }

View File

@ -47,10 +47,10 @@ func NewParserATNSimulator(parser IParser, atn *ATN, decisionToDFA []*DFA, share
return this return this
} }
var ParserATNSimulatorDebug = true var ParserATNSimulatorDebug = false
var ParserATNSimulatorListATNDecisions = true var ParserATNSimulatorListATNDecisions = false
var ParserATNSimulatorDFADebug = true var ParserATNSimulatorDFADebug = false
var ParserATNSimulatorRetryDebug = true var ParserATNSimulatorRetryDebug = false
func (this *ParserATNSimulator) reset() { func (this *ParserATNSimulator) reset() {
} }
@ -966,13 +966,6 @@ func (this *ParserATNSimulator) evalSemanticContext(predPredictions []*PredPredi
return predictions return predictions
} }
// TODO: If we are doing predicates, there is no point in pursuing
// closure operations if we reach a DFA state that uniquely predicts
// alternative. We will not be caching that DFA state and it is a
// waste to pursue the closure. Might have to advance when we do
// ambig detection thought :(
//
func (this *ParserATNSimulator) closure(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx, treatEofAsEpsilon bool) { func (this *ParserATNSimulator) closure(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx, treatEofAsEpsilon bool) {
var initialDepth = 0 var initialDepth = 0
this.closureCheckingStopState(config, configs, closureBusy, collectPredicates, this.closureCheckingStopState(config, configs, closureBusy, collectPredicates,
@ -982,7 +975,7 @@ func (this *ParserATNSimulator) closure(config IATNConfig, configs *ATNConfigSet
func (this *ParserATNSimulator) closureCheckingStopState(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx bool, depth int, treatEofAsEpsilon bool) { func (this *ParserATNSimulator) closureCheckingStopState(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx bool, depth int, treatEofAsEpsilon bool) {
if ParserATNSimulatorDebug { if ParserATNSimulatorDebug {
fmt.Println("closure(" + config.String() + ")") //config.String(this.parser,true) + ")") fmt.Println("closure(" + config.String() + ")")
fmt.Println("configs(" + configs.String() + ")") fmt.Println("configs(" + configs.String() + ")")
if config.GetReachesIntoOuterContext() > 50 { if config.GetReachesIntoOuterContext() > 50 {
panic("problem") panic("problem")

View File

@ -182,7 +182,6 @@ func (t *RuleTransition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) boo
type EpsilonTransition struct { type EpsilonTransition struct {
*Transition *Transition
isEpsilon bool
outermostPrecedenceReturn int outermostPrecedenceReturn int
} }

View File

@ -1462,6 +1462,7 @@ public class ParserATNSimulator extends ATNSimulator {
boolean fullCtx, boolean fullCtx,
boolean treatEofAsEpsilon) boolean treatEofAsEpsilon)
{ {
console.log("closure");
final int initialDepth = 0; final int initialDepth = 0;
closureCheckingStopState(config, configs, closureBusy, collectPredicates, closureCheckingStopState(config, configs, closureBusy, collectPredicates,
fullCtx, fullCtx,

View File

@ -313,10 +313,10 @@ function ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) {
ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype); ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype);
ParserATNSimulator.prototype.constructor = ParserATNSimulator; ParserATNSimulator.prototype.constructor = ParserATNSimulator;
ParserATNSimulator.prototype.debug = true; ParserATNSimulator.prototype.debug = false;
ParserATNSimulator.prototype.debug_list_atn_decisions = true; ParserATNSimulator.prototype.debug_list_atn_decisions = false;
ParserATNSimulator.prototype.dfa_debug = true; ParserATNSimulator.prototype.dfa_debug = false;
ParserATNSimulator.prototype.retry_debug = true; ParserATNSimulator.prototype.retry_debug = false;
ParserATNSimulator.prototype.reset = function() { ParserATNSimulator.prototype.reset = function() {