-- NodeNameTable.Mesa
-- written by Paxton. December 1980
-- last written by Paxton. April 5, 1981 3:00 PM

-- maintains a list of nodes that have names
-- a single node can have several names,
-- and a single name can be used with several nodes.
-- a "name" is simply a substring of the node text with look n

DIRECTORY
TextNode,
TextRope;

NodeNameTable: DEFINITIONS =
BEGIN OPEN nodeI:TextNode, ropeI:TextRope;

TextNode: TYPE = nodeI.RefTextNode;
Node: TYPE = nodeI.Ref;
Card: TYPE = nodeI.Card;
Rope: TYPE = ropeI.Rope;

NameTable: TYPE = REF NameTableBody;
NameTableBody: TYPE; -- exported by NodeNameTableImpl

Create: PROC RETURNS [NameTable];
-- creates an empty name table.

Get: PROC [n: Node] RETURNS [NameTable];
-- find the name table for node n.
-- look for nametable prop on n or ancestor.
-- returns NIL if reaches root node without finding a name table

Add: PROC [n: TextNode, table: NameTable];
-- add n to table. i.e., asserts that n now has a name

Remove: PROC [n: TextNode, table: NameTable];
-- remove n from table. i.e., asserts that n no longer has a name

RemoveSpan: PROC [parent: Node, start, len: Card, table: NameTable];
-- remove len children of parent starting at start.
-- and remove all their children too

Find: PROC [name: Rope, table: NameTable, prev: TextNode ← NIL]
RETURNS [TextNode];
-- returns a node that has the given name.
-- let prev be NIL for first call.
-- if prev # NIL, will return a different node with that name.
-- returns NIL when no more nodes with the name.
-- or when prev # NIL is not on list.

Map: PROC [table: NameTable, action: MapAction] RETURNS [BOOLEAN];
-- applies action to each node in table until an action returns true
-- action can remove entries; may or may not apply action to added entries

MapAction: TYPE = PROC [n: TextNode] RETURNS [BOOLEAN];

-- ***** Initialization

Start: PROC; -- for initialization only

END.