starscope icon indicating copy to clipboard operation
starscope copied to clipboard

Proper Go Parser

Open eapache opened this issue 9 years ago • 2 comments

This has been floating at the back of my mind for a while, but it really wouldn't be too difficult to hand-write a proper lexer/parser for Go since the syntax is so uniform and simple (possibly eventually as a separate gem).

This would permit proper parsing of all the weird corner cases that the current version breaks on, and much better recognition of variable uses, etc. Go provides a very nice spec with a full formal grammar etc (https://golang.org/ref/spec) so the information is available, I just need to bother to write it.

eapache avatar Jan 06 '15 02:01 eapache

I don't have a clear understanding of what starscope requires, but doesn't go already provide most of what you'd need, well beyond just the spec. See, for example: https://golang.org/pkg/go/ast/#example_Inspect

Is the problem that code for starscope would have to be in ruby?

arup42 avatar Dec 09 '15 22:12 arup42

code for starscope would have to be in ruby?

Yes. I've thought about writing a small tool in Go and then having starscope spawn it to get the AST, but on many files that would probably be too slow, since spawning processes is expensive.

eapache avatar Dec 09 '15 23:12 eapache