You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
describe'wildcard match'dolet(:affix_table)doCalyx::Production::AffixTable.parse({"%y"=>"%ies","%s"=>"%ses","%"=>"%s"},registry)endspecify'lookup from key to value'doexpect(affix_table.value_for('ferry')).toeq('ferries')expect(affix_table.value_for('bus')).toeq('buses')expect(affix_table.value_for('car')).toeq('cars')endspecify'lookup from value to key'doexpect(affix_table.key_for('ferries')).toeq('ferry')expect(affix_table.key_for('buses')).toeq('bus')expect(affix_table.key_for('cars')).toeq('car')endend
The proposed syntax for bidirectional lookups is to use the > and < characters to visually indicate the direction of mapping.
constgrammar=calyx.grammar({"plural": "the plural of {vehicle} is {vehicle>countable}","singular": "the singular of {vehicle} is {vehicle<countable}","countable": {"%y": "%ies","%s": "%ses","%": "%s"})grammar.generate({start: "{singular}",vehicle: "train"})grammar.generate({start: "{singular}",vehicle: "bus"})grammar.generate({start: "{singular}",vehicle: "ferry"})grammar.generate({start: "{plural}",vehicle: "trains"})grammar.generate({start: "{plural}",vehicle: "buses"})grammar.generate({start: "{plural}",vehicle: "ferries"})
This is pretty cool. But neither the string rewrite wildcard or the bidirectional mapping feels very intuitive.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: