My ambition was tickled. Attached you find a script that's a bit more complicated but much easier to maintain and enhance. It fulfils all your requirements and only needs as many trials as there are phrase lengths in your set (i.e. sentences from, for example, 2 to 5 words).
Adding phrases with lengths already covered in the script is easy. Just add the phrases as elements to the respective counter.
Making the script cover more phrase lengths looks intriguing but is in fact a quite mechanical process. You just have to carefully follow these steps:
(1) Define a new counter for your desired phrase length, say "COUNTER_phrases_length7"
(2) Expand the item "ITEM_canvas" by as many dummy entries as the maximum number of words in any phrase.
(3) Create as many "TEXT_phraseX" stimuli as the maximum number of words in any phrase and make sure to change the "/ select = X" property to the "X" in the text stimulus name
(4) Create a trial for the new phrase length by copy-pasting one of the existing trials
(4a) Add the required "TEXT_phraseX" stimuli to the "stimulustimes" list
(4b) Change the first "/ ontrialbegin" statement of the trial so that it refers to the counter containing the phrases with the new length e.g. "COUNTER_phrases_length7"
(4c) Repeat the following "/ ontrialbegin = [values.lastspacepos = search(substring ... values.lastphrase, 1)]" statements as often as the new phrase length
(4d) Make the last number in the just copied "/ ontrialbegin" statements increment by one with each statement, exactly as shown in the example trials.
I don't think you can get much more compact scripting in this matter. I see no way around creating separate trials for each phrase length (oh no, I just thought of one, so hold your breath). Also, since there are no loop expressions in Inquisit, you have to repeat the word selection routine for each word in a phrase.
Have fun,
Malte.