doctools::idx::import(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨ β€” doctools::idx::import

okay bestie, welcome to doctools::idx::import β€” this page lives in the Documentation tools manual collection, and yeah, the (3tcl) up top just means it's a Tcl library page. It's all about Importing keyword indices. πŸ’–


🌸 SYNOPSIS 🌸

package require doctools::idx::import ?0.2.2?

package require Tcl 8.5 9

package require struct::map

package require doctools::idx::structure

package require snit

package require pluginmgr

::doctools::idx::import objectName

objectName method ?arg arg ...?

objectName destroy

objectName import text text ?format?

objectName import file path ?format?

objectName import object text object text ?format?

objectName import object file object path ?format?

objectName config names

objectName config get

objectName config set name ?value?

objectName config unset pattern...

objectName includes

objectName include add path

objectName include remove path

objectName include clear

IncludeFile currentfile path

import text configuration

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically, this package hands you a class whose whole job is managing the plugins that import keyword indices from other formats β€” like, the conversion from something like docidx, json, etc. into the good stuff. ✨

This is one of the three public pillars that the management of keyword indices rests on. The other two pillars are, no cap:

  1. Exporting keyword indices, and
  2. Holding keyword indices

If you wanna know about the Concepts of keyword indices and all their little parts, go read the section literally called that. And if you wanna know about the data structure that's the main character output of the manager objects this package gives you, go read the section Keyword index serialization format. 🫢

The plugin system of our class rides on the pluginmgr package, and it's configured to go looking for plugins using:

  1. the environment variable DOCTOOLS_IDX_IMPORT_PLUGINS,
  2. the environment variable DOCTOOLS_IDX_PLUGINS,
  3. the environment variable DOCTOOLS_PLUGINS,
  4. the path "~/.doctools/idx/import/plugin"
  5. the path "~/.doctools/idx/plugin"
  6. the path "~/.doctools/plugin"
  7. the path "~/.doctools/idx/import/plugins"
  8. the path "~/.doctools/idx/plugins"
  9. the path "~/.doctools/plugins"
  10. the registry entry "HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\IDX\IMPORT\PLUGINS"
  11. the registry entry "HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\IDX\PLUGINS"
  12. the registry entry "HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\PLUGINS"
πŸ’€ heads up: those last three are only used when the package is running on a machine with the Windows(tm) operating system. Not us, bestie.

The whole system ships with two predefined import plugins, and they are:

  • docidx β€” see docidx import plugin for details.
  • json β€” see json import plugin for details.

And if you're a reader who wants to write their own import plugin for some format β€” i.e. you're a plugin writer β€” then reading and understanding the section holding the Import plugin API v2 reference is an absolute necessity. Like, non-negotiable. That section spells out the interaction between this package and its plugins in full detail. πŸ”₯


🧚 CONCEPTS 🧚

  1. A keyword index consists of a (possibly empty) set of keywords.
  2. Each keyword in the set is identified by its name.
  3. Each keyword has a (possibly empty) set of references.
  4. A reference can be associated with more than one keyword.
  5. A reference not associated with at least one keyword is not possible however.
  6. Each reference is identified by its target, specified as either an url or symbolic filename, depending on the type of reference (url, or manpage).
  7. The type of a reference (url, or manpage) depends only on the reference itself, and not the keywords it is associated with.
  8. In addition to a type, each reference has a descriptive label as well. This label depends only on the reference itself, and not the keywords it is associated with.

🌈 A few notes 🌈

  1. Manpage references are intended to be used for references to the documents the index is made for. Their target is a symbolic file name identifying the document, and export plugins may replace symbolic with actual file names, if specified.
  2. Url references, on the other hand, are intended to be used for links to anything else, like websites. Their target is an url.
  3. While url and manpage references share a namespace for their identifiers, this should be no problem, given that manpage identifiers are symbolic filenames and as such they should never look like urls β€” which is what the identifiers for url references are.

πŸ‘‘ API πŸ‘‘

πŸ’… PACKAGE COMMANDS πŸ’…

  • ::doctools::idx::import objectName β€” this command creates a brand-new import manager object, with an associated Tcl command whose name is objectName. That object command is explained in full detail over in the sections Object command and Object methods. The object command gets created under the current namespace if objectName isn't fully qualified, and in the specified namespace otherwise.

πŸŽ€ OBJECT COMMAND πŸŽ€

Every object made by the ::doctools::idx::import command has this general form:

  • objectName method ?arg arg ...? β€” the method method and its arg'uments decide the exact behavior of the command. Peep the section Object methods for the detailed specifications.

⭐ OBJECT METHODS ⭐

  • objectName destroy β€” this method destroys the object it's invoked for. bye bestie πŸ’€
  • objectName import text text ?format? β€” this method takes the text and converts it from the specified format to the canonical serialization of a keyword index, using the import plugin for that format. An error is thrown if no plugin could be found for the format. The serialization that comes out of the conversion process is returned as the result of this method.

If no format is specified the method defaults to docidx.

The specification of what a canonical serialization actually is can be found in the section Keyword index serialization format.

The plugin has to conform to the interface specified in the section Import plugin API v2 reference. no exceptions, periodt.

  • objectName import file path ?format? β€” this method is a convenient lil wrapper around the import text method from the previous item. It reads the contents of the specified file into memory, feeds the result into import text, and returns the resulting serialization as its own result. 🫢
  • objectName import object text object text ?format? β€” another convenient wrapper around import text, same deal. It expects that object is an object command supporting a deserialize method expecting the canonical serialization of a keyword index. It imports the text using import text, then feeds the resulting serialization into the object via deserialize. This method returns the empty string as its result.
  • objectName import object file object path ?format? β€” this method behaves like import object text, except that it reads the text to convert from the specified file instead of being handed it as an argument.
  • objectName config names β€” this method returns a list containing the names of all configuration variables currently known to the object.
  • objectName config get β€” this method returns a dictionary containing the names and values of all configuration variables currently known to the object.
  • objectName config set name ?value? β€” this method sets the configuration variable name to the specified value and returns the new value of the variable.

If no value is specified it simply returns the current value, without changing anything.

πŸ™ˆ note that while the user can set the predefined configuration variables user and format, doing so will have no effect β€” these values get internally overridden when invoking an import plugin.
  • objectName config unset pattern... β€” this method unsets all configuration variables matching the specified glob patterns. If no pattern is specified it will unset all currently defined configuration variables.
  • objectName includes β€” this method returns a list containing the currently specified paths to use to search for include files when processing input. The order of paths in the list corresponds to the order in which they are used, from first to last, and also corresponds to the order in which they were added to the object. πŸ’–
  • objectName include add path β€” this method adds the specified path to the list of paths to use to search for include files when processing input. The path is added to the end of the list, causing it to be searched after all previously added paths. The result of the command is the empty string.

The method does nothing if the path is already known.

  • objectName include remove path β€” this method removes the specified path from the list of paths to use to search for include files when processing input. The result of the command is the empty string.

The method does nothing if the path is not known.

  • objectName include clear β€” this method clears the list of paths to use to search for include files when processing input. The result of the command is the empty string.

✨ IMPORT PLUGIN API V2 REFERENCE ✨

okay so plugins are literally the whole reason this package can handle any input format beyond the Keyword index serialization format. Here we specify the API the objects created by this package use to interact with their plugins. fr fr this is important.

A plugin for this package has to follow the rules listed below:

  1. A plugin is a package. periodt.
  2. The name of a plugin package has the form doctools::idx::import::FOO, where FOO is the name of the format the plugin will generate output for. This name is also the argument to provide to the various import methods of import manager objects to get a string encoding a keyword index in that format. iykyk
  3. The plugin can expect that the package doctools::idx::export::plugin is present, as indicator that it was invoked from a genuine plugin manager. vibe check passed
  4. The plugin can expect that a command named IncludeFile is present, with the signature
IncludeFile currentfile path

This command has to be invoked by the plugin when it has to process an included file, if the format has the concept of such. An example of such a format would be docidx. lowkey iconic

The plugin has to supply the following arguments:

  • string currentfile β€” The path of the file it is currently processing. This may be the empty string if no such is known.
  • string path β€” The path of the include file as specified in the include directive being processed.

The result of the command will be a 5-element list containing:

  1. A boolean flag indicating the success (True) or failure (False) of the operation.
  2. In case of success the contents of the included file, and the empty string otherwise.
  3. The resolved, i.e. absolute path of the included file, if possible, or the unchanged path argument. This is for display in an error message, or as the currentfile argument of another call to IncludeFile should this file contain more files.
  4. In case of success an empty string, and for failure a code indicating the reason for it, one of:
    • notfound β€” The specified file could not be found.
    • notread β€” The specified file was found, but not be read into memory.
  5. An empty string in case of success of a notfound failure, and an additional error message describing the reason for a notread error in more detail. not me reading that five times πŸ’€
ngl, that last one is a bit of a tongue twister, but that's literally what the spec says.
  1. A plugin has to provide one command, with the signature shown below.
import text configuration

Whenever an import manager of doctools::idx has to parse input for an index it will invoke this command. slay

  • string text β€” This argument will contain the text encoding the index per the format the plugin is for.
  • dictionary configuration β€” This argument will contain the current configuration to apply to the parsing, as a dictionary mapping from variable names to values.

The following configuration variables have a predefined meaning all plugins have to obey, although they can ignore this information at their discretion. Any other other configuration variables recognized by a plugin will be described in the manpage for that plugin. no cap

  • user β€” This variable is expected to contain the name of the user owning the process invoking the plugin.
  • format β€” This variable is expected to contain the name of the format whose plugin is invoked.
  1. A single usage cycle of a plugin consists of the invokations of the command import. This call has to leave the plugin in a state where another usage cycle can be run without problems. main character energy

πŸ”₯ KEYWORD INDEX SERIALIZATION FORMAT πŸ”₯

Here we specify the format used by the doctools v2 packages to serialize keyword indices as immutable values for transport, comparison, etc. obsessed

We distinguish between regular and canonical serializations. While a keyword index may have more than one regular serialization only exactly one of them will be canonical. the way that works

πŸ’– regular serialization πŸ’–

  1. An index serialization is a nested Tcl dictionary.
  2. This dictionary holds a single key, doctools::idx, and its value. This value holds the contents of the index.
  3. The contents of the index are a Tcl dictionary holding the title of the index, a label, and the keywords and references. The relevant keys and their values are:
    • title β€” The value is a string containing the title of the index.
    • label β€” The value is a string containing a label for the index.
    • keywords β€” The value is a Tcl dictionary, using the keywords known to the index as keys. The associated values are lists containing the identifiers of the references associated with that particular keyword.

Any reference identifier used in these lists has to exist as a key in the references dictionary, see the next item for its definition.

  • references β€” The value is a Tcl dictionary, using the identifiers for the references known to the index as keys. The associated values are 2-element lists containing the type and label of the reference, in this order.

Any key here has to be associated with at least one keyword, i.e. occur in at least one of the reference lists which are the values in the keywords dictionary, see previous item for its definition.

  1. The type of a reference can be one of two values:
    • manpage β€” The identifier of the reference is interpreted as symbolic file name, referring to one of the documents the index was made for.
    • url β€” The identifier of the reference is interpreted as an url, referring to some external location, like a website, etc. it's giving external link energy

πŸ’« canonical serialization πŸ’«

The canonical serialization of a keyword index has the format as specified in the previous item, and then additionally satisfies the constraints below, which make it unique among all the possible serializations of the keyword index. the one and only

  1. The keys found in all the nested Tcl dictionaries are sorted in ascending dictionary order, as generated by Tcl's builtin command lsort -increasing -dict.
  2. The references listed for each keyword of the index, if any, are listed in ascending dictionary order of their labels, as generated by Tcl's builtin command lsort -increasing -dict. periodt.

πŸ› BUGS, IDEAS, FEEDBACK πŸ›

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category doctools of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. bestie we need your help

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk


πŸ”‘ KEYWORDS πŸ”‘

conversion, docidx, documentation, import, index, json, keyword index, manpage, markup, parsing, plugin, reference, url


πŸ“‚ CATEGORY πŸ“‚

Documentation tools


Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>


and that's a wrap, bestie! this whole vibe comes from tcllib version 0.2.2, for doctools::idx::import(3tcl). stay slay, stay iconic, and don't forget to read the docs! πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from