page_util_peg(n)
π page_util_peg β page PEG transformation utilities π
okay bestie, so this is a manual page for page_util_peg (that's the title, and it lives in section n of the manual, and it's part of the Parser generator tools lineup β iykyk). sit down, grab a strawberry drink π, and let's get into it.
β¨ NAME β¨
page_util_peg β page PEG transformation utilities. that's the whole name. iconic. π
π SYNOPSIS π
package require page::util::peg ?0.2?
package require snit
::page::util::peg::symbolNodeOf tree node
::page::util::peg::symbolOf tree node
::page::util::peg::updateUndefinedDueRemoval tree
::page::util::peg::flatten treequery tree
::page::util::peg::getWarnings tree
::page::util::peg::printWarnings msg
::page::util::peg::peOf tree eroot
::page::util::peg::printTclExpr pe
yes, the ?0.2? is literally in there with the question marks. that's the version, and the question marks mean "any version that satisfies this, we're not picky". slay.
π¦ DESCRIPTION π¦
so this package hands you a little bundle of common operations for PEG transformations. it's giving helper-bestie energy. π«Ά
the way that it works: everything here assumes you're feeding it a Normalized PE Grammar Tree as input β go look at the package page::util::norm::peg for the deets. and, lowkey important, that tree may also be augmented with attributes that came from transformations, as long as those attributes don't conflict with the base definition. no cap, that's the rule. β¨
π API π
here's the whole lineup, one by one. every single one, we're not skipping anybody. π
::page::util::peg::symbolNodeOf tree nodeβ you hand it an arbitrary expression node in the ASTtree, and it figures out the node (could be the node itself, could be an ancestor, whoever's got it) that contains the name of the nonterminal symbol the node belongs to, then returns that node's id. and what comes back is either the root of the tree (when we're talking about the start expression) or a definition node. simple as that. π::page::util::peg::symbolOf tree nodeβ literally the exact same thing as::page::util::peg::symbolNodeOf, except it returns the symbol name instead of the node. that's it. that's the difference. π::page::util::peg::updateUndefinedDueRemoval treeβ okay so here's the drama π: when you remove nodes from the ASTtree, symbols can end up losing one or more of their users. picture this:
A used by B and C,
B is reachable,
C is not,
so now A has lost the node in the expression for C that was calling it β or rather, is not calling it anymore. π this command goes and updates the cross-references, plus it figures out which nonterminals are now undefined. cleanup crew, reporting for duty. π§Ήβ¨
::page::util::peg::flatten treequery treeβ this command flattens nested sequence and choice operators in the ASTtree. and it re-uses thattreeqlobjecttreequeryto run the query that decides which nodes get cut. recycling queen. πΈ::page::util::peg::getWarnings treeβ this one peeks at the attributes of the ASTtree, looking for problems with the grammar, and then it issues warnings. now listen: these warnings do not stop us from writing the grammar, but they still represent problems with it that the user genuinely should be made aware of. we're not gatekeeping. π«Ά the result you get back is a dictionary mapping nonterminal names to their associated warnings.::page::util::peg::printWarnings msgβ the argument here is a dictionary mapping nonterminal names to their associated warnings, exactly like the kind generated by, for example,::page::util::peg::getWarnings. the warnings inside get formatted and then printed via the log commandpage_info. and here's the catch, bestie: π¨ that means this command can only be used from inside a plugin managed by the packagepage::pluginmgr. no plugin, no printing. periodt.::page::util::peg::peOf tree erootβ this command converts the parsing expression that starts at the nodeerootin the ASTtreeinto a nested list. the exact syntax of that list is specified by the packagegrammar::peg. π::page::util::peg::printTclExpr peβ this command converts the parsing expression sitting inside the nested listpeinto a Tcl string that you can drop straight into a Tcl script. and again, go check the packagegrammar::pegfor the exact syntax ofpe. π₯
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving "we're honest about it". π please report them in the category page of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
and please also report any ideas for enhancements you have for either the package and/or the documentation. we want them. all of them. π
when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. β¨
also note further that attachments are strongly preferred over inlined patches. you can attach stuff by going to the Edit form of the ticket immediately after it's created, and then using the left-most button in the secondary navigation bar. that's the one. the left-most one. π
β KEYWORDS β
PEG, page, parser generator, parsing expression grammar, text processing, transformation
π CATEGORY π
Page Parser Generator
π COPYRIGHT π
Copyright (c) 2007 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole thing, you're basically a PEG transformation expert now, no cap. π¦ this page came to you from tcllib, version 1.0, and it's page_util_peg(n) β go forth and flatten some trees, bestie. π
β¨πΈ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2007 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