More minor fixes
This commit is contained in:
parent
a2e6ee7570
commit
4ffb3f81b6
|
@ -151,7 +151,7 @@ func (this *ATNConfig) equals(other interface{}) bool {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
@ -163,7 +163,7 @@ func (this *ATNConfig) hashString() string {
|
|||
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 {
|
||||
|
@ -175,7 +175,7 @@ func (this *ATNConfig) String() string {
|
|||
|
||||
var b string
|
||||
if this.semanticContext != SemanticContextNONE {
|
||||
b = ("," + fmt.Sprint(this.semanticContext))
|
||||
b = "," + fmt.Sprint(this.semanticContext)
|
||||
}
|
||||
|
||||
var c string
|
||||
|
@ -186,6 +186,10 @@ func (this *ATNConfig) String() string {
|
|||
return "(" + fmt.Sprint(this.state) + "," + strconv.Itoa(this.alt) + a + b + c + ")"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
type LexerATNConfig struct {
|
||||
*ATNConfig
|
||||
|
||||
|
@ -265,7 +269,7 @@ func (this *LexerATNConfig) hashString() string {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ func hashATNConfig(c interface{}) string {
|
|||
}
|
||||
|
||||
func equalATNConfigs(a, b interface{}) bool {
|
||||
|
||||
fmt.Println("compare")
|
||||
fmt.Println(a)
|
||||
|
||||
if a == b {
|
||||
return true
|
||||
}
|
||||
|
@ -34,6 +38,7 @@ func equalATNConfigs(a, b interface{}) bool {
|
|||
ai.GetSemanticContext().equals(bi.GetSemanticContext())
|
||||
}
|
||||
|
||||
|
||||
type ATNConfigSet struct {
|
||||
readOnly bool
|
||||
fullCtx bool
|
||||
|
@ -102,6 +107,8 @@ func NewATNConfigSet(fullCtx bool) *ATNConfigSet {
|
|||
// /
|
||||
func (this *ATNConfigSet) add(config IATNConfig, mergeCache *DoubleDict) bool {
|
||||
|
||||
// fmt.Println("DEBUG = Adding config : " + config.String())
|
||||
|
||||
if this.readOnly {
|
||||
panic("This set is readonly")
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
//
|
||||
// This implementation of {@link ANTLRErrorListener} can be used to identify
|
||||
// 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.
|
||||
//
|
||||
// <ul>
|
||||
|
@ -48,7 +48,7 @@ func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer *Parser, dfa *DF
|
|||
this.getConflictingAlts(ambigAlts, configs).String() +
|
||||
", input='" +
|
||||
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) {
|
||||
|
@ -57,7 +57,7 @@ func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Par
|
|||
this.getDecisionDescription(recognizer, dfa) +
|
||||
", input='" +
|
||||
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) {
|
||||
|
@ -65,7 +65,7 @@ func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *Parser
|
|||
this.getDecisionDescription(recognizer, dfa) +
|
||||
", input='" +
|
||||
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 {
|
||||
|
|
|
@ -61,7 +61,7 @@ var ConsoleErrorListenerINSTANCE = NewConsoleErrorListener()
|
|||
// </pre>
|
||||
//
|
||||
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 {
|
||||
|
|
|
@ -106,7 +106,7 @@ func (this *DefaultErrorStrategy) ReportMatch(recognizer IParser) {
|
|||
// {@link //ReportInputMisMatch}</li>
|
||||
// <li>{@link FailedPredicateException}: Dispatches the call to
|
||||
// {@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>
|
||||
// </ul>
|
||||
//
|
||||
|
@ -122,7 +122,7 @@ func (this *DefaultErrorStrategy) ReportError(recognizer IParser, e IRecognition
|
|||
default:
|
||||
fmt.Println("unknown recognition error type: " + reflect.TypeOf(e).Name())
|
||||
// fmt.Println(e.stack)
|
||||
recognizer.notifyErrorListeners(e.GetMessage(), e.GetOffendingToken(), e)
|
||||
recognizer.NotifyErrorListeners(e.GetMessage(), e.GetOffendingToken(), e)
|
||||
case *NoViableAltException:
|
||||
this.ReportNoViableAlternative(recognizer, t)
|
||||
case *InputMisMatchException:
|
||||
|
@ -264,7 +264,7 @@ func (this *DefaultErrorStrategy) ReportNoViableAlternative(recognizer IParser,
|
|||
input = "<unknown 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) {
|
||||
var msg = "misMatched input " + this.GetTokenErrorDisplay(e.offendingToken) +
|
||||
" 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) {
|
||||
var ruleName = recognizer.GetRuleNames()[recognizer.GetParserRuleContext().GetRuleIndex()]
|
||||
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
|
||||
|
@ -310,7 +310,7 @@ func (this *DefaultErrorStrategy) ReportFailedPredicate(recognizer IParser, e *F
|
|||
// <p>The default implementation simply returns if the handler is already in
|
||||
// error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to
|
||||
// enter error recovery mode, followed by calling
|
||||
// {@link Parser//notifyErrorListeners}.</p>
|
||||
// {@link Parser//NotifyErrorListeners}.</p>
|
||||
//
|
||||
// @param recognizer the parser instance
|
||||
//
|
||||
|
@ -324,7 +324,7 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer IParser) {
|
|||
var expecting = this.getExpectedTokens(recognizer)
|
||||
var msg = "extraneous input " + tokenName + " expecting " +
|
||||
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
|
||||
|
@ -339,7 +339,7 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer IParser) {
|
|||
// <p>The default implementation simply returns if the handler is already in
|
||||
// error recovery mode. Otherwise, it calls {@link //beginErrorCondition} to
|
||||
// enter error recovery mode, followed by calling
|
||||
// {@link Parser//notifyErrorListeners}.</p>
|
||||
// {@link Parser//NotifyErrorListeners}.</p>
|
||||
//
|
||||
// @param recognizer the parser instance
|
||||
//
|
||||
|
@ -352,7 +352,7 @@ func (this *DefaultErrorStrategy) ReportMissingToken(recognizer IParser) {
|
|||
var expecting = this.getExpectedTokens(recognizer)
|
||||
var msg = "missing " + expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) +
|
||||
" 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
|
||||
|
|
|
@ -14,7 +14,7 @@ type IParser interface {
|
|||
GetInputStream() IntStream
|
||||
getCurrentToken() *Token
|
||||
getExpectedTokens() *IntervalSet
|
||||
notifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException)
|
||||
NotifyErrorListeners(msg string, offendingToken *Token, err IRecognitionException)
|
||||
isExpectedToken(symbol int) bool
|
||||
getPrecedence() int
|
||||
getRuleInvocationStack(IParserRuleContext) []string
|
||||
|
@ -68,7 +68,7 @@ func NewParser(input TokenStream) *Parser {
|
|||
// events during the parse.
|
||||
p._parseListeners = nil
|
||||
// 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.setInputStream(input)
|
||||
|
||||
|
@ -389,7 +389,7 @@ func (p *Parser) getCurrentToken() *Token {
|
|||
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 {
|
||||
offendingToken = p.getCurrentToken()
|
||||
}
|
||||
|
|
|
@ -47,10 +47,10 @@ func NewParserATNSimulator(parser IParser, atn *ATN, decisionToDFA []*DFA, share
|
|||
return this
|
||||
}
|
||||
|
||||
var ParserATNSimulatorDebug = true
|
||||
var ParserATNSimulatorListATNDecisions = true
|
||||
var ParserATNSimulatorDFADebug = true
|
||||
var ParserATNSimulatorRetryDebug = true
|
||||
var ParserATNSimulatorDebug = false
|
||||
var ParserATNSimulatorListATNDecisions = false
|
||||
var ParserATNSimulatorDFADebug = false
|
||||
var ParserATNSimulatorRetryDebug = false
|
||||
|
||||
func (this *ParserATNSimulator) reset() {
|
||||
}
|
||||
|
@ -966,13 +966,6 @@ func (this *ParserATNSimulator) evalSemanticContext(predPredictions []*PredPredi
|
|||
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) {
|
||||
var initialDepth = 0
|
||||
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) {
|
||||
|
||||
if ParserATNSimulatorDebug {
|
||||
fmt.Println("closure(" + config.String() + ")") //config.String(this.parser,true) + ")")
|
||||
fmt.Println("closure(" + config.String() + ")")
|
||||
fmt.Println("configs(" + configs.String() + ")")
|
||||
if config.GetReachesIntoOuterContext() > 50 {
|
||||
panic("problem")
|
||||
|
|
|
@ -182,7 +182,6 @@ func (t *RuleTransition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) boo
|
|||
type EpsilonTransition struct {
|
||||
*Transition
|
||||
|
||||
isEpsilon bool
|
||||
outermostPrecedenceReturn int
|
||||
}
|
||||
|
||||
|
|
|
@ -1462,6 +1462,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
boolean fullCtx,
|
||||
boolean treatEofAsEpsilon)
|
||||
{
|
||||
console.log("closure");
|
||||
final int initialDepth = 0;
|
||||
closureCheckingStopState(config, configs, closureBusy, collectPredicates,
|
||||
fullCtx,
|
||||
|
|
|
@ -313,10 +313,10 @@ function ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) {
|
|||
ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype);
|
||||
ParserATNSimulator.prototype.constructor = ParserATNSimulator;
|
||||
|
||||
ParserATNSimulator.prototype.debug = true;
|
||||
ParserATNSimulator.prototype.debug_list_atn_decisions = true;
|
||||
ParserATNSimulator.prototype.dfa_debug = true;
|
||||
ParserATNSimulator.prototype.retry_debug = true;
|
||||
ParserATNSimulator.prototype.debug = false;
|
||||
ParserATNSimulator.prototype.debug_list_atn_decisions = false;
|
||||
ParserATNSimulator.prototype.dfa_debug = false;
|
||||
ParserATNSimulator.prototype.retry_debug = false;
|
||||
|
||||
|
||||
ParserATNSimulator.prototype.reset = function() {
|
||||
|
|
Loading…
Reference in New Issue