|
|
|
|
|
by Thorrez
2180 days ago
|
|
Interesting, thanks for pointing out a use case. But I don't think backreferences will help with that, it needs to be parsed by something more powerful than a regex. And that example reminds me that Bash can do something similar: echo "$(echo "$(echo "$(echo "hi")")")"
|
|
Basically you can use backreferences for that if you also allow the regex to be recursive.
Note that `Regex` is a subtype of `Block`. That is why `&?BLOCK` can be used as a reference to the regex itself.`<foo=bar>` is a way to call `bar`, but also save it under the name of `foo`. `$<foo> = …` is a way to capture `…` and save it under the name of `foo`.
---
It is a lot nicer and modular when you use regexes as part of a grammar:
A `token` is just a `regex` with `:ratchet` mode turned on. (prevents backtracking) A `rule` is just a `token` with `:sigspace` also turned on. (makes it easier to deal with optional whitespace.)Every instance of `<foo>` is basically a method call.
`make` is about generating an `.ast` to pass up and out of the parse. In this case the only thing the actions class does is return what would be the resulting string if it were compiled in Raku.