errorNode() impl (#59)

This commit is contained in:
Peter Boyer 2016-10-06 16:19:05 -04:00 committed by GitHub
parent a5859fd54e
commit 10f15cabf8
1 changed files with 9 additions and 9 deletions

View File

@ -45,6 +45,8 @@ type TerminalNode interface {
type ErrorNode interface { type ErrorNode interface {
TerminalNode TerminalNode
errorNode()
} }
type ParseTreeVisitor interface { type ParseTreeVisitor interface {
@ -195,9 +197,7 @@ func NewErrorNodeImpl(token Token) *ErrorNodeImpl {
return en return en
} }
func (e *ErrorNodeImpl) IsErrorNode() bool { func (e *ErrorNodeImpl) errorNode() {}
return true
}
func (e *ErrorNodeImpl) Accept(v ParseTreeVisitor) interface{} { func (e *ErrorNodeImpl) Accept(v ParseTreeVisitor) interface{} {
return v.VisitErrorNode(e) return v.VisitErrorNode(e)
@ -211,12 +211,12 @@ func NewParseTreeWalker() *ParseTreeWalker {
} }
func (p *ParseTreeWalker) Walk(listener ParseTreeListener, t Tree) { func (p *ParseTreeWalker) Walk(listener ParseTreeListener, t Tree) {
switch tt := t.(type) {
if errorNode, ok := t.(ErrorNode); ok { case ErrorNode:
listener.VisitErrorNode(errorNode) listener.VisitErrorNode(tt)
} else if term, ok := t.(TerminalNode); ok { case TerminalNode:
listener.VisitTerminal(term) listener.VisitTerminal(tt)
} else { default:
p.EnterRule(listener, t.(RuleNode)) p.EnterRule(listener, t.(RuleNode))
for i := 0; i < t.GetChildCount(); i++ { for i := 0; i < t.GetChildCount(); i++ {
var child = t.GetChild(i) var child = t.GetChild(i)