doctools::toc::parse(3tcl)

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

πŸ¦‹ doctools::toc::parse πŸ¦‹

okay bestie, quick vibe check: this is doctools::toc::parse, living in the Documentation tools manual, section 3tcl. pull up a chair, we're parsing tables of contents and it's gonna be iconic πŸ’…


✨ NAME ✨

doctools::toc::parse β€” literally just parsing text that's written in doctoc format, no big deal πŸŽ€


🌈 SYNOPSIS 🌈

package require doctools::toc::parse ?0.2?

package require Tcl 8.5 9

package require doctools::toc::structure

package require doctools::msgcat

package require doctools::tcl::parse

package require fileutil

package require logger

package require snit

package require struct::list

package require struct::stack

::doctools::toc::parse text text

::doctools::toc::parse file path

::doctools::toc::parse includes

::doctools::toc::parse include add path

::doctools::toc::parse include remove path

::doctools::toc::parse include clear

::doctools::toc::parse vars

::doctools::toc::parse var set name value

::doctools::toc::parse var unset name

::doctools::toc::parse var clear ?pattern?

πŸ’– DESCRIPTION πŸ’–

so basically this package hands you the commands to parse text written in the doctoc markup language and turn it into the canonical serialization of the table of contents that was chillin' inside that text. if you wanna know exactly what that format looks like, go peek at the ToC serialization format section. iykyk 🫢

ngl, this is an internal package of doctools β€” it's meant to be used by the higher level packages that actually handle doctoc documents. it's the backstage crew, not the main character. (well. mostly not the main character.) πŸ‘‘


🌸 API 🌸

  • ::doctools::toc::parse text text β€” bestie, this one takes the string sitting in text and parses it, assuming it holds a document written in the doctoc markup language. if that assumption turns out to be false? it throws an error, periodt. the format of those errors is spelled out in the Parse errors section. when it does slay, it returns the canonical serialization of the table of contents that was encoded in the text β€” again, check ToC serialization format for the spec ✨
  • ::doctools::toc::parse file path β€” same energy as text, except the text it parses gets read from the file named by path. that's it, that's the whole thing πŸ“‚
  • ::doctools::toc::parse includes β€” returns the current list of search paths it uses when it goes looking for include files πŸ”
  • ::doctools::toc::parse include add path β€” adds path to the list of paths searched when looking for an include file. if path is already in the list, the call just gets ignored, no drama. returns the empty string as its result πŸŽ€
  • ::doctools::toc::parse include remove path β€” removes path from the list of paths searched when looking for an include file. if path isn't in the list, the call is ignored, we move on. returns the empty string as its result 🧚
  • ::doctools::toc::parse include clear β€” clears the whole list of search paths for include files. wipeout. bye πŸ’…
  • ::doctools::toc::parse vars β€” returns a dictionary containing the current set of predefined variables that the vset markup command knows about during processing πŸ“–
  • ::doctools::toc::parse var set name value β€” adds the variable name to the set of predefined variables known to the vset markup command during processing, and gives it the specified value. returns the empty string as its result ✨
  • ::doctools::toc::parse var unset name β€” removes the variable name from the set of predefined variables known to the vset markup command during processing. returns the empty string as its result 🫢
  • ::doctools::toc::parse var clear ?pattern? β€” removes all variables matching pattern from the set of predefined variables known to the vset markup command during processing. returns the empty string as its result.

the pattern matching is done with string match, and the default pattern used when you don't specify one is *. so yeah, no pattern = everything goes 🧹


😭 PARSE ERRORS 😭

the format of the parse error messages that get thrown when the doctoc markup syntax gets violated is human readable and not intended for processing by machines. so obviously it's not documented. you read it with your eyeballs, not your parser πŸ™ˆ

but β€” the errorCode attached to the message is machine-readable, and here's its format:

  1. the error code is a list, and each element describes a single error found in the input. the list has at least one element, possibly more. no empty lists here πŸ’€
  2. each error element is a list containing six strings describing an error in detail. those strings are:
    1. the path of the file the error occurred in. this may be empty.
    2. the range of the token the error was found at. this range is a two-element list containing the offset of the first and last character in the range, counted from the beginning of the input (file). offsets are counted from zero.
    3. the line the first character after the error is on. lines are counted from one.
    4. the column the first character after the error is at. columns are counted from zero.
    5. the message code of the error. this value can be used as an argument to msgcat::mc to obtain a localized error message β€” assuming the application had a suitable call of doctools::msgcat::init to initialize the necessary message catalogs (see package doctools::msgcat).
    6. a list of details for the error, like the markup command involved. in the case of message code doctoc/include/syntax this value is the set of errors found in the included file, using the format described right here. recursion, bestie, it's giving inception πŸŒ€

