diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-10 10:18:55 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-10 10:18:55 +0800 |
commit | e6fb2d5ac1f761be46a4d9fb50261de6a96acd00 (patch) | |
tree | 589f0962ef425645adac401017fd7dbcf8f62b3f /Notes | |
parent | 7a484c58a6a1d2ab9600384c46a1100bab42161b (diff) | |
download | mrust-e6fb2d5ac1f761be46a4d9fb50261de6a96acd00.tar.gz |
Notes - Further ponderings on macro_rules!
Diffstat (limited to 'Notes')
-rw-r--r-- | Notes/MacroRules.md | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Notes/MacroRules.md b/Notes/MacroRules.md index 062b448a..83bc703e 100644 --- a/Notes/MacroRules.md +++ b/Notes/MacroRules.md @@ -16,7 +16,7 @@ Problems: - All arms begin with $e:expr (or none) - Two arms follow the same pattern until the end. (where one terminates with no comma) -Parsing Ruleset +Parsing Ruleset? - if empty, ARM 2 - expect `:expr` - if `;` @@ -65,8 +65,25 @@ Merging - "EXPECT `:expr`" + (2) "EXPECT `:expr`" - "EXPECT `:expr`" - "EXPECT `;`" + "IF NOT `,` BREAK" - - TODO TODO TODO + - "IF `;` { EXPECT `;` ... } LOOP { IF + - TODO: This needs to break out of the loop. Problem: Generating LOOP ------------------------ Looping is ideally handled by a loop sub-tree as in the example ruleset, but generating that sub-tree from an overlapping set of rules may be non-trivial. + + + + +Solution 2: Lockstep execution +============================== + +- Generate a sequence of simple pattern rules from the parsed pattern + - `EXPECT`, `IF-BREAK`, `END` + - These are genrated by an "iterator" structure that has a way to be poked if an `IF` succeeded +- Run all arms in lockstep, pruning arms as they fail to match +- Error if two arms attempt to do an incompatible expect (basically any pattern with another pattern) +- TODO: How to handle bindings from `EXPECT` at different levels + - E.g. In the `vec!` example, the first arm binds at the root, but the other two bind inside a loop + - Possibly solvable with brute-force allowing non-repeating contexts to read from a single-repetition? + - Or multi-tagging the binding (so once the arm is known, the level is fixed) |