Hi, I've been working for a big chunk of my weekend on trying to learn Parslet and use it to parse the output of iptables-save (the linux firewall for anyone that doesn't know).
I'm struggling to understand the "right" way to do this and you can see several aborted attempts at https://github.com/apenney/iptables-parslet to figure out how to do this. My two big issues are: 1/ Is it better to push the entire contents of "examples" to parslet so that I can break things up into "buckets" before dividing further. That file breaks things up into two tables, *mangle, *filter. I had a vision of breaking this up into: { firewall: { tables: { mangle: {rules}, filter: {rules} }}} As a top level parser, then having subparsers that would keep breaking things down into smaller and smaller pierces. 2/ I absolutely cannot come up with a thing that will parse all possible cases of the rule "pieces". I basically need to be able to take a line like: -A INPUT -b blah -c ! blah -d blah ! -e -f --g blah:1 -h And build: '-A INPUT', '-b blah', '-c ! blah', '-d blah !', '-e', -'f', '--g blah:1', '-h' I ran into lots of problems, especially with end of lines. I was trying hard to figure out the right way to write something like: rule(:rule_piece) { argument >> stuff } What tends to happen is it swallows up everything into a single string and the only real delimiter is the next argument. If I do argument >> stuff >> argument then it swallows that argument up and parses beyond it. I guess more fundamentally I am looking for the right "model" for something like this. Should I focus on parsing line by line with more of the logic moved into ruby, splitting the file into 2 chunks of *mangle and *filter and then just focus on parsing the pieces line by line, or is my original idea of using a top level parser to split it into two chunks and then subparse it down from there? You can see from my code at github that I've tried a little of everything and just made a mess. -- Ashley Penney [email protected] Module Engineer *Join us at PuppetConf 2014**, September 23-24 in San Francisco - http://puppetconf.com <http://puppetconf.com/>*
