a/an before vowels

Yeah, I had sort of been under the impression that you had to at least define an I6 constant to get a segmented substitution working, but you don’t. (Or maybe I’m thinking of use options.) Anyway, this is from §27.28, which is the antepenultimate section of Writing with Inform. It does get translated directly into I6–well, everything does, but a-an_of gets turned directly into an I6 identifier, which is why I think I can’t define A-An_of separately, because I6 identifiers aren’t case-sensitive, I expect. Though if that were the problem it seems as though it should work to define [A-An of] and [end A-An of] and leave the I6 thingy as uppercase_A-an_of. Maybe the problem is that Inform doesn’t distinguish [end a-an of] and [end A-An of], because the difference in capitalization doesn’t come at the beginning.

Anyway, here’s something with a proviso for doing it in uppercase–oh, the blather in the last paragraph was all about why the straightforward way of doing that with “[A-An of]” doesn’t work. And a change in the routine so you can have a table of exception words. I made it a table rather than a list because I think tables are quicker to check, but who knows. If you have lots of hyphenations you might want to change things up a little, using punctuated words instead of words (if I’ve got that right).

Include Text Capture by Eric Eve.

Lab is a room. 

Capturing text for article is initially false.

To say a-an of -- beginning a-an_of: 
	if text capturing is active: [if we're capturing text already, we can't start capturing it again for the article, so we punt--a better solution would be to buffer the old captured text to another variable]
		say "a ";
	otherwise:
		now capturing text for article is true;
		start capturing text.

To say end a-an -- ending a-an_of:
	if capturing text for article is true: [if we wound up not capturing text for the article, we don't want to do this]
		stop capturing text;
		if "[captured text]" starts with a vowel sound:
			say "an [captured text]";
		otherwise:
			say "a [captured text]";
	now capturing text for article is false.
	
To say uppercase A-An of -- beginning uppercase_A-An_of: 
	if text capturing is active: [if we're capturing text already, we can't start capturing it again for the article, so we punt--a better solution would be to buffer the old captured text to another variable]
		say "A ";
	otherwise:
		now capturing text for article is true;
		start capturing text.

To say end uppercase A-An -- ending uppercase_A-An_of:
	if capturing text for article is true: [if we wound up not capturing text for the article, we don't want to do this]
		stop capturing text;
		if "[captured text]" starts with a vowel sound:
			say "An [captured text]";
		otherwise:
			say "A [captured text]";
	now capturing text for article is false.

To decide whether (string - a text) starts with a vowel sound:
	let the first word be word number 1 in string;
	if the first word is a word listed in the Table of Words That Start With Vowel Sounds, yes;
	if the first word is a word listed in the Table of Words That Don't Start With Vowel Sounds, no;
	if character number 1 in the first word is a vowel, yes;
	no.
	
To decide whether (letter - a text) is a vowel:
	if letter exactly matches the regular expression "a|e|i|o|u|A|E|I|O|U", yes;
	no.
	
Table of Words That Start With Vowel Sounds
word
"hour"
"hourglass"
"honest"
"yttrium"

Table of Words That Don't Start With Vowel Sounds
word
"uniform"
"unicorn"
"united"
"United"
	
Every turn: say "You see [a-an of][one of]red[or]orange[or]yellow[or]green[or]blue[or]indigo[or]violet[cycling][end a-an] light and [a-an of][one of]honest broker[or]hourglass[or]United States flag[or]umber hulk[or]unicorn[or]elf[or]battery[or]honest broker[at random][end a-an]. [Uppercase A-An of][one of]green[or]blue[or]violet[or]red[or]orange[or]what is the opposite of indigo really, that is such a bogus color[or]yellow[cycling][end uppercase A-An] afterimage is visible after it fades."

Note that the exception list is case-sensitive–you’d get “an Uniform Code of Criminal Justice.” It wouldn’t be that hard to fix that, probably by forcing the first word into upper case and then putting on caps lock while you type the tables of exceptions. Though if your game includes a US flag and an Us Weekly, you’ll want the case-sensitivity.