Testing for "[any X]" scope in grammar line

Suppose I wanted to use my Disambiguation Override extension to filter the match list, but only when the current grammar line uses a scope filter rather than the normal spatial scope loop:

[code]
A thing has a text called the comment.
Definition: A thing is noteworthy if the comment of it is not empty.

Before asking which do you mean when we are parsing for unseen objects:
filter the match list for noteworthy things, leaving at least one choice.

To decide whether we are parsing for unseen objects:
[I6 magic goes here];[/code]

What I6 variables do I need to check? I thought I could use scope_stage=2, but that doesn’t seem to work right.

scope_stage has to do with the three questions an I6 scope token can answer. (1: are multiple objects acceptable? 2: what is in scope? 3: what message should be printed if nothing in scope matches the input?) (In I7 the stages are dealt with in generated code, so you don’t have to deal with this.)

Looking at this generated code, maybe the suppress_scope_loops global will work?

suppress_scope_loops doesn’t seem to be set at the time we’re doing the test. Any other ideas?

Here’s an example to play with:

[code]
[Include Disambiguation Override by Mike Ciul.]

A thing has a text called the comment.
Definition: A thing is noteworthy if the comment of it is not empty.

To decide whether we are parsing for unseen objects: (- suppress_scope_loops -);

Before asking which do you mean when we are parsing for unseen objects:
say “Parsing for unseen objects.”;
[showme the list of noteworthy things;
filter the match list for noteworthy things, leaving at least one choice;]

Requesting commentary about is an action applying to one visible thing.

Understand “comment on [any thing]” as requesting commentary about.

Check requesting commentary about a not noteworthy thing:
say “No comment.”;
stop the action.

Report requesting commentary about:
say the comment of the noun.

Test is a room.

There is a green apple. The comment is “Tasty.”

There is a green ball in Test.

There is a green hammer in Test.

test me with “comment on green/x green”[/code]

Maybe I’ll get somewhere with the “scope_token” variable. This looks like it might be right:

[code][Include Disambiguation Override by Mike Ciul.]

A thing has a text called the comment.
Definition: A thing is noteworthy if the comment of it is not empty.

To decide whether we are parsing for unseen objects: (- scope_token ~= 0 -);

The scope decider is a rule producing a truth state that varies.
The scope decider variable translates into I6 as “scope_token”.

Before asking which do you mean when we are parsing for unseen objects:
showme the scope decider;
say “Parsing for unseen objects.”;
[showme the list of noteworthy things;
filter the match list for noteworthy things, leaving at least one choice;]

Requesting commentary about is an action applying to one visible thing.

Understand “comment on [any thing]” as requesting commentary about.

Check requesting commentary about a not noteworthy thing:
say “No comment.”;
stop the action.

Report requesting commentary about:
say the comment of the noun.

Test is a room.

There is a green apple. The comment is “Tasty.”

There is a green ball in Test.

There is a green hammer in Test.

test me with “comment on green/x green”[/code]

I don’t know if it’s right, but if it seems to be working…

The various no-such-thing-in-scope parser errors seem to use the scope_token global to distinguish their cases, so that’s a vote in favor or that method.

Try this.

[spoiler][code]“One of Those Mornings”

