page_util_peg(3tcl)
π page_util_peg β page PEG transformation utilities π
okay bestie, so this is a Tcllib page β it lives in the Parser generator tools corner of the manual, and the page itself is literally called page_util_peg. sit down, grab a strawberry π, and let me tell you about it.
β¨ 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
likeβ¦ that's the whole lineup π and yes, you can pull in page::util::peg at version 0.2 (or don't specify, whatever, it's optional) and it also needs snit to come along. no cap.
πΈ DESCRIPTION πΈ
so this package is basically a little toolkit of common operations for PEG transformations. the vibe is: it expects a Normalized PE Grammar Tree as its input (go look at the package page::util::norm::peg for that, iykyk) β and that tree might also be carrying extra attributes from other transformations, as long as those transformations don't clash with the base definition. it's giving flexible but respectful. π
π API π
::page::util::peg::symbolNodeOf tree node
you hand it any random expression node in the AST tree, and it figures out which node holds the name of the nonterminal symbol that node belongs to β either the node itself, or one of its ancestors β and gives you back that node's id. and the result is either the root of the tree (which is what you get for the start expression) or a definition node. slay. β¨
::page::util::peg::symbolOf tree node
literally the same as ::page::util::peg::symbolNodeOf, except it returns the symbol name instead of the node. same energy, different return value. π¦
::page::util::peg::updateUndefinedDueRemoval tree
okay so this one is about what happens when you remove nodes from the AST tree β because doing that can make symbols lose one or more of their users π like:
A used by B and C,
B is reachable,
C is not,
so now A loses the node in the expression for C calling it β or, honestly, not calling it anymore. π
this command updates the cross-references, and also which nonterminals are now undefined. it's the cleanup bestie.
::page::util::peg::flatten treequery tree
this command flattens the nested sequence and choice operators in the AST tree, and it re-uses the treeql object treequery to run the query that decides which nodes get cut. teamwork makes the dream work fr fr π«Ά
::page::util::peg::getWarnings tree
this one goes snooping through the attributes of the AST tree looking for problems with the grammar and issues warnings. important bit: these warnings do not stop us from writing the grammar, but they're still real problems with it that the user should be made aware of. β
the result you get back is a dictionary mapping nonterminal names to their associated warnings.
::page::util::peg::printWarnings msg
the argument here is that same dictionary β nonterminal names mapped to their warnings β exactly the kind of thing you'd get from, say, the command ::page::util::peg::getWarnings.
then all those warnings get formatted and printed via the log command page_info. heads up though: that means you can only use this command from inside a plugin managed by the package page::pluginmgr. not just anywhere, bestie. π€
::page::util::peg::peOf tree eroot
this converts the parsing expression that starts at node eroot in the AST tree into a nested list. the exact syntax of that list is defined by the package grammar::peg β go check it there if you need the deets. π
::page::util::peg::printTclExpr pe
this one takes the parsing expression sitting in the nested list pe and turns it into a Tcl string that you can drop straight into a Tcl script. and yeah β see the package grammar::peg for the exact syntax of pe. β¨
π BUGS, IDEAS, FEEDBACK π
ngl this document, and the package it describes, will undoubtedly contain bugs and other problems. it's not a maybe, it's a when. π
so please report them in the category page of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. and please also send in any ideas you have for enhancements β for the package, the docs, either, both, we're not picky, we're just obsessed with hearing from you. π«Ά
when you're proposing code changes, please provide unified diffs β i.e. the output of diff -u. that's the move.
also note: attachments are strongly preferred over inlined patches. how do you attach? go to the Edit form of the ticket right after you create it, then use the left-most button in the secondary navigation bar. iconic workflow, honestly. π
π§ 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 page, bestie, you ate it π
β¨ and just so you know where this came from β it's from the tcllib collection, version 1.0, and the man page goes by page_util_peg(3tcl). mwah, go forth and transform some PEGs ππ¦π
π¦ 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) 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