page_util_norm_peg(n)

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

πŸ’– page_util_norm_peg(n) β€” Parser generator tools ✨

okay bestie so this is a page from the Parser generator tools corner of the manual, and it's literally all about page_util_norm_peg. sit down, hydrate, we're normalizing grammars 🧚


🌸 NAME 🌸

page_util_norm_peg β€” page AST normalization, PEG. yes the whole name, we don't abbreviate here πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

package require page::util::norm_peg ?0.2?

package require snit

::page::util::norm::peg tree

that ?0.2? is doing the optional-version thing, and yes you also need snit, no skips 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

So this package is like… one single utility command, and that's it, that's the whole girl. She takes an AST for a parsing expression grammar and normalizes it in various ways. The glow-up result has a name and the name is a Normalized PE Grammar Tree. iconic ✨

⚠️ Real talk though, no cap: this package can only be used from within a plugin managed by the package page::pluginmgr. Don't try to use it solo, she doesn't do solo. 😭

πŸ‘‘ API πŸ‘‘

::page::util::norm::peg tree

This command assumes the tree object contains for a parsing expression grammar. It normalizes this tree in place β€” like, she's editing it right there, no copy, no backup, we move. And the result? You guessed it: a Normalized PE Grammar Tree πŸ’…

Here's everything she does, in order, and every step matters so don't skim, iykyk:

  1. The data for all terminals is stored in their grandparental nodes. The terminal nodes and their parents are removed. Type information is dropped. bye πŸ‘‹
  2. All nodes which have exactly one child are irrelevant and are removed, with the exception of the root node. The immediate child of the root is irrelevant as well, and removed as well. two-for-one deletion deal πŸŽ€
  3. The name of the grammar is moved from the tree node it is stored in to an attribute of the root node, and the tree node removed.

The node keeping the start expression separate is removed as irrelevant and the root node of the start expression tagged with a marker attribute, and its handle saved in an attribute of the root node for quick access. we love quick access ⭐

  1. Nonterminal hint information is moved from nodes into attributes, and the now irrelevant nodes are deleted.
Note: This transformation is dependent on the removal of all nodes with exactly one child, as it removes the all 'Attribute' nodes already. Otherwise this transformation would have to put the information into the grandparental node. (yes, that's a real dependency, respect the order bestie 😀)

The default mode given to the nonterminals is value.

Like with the global metadata definition specific information is moved out out of nodes into attributes, the now irrelevant nodes are deleted, and the root nodes of all definitions are tagged with marker attributes. This provides us with a mapping from nonterminal names to their defining nodes as well, which is saved in an attribute of the root node for quick reference.

At last the range in the input covered by a definition is computed. The left extent comes from the terminal for the nonterminal symbol it defines. The right extent comes from the rightmost child under the definition. While this not an expression tree yet the location data is sound already. she's built different fr fr 🧚

  1. The remaining nodes under all definitions are transformed into proper expression trees. First character ranges, followed by unary operations, characters, and nonterminals. At last the tree is flattened by the removal of superfluous inner nodes.

The order matters, to shed as much nodes as possible early, and to avoid unnecessary work later. efficiency is the vibe check 🌈


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

This document, and the package it describes, will undoubtedly contain bugs and other problems. (not me being honest in a manpage 😭)

Please report such in the category page of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. we love ideas, bring them 🫢

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

Note further that 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. yes, the left-most one. it's right there. go get it πŸ’…


⭐ KEYWORDS ⭐

PEG, graph walking, normalization, page, parser generator, text processing, tree walking


🌸 CATEGORY 🌸

Page Parser Generator


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


okay that's the whole page, you ate it, periodt πŸ’– this was tcllib, version 1.0, of page_util_norm_peg(n) β€” thanks for reading bestie, go normalize something gorgeous πŸŽ€βœ¨

πŸ“¦ where this page comes from