The next field after the cardNumber is also numeric. Therefore the alternative strategy I tried
def prefixLength = rule(zeroOrMore(ch('0')))
def issuerCode = rule(capture(6.times(CharPredicate.Digit)) ~> (_.toInt))
def individualSuffix = rule(capture(oneOrMore(CharPredicate.Digit)) ~> (BigInt(_)))
def cardNumber = rule(&(20.times(CharPredicate.Digit)) ~ fuelCardPrefixLength ~ cardIssuerCode ~ individualSuffix)
does not stop at the end of the cardNumber field. Rather, it also matches part of the subsequent field and thus produces an incorrect result.
How can I get around this? The only solution that I've come up with so far is to use a regex against the string the cardNumber rule has put on the stack in a parser action. However, that has the downside that I could not report a parsing error against the field content in a fashion consistent with other parsing errors.
If anyone has a recommendation for me how to deal with this properly, I'd appreciate it.
Thanks,
Christian