I’m trying to figure out how to get the information from the input buffer and the parse table into I7 lists. Anyone have any guidance on how to do that?
Not easily. Creating and manipulating lists is very difficult at the I6 level, which is why all the code surrounding the multiple object list is such a mess. But, that would be the template you want—it’s got code for converting an I6 array into an I7 list, and back again.
There has been substantial code drift since 8.5/6G60 for which it was written, but Original Parser, Ron Newcomb’s re-implementation of the parser in I7 remains your best bet for seeing how to get parser information back and forth between I6 and I7 representations.
I can’t believe that I’m going to be the one telling you to not use I6 for this, but…
The contents of the command buffer are most easily reached via the player's command
snippet. If you really want to have it as a list of individual letters instead of the entire string, then you can build that via character number N in the player's command
. See WWI 20.3 Characters, words, punctuated words, unpunctuated words, lines, paragraphs.
As for the contents of the parse array, these are in the form of I6 dictionary words, which have no analog in I7 and must be treated as numbers (or some new numeric kind) there, which is a pain. However, the entries of the parse array map (in most cases) to punctuated word N in the player's command
.
I’m guessing that you want to do this in order to do something else, not for its own sake. What’s your follow-on goal?
I tried your idea to use snippets and I think it worked!
The parsed command is a list of texts that varies.
repeat with r running from 1 to number of parsed words:
add "[parsed word r]" to the parsed command;
To decide what number is the number of parsed words:
(- parse-->0 -)
To decide what snippet is parsed word (n - a number):
(- {n} * 100 +1 -)
I’m not sure what my end goal is here, I’m sort of trying my hand at writing my own parser.
@Zed Yes, I’ve been using Ron’s extension to help me understand the parser.
The next challenge will be to pull out the grammar lines for the actions and the dictionary words.
You can do it, but the Inform code that does this is pure I6. See the I6 routine UnpackGrammarLine() and then the arrays line_ttype, line_tdata, line_token.
oh, I can help with this one.
Include Lexicography by Zed Lopez. |
Lab is a room.
when play begins:
repeat with d running through the dictionary entries begin;
say "[d] / ";
if d is meta-entry, say "meta ";
if d is verb-entry, say "verb ";
if d is preposition-entry, say "preposition ";
if d is noun-entry, say "noun ";
if d is plural-entry, say "//p";
say line break;
end repeat;
Lexicography.i7.txt (6.3 KB)
It took some doing, but I finally have something I’ve wanted for a while: I can reproduce the information from the showverb
test command without using any of the debug routines or writing to any of the parser’s globals. I’ll share it when it’s less of a mess.
This is amazing! I’m going to take some time to go through understanding all of this. Thanks.
warning: it was a work in progress by someone who still didn’t understand it at the end. But I think I’m finally close to understanding it.
So where are conditional names stored? As in:
Understand "text" as something when...
I7 generates a parse_name
routine with a bunch of messy conditional logic. This covers conditional synonyms, as well as understand-by-a-property and so on.
It’s not accessible like the grammar tables. All you can do is run the routine and see if it returns success or failure.