pt::pe::op(3tcl)
β¨ NAME β¨
pt::pe::op β Parsing Expression Utilities π
Bestie, this is the manual page for pt::pe::op(3tcl) from Parser Tools. It's giving internal-package main character energy, and we're gonna get into every single detail, no cap.
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require pt::pe::op ?1.0.2?
package require pt::pe ?1?
package require struct::set
::pt::pe::op drop dropset pe
::pt::pe::op rename nt ntnew pe
::pt::pe::op called pe
::pt::pe::op flatten pe
::pt::pe::op fusechars pe
β¨ DESCRIPTION β¨
Are you lost? Do you have trouble understanding this document? In that case please read the overview provided by the Introduction to Parser Tools. This document is the entrypoint to the whole system the current package is a part of.
This package provides additional commands to work with the serializations of parsing expressions as managed by the PEG and related packages, and specified in section PE serialization format.
This is an internal package, for use by the higher level packages handling PEGs, their conversion into and out of various other formats, or other uses.
β¨ API β¨
::pt::pe::op drop dropset peβ This command removes all occurrences of any of the nonterminals symbols in the setdropsetfrom the parsing expressionpe, and simplifies it. This may result in the expression becoming"epsilon", i.e. matching nothing.::pt::pe::op rename nt ntnew peβ This command renames all occurrences of the nonterminalntin the parsing expressionpeintontnew.::pt::pe::op called peβ This command extracts the set of all nonterminal symbols used, i.e. 'called', in the parsing expressionpe.::pt::pe::op flatten peβ This command transforms the parsing expression by eliminating sequences nested in sequences, and choices in choices, lifting the children of the nested expression into the parent. It further eliminates all sequences and choices with only one child, as these are redundant.
The resulting parsing expression is returned as the result of the command.
::pt::pe::op fusechars peβ This command transforms the parsing expression by fusing adjacent terminals in sequences and adjacent terminals and ranges in choices, it (re)constructs highlevel strings and character classes.
The resulting pseudo-parsing expression is returned as the result of the command and may contain the pseudo-operators str for character sequences, aka strings, and cl for character choices, aka character classes.
The result is called a pseudo-parsing expression because it is not a true parsing expression anymore, and will fail a check with ::pt::peg verify if the new pseudo-operators are present in the result, but is otherwise of sound structure for a parsing expression. Notably, the commands ::pt::peg bottomup and ::pt::peg topdown will process them without trouble.
β¨ PE SERIALIZATION FORMAT β¨
Here we specify the format used by the Parser Tools to serialize Parsing Expressions as immutable values for transport, comparison, etc.
We distinguish between regular and canonical serializations. While a parsing expression may have more than one regular serialization only exactly one of them will be canonical.
β¨ Regular serialization β¨
β¨ Atomic Parsing Expressions β¨
- The string
epsilonis an atomic parsing expression. It matches the empty string. - The string
dotis an atomic parsing expression. It matches any character. - The string
alnumis an atomic parsing expression. It matches any Unicode alphabet or digit character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
alphais an atomic parsing expression. It matches any Unicode alphabet character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
asciiis an atomic parsing expression. It matches any Unicode character belowU0080. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
controlis an atomic parsing expression. It matches any Unicode control character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
digitis an atomic parsing expression. It matches any Unicode digit character. Note that this includes characters outside of the[0..9]range. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
graphis an atomic parsing expression. It matches any Unicode printing character, except for space. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
loweris an atomic parsing expression. It matches any Unicode lower-case alphabet character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
printis an atomic parsing expression. It matches any Unicode printing character, including space. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
punctis an atomic parsing expression. It matches any Unicode punctuation character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
spaceis an atomic parsing expression. It matches any Unicode space character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
upperis an atomic parsing expression. It matches any Unicode upper-case alphabet character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
wordcharis an atomic parsing expression. It matches any Unicode word character. This is any alphanumeric character (seealnum), and any connector punctuation characters (e.g. underscore). This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
xdigitis an atomic parsing expression. It matches any hexadecimal digit character. This is a custom extension of PEs based on Tcl's builtin commandstring is. - The string
ddigitis an atomic parsing expression. It matches any decimal digit character. This is a custom extension of PEs based on Tcl's builtin commandregexp. - The expression
[list t x]is an atomic parsing expression. It matches the terminal stringx. - The expression
[list n A]is an atomic parsing expression. It matches the nonterminalA.
β¨ Combined Parsing Expressions β¨
- For parsing expressions e1, e2, ... the result of
[list / e1 e2 ... ]is a parsing expression as well. This is the ordered choice, aka prioritized choice. - For parsing expressions e1, e2, ... the result of
[list x e1 e2 ... ]is a parsing expression as well. This is the sequence. - For a parsing expression e the result of
[list * e]is a parsing expression as well. This is the kleene closure, describing zero or more repetitions. - For a parsing expression e the result of
[list + e]is a parsing expression as well. This is the positive kleene closure, describing one or more repetitions. - For a parsing expression e the result of
[list & e]is a parsing expression as well. This is the and lookahead predicate. - For a parsing expression e the result of
[list ! e]is a parsing expression as well. This is the not lookahead predicate. - For a parsing expression e the result of
[list ? e]is a parsing expression as well. This is the optional input.
β¨ Canonical serialization β¨
The canonical serialization of a parsing expression has the format as specified in the previous item, and then additionally satisfies the constraints below, which make it unique among all the possible serializations of this parsing expression.
- The string representation of the value is the canonical representation of a pure Tcl list. I.e. it does not contain superfluous whitespace.
- Terminals are not encoded as ranges (where start and end of the range are identical).
β¨ EXAMPLE β¨
Assuming the parsing expression shown on the right-hand side of the rule
Expression <- Term (AddOp Term)*
then its canonical serialization (except for whitespace) is
{x {n Term} {* {x {n AddOp} {n Term}}}}
π BUGS, IDEAS, FEEDBACK π
okay bestie, real talk: this doc and the package it's describing? yeah, they will have bugs and other problems. no cap, that's just how software is. π
so if you find something cursed, please report it in the category pt of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist] β go off, tell them everything. π«Ά
and if you have ideas for enhancements, whether it's for the package itself and/or the documentation, please report those too. we love a glow-up suggestion. β¨
π when you're proposing code changes
bestie listen. send unified diffs, okay? like, the actual output of diff -u. not vibes, not a screenshot, an actual diff. π
also note: attachments are strongly preferred over inlined patches. fr fr.
how do you attach? easy:
- create the ticket
- immediately go to its Edit form
- hit the left-most button in the secondary navigation bar
boom. attached. iconic. π
π KEYWORDS π
here's the whole vibe-check word cloud, every single one, no skips:
EBNF, LL(k), PEG, TDPL, context-free languages, expression, grammar, matching, parser, parsing expression, parsing expression grammar, push down automaton, recursive descent, state, top-down parsing languages, transducer
ποΈ CATEGORY πΈ
Parsing and Grammars
(yes that's the whole category. short and iconic. periodt.)
Β©οΈ COPYRIGHT π
Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's a wrap on part 2, bestie!! π¦ this whole thing lives in tcllib, version 1.0.2, on the page pt::pe::op(3tcl) β go forth, parse responsibly, and remember: attachments over inline patches, always. mwah. πβ¨
π¦ 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) 2009 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