Here's a quick and dirty sample solution
{
var in_quantity = false // Track whether or not we are in a quantity block
var quantity = []
var gst = null
var total = null
}
start =
// look for a quantity, then GST, then a total and finally anything else
(quantity / gst / total / line)+
{
return {quantity: quantity, gst: gst, total: total}
}
chr = [^\n]
eol = "\n"?
quantity = "Qty" chr+ eol { in_quantity = true; }
gst = "GST" g:chr+ eol { in_quantity = false; gst = g.join('').trim(); }
total = "Total Amount" t:line { in_quantity = false; total = t.trim(); }
line =
a:chr+ eol
{
if( in_quantity ){
// break quantities into columns based on tabs
quantity.push( a.join('').split(/[\t]/) );
}
return a.join('');
}