Debian Codegraph @

psgml-api.info

raw
1 This is psgml-api.info, produced by makeinfo version 4.0 from
2 psgml-api.texi.
3
4 START-INFO-DIR-ENTRY
5 * PSGML-API: (psgml-api). PSGML, the API documentation.
6 END-INFO-DIR-ENTRY
7
8 Documentation for PSGML, a major mode for SGML.
9
10 Copyright 1994 Lennart Staflin
11
12 Permission is granted to make and distribute verbatim copies of this
13 manual provided the copyright notice and this permission notice are
14 preserved on all copies.
15
16 Permission is granted to copy and distribute modified versions of
17 this manual under the conditions for verbatim copying, and provided
18 that the entire resulting derived work is distributed under the terms
19 of a permission notice identical to this one.
20
21 Permission is granted to copy and distribute translations of this
22 manual into another language, under the above conditions for modified
23 versions, except that this permission notice may be stated in a
24 translation approved by the Free Software Foundation.
25
26 
27 File: psgml-api.info, Node: Top, Next: Types, Prev: (dir), Up: (dir)
28
29 PSGML Internals
30 ***************
31
32 * Menu:
33
34 * Types:: Types and operations
35 * Hooks:: Hooks
36 * Implementation:: Implementation notes
37 * Index:: Index
38
39 --- The Detailed Node Listing ---
40
41 Types and operations
42
43 * element:: The element structure
44 * attribute:: Attribute Types
45 * parser state:: Parser state
46 * DTD:: DTD
47 * entities:: Entities
48
49 
50 File: psgml-api.info, Node: Types, Next: Hooks, Prev: Top, Up: Top
51
52 Types and operations
53 ********************
54
55 NOTE: Names of element types, attributes and entities should be
56 treated as far as possible as a real type. In versions prior to 1.0
57 names are represented by lisp symbols but in 1.0 they are strings.
58
59 Perhaps I should make a `psgml-api.el' that defines some functions
60 to deal with names. Then it would be possible to write code that works
61 in both 0.4 and 1.0.
62
63 * Menu:
64
65 * element:: The element structure
66 * attribute:: Attribute Types
67 * parser state:: Parser state
68 * DTD:: DTD
69 * entities:: Entities
70
71 
72 File: psgml-api.info, Node: element, Next: attribute, Prev: Types, Up: Types
73
74 The element structure
75 =====================
76
77 - Data type: element
78 The basic data type representing the element structure is the
79 Element (this happens to be a node in the parse tree).
80
81 Mapping buffer positions to elements
82 ------------------------------------
83
84 - Function: sgml-find-context-of pos
85 Return the element current at buffer position POS. If POS is in
86 markup, `sgml-markup-type' will be a symbol identifying the markup
87 type. It will be `nil' if POS is outside markup.
88
89 - Function: sgml-find-element-of pos
90 Return the element containing the character at buffer position POS.
91
92 Functions operating on elements
93 -------------------------------
94
95 - Function: sgml-element-name element
96 Returns the name of the element. (obsolete)
97
98 - Function: sgml-element-gi element
99 Return the general identifier (string) of ELEMENT.
100
101 - Function: sgml-element-level element
102 Returns the level of ELEMENT in the element structure. The
103 document element is level 1.
104
105 Structure
106 .........
107
108 - Function: sgml-top-element
109 Return the document element.
110
111 - Function: sgml-off-top-p element
112 True if ELEMENT is the pseudo element above the document element.
113
114 These functions return other related elements, or possibly `nil'.
115
116 - Function: sgml-element-content element
117 First element in content of ELEMENT, or nil.
118
119 - Function: sgml-element-next element
120 Next sibling of ELEMENT. To loop thru all sub elements of an
121 element, `el', You could do like this:
122
123 (let ((c (sgml-element-content el)))
124 (while c
125 <<Do something with c>>
126 (setq c (sgml-element-next c))))
127
128 - Function: sgml-element-parent element
129 Parent of ELEMENT.
130
131 Tags
132 ....
133
134 - Function: sgml-element-stag-optional element
135 Return true if the start-tag of ELEMENT is omissible.
136
137 - Function: sgml-element-etag-optional element
138 Return true if the end-tag of ELEMENT is omissible.
139
140 - Function: sgml-element-stag-len element
141 Return the length of the start-tag of ELEMENT. If the start-tag
142 has been omitted the length is 0.
143
144 - Function: sgml-element-etag-len element
145 Return the length of the end-tag of ELEMENT. If the end-tag has
146 been omitted the length is 0.
147
148 - Function: sgml-element-net-enabled element
149 Return true, if ELEMENT or some parent of the element has null end
150 tag (NET) enabled. Return `t', if it is ELEMENT that has NET
151 enabled.
152
153 Positions
154 .........
155
156 These functions relates an element to positions in the buffer.
157
158 - Function: sgml-element-start element
159 Position of start of ELEMENT.
160
161 - Function: sgml-element-end element
162 Position after ELEMENT.
163
164 - Function: sgml-element-stag-end element
165 Position after start-tag of ELEMENT.
166
167 - Function: sgml-element-etag-start element
168 Position before end-tag of ELEMENT.
169
170 Attributes
171 ..........
172
173 - Function: sgml-element-attlist element
174 Return the attribute declaration list for ELEMENT.
175
176 - Function: sgml-element-attribute-specification-list element
177 Return the attribute specification list for ELEMENT.
178
179 - Function: sgml-element-attval element attribute
180 Return the value of the ATTRIBUTE in ELEMENT, string or nil.
181
182 Misc technical
183 ..............
184
185 - Function: sgml-element-data-p element
186 True if ELEMENT can contain data characters.
187
188 - Function: sgml-element-mixed element
189 True if ELEMENT has mixed content.
190
191 - Function: sgml-element-eltype element
192
193 - Function: sgml-element-empty element
194 True if ELEMENT is empty.
195
196 - Function: sgml-element-excludes element
197
198 - Function: sgml-element-includes element
199
200 - Function: sgml-element-model element
201 Declared content or content model of ELEMENT.
202
203 - Function: sgml-element-context-string element
204 Return string describing context of ELEMENT.
205
206 
207 File: psgml-api.info, Node: attribute, Next: parser state, Prev: element, Up: Types
208
209 Attribute Types
210 ===============
211
212 Basic types for attributes are names and values. (See note about
213 names in *Note Types::.) And attribute values (attval) by lisp strings.
214
215 Attribute Declaration List Type
216 -------------------------------
217
218 - Data type: attlist attdecl*
219 This is the result of the ATTLIST declarations in the DTD. All
220 attribute declarations for an element is the elements attlist.
221
222 - Function: sgml-lookup-attdecl name attlist
223 Return attribute declaration (attdecl) for attribute NAME in
224 attribute declaration list ATTLIST.
225
226 - Function: sgml-attribute-with-declared-value attlist declared-value
227 Find the first attribute in ATTLIST that has DECLARED-VALUE.
228
229 Attribute Declaration Type
230 --------------------------
231
232 - Data type: attdecl name declared-value default-value
233 This is the representation of an individual attribute declaration
234 contained in an ATTLIST declaration.
235
236 - Function: sgml-make-attdecl name declared-value default-value
237 Produces an attdecl.
238
239 - Function: sgml-attdecl-name attdecl
240 Returns the name of an attribute declaration.
241
242 - Function: sgml-attdecl-declared-value attdecl
243 Returns the declared-value of attribute declaration ATTDECL.
244
245 - Function: sgml-attdecl-default-value: attdecl
246 Returns the default-value of attribute declaration ATTDECL.
247
248 Declared Value Type
249 -------------------
250
251 - Data type: declared-value (token-group | notation | simple)
252 A declared value of an SGML attribute can be of different kinds.
253 If the declared value is a token group there is an associated list
254 of name tokens. For notation there is also a list of associated
255 names, the allowed notation names. The other declared values are
256 represented by the type name as a lisp symbol.
257
258 - Function: sgml-declared-value-token-group declared-value
259 Return the name token group for the DECLARED-VALUE. This applies
260 to name token groups. For other declared values nil is returned.
261
262 - Function: sgml-declared-value-notation declared-value
263 Return the list of notation names for the DECLARED-VALUE. This
264 applies to notation declared value. For other declared values nil
265 is returned.
266
267 Default Value Type
268 ------------------
269
270 - Data type: default-value (required | implied | conref | specified )
271 There are several kinds of default values. The REQUIRED, IMPLIED,
272 and CONREF has no associated information. The SPECIFIED have an
273 associated attribute value and can be either `fixed' or `normal'.
274
275 - Function: sgml-make-default-value type &optional attval
276
277 - Function: sgml-default-value-attval default-value
278 Return the actual default value of the declared DEFAULT-VALUE.
279 The actual value is a string. Return `nil' if no actual value.
280
281 - Function: sgml-default-value-type-p type default-value
282 Return true if DEFAULT-VALUE is of TYPE. Where TYPE is a symbol,
283 one of `required', `implied', `conref', or `fixed'.
284
285 Attribute Specification Type
286 ----------------------------
287
288 - Data type: attspec name attval
289 This is the result of parsing an attribute specification.
290
291 - Function: sgml-make-attspec name attval
292 Create an attspec from NAME and ATTVAL. Special case, if ATTVAL
293 is `nil' this is an implied attribute.
294
295 - Function: sgml-attspec-name attspec
296 Return the name of the attribute specified by ATTSPEC.
297
298 - Function: sgml-attspec-attval attspec
299 Return the value (attval) of attribute specification ATTSPEC. If
300 ATTSPEC is `nil', `nil' is returned.
301
302 Attribute Specification List Type
303 ---------------------------------
304
305 - Data type: asl attspec*
306 This is the result of parsing an attribute specification list.
307
308 - Function: sgml-lookup-attspec name asl
309 Return the attribute specification for attribute with NAME in the
310 attribute specification list ASL. If the attribute is unspecified
311 `nil' is returned.
312
313 
314 File: psgml-api.info, Node: parser state, Next: DTD, Prev: attribute, Up: Types
315
316 Parser state
317 ============
318
319 The state of the parser that needs to be kept between commands are
320 stored in a buffer local variable. Some global variables are
321 initialised from this variable when parsing starts.
322
323 - Variable: sgml-buffer-parse-state
324 The state of the parser that is kept between commands. The value
325 of this variable is of type pstate.
326
327 - Data type: pstate
328 The parser state.
329
330 - Function: sgml-pstate-dtd pstate
331 The document type information (dtd) for the parser.
332
333 
334 File: psgml-api.info, Node: DTD, Next: entities, Prev: parser state, Up: Types
335
336 DTD
337 ===
338
339 - Data type: dtd
340 Represents what PSGML knows about the DTD.
341
342 - Function: sgml-dtd-doctype dtd
343 The document type name.
344
345 - Function: sgml-dtd-eltypes dtd
346 The table of element types.
347
348 - Function: sgml-dtd-entities dtd
349 The table of declared general entities (entity-table).
350
351 - Function: sgml-dtd-parameters dtd
352 The table of declared parameter entities (entity-table).
353
354 - Function: sgml-dtd-shortmaps dtd
355 The list of short reference maps.
356
357 - Function: sgml-dtd-notations dtd
358 Not yet implemented.
359
360 
361 File: psgml-api.info, Node: entities, Prev: DTD, Up: Types
362
363 Entities
364 ========
365
366 - Data type: entity
367 An entity has the following properties:
368
369 NAME
370 The name of the entity (a string). This is either the name
371 of a declared entity (general or parameter) or the doctype
372 name if it is the implicit entity referred to by the doctype
373 declaration.
374
375 TYPE
376 This is a symbol. It is `text' if it is a text entity, other
377 values are `cdata', `ndata', `sdata', `sgml' or `dtd'.
378
379 TEXT
380 This is the text of the entity, either a string or an external
381 identifier.
382
383 Operations on entities
384
385 - Function: sgml-make-entity name type text
386 Create an entity.
387
388 - Function: sgml-entity-name entity
389 The name of the entity.
390
391 - Function: sgml-entity-type entity
392 The type of the entity.
393
394 - Function: sgml-entity-text entity
395 The text of the entity.
396
397 - Function: sgml-entity-insert-text entity
398 Insert the text of the entity into the current buffer at point.
399
400 - Function: sgml-entity-data-p entity
401 True if ENTITY is a data entity, that is not of type `text'.
402
403 - Data type: entity-table
404 A table of entities that can be referenced by entity name.
405
406 - Function: sgml-lookup-entity name entity-table
407 The entity with named NAME in the table ENTITY-TABLE. If no such
408 entity exists, `nil' is returned.
409
410 - Function: sgml-entity-declare name entity-table type text
411 Create an entity from NAME, TYPE and TEXT; and enter the entity
412 into the table ENTITY-TABLE.
413
414 - Function: sgml-entity-completion-table entity-table
415 Make a completion table from the ENTITY-TABLE.
416
417 - Function: sgml-map-entities fn entity-table &optional collect
418 Apply the function FN to all entities in ENTITY-TABLE. If COLLECT
419 is `t', the results of the applications are collected in a list
420 and returned.
421
422 
423 File: psgml-api.info, Node: Hooks, Next: Implementation, Prev: Types, Up: Top
424
425 Hooks
426 *****
427
428 - Variable: sgml-open-element-hook
429 The hook run by `sgml-open-element'. Theses functions are called
430 with two arguments, the first argument is the opened element and
431 the second argument is the attribute specification list. It is
432 probably best not to refer to the content or the end-tag of the
433 element.
434
435 - Variable: sgml-close-element-hook
436 The hook run by `sgml-close-element'. These functions are invoked
437 with `sgml-current-tree' bound to the element just parsed.
438
439 - Variable: sgml-doctype-parsed-hook
440 This hook is called after the doctype has been parsed. It can be
441 used to load any additional information into the DTD structure.
442
443 - Variable: sgml-sysid-resolve-functions
444 This variable should contain a list of functions. Each function
445 should take one argument, the system identifier of an entity. If
446 the function can handle that identifier, it should insert the text
447 of the entity into the current buffer at point and return t. If
448 the system identifier is not handled the function should return
449 nil.
450
451 - Variable: sgml-doctype-parsed-hook
452 This hook is caled after the doctype has been parsed. It can be
453 used to load any additional information into the DTD structure.
454
455 - Variable: sgml-close-element-hook
456 The hook run by `sgml-close-element'. These functions are invoked
457 with `sgml-current-tree' bound to the element just parsed.
458
459 *** sgml-new-attribute-list-function This hook is run when a new
460 element is inserted to construct the attribute specification list. The
461 default function prompts for the required attributes.
462
463 
464 File: psgml-api.info, Node: Implementation, Next: Index, Prev: Hooks, Up: Top
465
466 Implementation notes
467 ********************
468
469 Data Types and Operations
470 =========================
471
472 Element Type
473 ------------
474
475 - Data type: eltype
476 Data type representing the information about an element type. An
477 `eltype' has information from `ELEMENT' and `ATTLIST'
478 declarations. It can also store data for the application.
479
480 The element types are symbols in a special oblist. The oblist is the
481 table of element types. The symbols name is the GI, its value is used
482 to store three flags and the function definition holds the content
483 model. Other information about the element type is stored on the
484 property list.
485
486 - Function: sgml-eltype-name et
487 The name (a string) of the element type ET.
488
489 - Function: sgml-eltype-appdata et prop
490 Get application data from element type ET with name PROP. PROP
491 should be a symbol, reserved names are: flags, model, attlist,
492 includes, excludes, conref-regexp, mixed, stag-optional,
493 etag-optional.
494
495 This function can be used as a place in `setf', `push' and other
496 functions from the CL library.
497
498 - Function: sgml-eltype-all-miscdata eltype
499 A list of all data properties for eltype except for flags, model,
500 includes and excludes. This function filters the property list of
501 ELTYPE. Used when saving the parsed DTD.
502
503 - Function: sgml-eltype-set-all-miscdata eltype miscdata
504 Append the MISCDATA data properties to the properties of ELTYPE.
505
506 - Function: sgml-eltype-attlist et
507 The attribute specification list for the element type ET.
508
509 - Function: sgml-eltype-completion-table eltypes
510 Make a completion table from a list, ELTYPES, of element types.
511
512 - Function: sgml-eltype-stag-optional et
513 True if the element type ET has optional start-tag.
514
515 - Function: sgml-eltype-etag-optional et
516 True if the element type ET has optional end-tag.
517
518 - Function: sgml-eltype-excludes et
519 The list of excluded element types for element type ET.
520
521 - Function: sgml-eltype-includes et
522 The list of included element types for element type ET.
523
524 - Function: sgml-eltype-flags et
525 Contains three flags as a number. The flags are stag-optional,
526 etag-optional and mixed.
527
528 - Function: sgml-eltype-mixed et
529 True if element type ET has mixed content.
530
531 - Function: sgml-eltype-model et
532 The content model of element type ET. The content model is either
533 the start state in the DFA for the content model or a symbol
534 identifying a declared content.
535
536 - Function: sgml-eltype-shortmap et
537 The name of the shortmap associated with element type ET. This
538 can also be the symbol `empty' (if declared with a `<!USEMAP gi
539 #EMPTY>' or `nil' (if no associated map).
540
541 - Function: sgml-eltype-token et
542 Return a token for the element type ET.
543
544 - Function: sgml-eltypes-in-state state tree
545 List of element types valid in STATE and TREE.
546
547 DTD
548 ---
549
550 The DTD data type is realised as a lisp vector using `defstruct'.
551
552 There are two additional fields for internal use: dependencies and
553 merged.
554
555 - Function: sgml-dtd-dependencies dtd
556 The list of files used to create this DTD.
557
558 - Function: sgml-dtd-merged dtd
559 The pair (FILE . MERGED-DTD), if the DTD has had a precompiled dtd
560 merged into it. FILE is the file containing the compiled DTD and
561 MERGED-DTD is the DTD loaded from that file.
562
563 Element and Tree
564 ----------------
565
566 - Data Type: tree
567 This is the data type for the nodes in the tree build by the
568 parser.
569
570 The tree nodes are represented as lisp vectors, using `defstruct' to
571 define basic operations.
572
573 The Element data type is a view of the tree built by the parser.
574
575 Parsing model
576 =============
577
578 PSGML uses finite state machines and a stack to parse SGML. Every
579 element type has an associated DFA (deterministic finite automaton).
580 This DFA is constructed from the content model.
581
582 SGML restricts the allowed content models in such a way that it is
583 easy to directly construct a DFA.
584
585 To be able to determine when a start-tag can be omitted the DFA need
586 to contain some more information than the traditional DFA. In PSGML a
587 DFA has a set of states and two sets of edges. The edges are associated
588 with tokens (corresponding to SGML's primitive content tokens). I call
589 these moves. One set of moves, the "optional moves", represents
590 optional tokens. I call the other set "required moves". The
591 correspondence to SGML definitions are: if there is precisely one
592 required move from one state, then the associated token is required. A
593 state is final if there is not required move from that state.
594
595 The SGML construct `(...&...&...)' ("AND-group") is another problem.
596 There is a simple translation to sequence- and or-connectors. For
597 example `(a & b & c)' is can be translated to:
598
599 ((a, ((c, b) | (b, c))) |
600 (b, ((a, c) | (c, a))) |
601 (c, ((a, b) | (b, a))) )
602
603 But this grows too fast to be of direct practical use. PSGML
604 represents an AND-group with one DFA for every (SGML) token in the
605 group. During parsing of an AND-group there is a pointer to a state in
606 one of the group's DFAs, and a list of the DFAs for the tokens not yet
607 satisfied. Most of this is hidden by the primitives for the state
608 type. The parser only sees states in a DFA and moves.
609
610 Entity manager
611 ==============
612
613 - Function: sgml-push-to-entity entity &optional ref-start type
614 Set current buffer to a buffer containing the entity ENTITY.
615 ENTITY can also be a file name. Optional argument REF-START should
616 be the start point of the entity reference. Optional argument
617 TYPE, overrides the entity type in entity look up.
618
619 - Function: sgml-pop-entity
620 Should be called after a `sgml-push-to-entity' (or similar).
621 Restore the current buffer to the buffer that was current when the
622 push to this buffer was made.
623
624 - Function: sgml-push-to-string string
625 Create an entity from STRING and push it on the top of the entity
626 stack. After this the current buffer will be a scratch buffer
627 containing the text of the new entity with point at the first
628 character.
629
630 Use `sgml-pop-entity' to exit from this buffer.
631
632 Parser functions
633 ================
634
635 - Function: sgml-need-dtd
636 This makes sure that the buffer has a DTD and set global variables
637 needed by parsing routines. One global variable is `sgml-dtd-info'
638 which contain the DTD (type dtd).
639
640 - Function: sgml-parse-to goal &optional extra-cond quiet
641 This is the low level interface to the parser.
642
643 Parse until (at least) GOAL, a buffer position. Optional argument
644 EXTRA-COND should be a function. This function is called in the
645 parser loop, and the loop is exited if the function returns t. If
646 third argument QUIT is non-`nil', no "`Parsing...'" message will
647 be displayed.
648
649 - Function: sgml-reparse-buffer shortref-fun
650 Reparse the buffer and let SHORTREF-FUN take care of short
651 references. SHORTREF-FUN is called with the entity as argument
652 and `sgml-markup-start' pointing to start of short reference and
653 point pointing to the end.
654
655 Saved DTD Format
656 ================
657
658 File = Comment,
659 File version,
660 S-expression --dependencies--,
661 Parameter entites,
662 Document type name,
663 Elements,
664 General entities,
665 S-expression --shortref maps--,
666 S-expression --notations--
667
668 Elements = Counted Sequence of S-expression --element type name--,
669 Counted Sequence of Element type description
670
671 File version = "(sgml-saved-dtd-version 5)
672 "
673
674 Comment = (";",
675 (CASE
676 OF [0-9]
677 OF [11-255])*,
678 [10] --end of line marker--)*
679
680 Element type description = S-expression --Misc info--,
681 CASE
682 OF [0-7] --Flags 1:stag-opt, 2:etag-opt, 4:mixed--,
683 Content specification,
684 Token list --includes--,
685 Token list --excludes--
686 OF [128] --Flag undefined element--
687
688 Content specification = CASE
689 OF [0] --cdata--
690 OF [1] --rcdata--
691 OF [2] --empty--
692 OF [3] --any--
693 OF [4] --undefined--
694 OF [128] --model follows--,
695 Model --nodes in the finite state automaton--
696
697 Model = Counted Sequence of Node
698
699 Node = CASE
700 OF Normal State
701 OF And Node
702
703 Normal State = Moves --moves for optional tokens--,
704 Moves --moves for required tokens--
705
706 Moves = Counted Sequence of (Token,
707 OCTET --state #--)
708
709 And Node = [255] --signals an AND node--,
710 Number --next state (node number)--,
711 Counted Sequence of Model --set of models--
712
713 Token = Number --index in list of elements--
714
715 Number = CASE
716 OF [0-250] --Small number 0--250--
717 OF [251-255] --Big number, first octet--,
718 OCTET --Big number, second octet--
719
720 Token list = Counted Sequence of Token
721
722 Parameter entites = S-expression --internal representation of parameter entities--
723
724 General entities = S-expression --internal representation of general entities--
725
726 Document type name = S-expression --name of document type as a string--
727
728 S-expression = OTHER
729
730 Counted Sequence = Number_a --length of sequence--,
731 (ARG_1)^a
732
733 
734 File: psgml-api.info, Node: Index, Prev: Implementation, Up: Top
735
736 Index
737 *****
738
739 Types
740
741 * Menu:
742
743 * asl: attribute.
744 * attdecl: attribute.
745 * attlist: attribute.
746 * attspec: attribute.
747 * declared-value: attribute.
748 * default-value: attribute.
749 * dtd: DTD.
750 * element: element.
751 * eltype: Implementation.
752 * entity: entities.
753 * entity-table: entities.
754 * pstate: parser state.
755 * tree: Implementation.
756
757
758 
759 Tag Table:
760 Node: Top942
761 Node: Types1526
762 Node: element2245
763 Node: attribute6165
764 Node: parser state10162
765 Node: DTD10750
766 Node: entities11379
767 Node: Hooks13294
768 Node: Implementation15026
769 Node: Index24613
770 
771 End Tag Table