Parslet transforms are applied depth first and replace the node of sub-tree, so each thing only gets one chance to be replaced. Hence you have to replace a whole hash at once. If you want a second chance to transform something you need another node in the tree.
In other words, add in another "as" at a lower level... then transform those... which seems to be what you are doing in your example (width and height). On Thu Jan 15 2015 at 16:06:04 Tom Wardrop <[email protected]> wrote: > Hi, > > I began using Parslet yesterday, and have been re-writing a Treetop parser > I wrote which parses certain HTTP headers according to the RFC. There's > been a few instances where I would like to preserve the tree at some level, > and only modify the parsed value. > > Here's a gist to demonstrate: > https://gist.github.com/Wardrop/604f5ec38315e510ecff > > Note that by default, none of the rules in the Transform apply, because > Parslet doesn't allow transformation of only the value component of of a > key/value pair. The commented out Transform rules show what I must do to > achieve the desired result. The problem with the commented out rule is that > it's repetitive. It no only requires me to redefine the inherit structure > of the tree, but it means if I had a larger parser where the ` width` and > `height` parslets are used in many contexts (all of which require integer > conversion in the transform), I need to repeat myself even more. > > My question is, does parslet allow any means of only transforming the > value of a key/value pair, preserving the key and the rest of the structure? > > Tom >
