Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next

  • Book - Scope

    Chapter - Scope

    [The scope of an actor is the set of objects which he can refer to in typed
    commands, which is normally the same as the set of visible objects; but this
    can be modified. This is how I7 handles tokens like ``[any room]''.

    Scope determination is done by calling |SearchScope| to iterate through the
    objects in scope, and ``visit'' each one: which means, carry out some task
    for each as we get there. The task depends on the current value of
    |scope_reason|, which is |PARSING_REASON| when the parser is matching
    command text against object names.

    The scope machinery is built on a number of levels, each making use only
    of lower levels:
    (0) Either |NounDomain|, |TestScope| or |LoopOverScope| makes one or more
    calls to |SearchScope| (on level 1). The point of making multiple calls
    is to influence the order in which items in scope are visited, which improves
    the quality of ``take all''-style multiple object lists, for instance.
    (1) |SearchScope| searches for the objects in scope which are within first
    one domain, and then another: for instance, first within the current room
    but not within the current actor, and then within the current actor. It can
    be called either from level 0, or externally from the choose-objects
    machinery, but is not recursive. It works within the context of a given
    token in the parser (when called for |PARSING_REASON|) and in particular
    the |multiinside| token, and also handles testing commands, scope tokens,
    scope in darkness, and intervention by the I7 ``deciding the scope of''
    activity. Most of its actual searches are delegated to |ScopeWithin| (level
    2), but it also uses |DoScopeActionAndRecurse| (level 3) and
    |DoScopeAction| (level 4) as necessary.
    (2) |ScopeWithin| iterates through the objects in scope which are within
    one supplied domain, but not within another. It can be called either
    from level 1, or independently from rules in the ``deciding the scope of''
    activity via the I7 ``place the contents of X in scope'' phrase. It calls
    |DoScopeActionAndRecurse| (level 3) on any unconcealed objects it finds.
    (3) |DoScopeActionAndRecurse| visits a given object by calling down to
    |DoScopeAction| (level 4), and recurses to all unconcealed object-tree
    contents and component parts of the object. The I7 phrase ``place X in
    scope'' uses this routine.
    (4) |DoScopeAction| simply visits a single object, taking whatever action
    is needed there -- which will depend on the |scope_reason|. The only use
    made by the parser of |TryGivenObject|, which tries to match command text
    against the name of a given object, is from here. The I7 phrase ``place X
    in scope, but not its contents'' uses this routine.

    Two routines are provided for code external to the parser to modify the
    scope. They should be called only during scope deliberations -- i.e.,
    in |scope=...| tokens or in rules for the ``deciding the scope of''
    activity. (At present, |AddToScope| is not used in I7 at all.) Note
    that this I7 form of |PlaceInScope| has a slightly different specification
    to its I6 library counterpart of the same name: it can place a room in
    scope. (In I6, room names were not normally parsed.)]

    To place (O - an object) in scope, but not its contents (this is PlaceInScope):
        now the parser's current word position is the next word to parse's position;
        if not but not its contents, recursively do scope action on O;
        otherwise do scope action on O.

    [ PlaceInScope O opts; ! If opts is set, do not place contents in scope
        wn = match_from;
        if (opts == false) DoScopeActionAndRecurse(O);
        else DoScopeAction(O);

    To add (obj - an object) to scope (this is AddToScope):
        if the add to scope flag is at least 2, recursively do scope action on obj excluding nothing under (add to scope flag - 2 as a grammar token);
        if the add to scope flag is 1 [meaning LOOPOVERSCOPE_REASON] and light can get out of the obj, now the add to scope has-light-source is true.

    [ AddToScope obj;
    if (ats_flag >= 2) DoScopeActionAndRecurse(obj, 0, ats_flag-2);
    if (ats_flag == 1) { if (HasLightSource(obj)==1) ats_hls = 1; }