ChangeQuote.mesa
Arnon, July 16, 1987 4:08:36 pm PDT
DIRECTORY
MathExpr,
MathRules,
MathDB,
MathTypes,
MathBox,
Imager,
Rope,
Vector,
MathConstructors;
ChangeQuote: CEDAR PROGRAM
IMPORTS MathBox, MathRules, MathExpr,
MathDB, MathConstructors
~
BEGIN
Type Abbreviations from Imported Interfaces
EXPR: TYPE ~ MathExpr.EXPR;
BOX: TYPE ~ MathBox.BOX;
ROPE: TYPE ~ Rope.ROPE;
VEC: TYPE ~ Vector.VEC;
CompoundBoxProc: TYPE ~ MathRules.CompoundBoxProc;
CompositionProc: TYPE ~ MathRules.CompositionProc;
Alignment2D: TYPE ~ MathRules.Alignment2D;
Offset: TYPE ~ MathRules.Offset;
Size: TYPE ~ MathRules.Size;
Argument: TYPE ~ MathExpr.Argument;
Symbol: TYPE ~ MathExpr.Symbol;
CompoundClass: TYPE ~ MathExpr.CompoundClass;
FormatClass: TYPE ~ MathTypes.FormatClass;
Style: TYPE ~ MathTypes.Style;
Procedure Abbreviations from Imported Interfaces
MakeArgument: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size] RETURNS[Argument] ~ MathExpr.MakeArgument;
MakeSymbol: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size, value: EXPR] RETURNS[Symbol] ~ MathExpr.MakeSymbol;
MakeCompoundClass: PROC[name: ATOM, formatClass: FormatClass, description: ROPE, args: LIST OF Argument, syms: LIST OF Symbol, boxRule: CompoundBoxProc, compBox: CompositionProc, cvtAS, cvtReduce, cvtSMP, cvtOther: ROPENIL] RETURNS[CompoundClass] ~ MathExpr.MakeCompoundClass;
Constants
smallGap: REAL = 0.05;
medGap: REAL = 0.10;
bigGap: REAL = 0.25;
Box Procs for Compound Expr Classes
SquareBoxRule: CompoundBoxProc ~ {
effects: Sizes boxes for expr of form ($square $a)
leftSquareBox: BOX ← MathBox.GetBox[$leftSquare, boxes];
rightSquareBox: BOX ← MathBox.GetBox[$rightSquare, boxes];
aBox: BOX ← MathBox.GetBox[$a, boxes];
right and left square brackets must be as tall as expression "a"
scaleFactor: REALMAX[0.25, 1.1 * aBox.Height[] / leftSquareBox.Height[]];
leftSquareBox ← MathBox.Scale[leftSquareBox, [scaleFactor, scaleFactor]];
rightSquareBox ← MathBox.Scale[rightSquareBox, [scaleFactor, scaleFactor]];
RETURN[LIST[aBox, leftSquareBox, rightSquareBox]];
};
Composition Procs for Compound Expr Classes
SquareCompRule: CompositionProc ~ {
effects: Composes layout for expr of form ($square $a) with symbols
$leftSquare and $rightSquare
tempBox: BOX;
tempBoxes: LIST OF BOX;
alignments: LIST OF Alignment2D ← LIST[
[$leftSquare,
[$a, [right], [left]],
[$a, [center], [center]]],
[$rightSquare,
[$a, [left], [right]],
[$a, [center], [center]]]];
[tempBox, tempBoxes] ←
MathRules.Compose[boxes, alignments, [$leftSquare, [origin]],
[$self, [center, -0.25]]];
RETURN[tempBox, tempBoxes];
};
Signals & Errors
wrongBoxType: PUBLIC ERROR = CODE;
Define & Install Expression Classes
InstallListClassesAA: PROC [] ~ {
local declarations
quoteClass: CompoundClass;
aSquareArg: Argument;
leftQuoteSym, rightQuoteSym: Symbol;
aSquareArg ← MakeArgument[$a, LIST[$aliasA, $aliasHot], normal];
leftQuoteSym ← MakeSymbol[$leftSquare, NIL, normal, MathConstructors.MakePlainRope["///"] ];
rightQuoteSym ← MakeSymbol[$rightSquare, NIL, normal, MathConstructors.MakePlainRope["///"] ];
quoteClass ← MakeCompoundClass[$quote, paren, "' a", LIST[aSquareArg], LIST[leftQuoteSym, rightQuoteSym], SquareBoxRule, SquareCompRule, "quote($a)"];
MathDB.KillCompoundClass[$quote];
MathDB.InstallCompoundClass[quoteClass];
MathDB.AddOperator[quoteClass, $List];
};
Install Classes Defined in this Module
InstallListClassesAA[];
END.