>EXAMINE ORGAN-GRINDER
The first room has an organ and an organ-grinder. I wanted to allow the player to refer to the grinder as "grinder," "organ grinder," and "organ-grinder." What I found, though, is that ZILF did not like ORGAN-GRINDER as a synonym; it did not like the dash in the definition.
For this problem, I needed Jesse McGrew's help. He gave me the following code to be inserted before "parser.zil" is included.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<REPLACE-DEFINITION READLINE | |
<ROUTINE READLINE ("OPT" PROMPT?) | |
<COND (.PROMPT? <TELL CR "> ">)> | |
<SETG READBUF ,KBD-READBUF> | |
<SETG LEXBUF ,KBD-LEXBUF> | |
<PUTB ,READBUF 0 <- ,READBUF-SIZE 2>> | |
;"The read buffer has a slightly different format on V3." | |
<VERSION? (ZIP) | |
(ELSE | |
<PUTB ,READBUF 1 0> | |
<UPDATE-STATUS-LINE>)> | |
<DO-READ ,READBUF ,LEXBUF> | |
<MASSAGE-BUFS> | |
<RTRUE>>> | |
<ROUTINE MASSAGE-BUFS ("AUX" (LEN <GETB ,LEXBUF 1>) WLEN WOFF) | |
;"Loop over all words, looking for ORGAN" | |
<REPEAT ((I 1)) | |
<COND (<G? .I .LEN> <RETURN>) | |
(<=? <GETWORD? .I> ,W?ORGAN> | |
;"If the word is >5 chars long, and its 6th character is '-', | |
replace it with the fake word O.GRINDER." | |
<SET WLEN <GETB ,LEXBUF <* .I 4>>> | |
<SET WOFF <GETB ,LEXBUF <+ <* .I 4> 1>>> | |
<COND (<AND <G? .WLEN 5> | |
<=? <GETB ,READBUF <+ .WOFF 5>> !\->> | |
<PUT ,LEXBUF <- <* .I 2> 1> ,W?GRINDER>)>)> | |
<SET I <+ .I 1>>>> |
The above code looks for a dash as the sixth character of a word then replaces it with the word of our choice. As you can see in the comments, it originally put in the fake synonym "O.GRINDER" but since there really wasn't any reason it couldn't just be changed to "GRINDER," I changed it to that.
Anyhow, a parsing trick like that could be very useful to someone at some point!
Ok, I was thinking I could also write something about DESCFCNs (where routines are used for object descriptions), but I see now that it was shown pretty well in the juggler code I shared in the other entry.
So yeah, that's all my ZIL for now!
No comments:
Post a Comment