pt::pe::op(n)

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

πŸ’– pt::pe::op β€” Parsing Expression Utilities πŸ’–

okay bestie, sit DOWN, because we're about to get into pt::pe::op(n), a page from the Parser Tools manual, and it is lowkey a lot but we're gonna slay it together 🫢


✨ NAME ✨

pt::pe::op β€” Parsing Expression Utilities. that's the whole name. cute. iconic. periodt.


🌸 SYNOPSIS 🌸

like here's the vibe check on how you actually load and call this thing:

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 ? 😭 bestie if that's you, pls go read the overview in the Introduction to Parser Tools first β€” that doc is literally the entrypoint to the whole system this package is part of. it's giving "read the syllabus before the lecture", fr fr.

This package hands you extra commands for working with the serializations of parsing expressions, the ones managed by the PEG and related packages, and specified over in the section PE serialization format.

heads up: this is an internal package πŸ”₯ β€” it's meant for the higher level packages handling PEGs, their conversion into and out of various other formats, or other uses. so like, it's not the main character, it's the backstage crew. but we love them.

πŸ‘‘ API πŸ‘‘

πŸ’… ::pt::pe::op drop dropset pe

This command removes all occurences of any of the nonterminals symbols in the set dropset from the parsing expression pe, and simplifies it. This may result in the expression becoming "epsilon", i.e. matching nothing. πŸ’€ like, it can genuinely just evaporate into nothingness.

πŸ’… ::pt::pe::op rename nt ntnew pe

This command renames all occurences of the nonterminal nt in the parsing expression pe into ntnew. glow-up via find-and-replace, we love to see it ✨

πŸ’… ::pt::pe::op called pe

This command extracts the set of all nonterminal symbols used, i.e. 'called', in the parsing expression pe. it's like a lil attendance sheet for your nonterminals πŸŽ€

πŸ’… ::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.

ngl this one is so satisfying β€” it's the "declutter your room" of commands. one child? redundant. nested in nested? lifted. clean. 🧚

πŸ’… ::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.

so yeah, fusechars gives you something that's almost a parsing expression but has main character energy and extra accessories. verify will side-eye it, but bottomup and topdown are unbothered queens and handle it just fine. πŸ’–

🌈 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

  1. The string epsilon is an atomic parsing expression. It matches the empty string.
  2. The string dot is an atomic parsing expression. It matches any character.
  3. The string alnum is an atomic parsing expression. It matches any Unicode alphabet or digit character. This is a custom extension of PEs based on Tcl's builtin command string is.
  4. The string alpha is an atomic parsing expression. It matches any Unicode alphabet character. This is a custom extension of PEs based on Tcl's builtin command string is.
  5. The string ascii is an atomic parsing expression. It matches any Unicode character below U0080. This is a custom extension of PEs based on Tcl's builtin command string is.
  6. The string control is an atomic parsing expression. It matches any Unicode control character. This is a custom extension of PEs based on Tcl's builtin command string is.
  7. The string digit is 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 command string is.
  8. The string graph is 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 command string is.
  9. The string lower is an atomic parsing expression. It matches any Unicode lower-case alphabet character. This is a custom extension of PEs based on Tcl's builtin command string is.
  10. The string print is an atomic parsing expression. It matches any Unicode printing character, including space. This is a custom extension of PEs based on Tcl's builtin command string is.
  11. The string punct is an atomic parsing expression. It matches any Unicode punctuation character. This is a custom extension of PEs based on Tcl's builtin command string is.
  12. The string space is an atomic parsing expression. It matches any Unicode space character. This is a custom extension of PEs based on Tcl's builtin command string is.
  13. The string upper is an atomic parsing expression. It matches any Unicode upper-case alphabet character. This is a custom extension of PEs based on Tcl's builtin command string is.
  14. The string wordchar is an atomic parsing expression. It matches any Unicode word character. This is any alphanumeric character (see alnum), and any connector punctuation characters (e.g. underscore). This is a custom extension of PEs based on Tcl's builtin command string is.
  15. The string xdigit is an atomic parsing expression. It matches any hexadecimal digit character. This is a custom extension of PEs based on Tcl's builtin command string is.
  16. The string ddigit is an atomic parsing expression. It matches any decimal digit character. This is a custom extension of PEs based on Tcl's builtin command regexp.
  17. The expression [list t x] is an atomic parsing expression. It matches the terminal string x.
  18. The expression [list n A] is an atomic parsing expression. It matches the nonterminal A.

πŸŽ€ Combined Parsing Expressions

  1. 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.
  2. For parsing expressions e1, e2, ... the result of [list x e1 e2 ... ] is a parsing expression as well. This is the sequence.
  3. 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.
  4. 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.
  5. For a parsing expression e the result of [list & e] is a parsing expression as well. This is the and lookahead predicate.
  6. For a parsing expression e the result of [list ! e] is a parsing expression as well. This is the not lookahead predicate.
  7. 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.

  1. The string representation of the value is the canonical representation of a pure Tcl list. I.e. it does not contain superfluous whitespace. ✨ no messy extra spaces, we keep it tidy.
  2. 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}}}}

like, look at that lil nested structure go 😭 it's so tidy. that's the canonical vibe.


πŸ› BUGS, IDEAS, FEEDBACK πŸ›

Okay bestie, real talk: this doc? and the whole package it's describing? yeah, they will have bugs and other problems. Not a maybe. A will. Every doc ever written has something weird lurking in it, it's giving inevitable πŸ’€

So if you spot one, pls pls pls report it β€” in the category pt of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist).

Also!! If you have ideas for enhancements for either the package and/or the documentation, drop those in the tracker too. Brainstorming is welcome, we're not gatekeeping improvement ✨


🧾 when you're proposing code changes

  • Give us unified diffs, i.e. the output of diff -u. That's the vibe. That's the format.
  • And listen β€” attachments are strongly preferred over inlined patches. Like, strongly. Not a suggestion, a whole preference.
  • How do you attach? Go to the Edit form of the ticket immediately after its creation, then hit the left-most button in the secondary navigation bar. That's the one. That's the door. πŸšͺπŸ¦‹

πŸ”‘ KEYWORDS πŸ”‘

Here's the whole tag cloud, no skips, no edits, exactly as it stands:

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

ngl that's a stacked keyword list. push down automaton?? iconic. transducer?? main character energy, honestly πŸ‘‘

πŸ—‚οΈ CATEGORY πŸ—‚οΈ

Parsing and Grammars β€” that's the shelf this one lives on, periodt.

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


And that's a wrap on pt::pe::op(n), bestie!! πŸŽ€ You made it to the end of the whole page, which is genuinely a flex. This one ships out of the tcllib package, version 1.0.2 β€” that's the source and the version riding along in the footer, so if you're citing it, cite it like that πŸ’…

Now go parse something cute. Byeee πŸ¦‹πŸ’–πŸŒΈ

πŸ“¦ where this page comes from