How to create an action for every situation.

This is pretty close. The changes you’d need are that the action applies to “one topic,” not “some text,” and that the text the player enters gets stored as “the topic understood.” Also, for comparing the topic understood to a topic, you don’t need “match the text”–just “match” will do. (There are actually two different kinds of text comparison that could be happening, one described in §18.33 of Writing with Inform and one in §20.5; this is confusing but here we need the first one.)

So we could do:

Understand "wall" or "cave" or "stone" or "rock" as "[rock]". Mining is an action applying to one topic. Understand "Mine [text]" as mining. Check mining: If player does not hold pickaxe, say "You need a pickaxe to do that."; If the topic understood does not match "[rock]", say "That isn't something you can mine." instead. Carry out mining: Say "You swing your pickaxe and chip away at the [topic understood]. It's hard work; no wonder it's left for the slaves.".

However, this requires the player to type one of our strings exactly–“mine rock” succeeds but “mine the rock” doesn’t, and your players will hate that. It might make sense to define mining as an action applying to a thing and make the rock a scenery object:

[code]Cave is a room. The player carries a pickaxe. The rock is scenery in the cave.

Understand “wall” or “cave” or “stone” or “rock” as the rock.
Mining is an action applying to one thing.
Understand “Mine [something]” as mining.
Check mining:
If player does not hold pickaxe, say “You need a pickaxe to do that.”;
If the noun is not the rock, say “That isn’t something you can mine.” instead.
Carry out mining:
Say “You swing your pickaxe and chip away at [the rock]. It’s hard work; no wonder it’s left for the slaves.”[/code]

Now you can say “mine rock” or “mine the rock.” Also, since the rock is now a thing in itself, we can use “[the rock]” as a text substitution.