The "Rewrite The Parser in Inform 7" Project

(I believe the code at viewtopic.php?f=7&t=3264&start=0#p23302 fixes that issue.)

However, I am seriously considering spinning off that part of the parser to its own rulebook, as a way of shortening Parser__parse, if no other reason.

How funny, and embarrassing, that you anticipated and answered my question, and I forgot about it! I think I mainly skipped over it because it uses indexed text, but it looks like “the player’s command matches the text ‘,’” is useful in itself. I didn’ t know there was any way to detect a comma.

I’m all for spinning off parts of the parser, especially that one!

Functions that are too big to fit on one screen are a pet peeve of mine. :laughing:

Hey Ron, how is this project going? I keep coming back to it, reading a little more each time. I ran into some issues between my Lost Items and Scope Caching extensions that made me think I really need to understand the parser better. It’s quite an impressive undertaking you have here!

I was just examining the “Truth States as ‘We’ Commands” mini-extension. I’d like to see these mini-extensions available, maybe as a package if they’re too small to justify independent release. It looks very handy, and I’m impressed that it’s possible to overload phrases like “we shouldn’t” as both a “to decide if” and a “to” phrase.

I put it on pause for the Comp. Current state as of a couple weeks ago: all functions translated, but I want to test it out and maybe rename some stuff for clarity’s sake before next release. Parser__parse is very long so I’m looking into extracting certain subsections.

As for the things I call mini-extensions in there, I didn’t really feel any of them are substantial enough for independent release. I only gathered related phrases under headings like that so readers can distinguish support code from the parser itself.

I still have another round of Comp games to go through before I come back to this.

Lo and behold, version 7 and Release Candidate #1 of the Parser Rewrite project is complete. Finally, all functions within the enormous template file Parser.i6t have been translated to Inform 7, including Parser__parse(), which alone comprises 448 lines of Inform 7 code excluding interspersed comments and wrapped lines. While “parse”, as it’s now known, was split into a few functions, this was done primarily to remove GOTO statements. Many such statements still exist in parse, and many sections could be tucked away into standalone functions themselves without too much effort.

In any event, Inform 7 is a very readable language, and while rewriting and revising names of variables and phrases and the like could go on theoretically forever, my own time has become monopolized by life concerns. As the recent IF Comp wound down, so did my unemployment insurance, and so I arranged a move some 40 miles away to cheaper housing. As the fates would have it, the day after my move started I was offered a position minutes away from where I used to live. And so for the past month or so I’ve been working a new job, as a professional software developer once again, for about 11 to 12 hours a day, with an hour and a half commute each way on top of that.

So, not much time for fun stuff. Well, nothing that should be expected to be completed in any reasonable timeframe anyway.

But the sun is shining today, and my financial woes are gone, and if my biggest problem right now is a nasty commute, I consider myself lucky.

I intend to release the parser rewrite as an extension on the official Inform 7 site, but first I’d greatly appreciate some community members poke at it to see if it breaks. I can fix the odd bug here or there, and release it officially in two to four weeks, say?

Congratulations on the job, Ron!

Also on the Parser project. This is insanely exciting, though I can’t really understand it.

I had an odd thing happen when I dropped this code into the parser in place of “The lab is a room.” Typing “test me” gave me a bunch of “you can’t start with a comma” errors, even though typing the commands in the test script worked as it should.

In the thing as it is, “me, jump” causes the game to hang in the Mac IDE, though “jump” and other commands work fine.

Hope this helps!

I think I’d be willing to try it out with my WIP. I’ve been following the project with great interest, and lately I’ve been referring to your version to figure out: a) how the parser works, and b) some tips on expressing various I6 components in I7.

I even borrowed your phrase idea for expressing truth states as “we should/will/are/etc…”

Congratulations on your new job, and good luck with the new location!

Congratulations. I would not have laid money on this project being finishable. :slight_smile:

Great news (both the job and the extension)!

Curiouser and curiouser; I tried again by uncommenting the scenario (with Bob and the coins) and adding ‘Test me with “Bob, get the coin”’. It seems like I get the “You can’t begin with the comma” error when I start with “test me” and then get it again when I type “Bob, get the coin”; but if I type “Bob, get the coin” I don’t get it, and sometimes if I follow it with test me it works.

I wonder if it’s related to this bug:

inform7.com/mantis/view.php?id=860

?

I can imagine that additional parser voodoo is going on when running test commands, given their nature.

Congratulations, Ron!

This is very exciting. I hope that eventually this will become the standard parser. It will make a lot of things easier!

“me, jump” is definitely sending it into a loop – it gets to “Actor is: yourself” and then starts running NounDomain on “me” again. That’s as much as I can figure out. (And I seem to be kind of intermittent at reproducing it.)

Thank you all very much! I’m pretty happy, even if I do have to debug someone else’s javascript nowadays. (sigh)

Matt I’ll hunt that down. It didn’t occur to me to test the Test Me functionality much. I generally find bugs by turning on full trace output and running 2 Inform projects side by side, flicking back and forth as I page down the output to see where things go off the rails. Thanks for the bug hunting.

The last bug I fixed before release was rather embarassingly having an Otherwise block at the wrong level of indentation near the end of Parse. :blush:

I just stumbled into it.

Interestingly, I can’t get the ‘You can’t begin with a comma’ message by beginning a command with a comma (in the ordinary parser or in yours).

Both bugs found & fixed. Re-download version 7.

It is true the can’t begin with a comma error cannot be elicited from the standard parser, but it can in the above. I took some pains to restore it. (Well, they weren’t very big pains.)

The above two bugs were both from the same spot as the 2nd-to-last bug I fixed, in which I had coded something regarding “the chosen (position)” instead of “where that word was found”, an error about as silly as having the wrong indentation.

But the infinite loop was fair. The phrase, “if the ‘comma’ is listed in the player’s parsed command”, in the original code actually has side effects: it leaves the parser’s current word position advanced down the command a ways. I coded the if-condition “correctly”, without that side effect, because asking the question shouldn’t change the answer. Mea culpa.

To fix it without breaking readability, I made a new global, “where the comma was found”, and check it explicitly in the same if-condition. If nothing else, that new global could be very useful to game or extension authors.

Thanks again for the detective work, Matt.

That does sound useful. I’m also interested to look into your other values like “where that word was found” - I was looking for something like that in another project I was working on.

This is indeed really great syntax.

Do you mind if I fold it into my next release of my port of Crowther’s Advent to I7 (crediting you, of course)? I made a few additions to allow adverbs to reflect past-tense conditions as well as present/future tense ones.

[code]Chapter 1 - Truth States as ‘We’ Commands (adapted from “The Parser” by Ron Newcomb)

[ It’s always difficult to name truth states because nothing reads naturally other than a letter: if x is true. These phrases allow us to name a truth state after an imperative sentence, and the optional adverbs allow us to imply how the variable is being used. ]
To decide if we still/should/need/must/have/-- (bool - a truth state): (- ({bool}) -).
To decide if we can’t/shouldn’t/haven’t (bool - a truth state): (- (({bool})) -).
To decide if we do/can/have not (bool - a truth state): (- (
({bool})) -).
To we will/should/just/now/still/may/must/have (bool - a truth state) again/–: (- {bool} = true; -);
To we no/do longer/not have/-- (bool - a truth state): (- {bool} = false; -).
To we needn’t/shouldn’t/won’t/haven’t (bool - a truth state): (- {bool} = false; -).
To we will/should/may/must (bool - a truth state) if (c - a condition): (- {bool} = ({c}); -);[/code]

Thanks Chris. Have at it.