123456789101112131415161718192021222324252627282930313233 |
- we have long ago accepted the notion of a marked extended literal syntax,
- ~foo(lit,er,als) { ... a-random-string ... }
- but we are going to have a symmetrical *destructuring* syntax as well, "match":
- match ~foo(lit,er,als) {
- case (case1-a-random-string) { ... normal rust code ... }
- ...
- case (caseN-a-random-string) { ... normal rust code ... }
- default { ... }
- }
- this permits the syntax-expander to compile a complicated
- pattern-matching switch in some domain-specific syntax into an
- optimized automaton. this is *extremely common* (regexps, insn decode,
- AST-destructuring), almost as common as literals, and benefits real
- applications tremendously since recognizer-automaton performance is
- typically crucial and this lets you optimize aggressively in any case
- where the patterns are static and you can lay them down in code.
- example?
- match ~rx {
- case ((?=<word>\w+)) { print("found a word: " + word); }
- case ([:punct:]) { npuncts++; }
- }
- note that the rx-matcher is completely within its rights to introduce
- locals and make assignments: it just needs to embed the case arm
- inside a block that performs the local bindings.
|