TextReplace:
CEDAR
DEFINITIONS = {
ROPE: TYPE = Rope.ROPE;
RopeMap: TYPE = REF RopeMapRep;
RopeMapRep:
TYPE =
RECORD [
Map: PROC [REF ANY, ROPE] RETURNS [ROPE],
data: REF ANY ← NIL];
Apply:
PROC [s: RopeMap, r:
ROPE]
RETURNS [mapped:
ROPE];
= {mapped ← s.Map[s.data, r]};
id: RopeMap;
addBrackets: 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: BOOL ← FALSE];
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.
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];
}.