DIRECTORY Basics, RopeParts; RopeSequence: CEDAR DEFINITIONS = BEGIN RopePart: TYPE ~ RopeParts.RopePart; nilPart: RopePart ~ RopeParts.nil; RopeSeq: TYPE = REF RopeSeqPrivate; RopeSeqPrivate: TYPE; nil: RopeSeq ~ NIL; MaxLen: INT ~ INT.LAST; QuaRopeSeq: PROC [REF ANY] RETURNS [MaybeRopeSeq]; MaybeRopeSeq: TYPE ~ RECORD [is: BOOL, as: RopeSeq]; IsRopeSeq: PROC [ra: REF ANY] RETURNS [BOOL] ~ INLINE {RETURN [QuaRopeSeq[ra].is]}; AsRopeSeq: PROC [ra: REF ANY] RETURNS [RopeSeq]; ParsePartToSeq: PROC [part: RopePart, seperator: CHAR] RETURNS [RopeSeq]; UnparseSeqToPart: PROC [seq: RopeSeq, seperator: CHAR] RETURNS [RopePart]; Cons: PROC [parts: LIST OF RopePart] RETURNS [RopeSeq]; FromProc: PROC [len: INT, Generate: PROC [INT] RETURNS [RopePart]] RETURNS [RopeSeq]; Cat: PROC [r1, r2, r3, r4, r5: RopeSeq _ nil] RETURNS [RopeSeq]; Concat: PROC [base, rest: RopeSeq _ nil] RETURNS [RopeSeq]; Compare: PROC [s1, s2: RopeSeq, case: BOOL _ TRUE] RETURNS [Basics.Comparison]; CompareSubseqs: PROC [ s1: RopeSeq, start1: INT _ 0, len1: INT _ MaxLen, s2: RopeSeq, start2: INT _ 0, len2: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [Basics.Comparison]; Equal: PROC [s1, s2: RopeSeq, case: BOOL _ TRUE] RETURNS [BOOL]; EqualSubseqs: PROC [ s1: RopeSeq, start1: INT _ 0, len1: INT _ MaxLen, s2: RopeSeq, start2: INT _ 0, len2: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [BOOL]; Fetch: PROC [base: RopeSeq, index: INT _ 0] RETURNS [RopePart]; Index: PROC [ s1: RopeSeq, start1: INT _ 0, len1: INT _ MaxLen, s2: RopeSeq, start2: INT _ 0, len2: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [INT]; Find: PROC [ s1: RopeSeq, start1: INT _ 0, len1: INT _ MaxLen, s2: RopeSeq, start2: INT _ 0, len2: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [INT]; FindBackward: PROC [ s1: RopeSeq, start1: INT _ 0, len1: INT _ MaxLen, s2: RopeSeq, start2: INT _ 0, len2: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [INT]; IsEmpty: PROC [RopeSeq] RETURNS [BOOL]; Length: PROC [RopeSeq] RETURNS [INT]; Subseq: PROC [base: RopeSeq, start: INT _ 0, len: INT _ MaxLen] RETURNS [RopeSeq]; Replace: PROC [base: RopeSeq, start: INT _ 0, len: INT _ MaxLen, with: RopeSeq _ nil] RETURNS [RopeSeq]; ReplaceElt: PROC [base: RopeSeq, index: INT, with: RopePart] RETURNS [RopeSeq]; ActionType: TYPE ~ PROC [RopePart] RETURNS [quit: BOOL _ FALSE]; TranslatorType: TYPE ~ PROC [RopePart] RETURNS [RopePart]; Run: PROC [s1: RopeSeq, pos1: INT _ 0, s2: RopeSeq, pos2: INT _ 0, case: BOOL _ TRUE] RETURNS [INT]; IsPrefix: PROC [prefix, subject: RopeSeq, case: BOOL _ TRUE] RETURNS [BOOL]; IsSuffix: PROC [suffix, subject: RopeSeq, case: BOOL _ TRUE] RETURNS [BOOL]; Match: PROC [pattern, object: RopeSeq, case: BOOL _ TRUE] RETURNS [BOOL]; MatchSubseqs: PROC [ pattern: RopeSeq, pStart: INT _ 0, pLen: INT _ MaxLen, object: RopeSeq, oStart: INT _ 0, oLen: INT _ MaxLen, case: BOOL _ TRUE] RETURNS [BOOL]; SkipTo: PROC [s: RopeSeq, pos: INT _ 0, skip: RopeSeq] RETURNS [INT]; SkipOver: PROC [s: RopeSeq, pos: INT _ 0, skip: RopeSeq] RETURNS [INT]; Map: PROC [base: RopeSeq, action: ActionType] RETURNS [BOOL]; Translate: PROC [base: RopeSeq, translator: TranslatorType _ NIL] RETURNS [RopeSeq]; Hash: PROC [base: RopeSeq, case: BOOL _ TRUE, seed: CARDINAL _ defaultSeed] RETURNS [CARDINAL]; defaultSeed: CARDINAL ~ 27183; END. \ RopeSequence.mesa Copyright Σ 1990 by Xerox Corporation. All rights reserved. Coolidge, July 9, 1990 6:37:44 pm GMT Last changed by Coolidge on July 17, 1990 10:37 am PDT Last tweaked by Mike Spreitzer on October 5, 1990 8:03:42 am PDT A RopeSequence represents an immutable sequence of RopeParts (which in turn represent immutable sequences of characters - thus, a RopeSequence represents an immutable sequence of immutable sequence of character). Part 1: Basic operations and definitions (NOT is) => (as = NIL). The length of the result is one more than the number of occurrences of seperator in part; each element of the result is the chars between two seperators. For all x, s: RopeParts.Equal[Equal[x, UnparseSeqToPart[ParsePartToSeq[x, s], s]]. Equal[x, ParsePartToSeq[UnparseSeqToPart[x, s], s]] when s doesn't occur in x. Builds, from a list of RopeParts, a RopeSeq which contains the parts. Generate is given the index, and is called len times, on 0, 1, ... len-1, in that order. Returns the smallest N such that 0 <= N-start1 < len1 and EqualSubseqs[s1, N, s2.Subseq[start2, len2].Length, s2, start2, len2, case]. If no such N exists, returns MIN[start1+len1, s1.Length]. Like Index, but returns -1 when s2 not found. Like Find, but returns largest such N. Bounds fault if index not in [0 .. base.Length). Part 2: Extended operations and definitions Κp•NewlineDelimiter ™code™K™