Open maetl opened 2 years ago
Another syntax option is to use a single unary application operator with bidirectional mapping handled by flipping the lhs and rhs tokens.
Instead of:
vehicle>countable
vehicle<countable
Do this:
vehicle|countable
countable|vehicle
This algorithm was implemented thanks to support from RubyNZ. It is an incredibly powerful feature for string rewriting and can reduce large amounts of boilerplate and complexity in grammars if used coherently, but the tradeoff is that it is a lot more difficult to understand than some of the other core features, and there are potentially logic edge cases to deal with.
The technical concept of the feature is to add new syntax that allows higher order application of a rewrite rule to the output of a standard grammar production. The rewrite rules are encoded in an affix table which can also use wildcard patterns to match on any string, but only in an affix position (so not implementing a full regular language). Affix tables can be bidirectional, so lookups/rewrites from key to value can be done from left to right or from right to left.
Test specification showing how this works atomically:
The proposed syntax for bidirectional lookups is to use the
>
and<
characters to visually indicate the direction of mapping.This is pretty cool. But neither the string rewrite wildcard or the bidirectional mapping feels very intuitive.