grammar::me::util(3tcl)
β¨ NAME β¨
grammar::me::util β AST utilities π (yes bestie, it's giving "little helper package that does the tree-to-value glow-up")
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require grammar::me::util ?0.2?
::grammar::me::util::ast2tree ast tree ?root?
::grammar::me::util::ast2etree ast mcmd tree ?root?
mcmd lc location
mcmd tok from ?to?
::grammar::me::util::tree2ast tree ?root?
π¦ DESCRIPTION π¦
okay so this package is literally the friend group of utility commands that lets you convert between the different representations of abstract syntax trees β the ones spelled out over in the grammar::me_ast document. no cap, that's the whole vibe. π
::grammar::me::util::ast2tree ast tree ?root?β this one converts anastfrom value representation to object representation. every single node in theastgets converted into a node of thistree, and the root of the AST becomes a child of the noderoot. if you don't explicitly hand over that node, the root of the tree is used instead, default behaviour slay. π«Ά and listen: existing content oftreeis not touched β not removed, not changed, nothing β with the one exception of the specified root node, which will gain a new child. so yeah, it's additive, she's respectful. β¨::grammar::me::util::ast2etree ast mcmd tree ?root?β basically::grammar::me::util::ast2tree's sibling, same energy, except the result comes out in the extended object representation of the input AST. and where does the extended info come from? the command prefixmcmd. π she has to understand two methods,lcandtok, with the semantics specified right below, so let's get into it:mcmd lc locationβ takes the location of a token, given as an offset in the input stream, and returns a 2-element list holding the associated line number and column index, in that order. two numbers, one list, iconic. πmcmd tok from ?to?β takes one or two locations,fromandto, as offsets in the input stream, and returns a Tcl list containing the specified part of the input stream. both locations are inclusive, so don't come for me about off-by-ones, she's inclusive on purpose. π iftoisn't specified it defaults to the value offromβ so you get exactly one. each element of the returned list is itself a list containing the token, its associated lexeme, the line number, and column index, in this order. four things, that order, periodt. π
and for the record, both the ensemble command ::grammar::me::tcl (provided by the package grammar::me::tcl) and the objects command created by the package ::grammar::me::cpu fit the above specification. so you've got options, bestie. π
::grammar::me::util::tree2ast tree ?root?β the reverse direction, the glow-down if you will. this one converts anastin (extended) object representation into a value and returns it. if you specify a root node, the AST gets generated from that node downward. otherwise the root of the tree object is used as the starting point. π
π BUGS, IDEAS, FEEDBACK π
ngl, this document, and the package it describes, will undoubtedly contain bugs and other problems. π please report such in the category grammar_me 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 all of it, fr fr. π
when proposing code changes, please provide unified diffs, i.e the output of diff -u. (yes, exactly that, don't freestyle it.)
also note, 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. iykyk.
β KEYWORDS β
abstract syntax tree, syntax tree, tree
π CATEGORY π
Grammars and finite automata
π COPYRIGHT π
Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's the whole page, bestie β brought to you by tcllib, version 0.2, living its best life as grammar::me::util(3tcl). go build some trees, you've got this π§β¨π
π¦ 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) 2005 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