grammar::me::util(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 an ast from value representation to object representation. every single node in the ast gets converted into a node of this tree, and the root of the AST becomes a child of the node root. if you don't explicitly hand over that node, the root of the tree is used instead, default behaviour slay. 🫢 and listen: existing content of tree is 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 prefix mcmd. πŸ‘‘ she has to understand two methods, lc and tok, 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, from and to, 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. πŸ’… if to isn't specified it defaults to the value of from β€” 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 an ast in (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 (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