7 ms·
Participle: A parser library for Go
- kjeetgill 8y agoParsers are one of those fields I wish I had the time to really study deeply. I'm especially impressed with LALRPOP. Cribbed from a previous comment of mine: From time to time I find myself revisiting this thread: "Writing parsers like it is 2017"[0]. In particular I love a Rust parser generator called LALRPOP and it's emphasis on diagnosing ambiguous grammars [1]. > What I’ve tried to do now in LALRPOP is to do that clever thinking for you, and instead present the error message in terms of your grammar. Perhaps even more importantly, I’ve also tried to identify common beginner problems and suggest solutions. They work out a fairly deep example with error guidance in ambiguous grammars in that post. [0]: https://news.ycombinator.com/item?id=15016061 https://news.ycombinator.com/item?id=15016061 [1]: http://smallcultfollowing.com/babysteps/blog/2016/03/02/nice-errors-in-lalrpop/ http://smallcultfollowing.com/babysteps/blog/2016/03/02/nice...
- pjmlp 8y agoClever idea of using struct tags for grammar rules.
- laumars 8y agoWouldn't that then require reflection, which is "slow" (comparatively speaking - if this isn't in a hot path then perhaps who cares?)
- childintime 8y agoThis maps well to how I think of parsing. Refreshing. I will have to give it a shot.
- weberc2 8y agoThis looks really cool. I spent a few weeks last year trying to build my first programming language, but I kept getting bogged down by parsing and eventually gave up.
- laumars 8y agoParsing isn't actually that hard once you wrap your hard around the problem. There are lots of good guides for writing parsers online which really helped me out when I was feeling the same bourdon as you are. So what I'm trying to say is stick with it and I'm sure you'll crack it. :)
- azhenley 8y agoDefinitely. I used to always get stuck on the parsing part, and it definitely is time consuming to get right, but once you get past it once it is much easier to tackle in the future. Then you realize that parsing is only a small piece of making your own language!
- laumars 8y agoThe Eureka moment for me was learning that a parser isn't a single entity. It's reading tokens, making an abstract syntax tree, etc. One I learned how to break the problems down I found writing parsers very easy. As for it only being a small part of making your own language, that is so true too. However I do think it's a rewarding project to tackle.
- jerf 8y agoThe ability to parse is one of the things that differentiates "power programmers" from people just hooking things together. If you wish to be one of the former, it is on the Must Study list. It is true that many, perhaps even most programmers can go their entire career without having to face the problem of writing their own code to take a text file and view it as a tree of tokens. This is even more true than ever with so many off-the-shelf serialization options, meaning that creating your own new one had better have a really, really darned good justification to it. But if you conceptualize a parser as "a thing that receives a stream of low level, primitive inputs and needs to extract sensible state information and know when constraints have been violated"... ah, now that sounds pretty useful, right? And very modern as we continue our inevitable marches towards viewing the world in terms of event streams rather than blobs of completed input that we can take in all at once. The generalized parsing problem of taking a stream of primitives and extracting higher level meaning from them is as relevant as ever, if not more relevant.
- pebers 8y agoI've used this before - really nice library and an easy way of getting started without having to write so much custom code. Only down side is that of course it's still faster to hand-write a parser :)
- appslure 8y agoAppslure is the best iOS apps development company in Delhi, Gurgaon, Noida, Mumbai, India. Our iOS app developers are expert in responsive iphone and iPad app development services. For more visit on- http://www.appslure.com/ios-app-development-company/ http://www.appslure.com/ios-app-development-company/
- iampims 8y agoA good intro by Rib Pike for those who’d like to learn more about parsers/lexers https://youtube.com/watch?v=HxaD_trXwRE https://youtube.com/watch?v=HxaD_trXwRE
- deklerk 8y agos/Rib/Rob :)
- skybrian 8y agoCool idea. The way it handles alternatives looks awkward since each alternative is a field in a struct. You have to check each field to find the one that's not nil. (See Term in the example.) Normally this would be done with an interface, like in go/ast
- skybrian 8y agoAlthough, on second thought, this means writing a chain of if-else statements instead of a type switch in a visitor. Maybe it's not that big a difference?