I have the code in: https://gist.github.com/ravbell/d94b37f1a346a1f73b5a827d9eaf7c92
use v6;
#use Grammar::Tracer;
grammar invoice {
token ws { \h*};
token super-word {\S+};
token super-phrase { <super-word> [\h <super-word>]*}
token line {^^ \h* [ <super-word> \h+]* <super-word>* \n};
token invoice-prelude-start {^^'Invoice Summary'\n}
token invoice-prelude-end {<line> <?before 'Start Invoice Details'\n>};
rule invoice-prelude {
<invoice-prelude-start>
<line>*?
<invoice-prelude-end>
<line>
}
}
multi sub MAIN(){
my $t = q :to/EOQ/;
Invoice Summary
asd fasdf
asdfasdf
asd 123-fasdf $1234.00
qwe {rq} [we-r_q] we
Start Invoice Details
EOQ
say $t;
say invoice.parse($t,:rule<invoice-prelude>);
}
multi sub MAIN('test'){
use Test;
ok invoice.parse('Invoice Summary' ~ "\n", rule => <invoice-prelude-start>);
ok invoice.parse('asdfa {sf} asd-[fasdf] #werwerw'~"\n", rule => <line>);
ok invoice.parse('asdfawerwerw'~"\n", rule => <line>);
ok invoice.subparse('fasdff;kjaf asdf asderwret'~"\n"~'Start Invoice Details'~"\n",rule => <invoice-prelude-end>);
ok invoice.parse('fasdff;kjaf asdf asderwret'~"\n"~'Start Invoice Details'~"\n",rule => <invoice-prelude-end>);
done-testing;
}
I have not been able to figure out why the parse on the rule <invoice-prelude>
fails with a Nil
. Note that even .subparse
also fails.
The tests for the individual tokens are passing as you can see by running MAIN
with 'test'
argument (except ofcourse the .parse
on <invoice-prelude>
fails because it does not the full string).
What should be modified in the rule <invoice-prelude>
so that the whole string $t
in MAIN()
can be parsed correctly?
Start Invoice Details
. This makes the lookahead regexp<?before 'Start Invoice Details'\n>
fail, since it expects a newline at the end of the line – Provost