Wednesday, January 25, 2017

down the rabbit hole of parsing

I've been wanting to write an update post just to assure those that care that I have been working on Roodylib stuff, but it's been hard to pull the trigger as I imagine parsing quirks isn't very interesting to most people.  Then again, if I knew of some blog that was one author's exploration of parser theory or battles against an existing parser, I'd probably read it.  Just the same, anyone who doesn't care can skip down to the "In other news" section below.

So, what with the release of HugoJS, I really want the next version of Roodylib to be as flawless as possible, both for the possible re-release of older games (so they operate best in all kinds of interpreters and make use of Roodylib's accessibility options) and for future games.  To this end, I've been making "recordings" (*) of games with available source and testing the playback against both the original and Roodylib-compiled version and then checking for errors.

( * In several IF systems, typing "RECORD" in a game will begin a transcript that only writes commands to a file.  Then, the next time you play the game, typing "PLAYBACK" will allow you to select the file.  At this point, the game plays all of the commands from the recorded file,  This is a great way to see how the same set of commands affects different versions of the same game.)

Luckily, several of the games have available walkthroughs to make this easier, but it's still slow going; many of the games have random elements so I "normalize" the random number generator to make them predictable.  Several of the games use a conversation system that handles choice entry through GetInput which isn't caught by recording/playback so I wrote a modification to the conversation system to allow making choices from the regular prompt.

I had finished going through a couple games (and, in the process, found a couple Roodylib bugs) when I caught a conversation where Jesse McGew speculated about optimal ZIL behavior when it comes to disambiguation questions within multiple-command inputs.

Say you have a command like this:
>EXAMINE BOX. GET IT. DROP IT.
The issue was, if the game responds with "Which box did you mean, the cardboard box or the glass box?" and the player chooses one, should it then proceed to process the rest of the command?  Inform does proceed, but making the player re-type the rest could be seen as a viable approach, as it is an error of sorts and every IF language is allowed its own expectations of how to handle such situations.

This got me curious about how Hugo/Roodylib currently handled it.  I found that if the player used the disambiguation system added by Roodylib (using "1", "former","2", "latter" and such to refer to listed options), it cleanly stopped processing the rest of the command, but if the player used the engine-based disambiguation system (typing in "glass" or "cardboard"), the rest of the word array got mangled and resulted in a "I didn't understand that." response.

First, I added some hacky code so the engine-based disambiguation also exited cleanly, but then I decided that I preferred the "KEEP ON PROCESSIN'" behavior and modified both versions to do that.

Unfortunately, this opened up another can of worms as I then noticed that the "G"/"AGAIN" code was somewhat broken.   Fixing this took quite a while as I had to re-acquaint myself with all of the parsing code.

Now, everything works again and, in fact, works better than it did before I started.  The old code, borrowed from the original Hugo library, only restored the last command when "AGAIN" is used, so a multiple command input like >SHAKE CAN. G.. OPEN IT.  would lose track of the rest of the command before it got to "OPEN IT". As in, when AGAIN is called, the entirety of the word array was replaced with just "SHAKE CAN".  Now successive commands are not lost and are properly parsed.

Now that I have it working, I plan to clean up the code a bit and maybe put in some hooks so authors can easily put in optional behavior.  For instance, if an NPC is given a command that is an xverb ("save","undo","restore"), Roodylib intentionally gives the error "That doesn't make any sense."  The previous Hugo behavior was just parsing it like all is well, likely leading to a "So-and-so ignores you." response.  So, I'm sort of considering putting in some kind of hook so authors can re-direct it to some kind of "So-and-so says, 'Do what now?'" response if they'd like.

As soon as I'm done with that, it's back to testing games, followed by more general code clean-up and documentation updates.  Given that real life has been fairly hectic and will be for the foreseeable future, this will be a multiple month process.

In Other News

Hugor's Nikos Chantziaras is credited on the development team for a new TADS 3 game by Bob Bates (of Infocom and Legend Entertainment fame).  "Thaumistry: In Charm's Way" is currently being funded on Kickstarter.  I was lucky enough to be in its first wave of alpha testers and found it to be quite a fun romp.  I've been watching the kickstarter progress obsessively and am really looking forward to the finished product.  I'm sure almost all readers of this blog have seen an announcement for it somewhere else, but I just wanted to throw my personal recommendation out there!

3 comments:

  1. It's with great pleasure that I'm announcing that today a new edition of The Hugo Book was published as a single HTML document readable on-line:

    https://git.io/hugo-book

    This new edition is an AsciiDoc port of the original book, now released under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) with permission by original author Kent Tessman.

    The new edition contains some errata and other minor improvement carried out under the supervision of Kent Tessman, making this the official First edition, revised January 2020.

    The full source code of the project is publicly available on GitHub:

    https://github.com/tajmone/hugo-book

    A ZIP archive containing just the HTML book and a single-file AsciiDoc source can be downloaded from the releases page:

    https://github.com/tajmone/hugo-book/releases

    This new publication of The Hugo Book is part of an on-going effort to revive Hugo and its assets. For more Hugo related projects, see:

    https://github.com/tajmone/hugo
    https://github.com/tajmone/hugo-library
    https://github.com/tajmone/sublime-hugo-if

    ReplyDelete
    Replies
    1. Thanks, this should be helpful. You'll probably also want to announce this here as it is visited by a high percentage of Hugo users:
      http://www.joltcountry.com/phpBB3/viewforum.php?f=8&sid=fe478fd1e49d9c4e96c40abdb63ccfdc

      I haven't yet looked closely at your work, so I'm not sure if you have incorporated my own notes on "The Hugo Book." They are written in comments on this PDF: https://drive.google.com/open?id=0B_4ZXs4Z_yoWRnA1bzE3X21oTXc

      Unfortunately, they can only be viewed in Adobe Reader. If that is unavailable to you, I can write you an e-mail detailing all of the mistakes.

      I was going to point you to the hugo unix repository just to make sure you were up to date, but I looked at your page and see you are already well aware of everything. Fantastic, your pages are looking like they will be a great way to keep track of everything.

      I don't know if you use Windows, but my Notepad++ add-on has an option to highlight a word and then open up the Hugo Book PDF searching for that word (I'm sure this feature is barely used but I like supporting it). I've never liked forcing Adobe Reader on everyone, though; it was just the only program I could find that supported searching a pdf with a string from command line. Do you know of some way I could do this with your HTML version? A cursory Googling hasn't helped me.

      Anyhow, your edition looks nice, and thanks for everything you've put together so far. I hope to have another release of Roodylib out sometime this year, and if you didn't catch it, Juhana Leinonen made an app which, among other things, allows people to compile Hugo games online: https://borogove.app/

      Here's to 2020 being a great year for Hugo!

      Delete
  2. > You'll probably also want to announce this here ...

    I've subscribe to Jolt Country, now waiting for account activation.

    > I'm not sure if you have incorporated my own notes on "The Hugo Book."

    I wasn't aware of the existence of this PDF. After a quick look through the
    notes I now wish I had access to it it before. Some of the mistakes pointed out
    in the PDF were already caught and fixed, others not.
    When I'll have time I'll go through all the notes and see what can be done.

    > Unfortunately, they can only be viewed in Adobe Reader.

    I have Adobe Reader and can see the notes alright, but I'm not a great fan of
    PDF docs (or any non-text doc format that can leak privacy via hidden metadata).
    Tanks, I might need your support in discussing some of the notes.

    > Fantastic, your pages are looking like they will be a great way to keep track
    > of everything.

    Hopefully the enforced code-styles in these repositories should facilitate future
    collaborative work using Git across different OSs.

    > I don't know if you use Windows, but my Notepad++ add-on has an option to
    > highlight a word and then open up the Hugo Book PDF searching for that word
    > ... I've never liked forcing Adobe Reader on everyone, though; it was just
    > the only program I could find that supported searching a pdf with a string
    > from command line.

    Yes, I use Windows. I agree, Adobe uses many non standard PDF features, which are
    not granted to work on other readers. It also collects lots of user data and
    information about the documents read, which is not nice.

    The idea of supporting keywords documentation-lookup in editors is indeed useful.

    > Do you know of some way I could do this with your HTML version? A cursory
    > Googling hasn't helped me.

    Asciidoctor supports creation of an Index in PDF, but not in the HTML backend.
    Reconstruction of the original book Index was already planned, for when the PDF
    edition will be added to the project.

    I haven't checked the current status of Asciidoctor support for CHM documents,
    but definitely this would be best approach on Windows, which still supports CHM
    (although I'm not sure for how long). My guess is that the CHM backend should
    support Index.
    The CHM Help Viewer natively supports keywords look-up at invocation, and there
    are dedicated WinAPI functions for this feature. Since Npp uses Scintilla, this
    should be easy to integrate in any custom extension, and Scintilla for Windows
    should provide some helpers to launch CHM files with a lookup request for the
    token located at the cursor.

    Currently, you can target any book section by using the custom ID added anchors,
    which use an intuitive naming convention, documented here:

    https://github.com/tajmone/hugo-book/blob/master/CONVENTIONS.md#sections-ids-customization

    But if you need extra anchors to be added to the book, I'll be happy to add them
    (anchors are cheap and harmless), so just open an Issue on the repository.

    The subjects you brought up are quite interesting, and it might be a good idea
    if you opened an Issue on the repository to further disccuss them, so I can
    integrate their planning into project's TODOs list on GitHub. Obviously, any
    use needs for the Hugo Book will be taken into consideration in the project, and
    I'll try my best to be forthcoming toward users demands, and adapt the project
    accordingly.

    > I hope to have another release of Roodylib out sometime this year,

    I was planning to create a repository gathering third party libraries and
    extensions in one place (license permitting), and your lib was already in the
    readar. In due time, I'll start contacting the various authors (which is not
    always an easy task after so many years have gone by).

    > Juhana Leinonen made an app which, among other things, allows people to compile Hugo games online: https://borogove.app/

    I missed that one, thanks for the link!

    ReplyDelete