On Mon, May 09, 2011 at 03:47:19PM +0100, Ant Skelton wrote:
> 
> If I'm understanding what you want correctly, it is possible to do your
> transformation in a single rule, but only if you re-jig the grammar
> slightly:
> 
> 
> class Parser < Parslet::Parser
>  rule(:indent) { str(' ').repeat(1) }
>  rule(:content) { match('[^\n]').repeat(1) }
>  rule(:line) { str('\n') | indent.maybe.as(:indentation) >>
> content.maybe.as(:stuff)
> >> str("\n") }
>  rule(:lines) { line.repeat }
>  root(:lines)
> end
> 
> class Transformer < Parslet::Transform
>  # vanilla rule
>  rule(:indentation => simple(:ind), :stuff => simple(:stu)) {
>    [ ind.to_s.length, stu.to_s ]
>  }
> end
> 
> 
> Although I don't think that's as easy to follow, personally.

Hello Ant,

thanks for the re-jig, it works nicely. I will go and use that for now.

Best regards,

John

Reply via email to