home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Text / Docu / Mappers (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  19.8 KB  |  381 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. Geneva
  23. 6.2 TextMappers
  24. DEFINITION TextMappers;
  25.     IMPORT Views, TextModels;
  26.     CONST
  27.         returnLChars = 0; returnCtrlChars = 1; returnQualIdents = 2; returnViews = 3;
  28.         interpretBools = 4; interpretSets = 5;
  29.         maskViews = 6;
  30.         char = 0; lchar = 1; string = 2; lstring = 3; int = 4; real = 5;
  31.         bool = 6; set = 7; view = 8; tab = 9; line = 10; para = 11;
  32.         eot = 30; invalid = 31;
  33.         charCode = -16; decimal = 10; hexadecimal = 16;
  34.         hideBase = FALSE; showBase = TRUE;
  35.     TYPE
  36.         LONGCHAR = INTEGER;
  37.         String = ARRAY 256 OF CHAR;
  38.         LongString = ARRAY 256 OF LONGCHAR;
  39.         Scanner = RECORD
  40.             opts-: SET;
  41.             rider-: TextModels.Reader;
  42.             type: INTEGER;
  43.             start, lines, paras: LONGINT;
  44.             char: CHAR;
  45.             lchar: LONGCHAR;
  46.             int, base: LONGINT;
  47.             real: LONGREAL;
  48.             bool: BOOLEAN;
  49.             set: SET;
  50.             len: INTEGER;
  51.             string: String;
  52.             lstring: LongString;
  53.             view: Views.View; w, h: LONGINT;
  54.             PROCEDURE (VAR s: Scanner) ConnectTo (text: TextModels.Model);
  55.             PROCEDURE (VAR s: Scanner) Pos (): LONGINT;
  56.             PROCEDURE (VAR s: Scanner) SetPos (pos: LONGINT);
  57.             PROCEDURE (VAR s: Scanner) SetOpts (opts: SET);
  58.             PROCEDURE (VAR s: Scanner) Skip (VAR ch: CHAR);
  59.             PROCEDURE (VAR s: Scanner) Scan
  60.         END;
  61.         Formatter = RECORD
  62.             rider-: TextModels.Writer;
  63.             PROCEDURE (VAR f: Formatter) ConnectTo (text: TextModels.Model);
  64.             PROCEDURE (VAR f: Formatter) Pos (): LONGINT;
  65.             PROCEDURE (VAR f: Formatter) SetPos (pos: LONGINT);
  66.             PROCEDURE (VAR f: Formatter) WriteChar (x: CHAR);
  67.             PROCEDURE (VAR f: Formatter) WriteLChar (x: LONGCHAR);
  68.             PROCEDURE (VAR f: Formatter) WriteInt (x: LONGINT);
  69.             PROCEDURE (VAR f: Formatter) WriteReal (x: REAL);
  70.             PROCEDURE (VAR f: Formatter) WriteLReal (x: LONGREAL);
  71.             PROCEDURE (VAR f: Formatter) WriteString (x: ARRAY OF CHAR);
  72.             PROCEDURE (VAR f: Formatter) WriteLString (x: ARRAY OF LONGCHAR);
  73.             PROCEDURE (VAR f: Formatter) WriteBool (x: BOOLEAN);
  74.             PROCEDURE (VAR f: Formatter) WriteSet (x: SET);
  75.             PROCEDURE (VAR f: Formatter) WriteTab;
  76.             PROCEDURE (VAR f: Formatter) WriteLn;
  77.             PROCEDURE (VAR f: Formatter) WritePara;
  78.             PROCEDURE (VAR f: Formatter) WriteView (v: Views.View);
  79.             PROCEDURE (VAR f: Formatter) WriteIntForm (x: LONGINT; base, minWidth: INTEGER;
  80.             PROCEDURE (VAR f: Formatter) WriteRealForm (x: LONGREAL; precision, minW,
  81.                                                                                                     expW: INTEGER; fillCh: CHAR);
  82.             PROCEDURE (VAR f: Formatter) WriteViewForm (v: Views.View; w, h: LONGINT);
  83.             PROCEDURE (VAR f: Formatter) WriteParamMsg (msg, p0, p1, p2: ARRAY OF CHAR);
  84.             PROCEDURE (VAR f: Formatter) WriteMsg (msg: ARRAY OF CHAR)
  85.         END;
  86.     PROCEDURE IsQualIdent (VAR s: ARRAY OF CHAR): BOOLEAN;
  87.     PROCEDURE ScanQualIdent (VAR s: Scanner; VAR x: ARRAY OF CHAR; VAR done: BOOLEAN);
  88. END TextMappers.
  89. TextMappers are mappers that use text riders to scan and format structured text.
  90. CONST returnLChars
  91. Option element
  92. Possible element of Scanner.opts. If present, the scanner will return long characters; otherwise long characters are projected to TextModels.unicode.
  93. CONST returnCtrlChars
  94. Option element
  95. Possible element of Scanner.opts. If present, the scanner will return tab, line, and para characters; otherwise these control characters are treated as white space and read over.
  96. CONST returnQualIdents
  97. Option element
  98. Possible element of Scanner.opts. If present, the scanner will return "qualified identifiers" as a single string; otherwise, the name and period parts of the qualified identifier will be returned individually. (A qualified string, as defined by the language Oberon follows the syntax name ["." name].)
  99. CONST returnViews
  100. Option element
  101. Possible element of Scanner.opts. If present, the scanner will return embedded views; otherwise these are treated as white space and read over.
  102. CONST interpretBools
  103. Option element
  104. Possible element of Scanner.opts. If present, the scanner will recognize boolean truth values "$TRUE" and "$FALSE", as output by the formatter when writing Boolean values; otherwise "$", "TRUE", and "FALSE" are returned individually, without interpretation.
  105. CONST interpretSets
  106. Option element
  107. Possible element of Scanner.opts. If present, the scanner will recognize set values: sets of integers in the range MIN(SET) .. MAX(SET) as defined by the language Oberon; otherwise "{", ".", and enclosed integers will be returned individually. (The syntax of set values is {" integer [".." integer "]" { "," integer [".." integer] "}.)
  108. CONST maskViews
  109. Option element
  110. Possible element of scanner.opts. If present, the scanner will try to interpret a view as a character code, if the view has a preferred character code. Otherwise, the view is returned.
  111. CONST char
  112. Possible value of scanner.type, signalling that a plain character has been scanned. A character is returned in this class if it does not form a valid first character of any of the structured scan types below.
  113. CONST lchar
  114. Possible value of scanner.type, signalling that a long character has been scanned.
  115. CONST string
  116. Possible value of scanner.type, signalling that a string has been scanned.
  117. CONST lstring
  118. Possible value of scanner.type, signalling that a long string has been scanned.
  119. CONST int
  120. Possible value of scanner.type, signalling that an integer has been scanned.
  121. CONST real
  122. Possible value of scanner.type, signalling that a real has been scanned.
  123. CONST bool
  124. Possible value of scanner.type, signalling that a Boolean has been scanned.
  125. CONST set
  126. Possible value of scanner.type, signalling that a set has been scanned.
  127. CONST view
  128. Possible value of scanner.type, signalling that an embedded view has been scanned.
  129. CONST tab
  130. Possible value of scanner.type, signalling that a tab character has been scanned.
  131. CONST line
  132. Possible value of scanner.type, signalling that a line character has been scanned.
  133. CONST para
  134. Possible value of scanner.type, signalling that a para character has been scanned.
  135. CONST eot
  136. Possible value of scanner.type, signalling that the most recent call to Scan hit the end of the text.
  137. CONST invalid
  138. Possible value of scanner.type, signalling that the most recent call to Scan encountered a syntactically ill formed sequence.
  139. CONST charCode
  140. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers following the syntax of Oberon numerical character literals. (For example, 0DX is the code for line, and 37X the code for "7".)
  141. CONST decimal
  142. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers as decimal literals.
  143. CONST hexadecimal
  144. Possible value for parameter base of formatter.WriteIntForm, asking for formatting integers as hexadecimal literals.
  145. CONST hideBase
  146. Possible value for parameter showBase of formatter.WriteIntForm, asking for suppresion of the base indicator.
  147. CONST showBase
  148. Possible value for parameter showBase of formatter.WriteIntForm, asking for output of the base indicator.
  149. TYPE LONGCHAR
  150. Type of long characters.
  151. TYPE String
  152. Strings of characters as detectable by scanners.
  153. TYPE LongString
  154. Strings of long characters as detectable by scanners.
  155. TYPE Scanner
  156. Scanners are connectable to texts. They allow to scan the sequence of characters and embedded views which form a text for recognized structured subsequences (symbols). The various symbols that a scanner can recognize are defined in terms of scan types (cf. the constants above).
  157. opts-: SET
  158. The scanning options, drawn from the set {returnLChars, returnCtrlChars, returnQualIdents, returnViews, interpretBools, interpretSets, maskViews}.
  159. rider-: TextModels.Reader
  160. The rider connecting the scanner to the text. The rider state is used by the scanner as a single element look
  161. ahead buffer. A sequence of rider.Read or rider.ReadPrev, or positioning the rider followed by rider.Read are all legal manipulations of that look
  162. ahead state.
  163. type: INTEGER
  164. Type of symbol scanned most recently.
  165. start: LONGINT
  166. Starting position of the symbol scanned most recently. Set by scanner.Scan after skipping initial white space.
  167. lines, paras: LONGINT
  168. Number of lines (line characters) and paragraphs (para characters) passed by the scanner since being connected. Updated by scanner.Skip (called initially in scanner.Scan) when skipping white space.
  169. char: CHAR    valid if type = char
  170. Character scanned most recently.
  171. lchar: LONGCHAR    valid iff type IN {char, lchar}
  172. Long character scanned most recently.
  173. int, base: LONGINT    valid iff type = int
  174. Integer scanned most recently, and the base that was used for its formatting. The string representation of the scanned integer is available in (len, string) after scanning.
  175. real: LONGREAL    valid iff type = real
  176. Real scanned most recently.
  177. bool: BOOLEAN    valid iff type = bool
  178. Boolean scanned most recently.
  179. set: SET    valid iff type = set
  180. Set scanned most recently.
  181. len: INTEGER    valid iff type IN {string, lstring, int}
  182. Length of string or lstring field, depending on type.
  183. string: String    valid iff type IN {string, int, bool}
  184. String of characters scanned most recently.
  185. lstring: LongString    valid iff type IN {string, lstring}
  186. String of long characters scanned most recently.
  187. view: Views.View; w, h: LONGINT    valid iff type = view
  188. View scanned most recently, and its width and height.
  189. PROCEDURE (VAR s: Scanner) ConnectTo (text: TextModels.Model)
  190. Disconnect the scanner from the text it was connected to previously (if any), and connect the scanner to the given text (if any).
  191. text = NIL
  192.     s.rider = NIL
  193. text # NIL
  194.     s.rider.Base() = text
  195.     s.Pos() = 0
  196.     s.opts = {}
  197. PROCEDURE (VAR s: Scanner) Pos (): LONGINT
  198. Current position of the scanner's look
  199. ahead rider.
  200. s.rider # NIL    (not explicitly checked)
  201. result = s.rider.Pos()
  202. PROCEDURE (VAR s: Scanner) SetPos (pos: LONGINT)
  203. Reposition the scanner.
  204. s.rider # NIL    (not explicitly checked)
  205. preconditions of s.rider.SetPos
  206. s.Pos() = pos
  207. s.start = pos
  208. s.lines = 0
  209. s.paras = 0
  210. s.type = invalid
  211. PROCEDURE (VAR s: Scanner) SetOpts (opts: SET)
  212. Set scanning options.
  213. s.opts = opts
  214. PROCEDURE (VAR s: Scanner) Skip (VAR ch: CHAR)
  215. Skip white space, as specified by the scanning options picked from {returnLChars, returnCtrlChars, returnViews}.
  216. s.rider # NIL    (not explicitly checked)
  217. ~s.rider.eot
  218.     s.start = s.rider.Pos() - 1
  219. s.rider.eot
  220.     s.start = s.rider.Base().Length()
  221.     s.type = eot
  222. PROCEDURE (VAR s: Scanner) Scan
  223. Scan the text for the next symbol as specified by the scanning options.
  224. s.rider # NIL    (not explicitly checked)
  225. s.rider.eot OR s.Pos() = s.start + Length(symbol) + 1
  226. TYPE Formatter
  227. Formatters connectable to texts in order to write formatted entities to the text.
  228. rider-: TextModels.Writer
  229. The rider connecting the formatter to the text.
  230. PROCEDURE (VAR f: Formatter) ConnectTo (text: TextModels.Model)
  231. Disconnect the formatter from the text it was previously connected to (if any), and connect it to the given text (if any).
  232. text = NIL
  233.     f.rider = NIL
  234. text # NIL
  235.     f.rider # NIL
  236.     f.rider.Base() = text
  237.     f.Pos() = text.Length()
  238. PROCEDURE (VAR f: Formatter) Pos (): LONGINT
  239. Position of the formatter.
  240. f.rider # NIL    (not explicitly checked)
  241. PROCEDURE (VAR f: Formatter) SetPos (pos: LONGINT)
  242. Reposition the formatter.
  243. f.rider # NIL    (not explicitly checked)
  244. f.Pos() = pos
  245. PROCEDURE (VAR f: Formatter) WriteChar (x: CHAR)
  246. Write character x. For control characters the numerical literal form enclosed in spaces is written.
  247. f.rider # NIL    (not explicitly checked)
  248. x >= " "  &  x # 7FX
  249.     character written as is
  250. x < " "  OR  x = 7FX
  251.     " " code(x) " " written
  252. PROCEDURE (VAR f: Formatter) WriteLChar (x: LONGCHAR)
  253. Not yet implemented.
  254. PROCEDURE (VAR f: Formatter) WriteInt (x: LONGINT)
  255. Write integer in default format.
  256. Except for performance, equivalent to:
  257.     f.WriteIntForm(x, decimal, 0, " ", showBase)
  258. PROCEDURE (VAR f: Formatter) WriteReal (x: REAL)
  259. Write real in default format.
  260. Except for performance, equivalent to:
  261.     f.WriteRealForm(x, 7, 0, 0, " ")
  262. PROCEDURE (VAR f: Formatter) WriteLReal (x: LONGREAL)
  263. Write long real in default format.
  264. Except for performance, equivalent to:
  265.     f.WriteRealForm(x, 16, 0, 0, " ")
  266. PROCEDURE (VAR f: Formatter) WriteString (x: ARRAY OF CHAR)
  267. Write string of characters.
  268. Except for performance, equivalent to:
  269.     VAR i: INTEGER;
  270.     i := 0; WHILE x[i] # 0X DO f.WriteChar(x[i]); INC(i) END
  271. PROCEDURE (VAR f: Formatter) WriteLString (x: ARRAY OF LONGCHAR)
  272. Write string of long characters.
  273. Except for performance, equivalent to:
  274.     VAR i: INTEGER;
  275.     i := 0; WHILE x[i] # 0 DO f.WriteLChar(x[i]); INC(i) END
  276. PROCEDURE (VAR f: Formatter) WriteBool (x: BOOLEAN)
  277. Write Boolean.
  278. Except for performance, equivalent to:
  279.     IF x THEN f.WriteString("$TRUE") ELSE f.WriteString("$FALSE") END
  280. PROCEDURE (VAR f: Formatter) WriteSet (x: SET)
  281. Write set.
  282. Except for performance, equivalent to:
  283.     VAR i: INTEGER;
  284.     f.WriteChar("{"); i := MIN(SET);
  285.     WHILE x # {} DO
  286.         IF i IN x THEN f.WriteInt(i); EXCL(x, i);
  287.             IF (i + 2 <= MAX(SET)) & (i+1 IN x) & (i+2 IN x) THEN f.WriteString("..");
  288.                 x := x - {i+1, i+2}; INC(i, 3);
  289.                 WHILE (i <= MAX(SET)) & (i IN x) DO EXCL(x, i); INC(i) END;
  290.                 f.WriteInt(i-1)
  291.             END;
  292.             IF x # {} THEN f.WriteString(", ") END
  293.         END;
  294.         INC(i)
  295.     END;
  296.     f.WriteChar("}")
  297. PROCEDURE (VAR f: Formatter) WriteTab
  298. Write tab character.
  299. Except for performance, equivalent to:
  300.     f.rider.WriteChar(TextMappers.tab)
  301. PROCEDURE (VAR f: Formatter) WriteLn
  302. Write line character.
  303. Except for performance, equivalent to:
  304.     f.rider.WriteChar(TextMappers.line)
  305. PROCEDURE (VAR f: Formatter) WritePara
  306. Write para character.
  307. Except for performance, equivalent to:
  308.     f.rider.WriteChar(TextMappers.para)
  309. PROCEDURE (VAR f: Formatter) WriteView (v: Views.View)
  310. Embed view.
  311. Except for performance, equivalent to:
  312.     f.WriteViewForm(v, Views.undefined, Views.undefined)
  313. v # NIL    20
  314. v.context = NIL    21
  315. PROCEDURE (VAR f: Formatter) WriteIntForm (x: LONGINT; base, minWidth: INTEGER;
  316.                                                                                         fillCh: CHAR; showBase: BOOLEAN)
  317. Write integer x. The numeral string used to represent the number is relative to base base. The total representation form will at least have a width of minWidth characters, where padding (if required) takes place to the left using characters as specified by fillCh. If non
  318. decimal, the base can be requested to form part of the representation using showBase. The special value base = charCode renders the base suffix "X", while base = hexadecimal renders the suffix "H". All other non
  319. decimal bases are represented by a trailing "%" followed by the decimal numerical literal representing the base value itself. Non
  320. decimal representations of negative integers are formed using a base
  321. complement form of width minWidth. E.g., x = -3 renders for base = 16 and minWidth = 2 as "FD".
  322. f.rider # NIL    (not explicitly checked)
  323. base = charCode  OR  base >= 2    20
  324. base <= 16    21
  325. minWidth >= 0    22
  326. PROCEDURE (VAR f: Formatter) WriteRealForm (x: LONGREAL; precision, minW,
  327.                                                                                             expW: INTEGER; fillCh: CHAR)
  328. Write real x. The numeral string used to represent the number is either in fixed point or in scientific format, as specified by scientific.
  329. f.rider # NIL    (not explicitly checked)
  330. 0 < precision <= 16    20
  331. 0 <= minW < LEN(s)    21
  332. -LEN(s) < expW <= 3    22
  333. precision denotes the number of valid decimal places (usually 7 for reals and 16 for long reals).
  334. minW denotes the minimal length in characters. If necessary, preceding fillCh will be inserted.
  335. expW > 0: exponential format (scientific) with at least expW digits in the exponent.
  336. expW = 0: fixpoint or floatingpoint format, depending on x.
  337. expW < 0: fixpoint format with -expW digits after the decimal point.
  338. Numbers are always rounded to the last valid and visible digit.
  339. PROCEDURE (VAR f: Formatter) WriteViewForm (v: Views.View; w, h: LONGINT)
  340. Embed a view with width w and height h.
  341. f.rider # NIL    (not explicitly checked)
  342. v # NIL    20
  343. v.context = NIL    21
  344. PROCEDURE (VAR f: Formatter) WriteParamMsg (msg, p0, p1, p2: ARRAY OF CHAR)
  345. Write a parameterized message string mapped by the Dialog.MapParamString facility. The resulting string is allowed to contain line, para and tab characters, all of which will be written as such.
  346. f.rider # NIL    (not explicitly checked)
  347. PROCEDURE (VAR f: Formatter) WriteMsg (msg: ARRAY OF CHAR)
  348. Write a message string mapped by the Dialog.MapParamString facility.
  349. Except for performace, equivalent to:
  350.     f.WriteParamMsg(msg, "", "", "")
  351. PROCEDURE IsQualIdent (VAR s: ARRAY OF CHAR): BOOLEAN
  352. Test whether the string s fulfills the syntax of an Oberon qualident, i.e. ident ["." ident].
  353. PROCEDURE ScanQualIdent (VAR s: Scanner; VAR x: ARRAY OF CHAR;
  354.                                                         VAR done: BOOLEAN)
  355. Assuming that the scanner returned a string, check if the succeeding symbols can be consumed to scan a qualident. If the scanned string is not a qualident, the scanner is reset the position it had before the call to ScanQualIdent.
  356. s'.type = string
  357.     IsQualIdent(s'.string)
  358.         done = TRUE
  359.         x = s'.string
  360.         s = s'
  361.     ~IsQualIdent(s'.string)
  362.         s'.Scan.type = char  &  s'.Scan.char = "."
  363.             s'.Scan.Scan.type = string & (s'.len + 1 + s'.Scan.Scan.len < LEN(x))
  364.                 done = TRUE
  365.                 x = s'.string + "." + s'.Scan.Scan.string
  366.                 s = s'.Scan.Scan
  367.             s'.Scan.Scan.type # string OR (s'.len + 1 + s'.Scan.Scan.len >= LEN(x))
  368.                 done = FALSE
  369.         s'.Scan.type # char  OR  s'.Scan.char # "."
  370.             done = FALSE
  371. s'.type # string
  372.         done = FALSE
  373. ~done
  374.     s = s'.SetPos(s'.start).Scan()
  375. TextControllers.StdCtrlDesc
  376. TextControllers.ControllerDesc
  377. Containers.ControllerDesc
  378. Controllers.ControllerDesc
  379. Geneva
  380. Documents.ControllerDesc
  381.