VariableSequencesImpl.mesa
Last Edited by: Arnon, June 10, 1985 4:19:22 pm PDT
DIRECTORY
Rope,
IO,
Convert,
AlgebraClasses,
Variables,
Ints,
Sequences,
VariableSequences;
VariableSequencesImpl: CEDAR PROGRAM
IMPORTS Rope, Convert, AlgebraClasses, Variables, Sequences
EXPORTS VariableSequences =
BEGIN OPEN AC: AlgebraClasses, VARS: Variables, SEQ: Sequences, VariableSequences;
Types
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Object: TYPE = AC.Object;
Method: TYPE = AC.Method;
TypeError: PUBLIC ERROR [message: ATOM ← $Unspecified] = CODE;
Public Structure
VariableSequences: PUBLIC AC.Object ← SEQ.MakeSequenceStructure[VARS.Variables];
Operations
VariableFirstChar: PUBLIC PROC [char: CHAR, V: VariableSequence] RETURNS [BOOL] ~ {
vData: SEQ.SequenceData ← NARROW[V.data];
FOR i:NAT IN [1..vData.lengthPlus1) DO
IF Rope.Equal[
Convert.RopeFromChar[from: char, quote: FALSE],
Rope.Substr[VARS.ToRope[vData[i] ], 0, 1]
] THEN RETURN[TRUE];
ENDLOOP;
RETURN[FALSE];
};
MakeVariableSequence: PUBLIC AC.ListImbedOp ~ SEQ.MakeSequence;
This will become Method $variableSequence of structure VariableSequences.
MergeVariableSequences: PUBLIC AC.BinaryOp ~ {
All variables of firstArg that do not occur in secondArg are placed at left (low) end of result; all variables Variables X and Y may occur in different order in the two args; no note is made of this; they will occur in result in the order they had in secondArg.
firstSeqData: SEQ.SequenceData ← NARROW[firstArg.data];
secondSeqData: SEQ.SequenceData ← NARROW[secondArg.data];
firstStructureData: SEQ.SequenceStructureData ← NARROW[firstArg.class.data];
secondStructureData: SEQ.SequenceStructureData ← NARROW[firstArg.class.data];
firstElementStructure: Object ← firstStructureData.elementStructure;
secondElementStructure: Object ← firstStructureData.elementStructure;
intIndex: Ints.Int;
lowVars, lowVarsPointer: LIST OF VARS.Variable;
lowVarSeq: VariableSequence ← NIL;
IF NOT AC.StructureEqual[firstElementStructure, secondElementStructure] THEN TypeError[];
FOR i:INT IN [1..firstSeqData.lengthPlus1) DO
intIndex ← SEQ.Find[secondArg, firstSeqData[i] ];
IF intIndex=NIL THEN {
IF lowVars # NIL THEN
lowVarsPointer ← lowVarsPointer.rest ← LIST[firstSeqData[i] ]
ELSE
lowVars ← lowVarsPointer ← LIST[firstSeqData[i] ];
};
ENDLOOP;
IF lowVars # NIL THEN lowVarSeq ← SEQ.MakeSequence[lowVars, VariableSequences];
RETURN[SEQ.Concatenate[lowVarSeq, secondArg] ];
};
NewMainVariable: PUBLIC AC.BinaryOp ~ {
firstArg is a VariableSequence, secondArg is a Variable that may or may not occur in firstArg. result is firstArg with reordered variables so that secondArg is new main variable. Order of other variables is preserved
pos: Ints.Int ← SEQ.Find[firstArg, secondArg];
delSeq: Object;
IF pos#NIL THEN
delSeq ← SEQ.Delete[firstArg, pos]
ELSE
delSeq ← firstArg;
RETURN[ SEQ.Append[delSeq, secondArg] ];
};
Start Code
Kludge up special subclass for VariableSequences **5/3/87 obsolete
variableSequenceMethod: Method ← AC.MakeMethod[ListImbedOp, FALSE, NEW[AC.ListImbedOp ← MakeVariableSequence], NIL, "variableSequence"];
variableSequencesClass: AC.Object ← AC.MakeClass["variableSequencesClass", VariableSequences.class, NIL];
AC.AddMethodToClass[$variableSequence, variableSequenceMethod, variableSequencesClass];
VariableSequences.class ← variableSequencesClass;
AC.InstallStructure[VariableSequences];
END.