πŸ‘‘ [DOCTOC] NOTATION OF TABLES OF CONTENTS πŸ‘‘

the doctoc format for tables of contents β€” also called the doctoc markup language β€” is too large to be covered in a single section. it's a whole universe, not a paragraph 🌌

so if you're the interested reader (and honestly? you should be), start with this document:

  1. doctoc language introduction

and then proceed from there to the formal specifications, i.e. the documents:

  1. doctoc language syntax and
  2. doctoc language command reference

...and that's how you get a thorough understanding of the language. study era fr fr πŸ“šβœ¨


πŸ“ TOC SERIALIZATION FORMAT πŸ“

okay so bestie, this is the part where we talk about how doctools v2 packages serialize tables of contents into immutable values β€” you know, so they can be shipped around, compared, all that good stuff ✨

We split it into two flavors: regular and canonical serializations. A table of contents can have more than one regular serialization, but exactly one of them gets to be the canonical one. Only one. It's giving main character πŸ’…


regular serialization

  1. The serialization of any table of contents is a nested Tcl dictionary. yes really, it's dicts all the way down πŸͺ†
  2. This dictionary holds a single key, doctools::toc, and its value. That value holds the contents of the table of contents.
  3. The contents of the table of contents are a Tcl dictionary holding the title of the table of contents, a label, and its elements. The relevant keys and their values are:
    • title β€” the value is a string containing the title of the table of contents. iconic, no notes πŸ’–
    • label β€” the value is a string containing a label for the table of contents.
    • items β€” the value is a Tcl list holding the elements of the table, in the order they are to be shown. ✨

Each element is a Tcl list holding the type of the item, and its description, in this order. Or, if you wanna say it a different way: it's a Tcl dictionary holding a single key β€” the item type β€” mapped to the item description. Same thing, different vibe πŸ¦‹

The two legal item types and their descriptions are:

  • reference β€” this item describes a single entry in the table of contents, referencing a single document. To this end its value is a Tcl dictionary containing an id for the referenced document, a label, and a longer textual description which can be associated with the entry. The relevant keys and their values are:
    • id β€” the value is a string containing the id of the document associated with the entry.
    • label β€” the value is a string containing a label for this entry. This string also identifies the entry, and no two entries (references and divisions) in the containing list are allowed to have the same label. so like, no twin labels bestie, it's a whole thing 😭
    • desc β€” the value is a string containing a longer description for this entry.
  • division β€” this item describes a group of entries in the table of contents, inducing a hierarchy of entries. To this end its value is a Tcl dictionary containing a label for the group, an optional id to a document for the whole group, and the list of entries in the group. The relevant keys and their values are:
    • id β€” the value is a string containing the id of the document associated with the whole group. This key is optional 🫢
    • label β€” the value is a string containing a label for the group. This string also identifies the entry, and no two entries (references and divisions) in the containing list are allowed to have the same label. again! unique labels only, periodt πŸ’…
    • items β€” the value is a Tcl list holding the elements of the group, in the order they are to be shown. This list has the same structure as the value for the keyword items used to describe the whole table of contents, see above. This closes the recursive definition of the structure β€” divisions holding the same type of elements as the whole table of contents, including other divisions. πŸͺ†πŸͺ†πŸͺ†
ngl the original manpage spells it "recusrive" and we're just gonna let that be its little quirk πŸ“

canonical serialization

The canonical serialization of a table of contents has the format as specified in the previous item, and then additionally satisfies the constraints below β€” which is what makes it unique among all the possible serializations of this table of contents. like, there's exactly one glow-up version ✨

  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. sorted, bestie. alphabetized. no cap πŸ”₯

πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

This document, and the package it describes, will undoubtedly contain bugs and other problems. 😭 it's not a maybe, it's a will. Please report such in the category doctools of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. And please also report any ideas for enhancements you may have for either the package and/or the documentation β€” we want the ideas too, fr fr 🫢

When proposing code changes, please provide unified diffs, i.e the output of diff -u. no vibes-based patches, actual diffs please πŸ™ˆ

Also note: attachments are strongly preferred over inlined patches. You can attach stuff 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. go forth and attach πŸ’…


πŸŽ€ KEYWORDS πŸŽ€

doctoc, doctools, lexer, parser


πŸ‘‘ CATEGORY πŸ‘‘

Documentation tools


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


and that's a wrap bestie!! πŸ’– this whole thing is from the tcllib source, version 1, dated 2009, and it's the doctools::toc::parse(3tcl) page β€” go parse some tables of contents, you absolute icon πŸ¦‹βœ¨ slay 🫢

πŸ“¦ where this page comes from