I7 new user, parsing names of kinds

Hi, I’m new to Inform 7 (but an experienced programmer in many other lanugages), and I have a particular use of the parser that I want to try out. I’ve looked for extensions/information on this and I can’t find anything so I’m not sure if it will be possible.

I want to be able to answer parser queries about properties. For example “what colour is the turtle”, “what size is the dog” (forgoing for now whether this is a good idea or not game wise…).

The closest I’ve got is providing Understanding clauses for individual properties, e.g.

[code]Color is a kind of value. A thing has a color. The colors are red, blue, and black and neutral. A thing is usually neutral.
Whatiscoloring is an action applying to one visible thing.
Report whatiscoloring something:
say “[The noun] is [color of noun].”
Understand “what color is [something]” as whatiscoloring.

Size is a kind of value. A thing has a size. The sizes are tiny, small, large, big and huge. A thing is usually small.
Whatissizing is an action applying to one visible thing.
Report whatissizing something:
say “[The noun] is [size of noun].”
Understand “what size is [something]” as whatissizing.[/code]

I don’t really like this approach aesthetically/elegance-wise, but also I have to repeat the code for each property. I’m wanting to do if anyone can find a way I can generically write rules to parse the user input of specific property names like “color” or “size”. The issue is that these are names of kinds, not adjective properties so I don’t think I can parse them.

Here’s my ignorance-fueled idea of how it might look:

Whatis is an action applying to one kind of property and one thing. Report whatis something: say "[The noun] is [property of noun]." Understand "what [property] is [something]" as whatising.

So anyone have any ideas that are nicer than the first implementation above?
Thanks!

I don’t think there’s a way to do this directly, because there’s no way (as far as I know) to get Inform’s parser to understand the name of a kind or the name of a property.

However, you may be able to use a workaround to reduce the amount of repetition you need to do. Define a bunch of archetypes for the action to work on, define the querying action to apply to those archetypes, and then you just have to define an archetype for each kind of value you want to query (you can do this when you define the kind of value) and write a rule that picks out the relevant property for each archetype.

[code]Starting location is a room.

An archetype is a kind of thing. Archetype Storage is a room.

Color is a kind of value. A thing has a color. The colors are red, blue, and black and neutral. A thing is usually neutral. Generic color is an archetype in Archetype Storage.
Size is a kind of value. A thing has a size. The sizes are tiny, small, large, big and huge. A thing is usually small. Generic size is an archetype in Archetype Storage.

Querying it of is an action applying to one visible thing and one thing. Understand “what [any archetype] is/am/are [something]” as querying it of. Understand “i/myself” as yourself.

Report querying:
say "[The second noun] [are] ";
if the noun is:
– generic size: say “[size of the second noun]”;
– generic color: say “[color of the second noun]”;
say “.”

A rock is in Starting location. The rock is large. The rock is blue.
A bug is in Starting location. The bug is tiny. The bug is black.[/code]

Or I guess you could use text variables and dispense with the archetypes:

[code]Starting location is a room.

Color is a kind of value. A thing has a color. The colors are red, blue, and black and neutral. A thing is usually neutral.
Size is a kind of value. A thing has a size. The sizes are tiny, small, large, big and huge. A thing is usually small.

Querying it of is an action applying to one topic and one thing. Understand “what [text] is/am/are [something]” as querying it of. Understand “i/myself” as yourself.

Report querying:
if the topic understood is a topic listed in the Table of Queries:
say the response entry;
otherwise:
say “I’m not sure what property you’re asking about.”;
say line break. [Inform doesn’t manage to automatically print a paragraph break when you’ve just printed a text from a table, or something like that.]

Table of Queries
topic response
“size” “[The second noun] is [size of the second noun].”
“color/colour” “[The second noun] is [color of the second noun].”
“alignment” “Whaddaya think this is, D&D? Knock it off.”

A rock is in Starting location. The rock is large. The rock is blue.
A bug is in Starting location. The bug is tiny. The bug is black.[/code]

This even lets you use the power of the topic column (see Writing with Inform §16.13) to allow for alternatives, as well as providing custom responses for non-properties. If you were using the archetype approach, you could accomplish something similar by defining synonyms for the archetypes, like this:

Understand "colour" as the generic color.

Inform sort of does this already for disambiguation.

If you have three different colored flower pots, and you type EXAMINE FLOWER POT, it will respond “Which do you mean? The red flower pot, the blue flower pot, or the yellow flower pot?”

If you have ten flower pots of different colors, some made of china and some of terra cotta, you can say

TAKE A YELLOW CHINA FLOWER POT. Inform will usually select a random one that fits the command.

[code]Colour is a kind of value. The colours are red, green and blue. A flower pot has a colour. Understand the colour property as describing a flower pot.

Material is a kind of value. The materials are china and terra cotta. A flower pot has a material. Understand the material property as describing a flower pot.[/code]

Understand the…as describing let’s the player discern between properties and type TAKE THREE BLUE CHINA FLOWER POTS.

See §17.15. Understanding things by their properties. (And most of Chapter 17 as well.)

You can also build up trees of things.

[code]Living Room is a room.

A mammal is a kind of animal. A cat is a kind of mammal. A dog is a kind of mammal. A beagle is a kind of dog. a chihuahua is a kind of dog. A tabby is a kind of cat. A persian is a kind of cat. Peepers is a tabby in Living Room. Fido is a beagle in Living Room. Senor Pipi is a chihuahua in Living Room. Lady Floofypuss is a persian in living room.

Understand “animal” as an animal. Understand “mammal” as a mammal. Understand “cat” as a cat. Understand “tabby” as a tabby. Understand “dog” as a dog. Understand “beagle” as a beagle. Understand “persian” as a persian. Understand “chihuahua” as a chihuahua.

Hairiness is a kind of value. The hairinesses are shorthair, longhair, and hairless. A mammal has a hairiness. Understand the hairiness property as describing a mammal.

A tabby is usually shorthair. A persian is usually longhair. A beagle is usually shorthair. A chihuahua is usually hairless.

The description of a mammal is usually “[The noun] is a [hairiness of the noun] [if the noun is a dog]dog[otherwise if the noun is a cat]cat[otherwise]mammal[end if] who lives in the house.”
[/code]

Matt w thanks for the thorough examples, that’s really helpful… And i prefer your workarounds to the way I was doing it + gives me some good techniques for workarounds generally too. If I have a large number of properties I could even do some preprocessing to auto generate the inform code for all properties (in python or something).

HanonO, yeah I realise it does this well, that’s why I found it difficult to imagine it couldn’t work from the parser direction. I wish the user parser was as rich as the actual inform language parser…

Thanks all very much for help

o.O