doctools::tcl::parse(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

doctools::tcl::parse β€” bestie, this is the manual page for it, and it's all about 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 πŸ¦‹

Okay so this package hands you commands for parsing text that has Tcl commands embedded in it β€” the exact kind of text the Tcl builtin command subst -novariables accepts. And what do you get back? An abstract syntax tree, obviously πŸ’…

Important lore: this is an internal package of doctools. It exists for the higher level parsers to use β€” the ones chewing through the docidx, doctoc, and doctools markup languages 🫢


✨ API ✨

πŸŽ€ ::doctools::tcl::parse text tree text ?root?

This one takes the text and parses it, assuming it contains a string acceptable to the Tcl builtin command subst -novariables. If it's not? Errors get thrown during the parsing, no cap. The format those errors come in is described down in Error format πŸ‘€

The command returns the empty string as its result β€” yeah, the actual result goes into the tree structure tree, under the node root. If root isn't specified, the root of tree is used. The tree has to exist and be the command of a tree object that supports the same methods as trees created by the package struct::tree 🌳

😭 Heads up: in case of errors, tree will be left in an undefined state. So like... be careful.

πŸŽ€ ::doctools::tcl::parse file tree path ?root?

Literally the same as text, except the text to parse is read from the file specified by path. Same vibes, different source πŸ“‚


πŸ’€ ERROR FORMAT πŸ’€

When the parser hits a problem in the input it throws an error using the format described right here. Sit with me, this part is structured:

  1. The message will contain the reason for the problem (unexpected character or end of input in input), the character in question, if any, and the line and column the problem was found at, in a human readable form. This part is not documented further, because its format may change whenever we feel like it. It's intended for human consumption, not machine. πŸ™ˆ
  2. The error code, though? That one's got a machine-readable representation of the problem, in the form of a 5-element list containing, in the order listed below:
    1. the constant string doctools::tcl::parse
    2. the cause of the problem, one of:
      • char β€” Unexpected character in input
      • eof β€” Unexpected end of the input
    3. The location of the problem as offset from the beginning of the input, counted in characters. Note: Line markers count as one character.
    4. The line the problem was found on (counted from 1 (one)),
    5. The column the problem was found at (counted from 0 (zero))

🌈 TREE STRUCTURE 🌈

After successfully parsing a string, the generated tree will have the following structure. Strap in, bestie, there's ten of these:

  1. In the following items the word root refers to the node which was specified as the root of the tree when invoking either text or file. This may be the actual root of the tree.
  2. All the following items further ignore the possibility of pre-existing attributes in the pre-existing nodes. If attributes exists 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.
  3. The root node has no attributes. Clean. Minimalist. Iconic.
  4. 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).
  5. The children of the root, if any, are of type Command and Text, in semi-alternation. This means: After a Text node a Command node has to follow, and anything can follow a Command node, a Text or other Command node.
  6. The children of a Command node, if any, are of type Command, and Text, and Word, they describe the arguments of the command.
  7. The children of a Word node, if any, are of type Command, Text, in semi-alternation. This means: After a Text node a Command node has to follow, and anything can follow a Command node, a Text or other Command node.
  8. A Word node without children represents the empty string.
  9. All Text nodes are leaves of the tree.
  10. All leaves of the tree are either Text or Command nodes. Word nodes cannot be leaves.

🫢 BUGS, IDEAS, FEEDBACK 🫢

This document, and the package it describes, will undoubtedly contain bugs and other problems β€” like, obviously, it's software πŸ’€ 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 wanna hear it fr fr πŸ—£οΈ

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

Also note: attachments are strongly preferred over inlined patches. You can make an attachment 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 ⭐

Tcl syntax, command, doctools, parser, subst, word


πŸ‘‘ CATEGORY πŸ‘‘

Documentation tools


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


okay that's the whole page bestie, you ate that πŸ’… this was doctools::tcl::parse(n), version 0.2, from tcllib β€” go forth and parse, mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from