pboyer / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
Other
26 stars 1 forks source link

Fix #57 #59

Closed pboyer closed 8 years ago

pboyer commented 8 years ago

Fix for #57

@willfaught PTAL

willfaught commented 8 years ago

How was that causing the test failure?

On Oct 5, 2016, at 7:56 PM, Peter Boyer notifications@github.com wrote:

@pboyer commented on this pull request.

In runtime/Go/antlr/tree.go:

@@ -45,6 +45,8 @@ type TerminalNode interface {

type ErrorNode interface { TerminalNode +

  • errorNode() Before this change, an ErrorNode and TerminalNode were indistinguishable.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

pboyer commented 8 years ago

@willfaught This test created a custom ParseTreeListener. This data structure implemented a VisitTerminal method that printed the node. The VisitErrorNode method was empty.

Before this change, an ErrorNode and TerminalNode were type-wise identical. Note the implementation of the ErrorNode interface. So, the VisitErrorNode method was called (see the type switch) and the node was not printed. In Java, these would be distinguishable. Go's duck typing like semantics cause this issue.

A common approach to this problem is to have a method that distinguishes the interface. See for example: https://github.com/golang/go/blob/master/src/go/ast/ast.go#L491

This is the approach I took here.

willfaught commented 8 years ago

I was interested more in where in the code the type confusion was causing the problem. In any case the change makes sense and LGTM!