doctools::tcl::parse(3tcl)
π doctools::tcl::parse β the Tcl-parsing era β¨
okay bestie, grab your iced coffee because we're diving into doctools::tcl::parse from the Documentation tools manual (that's the 3tcl one, iykyk). She's internal, she's picky, and she will throw hands if your input isn't valid. Let's go π
β¨ NAME β¨
doctools::tcl::parse β Processing text in subst -novariables format π¦
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require snit
package require fileutil
package require logger
package require struct::list
package require struct::stack
package require struct::set
package require treeql
package require doctools::tcl::parse ?0.2?
::doctools::tcl::parse text tree text ?root?
::doctools::tcl::parse file tree path ?root?
π DESCRIPTION π
This package hands you the commands for parsing text that has Tcl commands embedded in it β the exact flavour the Tcl builtin command subst -novariables accepts. And what do you get back? Not vibes. An abstract syntax tree. Literally iconic.
She's an internal package of doctools, bestie, which means she exists for the higher-level parsers that chew through the docidx, doctoc, and doctools markup languages. Main character supporting cast energy. π
π₯ API π₯
::doctools::tcl::parse text tree text ?root?
The command takes the text and parses it assuming it contains a string that's acceptable to the Tcl builtin command subst -novariables. If it's not? Errors get thrown mid-parse, no cap. The format of those errors is laid out in the Error format section below.
The command returns the empty string as its result β yes, an empty string, that's not a typo, she's giving mysterious. The actual result of the parsing gets dropped into the tree structure tree, under the node root. If you don't specify root, the root of tree is used instead. That tree has to exist and be the command of a tree object that supports the same methods as trees made by the struct::tree package.
β οΈ Heads up bestie: in case of errors, tree will be left in an undefined state. Not a cute look, so parse carefully. π
::doctools::tcl::parse file tree path ?root?
Same as text, except the text to parse gets read from the file specified by path. That's it, that's the difference. π«Ά
π ERROR FORMAT π
When the parser runs into a problem in the input, she throws an error using the format described right here. Pay attention, this part matters:
- The message will contain the reason for the problem (unexpected character or end of input in input), the character in question β if there even is one β and the line and column where the problem was found, all in a human readable form. This part isn't documented any further because its format may change as they see fit. It's intended for human consumption, not machine. So don't go parsing the error message, bestie, it will betray you. π
- The error code, however, will contain a machine-readable representation of the problem, in the form of a 5-element list containing, in the order listed below:
- the constant string
doctools::tcl::parse - the cause of the problem, one of
charβ Unexpected character in inputeofβ Unexpected end of the input
- The location of the problem as offset from the beginning of the input, counted in characters. Note: line markers count as one character. β
- The line the problem was found on (counted from 1 (one)),
- The column the problem was found at (counted from 0 (zero))
- the constant string
π TREE STRUCTURE π
After successfully parsing a string, the generated tree will have the following structure:
- In the following items the word 'root' refers to the node which was specified as the root of the tree when invoking either
textorfile. This may be the actual root of the tree. - All the following items further ignore the possibility of pre-existing attributes in the pre-existing nodes. If attributes exist with the same names as the attributes used by the parser, the pre-existing values are written over. Attributes with names not clashing with the parser's attributes are not touched. She's respectful like that. π
- The root node has no attributes. Naked. Free. Unbothered.
- All other nodes have the attributes:
typeβ The value is a string from the set {Command,Text,Word}rangeβ The value is either empty or a 2-element list containing integer numbers. The numbers are the offsets of the first and last character in the input text, of the token described by the node,.lineβ The value is an integer, it describes the line in the input the token described by the node ends on. Lines are counted from 1 (one).colβ The value is an integer, it describes the column in the line in the input the token described by the node ends on. Columns are counted from 0 (zero).
- The children of the root, if any, are of type
CommandandText, in semi-alternation. This means: after aTextnode aCommandnode has to follow, and anything can follow aCommandnode β aTextor anotherCommandnode. Semi-alternation is lowkey a whole personality trait. β¨ - The children of a
Commandnode, if any, are of typeCommand, andText, andWord, they describe the arguments of the command. - The children of a
Wordnode, if any, are of typeCommand,Text, in semi-alternation. This means: after aTextnode aCommandnode has to follow, and anything can follow aCommandnode β aTextor anotherCommandnode. - A
Wordnode without children represents the empty string. She contains multitudes (none of them). - All
Textnodes are leaves of the tree. π - All leaves of the tree are either
TextorCommandnodes.Wordnodes cannot be leaves. Periodt. π
π¦ BUGS, IDEAS, FEEDBACK π¦
This document, and the package it describes, will undoubtedly contain bugs and other problems. (Not me being shady, that's literally what the manpage says, fr fr.) 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. They want the ideas, bestie, send them. π«Ά
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. Go forth and attach. π
β KEYWORDS β
Tcl syntax, command, doctools, parser, subst, word
π CATEGORY π
Documentation tools
π COPYRIGHT π
Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's the whole page, bestie π go parse something iconic. This beauty ships as part of tcllib, version 0.2, and yeah β she's doctools::tcl::parse(3tcl), no cap. πΈβ¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2009 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms