def-gthill / lexurgy

A high-powered sound change applier
GNU General Public License v3.0
42 stars 5 forks source link

Feature Request: Propagate `n`-number of times #52

Closed bigyihsuan closed 1 year ago

bigyihsuan commented 1 year ago

I wish to be able to propagate a rule a maximum number of times.

I suggest the following syntax: Whenever a propagate appears, it can an optional X modifier to limit the maximum number of times the propagating rule will run:

rule-name propagate X:
# rules

where X is some number signifying the maximum number of times that this rule will run before going to the next one.

Here's an example, which takes an input string and would double itself, three times:

double propagate 3:
([]+)$1 => $1 $1

Here is another example, where, when given a string with some marker, in this case a tilde, will move it to the right two places:

move-right propagate 2:
~ []$1 => $1 ~

You can (ab)use this for an incrementor:

class digit {\0,\1,\2,\3,\4,\5,\6,\7,\8,\9}
class digitPlusOne {\1,\2,\3,\4,\5,\6,\7,\8,\9,a}

increment-three propagate 3:
@digit => @digitPlusOne
then:
a => \10
def-gthill commented 1 year ago

At this point I doubt I'll provide special syntax for this. Needing to repeat a rule a specific number of times just isn't a common situation for evolving languages in my experience.

If you really need to limit propagation, you can use temporary symbols, e.g.:

class digit {\0,\1,\2,\3,\4,\5,\6,\7,\8,\9}
class digitPlusOne {\1,\2,\3,\4,\5,\6,\7,\8,\9,^\0}

increment-three:
 * => \~\~\~ / @digit _ // _ @digit
 then propagate:
 (
 @digit \~ => @digitPlusOne *
 then propagate:
 @digit ^ => @digitPlusOne *
 then:
 ^ => \1
 )