Comment by librasteve
10 hours ago
Here's how the built-in Raku Grammar can be used to parse this. I can see Raku generating the XML as the Actions from this Grammar so allow ease of DSL authoring with XML as a interchange and strict scheme validation format.
grammar InvoiceDSL {
token TOP {
^ <invoice>+ % \n* $
}
token invoice {
<header>
\n
<line>+
}
token header {
'invoice' \h+ <id=string> \h+ 'for' \h+ <client=string>
}
token line {
\h**4 <entry> \n?
}
token entry {
| <item>
| <tax>
| <discount>
}
token item {
'item' \h+ <desc=string> \h+ <price=num> \h+ 'x' \h+ <qty=int>
}
token tax {
'tax' \h+ <percent=num> '%'
}
token discount {
'discount' \h+ <percent=num> '%'
}
token string { \" <( <-["]>* )> \" }
token num { \d+ [ '.' \d+ ]? }
token int { \d+ }
}
No comments yet
Contribute on Hacker News ↗