Parsing of input / dictionary words?

As far as I can tell, there’s no way to pull apart a diction word to parse it, as you seemingly can in Inform:

A frequency is a kind of value. 100.9kHz specifies a frequency. 100.9 kHz specifies a frequency. 100.9 specifies a frequency with parts integer and decimal.

I wonder if it would be possible to split a dictionary word into multiple dictionary words, maybe something like (split word $Word at @. into $FrequencyInt and $FrequencyDec), though that would still involve some way to verify that the two split parts were themselves numeric and in-range.

This is probably the one puzzle from Sand-dancer I’ll have to completely change.

I’ve been considering adding a pair of built-in predicates for splitting a word into a list of single-character words, and joining a list of words (single-character or otherwise) into a bigger word.

The join operation would subject its result to the same tokenization process that’s part of normal input handling. That is, try to find the word in the game dictionary, possibly after removing word endings. Convert to integer if applicable.

I think the splitting operation would have to be able to split integers into digits, for consistency.

You could then take an input word such as “$1.99”, split it into [\$ 1 . 9 9], and then parse that using ordinary list manipulation predicates to obtain [1] and [9 9], and finally merge those back into 1 and 99.

Meanwhile, this would also provide a better way to deal with genitive forms: If “hero’s” is constructed from “hero” and “'s” by joining the words using the new built-in, the result would be a word that is guaranteed to match “hero’s” in the player’s input, regardless of whether “'s” is a removable word ending or not.

All of this requires an update to the Å-machine, so it needs to be thought through carefully, but it seems to me like a promising idea.

1 Like

I would suggest to do this before removing word endings. Whenever the author might wish to interfere into the parsing process directly, he should be able do this before the word is changed by the system itself.
Great idea, it would help to deal with umlauts or special accented charaters for translations into foreign languages.

1 Like