see https://gist.github.com/NigelThorne/9425445#file-example-rb
Have two rules, one for the default version and one for the 'with offset' version. I thought you could transform to add a default value, then have other rules just match it... but that didn't work for me. Cheers Nigel --- "Man, I'm going to have so many chickens when this lot hatch!" On Sat, Mar 8, 2014 at 4:25 AM, Foster, Ron <[email protected]> wrote: > > > Hi. > > Am having some trouble composing a transform on a grammar that has an > optional field. > > > > A simple example: > > > > I'm looking for a formatting code: e.g. " d ", > > But it could include an optional offset specification: " [16] d " > > > > If that optional field is there, I need to grab the number between the > brackets. > > Ot herwise, I can assume it to be zero. > > > > I can parse both forms ok, > > > > But haven't figured out how to build a transform to handle both the > presence or absence of the optional digits in brackets. > > > > Any suggestions would be greatly appreciated. > > > > > > Thanks. >
