Types
LexType: TYPE ~ {ucAlpha, lcAlpha, digit, decimalPoint, leftBracket, backSpace, singleCharTemplate, templateDelimiter, symbolDelimiter, other}; -- categories for scanned characters
ReplacementExprType: TYPE ~ {integer, real, variable, templateName, symbol, template, none}; -- categories of Exprs that be grafted into the parse (i.e. Expression) tree
KbBuffer: TYPE ~ RECORD[type: ReplacementExprType ← none, data: ROPE, savedWrapArg: DisplayExpr ← NIL]; -- build a "string of characters" token
ParseAction: TYPE ~ REF ParseActionRep;
ReplaceAction: TYPE ~ replace ParseActionRep;
BeginMultiCharTemplateAction: TYPE ~ beginMultiCharTemplate ParseActionRep;
FinishMultiCharTemplateAction: TYPE ~ finishMultiCharTemplate ParseActionRep;
WrapAction: TYPE ~ wrap ParseActionRep;
UndoAction: TYPE ~ undo ParseActionRep;
NoAction: TYPE ~ none ParseActionRep;
ParseActionRep:
TYPE ~
RECORD [
SELECT type:*
FROM
beginMultiCharTemplate => [
oldSelection: ATOM -- old selection flavor which contains expr to be wrapped
],
finishMultiCharTemplate => [
class: ATOM -- class for template wrapper
],
replace => [
oldSelection: ATOM, -- old selection flavor which contains expr to replace; expected to always be $primary (i.e. we're starting to build a KB selection), or $keyboard (i.e. we're appending to the current KB selection)
replacementType: ReplacementExprType, -- new expression to be constructed
fromRope: ROPE, -- data for construction
newSelection: ATOM -- selection flavor to select as after replacement
],
wrap => [
selection: ATOM, -- old selection flavor
class: ATOM -- class for template wrapper
],
undo => NULL,
none => NULL -- nothing
ENDCASE
];
Ops
ParseKBChar:
PUBLIC
PROC[c:
CHAR, inBuffer: KbBuffer, primaryActive, keyboardActive:
BOOL ←
FALSE]
RETURNS [outBuffer: KbBuffer, action: ParseAction ←
NIL];
The parser.
LexChar:
PROC[c:
CHAR]
RETURNS[LexType];
Classify a scanned character
ExpandAbbreviation:
PROC [name:
ROPE]
RETURNS [
ROPE];
Recognize abbreviations for template names