Running a routine once only before parsing each component command of a multi-command input line

Well, if you’re already slicing the player’s command up at every “.” or “then,” you should just be able to feed the bits that you slice back into the parser by writing a rule For reading a command.

This is what I came up with, for periods only:

Command chaining is a truth state that varies.

The command remainder is a text that varies.

First after reading a command when command chaining is false and the player's command matches the regular expression "(.+?)\.(.+)":
	now the command remainder is the text matching subexpression 2;
	change the text of the player's command to the text matching subexpression 1;
	now command chaining is true.
	
For reading a command when command chaining is true:
	if the command remainder matches the regular expression "(.+?)\.(.+)":
		change the text of the player's command to the text matching subexpression 1;
		now the command remainder is the text matching subexpression 2;
	otherwise:
		change the text of the player's command to the command remainder;	
		now command chaining is false.
	
After reading a command:
	say "command: [player's command]."

For my sins, the idea behind the regular expression the regular expression “(.+?)\.(.+)” is that the first expression in parentheses matches everything up to the first period, as long as there’s one or more characters before the period, and then the second expression matches everything after it. (The . means “any character,” the + means “at least one repetition,” the ? means “match lazily, so as little text as possible,” the \. escapes the period so it’s an actual period, and then the .+ means “any sequence of at least one character” again.) “text matching subexpression 1” and “text matching subexpression 2” are the texts matching the respective parenthesized groups, so what’s before the first period and what’s after it.

I guess you can extend this to . and then like this:

Command chaining is a truth state that varies.

The command remainder is a text that varies.

First after reading a command when command chaining is false and the player's command matches the regular expression "(.+?)(\.|\bthen\b)(.+)":
	now the command remainder is the text matching subexpression 3;
	change the text of the player's command to the text matching subexpression 1;
	now command chaining is true.
	
For reading a command when command chaining is true:
	if the command remainder matches the regular expression "(.+?)(\.|\bthen\b)(.+)":
		change the text of the player's command to the text matching subexpression 1;
		now the command remainder is the text matching subexpression 3;
	otherwise:
		change the text of the player's command to the command remainder;	
		now command chaining is false.
	
After reading a command:
	say "command: [player's command]."
	
Lab is a room.

The pipe character | is an “or,” and \b means a word boundary, so (\.|\bthen\b)
means “either a period or ‘then’ as a whole word.” And we’ve put in a new group so now the command remainder is the text matching subexpression 3 rather than 2.

I’ve only tested this a little and not with After reading rules that changes the text, so handle with care. Also of course it still doesn’t deal with commas, but since those are kind of buggy anyway it might be legitimate to hope nobody tries entering multiple commands that way.

Also, do you have a toy example of what you’re trying to do? Maybe there’s a more natural way of accomplishing it than amending the command before parsing (I’ve occasionally tried something that needs to be done that way, but those were usually pretty weird experiments).