TextReplace.mesa
Copyright Ó 1986, 1992 by Xerox Corporation. All rights reserved.
Last Edited by: Spreitzer, January 10, 1986 10:17:05 pm PST
Last tweaked by Mike Spreitzer on August 18, 1988 12:35:03 pm PDT
Doug Wyatt, September 25, 1992 1:58 pm PDT
DIRECTORY Rope USING [ROPE];
TextReplace: CEDAR DEFINITIONS = BEGIN
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;
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.
Pair: TYPE = RECORD [match, replace: ROPE, literal, word, ignoreCase: BOOL ¬ FALSE];
PairList: TYPE = LIST OF Pair;
RopeMapFromPairs: PROC [PairList] RETURNS [RopeMap];
Returns a RopeMap that replaces every occurence of a match by its corresponding replace.
END.