Include (-

token_filter = 0;
parser_inflection = name;
switch (given_ttype) {
  ELEMENTARY_TT:
	switch (given_tdata) {
	  SPECIAL_TOKEN:
		l = TryNumber(wn);
		special_word = NextWord();
		#Ifdef DEBUG;
		if (l ~= -1000)
			if (parser_trace >= 3) print "  [Read special as the number ", l, "]^";
		#Endif; ! DEBUG
		if (l == -1000) {
			#Ifdef DEBUG;
			if (parser_trace >= 3) print "  [Read special word at word number ", wn, "]^";
			#Endif; ! DEBUG
			l = special_word;
		}
		parsed_number = l;
		return GPR_NUMBER;

	  NUMBER_TOKEN:
		l=TryNumber(wn++);
		if (l == -1000) {
			etype = NUMBER_PE;
			return GPR_FAIL;
		}
		#Ifdef DEBUG;
		if (parser_trace>=3) print "  [Read number as ", l, "]^";
		#Endif; ! DEBUG
		parsed_number = l;
		return GPR_NUMBER;

	  CREATURE_TOKEN:
		if (action_to_be == ##Answer or ##Ask or ##AskFor or ##Tell)
			scope_reason = TALKING_REASON;

	  TOPIC_TOKEN:
		consult_from = wn;
		if ((line_ttype-->(token_n+1) ~= PREPOSITION_TT) &&
		   (line_token-->(token_n+1) ~= ENDIT_TOKEN))
			RunTimeError(13);
		do o = NextWordStopped();
		until (o == -1 || PrepositionChain(o, token_n+1) ~= -1);
		wn--;
		consult_words = wn-consult_from;
		if (consult_words == 0) return GPR_FAIL;
		if (action_to_be == ##Ask or ##Answer or ##Tell) {
			o = wn; wn = consult_from; parsed_number = NextWord();
			wn = o; return 1;
		}
		if (o==-1 && (line_ttype-->(token_n+1) == PREPOSITION_TT))
			return GPR_FAIL;    ! don't infer if required preposition is absent
		return GPR_PREPOSITION;
	}

  PREPOSITION_TT:
	! Is it an unnecessary alternative preposition, when a previous choice
	! has already been matched?
	if ((token->0) & $10) return GPR_PREPOSITION;

	! If we've run out of the player's input, but still have parameters to
	! specify, we go into "infer" mode, remembering where we are and the
	! preposition we are inferring...

	if (wn > num_words) {
		if (inferfrom==0 && parameters<params_wanted) {
			inferfrom = pcount; inferword = token;
			pattern-->pcount = REPARSE_CODE + VM_DictionaryAddressToNumber(given_tdata);
		}

		! If we are not inferring, then the line is wrong...

		if (inferfrom == 0) return -1;

		! If not, then the line is right but we mark in the preposition...

		pattern-->pcount = REPARSE_CODE + VM_DictionaryAddressToNumber(given_tdata);
		return GPR_PREPOSITION;
	}

	o = NextWord();

	pattern-->pcount = REPARSE_CODE + VM_DictionaryAddressToNumber(o);

	! Whereas, if the player has typed something here, see if it is the
	! required preposition... if it's wrong, the line must be wrong,
	! but if it's right, the token is passed (jump to finish this token).

	if (o == given_tdata) return GPR_PREPOSITION;
	if (PrepositionChain(o, token_n) ~= -1) return GPR_PREPOSITION;
	return -1;

  GPR_TT:
	l = indirect(given_tdata);
	#Ifdef DEBUG;
	if (parser_trace >= 3) print "  [Outside parsing routine returned ", l, "]^";
	#Endif; ! DEBUG
	return l;

  SCOPE_TT:
	(+ anywhere mode +) = true;
	scope_token = given_tdata;
	scope_stage = 1;
	#Ifdef DEBUG;
	if (parser_trace >= 3) print "  [Scope routine called at stage 1]^";
	#Endif; ! DEBUG
	l = indirect(scope_token);
	#Ifdef DEBUG;
	if (parser_trace >= 3) print "  [Scope routine returned multiple-flag of ", l, "]^";
	#Endif; ! DEBUG
	if (l == 1) given_tdata = MULTI_TOKEN; else given_tdata = NOUN_TOKEN;

  ATTR_FILTER_TT:
	token_filter = 1 + given_tdata;
	given_tdata = NOUN_TOKEN;

  ROUTINE_FILTER_TT:
	token_filter = given_tdata;
	given_tdata = NOUN_TOKEN;

} ! end of switch(given_ttype)

token = given_tdata;

-) instead of “Parse Token Letter A” in “Parser.i6t”.

Anywhere mode is a truth state that varies. Before reading a command: now anywhere mode is false.

A first before rule: say “(anywhere mode => [anywhere mode])[line break]”.

Finding is an action applying to one visible thing. Understand “find [any thing]” as finding.

Carry out finding:
if the player is carrying the noun begin;
say “You’re holding [the noun]!”;
otherwise;
say “You left [the noun] [if the noun is on a supporter]on[otherwise]in[end if] [the holder of the noun].”;
end if.

[The holder of the noun can be a room, a supporter, or a container: the phrase is not picky. We would want to be a little more careful if it were ever possible for an item to have been “removed from play” in our game, since then the holder could be nothing, and that would have odd results. In this particular example, though, that will not arise.]

[And that’s it, as far as the find command goes. The rest is local color.]

The Exhibition Room is a room. It contains a closed locked lockable transparent openable container called the display case. The display case contains a priceless pearl. The display case is scenery. The description of the Exhibition Room is “By far the finest thing in the room is a priceless pearl in a glass display case. It should of course be yours[if key is not visible], if only you can remember where you hid the key[end if].”

The silver key unlocks the display case.

A jade vase, a teak chest, a bronze teakettle and a child’s burial casket are openable closed containers in the Exhibition Room.

After taking the pearl:
say “The pearl rolls into your hand, gleaming in the oblique light; your fortune is made.”;
end the story finally.

[If we want to have the key found in different places when the game is replayed:]

When play begins:
let the space be a random container which is not the display case;
move the silver key to the space.

Every turn:
say “Your watch ticks with maddening loudness.”.

The time of day is 1:02 AM.

At 1:08 AM:
say “The security guard arrives to find you fumbling about with keys. Curses.”;
end the story.

Test me with “find pearl / find teakettle / get teakettle / find teakettle / find key”.[/code][/spoiler]

The truth state “anywhere mode” is true when the action uses a token of the form “[any X]” and false if not. Basically, you need to check if “given_tdata” is equal to “SCOPE_TT” (which is 5) at least once during the parse command stage.

Hope this helps.