TextReplace.Mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Spreitzer, January 10, 1986 10:17:05 pm PST
DIRECTORY Rope, TextFind;
TextReplace: CEDAR DEFINITIONS = {
ROPE: TYPE = Rope.ROPE;
RopeMap: TYPE = REF RopeMapRep;
RopeMapRep: TYPE = RECORD [
Map: PROC [REF ANY, ROPE] RETURNS [ROPE],
data: REF ANYNIL];
Apply: PROC [s: RopeMap, r: ROPE] RETURNS [mapped: ROPE];
= {mapped ← s.Map[s.data, r]};
id: RopeMap;
addBrackets: RopeMap;
Constant: PROC [result: ROPE] RETURNS [rm: RopeMap];
Cat: PROC [first, second: RopeMap] RETURNS [catted: RopeMap];
Map through first, then second.
Layer: PROC [first, later: RopeMap] RETURNS [layered: RopeMap];
IF first declines (i.e., returns NIL), later is consulted.
RopeMapFromPairs: PROC [PairList] RETURNS [RopeMap];
PairList: TYPE = LIST OF Pair;
Pair: TYPE = RECORD [match, replace: ROPE, literal, addBounds: BOOLFALSE];
Returns a RopeMap that replaces every occurance of a match by its corresponding replace.
MapNamedSubfieldToMatch: PROC [finder: TextFind.Finder, lastMatchedRope: ROPE] RETURNS [rm: RopeMap];
If lastMatchedRope is what finder was last matched against (i.e., TextFind.SearchRope[rope: lastMatchedRope, ...]), this returns a RopeMap that maps the name of a named subpattern in the finder to the rope it matched in lastMatchedRope.
MapByMatchToTemplate: PROC [finder: TextFind.Finder, template: ROPE] RETURNS [rm: RopeMap];
Returns a mapper which:
matches input against finder;
if that succeeds, the mapper returns the template modified as if it were the Replacement field of the EditTool;
otherwise, the mapper returns NIL.
Nest: PROC [rm: RopeMap] RETURNS [nested: RopeMap];
A thusly nested RopeMap parses its argument like the Replacement field of the EditTool.
Where <name> is found, it is replaced by what rm has for name.
No metachars in name please.
Quote character is single quote.
SyntaxError: ERROR;
May be raised from a nested RopeMapper (e.g., when last char of arg is quote, or arg has < without matching >).
NoMapping: SIGNAL [rm: RopeMap, from: ROPE] RETURNS [to: ROPE];
Raised from a nested RopeMapper if mapping is NIL. RESUME if you have a good idea.
MatchAndSubstitute: PROC [pattern, against, template: ROPE] RETURNS [ROPE];
}.