![]() |
The data relation descriptor (DRD) | ![]() |
A TeXmacs document is a tree whose nodes carry arbitrary labels. Only a fixed set of labels is known to the C++ kernel (the primitives concat, frac, with, …); all other labels are macros defined by style files or by the user. Generic tree-manipulating code, however, constantly needs to know things about a label which are not visible in the tree itself:
how many children a tag may have, and where new children may be inserted;
which children may contain the cursor, which are hidden, which are read-only;
what kind of data each child holds (text, a length, a color, a variable name, a URL, …);
which environment variables change inside a child (for instance, that the body of equation is in math mode);
whether the cursor may stand just before or after the tag;
whether the tag only modifies the environment (like with or strong);
a human readable name for the tag and its children.
This information is collected in the data relation descriptor, or DRD. The general idea, and the user-level view, are explained in data relation descriptions; the primitive drd-props, by which style files declare properties, is documented in macro primitives. This chapter is the developer reference for the whole subsystem, on the C++ side and on the Scheme side.
On the C++ side, a DRD is an object of class drd_info (
Data/Drd/drd_info.hpp
) which maps tree labels to tag_info records (
Data/Drd/tag_info.hpp
). There are several DRDs at any time:
The standard DRD std_drd, filled once at start-up by init_std_drd (
Data/Drd/drd_std.cpp
). It describes all built-in primitives and environment variables and also registers the string names of the built-in tree labels.
One DRD per style (more precisely, per style tuple such as (article number-europe)), computed by compute_env_and_drd (
Data/Document/new_style.cpp
) on top of std_drd, partly by heuristic inference from the macro definitions and partly from explicit drd-props declarations, and cached in memory and on disk.
One DRD per editor (the member editor_rep::drd), obtained from the style DRD and completed with the macros defined in the preamble and in the body of the document.
The global variable the_drd, which points to the DRD of the current view and is consulted by all generic tree routines (cursor movement, traversal, correction, spell checking, …).
The typesetting environment edit_env holds a reference to the DRD of its editor, which is how drd-props declarations executed during typesetting end up in the right DRD.
On the Scheme side, there are two different layers:
Glue functions such as tree-accessible-child?, tree-child-type, tree-child-env or tag-minimal-arity, which query the_drd.
Purely Scheme declarative data about tags: tag groups declared by define-group in the files *-drd.scm (variant-tag, similar-tag, numbered-tag, …), and tables, groups and dispatchers of the small logic programming engine (logic-group, logic-table, logic-dispatcher), used mainly by the converters.
The two layers are independent: tag groups are not stored in the C++ DRD, and C++ properties are not visible to the logic engine.
Data/Drd/tag_info.hpp,
tag_info.cpp
The records parent_info, child_info and tag_info, the type constants TYPE_*, the compact environment table (drd_encode, drd_decode) and the conversion of type names (drd_encode_type, drd_decode_type).
Data/Drd/drd_info.hpp,
drd_info.cpp
The class drd_info: getters, setters and freezing of all properties, the high-level queries (is_accessible_child, get_env_child, …) and the heuristic inference from macros.
Data/Drd/drd_std.hpp,
drd_std.cpp
The standard DRD std_drd, the current DRD the_drd, the table STD_CODE of built-in tag names and the helper with_drd.
Data/Drd/drd_mode.hpp,
drd_mode.cpp
The global access mode and writability mode.
Data/Drd/vars.hpp,
vars.cpp
String constants for the names of the built-in environment variables (MODE, FONT_SIZE, …), several hundred of which get a type in std_drd.
Data/Document/new_style.cpp
Computation and caching of style DRDs (compute_env_and_drd, get_style_drd, get_document_drd, style_get_cache, style_set_cache).
Edit/Editor/edit_typeset.cpp
Initialization and update of the DRD of an editor (typeset_style_use_cache, typeset_preamble, drd_update).
Typeset/Env/env_exec.cpp
The evaluation of drd-props (edit_env_rep::exec_drd_props).
Data/Tree/tree_traverse.cpp
Free functions wrapping the_drd (is_accessible_child, minimal_arity, get_child_type, …), most of which are exported to Scheme.
Scheme/Glue/build-glue-basic.scm
The declarations of the Scheme glue.
utils/edit/variants.scm
The Scheme macro define-group and the standard tag groups.
Tag groups and tables of the various editing modes and converters (
text/text-drd.scm
,
math/math-drd.scm
,
dynamic/dynamic-drd.scm
, …).
The logic programming engine.
The page the data relation descriptor of the chapter on macro expansion describes the heuristic inference of properties from macro definitions in more detail; it is summarized, not repeated, here.