tl;dr: write a parser using goyacc, a yacc port that therefore has some impedance mismatch with Go. (go)yacc is LALR(1)
I've been using PEG/Packrat implementations providing a more "native" experience to great effect lately, notably ruby's treetop and golang's pointlander/peg.
This project gives me I have a solution please give me a problem feeling. I remember looking into yacc a while ago, for some reason but I can't really remember doing why. Might've been for a configuration type of deal, but nowadays I just use json for that because it intersects other areas of the code and therefore saves time.
Over the past two days I also switched a toy-project for deploying software via SSH/SCP to using a lexer/parser, rather than parsing via regular expressions and string-splits. I guess that means that I learned something:
I played with this last year but couldn’t wrap my head around it. I don’t recall if it was poorly documented at the time or if it couldn’t handle something I was trying to do or if I was just depressed by the generated code quality, but I eventually gave up and tried rolling my own parser by hand. It was the first time I’d done such a thing and I didn’t really understand patterns for writing parsers so I eventually gave up there too. I’m really excited to read Thorsten Ball’s “How to write an Interpreter in Go” book which walks the reader through writing a parser by hand (his blog post about book-writing tools was on the front page here—or maybe it was /r/programming?—yesterday, incidentally).
8 comments
[ 3.1 ms ] story [ 31.6 ms ] threadI've been using PEG/Packrat implementations providing a more "native" experience to great effect lately, notably ruby's treetop and golang's pointlander/peg.
https://github.com/cjheath/treetop
https://github.com/pointlander/peg
https://www.youtube.com/watch?v=HxaD_trXwRE
https://github.com/skx/monkey/
Over the past two days I also switched a toy-project for deploying software via SSH/SCP to using a lexer/parser, rather than parsing via regular expressions and string-splits. I guess that means that I learned something:
https://github.com/skx/deployr