packages feed

phino-0.0.173 / README.md

<!--SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.comSPDX-License-Identifier: MIT--># Command-Line Manipulator of 𝜑-Calculus Expressions[![DevOps By Rultor.com](https://www.rultor.com/b/objectionary/phino)](https://www.rultor.com/p/objectionary/phino)[![`phino` on Hackage](https://img.shields.io/hackage/v/phino)](http://hackage.haskell.org/package/phino)[![cabal-linux](https://github.com/objectionary/phino/actions/workflows/cabal.yml/badge.svg)](https://github.com/objectionary/phino/actions/workflows/cabal.yml)[![stack-linux](https://github.com/objectionary/phino/actions/workflows/stack.yml/badge.svg)](https://github.com/objectionary/phino/actions/workflows/stack.yml)[![codecov](https://codecov.io/gh/objectionary/phino/branch/master/graph/badge.svg)](https://app.codecov.io/gh/objectionary/phino)[![Haddock](https://img.shields.io/badge/docs-Haddock-blue.svg)](https://objectionary.github.io/phino/)[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSES/MIT.txt)[![Hits-of-Code](https://hitsofcode.com/github/objectionary/phino?branch=master&label=Hits-of-Code)](https://hitsofcode.com/github/objectionary/phino/view?branch=master&label=Hits-of-Code)[![PDD status](https://www.0pdd.com/svg?name=objectionary/phino)](https://www.0pdd.com/p?name=objectionary/phino)This is a command-line normalizer, rewriter, and dataizerof [𝜑-calculus](https://www.eolang.org) expressions.First, you write a simple [𝜑-calculus](https://www.eolang.org) expressionin the `hello.phi` file:```text⟦ φ ↦ ⟦ Δ ⤍ 68-65-6C-6C-6F ⟧, t ↦ ξ.k, k ↦ ⟦⟧ ⟧```## InstallationThen you can install `phino` in two ways:Install [Cabal][cabal] first and then:```bashcabal updatecabal install --overwrite-policy=always phino-0.0.172phino --version```Or download binary from the internet using [curl](https://curl.se/) or[wget](https://en.wikipedia.org/wiki/Wget):```bashsudo curl -o /usr/local/bin/phino http://phino.objectionary.com/releases/macos-15/phino-latestsudo chmod +x /usr/local/bin/phinophino --version```Download paths are:* Ubuntu 22.04: <http://phino.objectionary.com/releases/ubuntu-22.04/phino-latest>* Ubuntu 24.04: <http://phino.objectionary.com/releases/ubuntu-24.04/phino-latest>* MacOS (ARM): <http://phino.objectionary.com/releases/macos-15/phino-latest>* MacOS (Intel): <http://phino.objectionary.com/releases/macos-14-large/phino-latest>* Windows: <http://phino.objectionary.com/releases/windows-2022/phino-latest.exe>In a [GitHub Actions][gha] workflow, one step downloads the binaryfor the runner and puts it on the `PATH`:```yaml- uses: objectionary/phino@0.0.172  with:    version-file: phino-version.txt- run: phino --version```The file holds the version to install, such as `0.0.150`.Give `version: 0.0.150` instead of `version-file` to write the versionin the workflow itself.## BuildTo build `phino` from source, clone this repository and build it with[Cabal][cabal]:```bashgit clone git@github.com:objectionary/phino.gitcd phinocabal build allsudo cp "$(cabal list-bin phino)" /usr/local/bin/phino```The global `--pin` option fails the run when the installed version is notthe one given, and `--pin-file` reads that version from a file:```bashphino --pin=0.0.0.67 dataize hello.phi```## DataizeThen, you dataize the expression:```bash$ phino dataize hello.phi68-65-6C-6C-6F```### Symbolic λ functions`phino` implements no λ function.They come from a YAML file given with `--symbolic`, one entry per λ function.An entry never computes a value.It answers with a term that holds a symbol, `𝜎`, which names a value nobodyworked out.Here is `atoms.yaml`, which the examples below use:```yaml- λ: L_number_(plus|times)  dataize:    𝛿1: $.ρ    𝛿2: $.x  𝑛: Φ.number( φ ↦ ⟦ λ ⤍ 𝜎 ⟧ )``````bash$ cat sum.phi⟦  bytes ↦ ⟦ φ ↦ ∅ ⟧,  number ↦ ⟦ φ ↦ ∅, plus(ρ, x) ↦ ⟦ λ ⤍ L_number_plus ⟧ ⟧,  φ ↦ 5.plus( x ↦ 6 )⟧$ phino dataize --symbolic=atoms.yaml --sweet --hide-rho sum.phi40-45-00-00-00-00-00-00```Dataizing a symbol always gives the same bytes, the number 42, as above.Like `morph`, `dataize` fails on a term that is not a normal form.Inside an entry, `$` is the formation being fired and `Φ` is the universe.A meta is a named placeholder: `𝛿1`, `𝛿2` and so on hold bytes, while `𝑛1`,`𝑛2` and so on hold normal forms, and a line that would bind one to any otherterm fails the run.An entry may hold only the keys below, and any other key refuses the wholefile:* `λ` is a regular expression that matches the whole λ name.  No two entries may match the same name.* `dataize` binds a bytes meta to the data a term comes down to through  dataization, 𝔻.  The term is a path from `$`, as in `𝛿1: $.ρ`, or a meta another line binds,  as in `𝛿2: 𝑛1`.* `morph` binds a term meta to the normal form a term reaches through  morphing, 𝕄.  The term is a path from `$`, as in `𝑛1: $.x`, or a meta another line binds,  as in `𝑛4: 𝑛3`.* `undress` binds a term meta as `morph` does, and then, while the term is a  formation binding `φ` alone beside its `ρ`, takes its `φ` and morphs that.* `evaluate` binds a term meta to the answer of firing the formation another  meta holds, through evaluation, 𝔼, as in `𝑛2: 𝑛1`.* `defer` binds a term meta to a fresh symbol when another meta holds a copy  of an object whose argument is a bare symbol, `⟦ λ ⤍ 𝜎1 ⟧`, and to that  term as it is otherwise, or when under `--acyclic` the φ of the copy  repeats a formation the run is inside.* `stay` binds a term meta to the term another meta holds, with every  `( ρ ↦ … )` applied to a dispatch dropped.* `symbolize` binds a term meta to the term another meta holds, with every  datum turned into a fresh symbol.* `rewrite` binds a term meta to the term the meta under `of` holds, with the  rules under `rules` applied and nothing normalized afterwards.  The rules are written as in a [rule file](#rule-structure).* `cast` holds exactly two lines and binds their two metas as one pair.  When one term is a bare symbol, `⟦ λ ⤍ 𝜎1 ⟧`, and the other is a formation  binding φ, the bare symbol becomes a copy of the other term with `𝜎1` in  place of the term its φ chain ends in, whatever that term is.* `𝑛` is the term the entry answers with.  A bare `𝜎` in it stands for a fresh symbol, and no `𝛿` may appear in it.* `join` answers with one term made of two sides, in place of `𝑛`.  It holds `on`, the condition, which is a bytes meta of `dataize` or a path  from `$`.  It holds `left` and `right`, the two sides, each a path from `$` or a term  meta.  It may hold `otherwise`, a λ name that joins two formations of different  shapes one attribute at a time, and the file must answer that name too.  It may be a mapping instead, holding that name under `λ` and the names of  the condition and the two sides in the formation it makes under `on`,  `left` and `right`, such as `c🌵`; each ends with `🌵`, and a missing one  is `on🌵`, `left🌵` or `right🌵`.* `terminators` lists λ names that only raise, as in `[L_throw]`.  A term holding one of them, or an application of one, passes every line  as it is, and `join` takes it for a side that raises, as it takes `⊥`.  No entry of the file may answer such a name.* `site` is a path of one attribute from `$`, as in `$.site🌵`, naming the  place of the `if` a fork comes from.  Under `--acyclic=plausible`, a formation of the entry repeats one above it  only when both hold the same site, and `symbolize` leaves the site as it is.An entry holds either `𝑛` or `join`, never both.The lines of all blocks run in the order of the metas they read, not in theorder of the blocks.A line that reads a meta nothing binds refuses the file.### Partial evaluationA λ name that no entry answers stops the run with an error.With `--partial`, the run prints the residual program instead: what the knowninputs decide is computed, and the rest stays in place:```bash$ cat partial.phi⟦  bytes ↦ ⟦ φ ↦ ∅ ⟧,  number ↦ ⟦    φ ↦ ∅,    plus(ρ, x) ↦ ⟦ λ ⤍ L_number_plus ⟧,    times(ρ, x) ↦ ⟦ λ ⤍ L_number_times ⟧,    as-bool ↦ ⟦ λ ⤍ L_number_as_bool ⟧  ⟧,  φ ↦ 2.times( x ↦ 3 ).plus( x ↦ 4 ).as-bool⟧$ phino dataize --symbolic=atoms.yaml --sweet --hide-rho partial.phi[ERROR]: No entry of --symbolic answers the λ function 'L_number_as_bool'$ phino dataize --symbolic=atoms.yaml --partial --sweet --hide-rho partial.phiL_number_as_bool:λ```Here `2.times( x ↦ 3 ).plus( x ↦ 4 )` was computed, and the symbol it came tosits in the hidden `ρ`, while `as-bool` stays where it was.An operand that reaches the terminator `⊥` is left in place the same way.### Reducing a term inside a universeThe `--inside` option reduces a term the program does not hold, taking theprogram as the universe Φ.It cannot be combined with `--locator`:```bash$ cat universe.phi⟦  bytes ↦ ⟦ φ ↦ ∅ ⟧,  number ↦ ⟦ φ ↦ ∅, plus(ρ, x) ↦ ⟦ λ ⤍ L_number_plus ⟧ ⟧⟧$ phino dataize --symbolic=atoms.yaml --inside='5.plus( x ↦ 6 )' universe.phi40-45-00-00-00-00-00-00```### LimitsFive options stop a run that goes on for too long:* `--max-steps` bounds how deep morphing and dataization may nest,  `1000` by default;* `--max-firings` bounds how many λ functions the whole run may fire;* `--max-seconds` bounds how many seconds the whole run may take,  such as `0.5`;* `--max-nodes` bounds how many nodes the term of the run may grow to;* `--max-memory` bounds the live heap of the run, such as `8G`.`--partial` leaves a site in place when it runs out of steps, firings,seconds, nodes or memory.## MorphMorphing, 𝕄, evaluates as far as the object model allows without askingfor data, and stops at the first formation it reaches:```bash$ cat two.phi⟦  bytes ↦ ⟦ φ ↦ ∅ ⟧,  number ↦ ⟦ φ ↦ ∅, plus(ρ, x) ↦ ⟦ λ ⤍ L_number_plus ⟧ ⟧,  φ ↦ 5.plus( x ↦ 6 ).plus( x ↦ 7 )⟧$ phino dataize --symbolic=atoms.yaml --sweet --hide-rho two.phi40-45-00-00-00-00-00-00$ phino morph --symbolic=atoms.yaml --locator=Q.φ --sweet --hide-rho two.phi⟦ λ ⤍ L_number_plus, x ↦ 7.0 ⟧```The inner `5.plus( x ↦ 6 )` fires, because `.plus` is dispatched on itsresult, while the outer call is left for dataization.Where no formation is reachable, `morph` prints `⊥`.It fails on a term that is not a normal form.It takes every option of `dataize`.### Acyclic morphing`phino` stops no recursion by itself, so a run that never ends fails once`--max-steps` runs out, with `Morphing did not finish before reaching thelimit of steps: --max-steps=<n>`.The `--acyclic=<mode>` option makes the run notice a loop instead.When a reduction is about to enter a formation it is already inside, the runanswers a copy of an object binding φ with a fresh symbol and goes on, andstops at any other formation and leaves the term in place, as `--partial`does.The mode says when two formations are the same:* `proven` means equal up to a renaming of symbols;* `plausible` also means that the later one holds the earlier one under  wrappers it gained, such as a growing accumulator, so it may cut a  recursion that would have stopped.Under `plausible`, a formation is fired only once, and a later firing of ittakes the answer of the first one.The `--max-loops=<n>` option lets a reduction enter such a formation `n` moretimes before it is cut.`dataize` takes `--acyclic` too, and fails on a term left in place unless`--partial` is given, since such a term holds no data to print.## ProtocolThe `--protocol` option writes every λ function the run fired into a file,as a tree in XML, for a program to read.The `--minutes` option writes the same tree as indented text, and one runmay take both.With `--profile`, every record of the minutes ends with the millisecondsit took, the time since the start, and the memory in use.Here, `L_down` answers with a call of its own object over a fresh symbol, sowithout `--acyclic` the run would go on until `--max-steps` runs out:```bash$ cat down.yaml- λ: L_down  dataize:    𝛿1: $.x  𝑛: Φ.down( x ↦ ⟦ λ ⤍ 𝜎 ⟧ )$ cat down.phi⟦  down ↦ ⟦ x ↦ ∅, λ ⤍ L_down ⟧,  y ↦ Φ.down( x ↦ ⟦ λ ⤍ 𝜎1 ⟧ ).φ⟧$ phino morph --symbolic=down.yaml --locator=Q.y --acyclic=proven \    --minutes=down.txt --sweet --hide-rho down.phi𝜎3:λ$ cat down.txt𝕄(Φ.y):  remembered 𝑛·0·1 ≡ Φ.down  # ⟦ x ↦ ∅, λ ⤍ L_down ⟧  𝑛·0·2 ≔ Φ.down( x ↦ 𝜎1:λ )  𝑛·0·3 ≔ ⟦ λ ⤍ L_down, x ↦ 𝜎1:λ ⟧  remembered 𝑛·0·3 ≡ 𝑛·0·1( x ↦ 𝜎1:λ )  𝔼(L_down):    𝔻(ξ.x):      𝛿·1·1 ≔ 𝔻(𝜎1:λ)    𝛿1·1 ≔ 𝛿·1·1  # 𝔻(ξ.x)    𝑛·1·1 ≔ Φ.down( x ↦ 𝜎2:λ )  # 𝑛 of L_down    𝕄(𝑛·1·1):      𝑛·1·2 ≔ Φ.down( x ↦ 𝜎2:λ )      𝑛·1·3 ≔ ⟦ λ ⤍ L_down, x ↦ 𝜎2:λ ⟧      remembered 𝑛·1·3 ≡ 𝑛·0·1( x ↦ 𝜎2:λ )      morphed 𝑛·1·4 ≔ 𝑛·1·3    𝑛·1·5 ≔ 𝑛·1·3  # 𝕄(𝑛·1·1)    remembered 𝑛·1·3 ≡ 𝑛·0·3    evaluated 𝑛·1·6 ≔ 𝑛·1·3  # 𝑛·0·3  recalled 𝑛·1·3 ⇒ 𝑛·0·3  recalled 𝑛·0·3 ⇒ 𝑛·0·1( x ↦ 𝜎1:λ )  recalled 𝑛·0·1 ⇒ Φ.down  looped 𝜎3 ≔ 𝑛·0·2.φ  # proven, repeats 𝑛·0·3  morphed 𝑛·0·4 ≔ 𝜎3:λ```In a name such as `𝑛·1·2`, the first number counts the firings, `0` outsideevery firing, and the second counts the names within that firing.The name `𝛿1·1` is the meta `𝛿1` of the first firing.A protocol may hold these lines:* `# …` lines open the file with the phino that wrote it, the command, the  world, the λ functions, the locator, and the expression it points at.* `𝔻(…):` and `𝕄(…):` open a block where dataization or morphing starts at a  new site, and what it does stands under it.* `𝔼(…):` opens one firing, named by its λ function.* `𝑛·0·1 ≔ …` names an application, and the line after it names the  object the application made.* `𝛿1·1 ≔ …` binds a meta of the entry, and the comment names the judgment  and the term it came from.* `𝑛·1·1 ≔ …  # 𝑛` is the term the entry answered with, and the line  commented with `𝕄(𝑛·1·1)` is its normal form.* `boxed …` is dataization stepping into the `φ` of a formation.* `undressed …` is an `undress` line taking the `φ` of a formation.* `shared 𝑛·1 ≔ …` names an argument a recursion keeps wrapping, so later  lines spell it by that name.* `𝛿·1·1 ≔ …` closes a `𝔻` block with the data it found, or with  `𝔻(𝜎1:λ)` where it came down to a symbol.* `morphed …` closes a `𝕄` block with the term it came to.* `evaluated …` closes an `𝔼` block with what the firing answered, and the  comment names the formation fired.* `normalized …` is the term a normalization came to, where no line named it  before, and the comment names the term it came from.* `joined …`, `fabricated …`, `diverged …` and `unripe …` are what a `join`  made of its two sides, or why it could not join them.* `deferred …` and `symbolized …` are the symbols a `defer` or a `symbolize`  line minted.* `cast …` binds a meta to the copy a `cast` block made of a bare symbol, and  the comment names the meta it read and the meta whose shape it took.* `unanswered …` is a λ name no entry answers, and `opaque …` a symbol  nothing can fire; the comment names the term 𝕄 or 𝔻 worked on.  `opaque 𝜎2:λ ≔ 𝜎1:λ.foo` is the new symbol an attribute of a symbol gives.* `stuck …` closes a firing that got stuck, and `stall …` stands under one  that `--acyclic=plausible` answered with an earlier stall.* `remembered 𝑛·0·1 ≡ Φ.down` is a fact the run keeps: the term on the  left came from the one on the right, a path or a call of the world, or  a formation it was the answer of.* `memoized 𝑛·0·5 ⇛ 𝑛·1·9` is what `--acyclic=plausible` keeps: the  formation on the left fired to the term on the right.* `renamed 𝑛·1·10 ⇛ 𝜎5:λ` is a memo entry used for a formation alike it up  to symbols, with the symbols the comment lists renamed.* `recalled 𝑛·0·3 ⇒ 𝑛·0·1( x ↦ ⟦⟧ )` is a fact or a memo entry used again,  spelled as its `remembered` or `memoized` line spelled it.* `looped …` is where `--acyclic` cut a loop, and `looped 𝜎1 ≔ …` names  the call of the object it answered with that symbol, when a fact names it,  or else the copy itself.* `passed 𝑛·1·2 ≔ …` is where an operand came to an object `--acyclic`  takes for a loop, handed on as it is.* `starved …`, `spent …`, `timeout …`, `oversized …` and `blown …` are  where `--max-steps`, `--max-firings`, `--max-seconds`, `--max-nodes` and  `--max-memory` ran out.* `msec …`, `firings …` and `fps …` close the file, and the listing above  leaves them and the `# …` lines out, since they differ from run to run.The `--abridged` option folds every formation longer than sixty-fourcharacters, or than `--abridged=WIDTH`, into its `φ`, `Δ` and `λ` and a countof the rest, and every application that long into its head and a count of itsarguments.The `--abridged-data` option also cuts every byte string longer than eightbytes down to its first two bytes and its last two.## RewriteYou can rewrite this expression with the help of [rules](#rule-structure)defined in the `my-rule.yml` YAML file (here, the `!d1` and `!B1` are capturinggroups, similar to regular expressions):```yamlname: My custom rulepattern: ⟦ Δ ⤍ !d1, !B1 ⟧result: ⟦ Δ ⤍ 62-79-65, !B1 ⟧```Then, rewrite:```bash$ phino rewrite --rule=my-rule.yml hello.phi⟦ φ ↦ ⟦ Δ ⤍ 62-79-65 ⟧, t ↦ ξ.k, k ↦ ⟦⟧ ⟧```If you want to use many rules, just use `--rule` as many times as you need:```bashphino rewrite --rule=rule1.yaml --rule=rule2.yaml ...```You can also use [built-in rules](resources), which are designedto normalize expressions, alone or together with your own rules:```bashphino rewrite --normalize --rule=my-rule.yaml hello.phi```Some rules mint fresh names with the `random-string` function, and `--seed`picks the seed of its random generator, `0` by default.If no input file is provided, the 𝜑-expression is taken from `stdin`:```bash$ echo '⟦ φ ↦ ⟦ Δ ⤍ 68-65-6C-6C-6F ⟧ ⟧' | phino rewrite --rule=my-rule.yml⟦ φ ↦ ⟦ Δ ⤍ 62-79-65 ⟧ ⟧```You're able to pass [`XMIR`][xmir] as input. Use `--input=xmir` and `phino`will parse given `XMIR` from file or `stdin` and convert it to `phi` AST.```bashphino rewrite --rule=my-rule.yaml --input=xmir file.xmir```Also `phino` supports 𝜑-expressions in[ASCII](https://en.wikipedia.org/wiki/ASCII) format and withsyntax sugar. The `rewrite` command also allows you to desugar the expressionand print it in canonical syntax:```bash$ echo '[[ @ -> Q.io.stdout(text -> "hello") ]]' | phino rewrite⟦  φ ↦ Φ.io.stdout(    text ↦ Φ.string( φ ↦ Φ.bytes( φ ↦ ⟦ Δ ⤍ 68-65-6C-6C-6F ⟧ ) )  )⟧```The two styles may be mixed in one expression, unless `--monoform` is given.A formation of a single binding may be written as its asset, a colon,and the attribute the asset is bound to:```text⟦ Δ ⤍ FF-AA ⟧    = FF-AA:Δ    = FF-AA:D⟦ λ ⤍ 𝜎1 ⟧       = 𝜎1:λ       = !S1:L⟦ a ↦ ∅ ⟧        = ∅:a        = ?:a⟦ φ ↦ ξ.a ⟧      = ξ.a:φ      = $.a:@```The colon binds as tightly as a dot, so `ξ.a:φ.b` is `⟦ φ ↦ ξ.a ⟧.b`.With `--sweet`, `phino` prints every such formation this way.A formation has a receiver `ρ` only when it declares one among its voids, theway EO declares `^`, as in `⟦ ρ ↦ ∅, t ↦ ξ.ρ.k ⟧`.`phino` adds none of its own, so `ξ.ρ` in a formation that declares noneis `⊥`.## MergeYou can merge several 𝜑-expressions into a single one by merging theirtop level formations:```bash$ cat bytes.phi⟦ bytes ↦ ⟦ φ ↦ ∅ ⟧ ⟧$ cat number.phi⟦  number ↦ ⟦    φ ↦ ∅,    plus(x) ↦ ⟦ λ ⤍ L_number_plus ⟧  ⟧⟧$ cat minus.phi⟦ number ↦ ⟦ minus(x) ↦ ⟦ λ ⤍ L_number_minus ⟧ ⟧ ⟧$ phino merge bytes.phi number.phi minus.phi --sweet⟦  bytes(φ) ↦ ⟦⟧,  number(φ) ↦ ⟦ plus(x) ↦ L_number_plus:λ, minus(x) ↦ L_number_minus:λ ⟧⟧```## MatchYou can test the 𝜑-expression matches against the [rule](#rule-structure)pattern. The result output contains matched substitutions:```bash$ phino match --pattern='⟦ Δ ⤍ !d, !B ⟧' hello.phiB >> ⟦⟧d >> 68-65-6C-6C-6F```## SODGThe `sodg` command prints the commands that build the graph of a𝜑-expression, one per line, in the language of[sodg-maven-plugin](https://github.com/objectionary/sodg-maven-plugin):```bash$ echo '⟦ x ↦ ξ.y, y ↦ ∅ ⟧' | phino sodgF η0 x yD η1 η0 yP η0 x η1```With `--drop-tests`, it skips the unit tests of every object, the attributesnamed `p🌵…` and `n🌵…`, with all the cells they hold.## CompileBy default, `phino` reads its rules from YAML and interprets them at everystep.The `compile` command turns the built-in rules of normalization,contextualization, morphing and dataization, and every `--rule` file, intothe Haskell module `compiled/generated/Compiled.hs`, and a second build linksit in:```bashphino compilecabal build all```The build links the module in only when the Cabal flag `compiled` is on.If there is no `cabal.project.local`, `compile` creates one that turns theflag on, and otherwise it prints the lines to add to it.The compiled rules take exactly the same steps as the YAML ones.`compile` refuses a rule it cannot turn into Haskell and names the reason.A binary built this way refuses to run once the built-in rules changed afterthe last `compile`.To test the whole suite against the compiled rules, run `make compiled`.## ExplainYou can _explain_ the built-in rules by printing them in [LaTeX][latex]format. Pass exactly one of `--normalize`, `--morph`, `--dataize` or`--contextualize` for the rewriting, morphing (𝕄), dataization (𝔻) orcontextualization (𝒞) rules (or `--rule` for a custom rule file):```bashphino explain --normalize```For more details, use `phino [COMMAND] --help` option.## Rule structureThis is BNF-like yaml rule structure. Here types ended withapostrophe, like `Attribute'` are built types from 𝜑-expression [AST](src/AST.hs)```bnfcRule:  name: String  pattern: String  result: String  when: Condition?       # predicate, works with substitutions before extension  where: [Extension]?    # substitution extensions  having: Condition?     # predicate, works with substitutions after extensionCondition:  = and: [Condition]     # logical AND  | or:  [Condition]     # logical OR  | not: Condition       # logical NOT  | eq:                  # compare two comparable objects      - Comparable      - Comparable  | in:                  # returns True if every given attribute exists in      - Attribute' | [Attribute'] # the union of the given bindings      - Binding' | [Binding']  | nf: Expression'      # returns True if given expression in normal form                         # which means that no more other normalization rules                         # can be applied  | absolute: Expression' # returns True if given expression is xi-free, i.e.                         # there is no ξ outside of a formation: it is Φ, a                         # formation, a dispatch with a xi-free subject, or an                         # application with a xi-free subject and argument.                         # Combined with a normal-form check by the '𝑘'/'!k'                         # meta variable, which ranges over the absolute                         # expressions 𝒦 ⊆ 𝒩, used by the Rcopy rule.  | matches:             # returns True if given expression after dataization      - String           # matches to given regex      - Expression  | part-of:             # returns True if given expression is attached to any      - Expression'      # attribute in ginve bindings      - BiMeta'  | formation:           # returns True if given expression is a formation      Expression'        # (an abstraction ⟦…⟧); used by morphing 'md'                         # as 'not (formation 𝑛)', so a non-formation head is                         # morphed and a formation head is left to 'ml'  | gt:                  # returns True if the first comparable object is      - Comparable       # greater than the second one      - Comparable  | disjoint:            # returns True if none of the given attributes exists      - [Attribute']     # in the given bindings      - Binding'Comparable:              # comparable object that may be used in 'eq' condition  = Attribute'  | Number  | Expression'Number:                  # comparable number  = Integer              # just regular integer  | length: BiMeta'      # calculate length of bindings by given meta bindingExtension:               # substitutions extension used to introduce new meta variables  meta: [ExtArgument]    # new introduced meta variable  function: String       # name of the function  args: [ExtArgument]    # arguments of the functionExtArgument  = Bytes'               # !d  | Binding'             # !B  | Expression'          # !e  | Attribute'           # !t```Regular expressions in `matches` and `sed` are limited to 1,000,000 matchcalls and 256 levels of recursion per execution. Exceeding either limitstops the command with `Regex execution failed` and exit code 1. The recursionlimit protects small native thread stacks; a repeated capturing group such as`(a|b)*` can reach it even on a string of a few hundred characters. Long stringscan still be matched with patterns that need little recursion, such as `[ab]*`.Here's list of functions that are supported for extensions:* `contextualize` - function of two arguments, that rewrites given expression  depending on provided context according to the contextualization  [rules](resources/contextualization)* `random-tau` - creates an attribute with a random unique name. It accepts no  arguments; uniqueness is guaranteed across all names already taken in the  document.* `dataize` - dataizes given expression and returns bytes.* `concat` - accepts bytes or dataizable expressions as arguments,  concatenates them into single sequence and convert it to expression  that can be pretty printed as human readable string:  `Φ.string( φ ↦ Φ.bytes( φ ↦ ⟦ Δ ⤍ !d ⟧ ) )`.* `sed` - pattern replacer, works like unix `sed` function.  Accepts two arguments: target expression and pattern.  Pattern must start with `s/`, consists of three parts  separated by `/`, for example, this pattern `s/\\s+//g`  replaces all the spaces with empty string. To escape braces and slashes  in pattern and replacement parts - use them with `\\`,  e.g. `s/\\(.+\\)//g`. In the replacement, `\\1` to `\\9`, as well as  `$1`, put what a group of the pattern matched, e.g. `s/([0-9]+)/\\1!/g`,  and `&` puts the whole match, e.g. `s/[0-9]+/<&>/g`, while `\\&` puts a  literal `&`.* `random-string` - accepts dataizable expression or bytes as pattern.  Replaces `%x` and `%d` formatters with random hex numbers and  decimals accordingly. Uniqueness is guaranteed during one  execution of `phino`.* `size` - accepts exactly one meta binding and returns size of it and  `Φ.number`.* `tau` - accepts `Φ.string`, dataizes it and converts it to attribute.  If dataized string can't be converted to attribute - an error is thrown.* `string` - accepts `Φ.string` or `Φ.number` or attribute and converts it  to `Φ.string`.* `number` - accepts `Φ.string` and converts it `Φ.number`* `sum` - accepts list of `Φ.number` or `Φ.bytes` and returns sum of them as `Φ.number`* `join` - accepts list of bindings and returns list of joined bindings. Duplicated  `ρ`, `Δ` and `λ` attributes are ignored, all other duplicated attributes are replaced  with unique attributes using `random-tau` function.## Meta variablesThe `phino` supports meta variables to write 𝜑-expression patterns forcapturing attributes, bindings, etc.This is the list of supported meta variables:* `!t` || `𝜏` - attribute* `!e` || `𝑒` - any expression* `!n` || `𝑛` - any expression that is already in normal form (behaves like                `!e`/`𝑒`, but only binds a sub-expression in NF, so no explicit                `nf:` guard is needed)* `!k` || `𝑘` - any expression that is absolute, i.e. xi-free and in normal                form (ranges over `𝒦 ⊆ 𝒩`); behaves like `!e`/`𝑒` but only                binds an absolute sub-expression, so no explicit `absolute:`                or `nf:` guard is needed* `!B` || `𝐵` - list of bindings, at most one in a formation, which has                no order, unless `rewrite --preserve-order`* `!d` || `𝛿` - bytes in meta delta binding* `!F` || `𝑓` - function name in meta lambda binding* `!S` || `𝜎` - a symbol standing where a λ name stands (see                [Symbolic λ functions](#symbolic-λ-functions)). It is spelled                the way a meta variable is spelled but is a name and no                capture: `𝜎1` is one concrete symbol, which no substitution                ever binds, and a bare `𝜎` in the answer of a `--symbolic`                entry asks for a fresh oneA meta variable carries a suffix, like `!B1` or `𝜏2`, to name what itcaptured, so that the `result`, `when`, `where` and `having` of a rule canread it back.A suffix starts with one, so `!B0` is refused.Without a suffix, a meta variable is anonymous: it matches any term on itsown, binds no name, and is refused anywhere but in a pattern, so`⟦ 𝜏 ↦ 𝑒, 𝜏 ↦ 𝑒 ⟧` matches any two attributes.An application argument is always given by the name of the attribute it goesto, as in `Φ.f( x ↦ ξ.y )`, and a positional one, such as `Φ.f( ξ.y )` or`Φ.f( α0 ↦ ξ.y )`, is refused.## BenchmarkTo run performance benchmarks, you need [Java 8+][java] and [curl][curl]:```bashmake bench```On the first run, `make bench` downloads the compiled [`Native`][jna-native]class of [JNA][jna], turns it into [XMIR][xmir] with[jeo-maven-plugin][jeo] and then into 𝜑, and caches the results in`benchmark/tmp/`.Besides parsing, printing and rewriting that class, the suite morphs theentries of `benchmark/demo.phi` symbolically, one case per entry.<!-- benchmark_begin -->```text=== parse/phi ===  warmup:     3 iterations  batches:    10 x 1  total:      1817079.413 μs  avg:        181707.941 μs  min:        164807.231 μs  max:        205518.423 μs  std dev:    17870.767 μs=== parse/xmir ===  warmup:     3 iterations  batches:    10 x 1  total:      7860141.670 μs  avg:        786014.167 μs  min:        739622.130 μs  max:        892586.550 μs  std dev:    51459.020 μs=== rewrite/normalize ===  warmup:     3 iterations  batches:    10 x 1  total:      11.371 μs  avg:        1.137 μs  min:        1.053 μs  max:        1.537 μs  std dev:    0.136 μs=== print/sweet/multiline ===  warmup:     3 iterations  batches:    10 x 1  total:      1476341.035 μs  avg:        147634.104 μs  min:        143163.468 μs  max:        159257.458 μs  std dev:    4796.363 μs=== print/sweet/flat ===  warmup:     3 iterations  batches:    10 x 1  total:      780800.712 μs  avg:        78080.071 μs  min:        65787.616 μs  max:        96222.881 μs  std dev:    9333.636 μs=== print/salty/multiline ===  warmup:     3 iterations  batches:    10 x 1  total:      5808590.269 μs  avg:        580859.027 μs  min:        546062.759 μs  max:        625821.280 μs  std dev:    24899.656 μs=== morph/symbolic/demo/e1 ===  warmup:     3 iterations  batches:    10 x 13  total:      15407.077 μs  avg:        118.516 μs  min:        110.364 μs  max:        124.315 μs  std dev:    4.525 μs=== morph/symbolic/demo/e2 ===  warmup:     3 iterations  batches:    10 x 148  total:      196118.294 μs  avg:        132.512 μs  min:        110.295 μs  max:        187.052 μs  std dev:    21.211 μs=== morph/symbolic/demo/e3 ===  warmup:     3 iterations  batches:    10 x 148  total:      171831.495 μs  avg:        116.102 μs  min:        111.857 μs  max:        122.684 μs  std dev:    3.360 μs=== morph/symbolic/demo/e4 ===  warmup:     3 iterations  batches:    10 x 151  total:      176286.007 μs  avg:        116.746 μs  min:        110.924 μs  max:        121.950 μs  std dev:    3.950 μs=== morph/symbolic/demo/e5 ===  warmup:     3 iterations  batches:    10 x 116  total:      166326.077 μs  avg:        143.385 μs  min:        124.257 μs  max:        170.471 μs  std dev:    14.090 μs=== morph/symbolic/native/e5 ===  warmup:     3 iterations  batches:    10 x 1  total:      126809.762 μs  avg:        12680.976 μs  min:        12033.615 μs  max:        13380.528 μs  std dev:    385.658 μs=== morph/symbolic/accum/0 ===  warmup:     3 iterations  batches:    10 x 78  total:      75701.566 μs  avg:        97.053 μs  min:        93.905 μs  max:        106.537 μs  std dev:    3.774 μs=== morph/symbolic/accum/400 ===  warmup:     3 iterations  batches:    10 x 63  total:      68593.670 μs  avg:        108.879 μs  min:        106.440 μs  max:        115.421 μs  std dev:    2.429 μs```The results were calculated in [this GHA job][benchmark-gha]on 2026-11-25 at 12:54,on Linux with 4 CPUs.<!-- benchmark_end -->## How to ContributeFork repository, make changes, then send us a [pull request][guidelines].We will review your changes and apply them to the `master` branch shortly,provided they don't violate our quality standards. To avoid frustration,before sending us your pull request please make sure all your tests pass:```bashmake all```To generate a local coverage report for development, run:```bashmake coverage```To build a `phino` executable into the root of the repository, run:```bashmake phino```You will need [GHC ≥ 9.6.7][GHC] and [Cabal ≥ 3.0 (recommended)][cabal]or [Stack ≥ 3.0][stack] installed.[cabal]: https://www.haskell.org/cabal/[stack]: https://docs.haskellstack.org/en/stable/install_and_upgrade/[GHC]: https://www.haskell.org/ghc/[guidelines]: https://www.yegor256.com/2014/04/15/github-guidelines.html[xmir]: https://news.eolang.org/2022-11-25-xmir-guide.html[latex]: https://en.wikipedia.org/wiki/LaTeX[java]: https://www.java.com/en/download/[curl]: https://curl.se/[gha]: https://docs.github.com/en/actions[jna]: https://github.com/java-native-access/jna[jna-native]: https://github.com/java-native-access/jna/blob/master/src/com/sun/jna/Native.java[jeo]: https://github.com/objectionary/jeo-maven-plugin[benchmark-gha]: https://github.com/objectionary/phino/actions/runs/45615140704