Golang autocompletion

71 views
Skip to first unread message

Vadim Dmitriev

unread,
Jan 28, 2019, 9:25:09 AM1/28/19
to antlr-di...@googlegroups.com

Hello. I`m using golang to built ANTLRv4 autocompletion.
Here is golang runtime package for ANTLR: https://godoc.org/github.com/antlr/antlr4/runtime/Go/antlr

I created simple grammar:
grammar Simple;

start  
: START (MIDDLE | END) ;

START  
: 'start' ;
MIDDLE
: 'middle' ;
END    : 'end' ;
WS    
: [ \t] -> skip ;

And here my Go code:
listener := new(simple.BaseSimpleListener)

lexer
:= simple.NewSimpleLexer(input)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
parser
:= simple.NewSimpleParser(stream)
parser
.BuildParseTrees = true

tree
:= parser.Start()
antlr
.ParseTreeWalkerDefault.Walk(listener, tree)

// Print expected tokens
fmt.Println(parser.GetExpectedTokens())

And when i run my code like this
go build && echo 'start' | ./autocompletion
I have panic:
line 1:5 missing {'middle', 'end'} at '<EOF>'
panic
: Invalid state number.

But the most important thing is ErrorListener massage:
line 1:5 missing {'middle', 'end'} at '<EOF>

It means that ErrorListener works right. He can predict missing tokens.
How can I get this {'middle', 'end'} tokens without panic?

Thanks!
Reply all
Reply to author
Forward
0 new messages