Phino
Command-Line Normalizer, Rewriter, and Dataizer of 𝜑-Calculus Expressions
Install / Use
/learn @objectionary/PhinoREADME
Command-Line Manipulator of 𝜑-Calculus Expressions
This is a command-line normalizer, rewriter, and dataizer of 𝜑-calculus expressions.
First, you write a simple 𝜑-calculus program
in the hello.phi file:
Φ ↦ ⟦ φ ↦ ⟦ Δ ⤍ 68-65-6C-6C-6F ⟧, t ↦ ξ.k, k ↦ ⟦⟧ ⟧
Installation
Then you can install phino in two ways:
Install [Cabal][cabal] first and then:
cabal update
cabal install --overwrite-policy=always phino-0.0.0.67
phino --version
Or download binary from the internet using curl or wget:
sudo curl -o /usr/local/bin/phino http://phino.objectionary.com/releases/macos-15/phino-latest
sudo chmod +x /usr/local/bin/phino
phino --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
Build
To build phino from source, clone this repository:
git clone git@github.com:objectionary/phino.git
cd phino
Then, run the following command (ensure you have [Cabal][cabal] installed):
cabal build all
Next, run this command to install phino system-wide:
sudo cp "$(cabal list-bin phino)" /usr/local/bin/phino
Verify that phino is installed correctly:
$ phino --version
0.0.0.0
Dataize
Then, you dataize the program:
$ phino dataize hello.phi
68-65-6C-6C-6F
Rewrite
You can rewrite this expression with the help of rules
defined in the my-rule.yml YAML file (here, the !d is a capturing group,
similar to regular expressions):
name: My custom rule
pattern: Δ ⤍ !d
result: Δ ⤍ 62-79-65
Then, rewrite:
$ 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:
phino rewrite --rule=rule1.yaml --rule=rule2.yaml ...
You can also use built-in rules, which are designed to normalize expressions:
phino rewrite --normalize hello.phi
If no input file is provided, the 𝜑-expression is taken from stdin:
$ 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.
phino rewrite --rule=my-rule.yaml --input=xmir file.xmir
Also phino supports 𝜑-expressions in
ASCII format and with
syntax sugar. The rewrite command also allows you to desugar the expression
and print it in canonical syntax:
$ echo 'Q -> [[ @ -> Q.io.stdout("hello") ]]' | phino rewrite
Φ ↦ ⟦
φ ↦ Φ.io.stdout(
α0 ↦ Φ.string(
α0 ↦ Φ.bytes(
α0 ↦ ⟦ Δ ⤍ 68-65-6C-6C-6F ⟧
)
)
)
⟧
Merge
You can merge several 𝜑-programs into a single one by merging their top level formations:
$ cat bytes.phi
{⟦ bytes(data) ↦ ⟦ φ ↦ data ⟧ ⟧}
$ cat number.phi
{⟦
number(as-bytes) ↦ ⟦
φ ↦ as-bytes,
plus(x) ↦ ⟦ λ ⤍ L_number_plus ⟧
⟧
⟧}
$ cat minus.phi
{⟦ number ↦ ⟦ minus(x) ↦ ⟦ λ ⤍ L_number_minus ⟧ ⟧ ⟧}
$ phino merge bytes.phi number.phi minus.phi --sweet
{⟦
bytes(data) ↦ ⟦ φ ↦ data ⟧,
number(as-bytes) ↦ ⟦
φ ↦ as-bytes,
plus(x) ↦ ⟦ λ ⤍ L_number_plus ⟧,
minus(x) ↦ ⟦ λ ⤍ L_number_minus ⟧
⟧
⟧}
Match
You can test the 𝜑-program matches against the rule pattern. The result output contains matched substitutions:
$ phino match --pattern='⟦ Δ ⤍ !d, !B ⟧' hello.phi
B >> ⟦ ρ ↦ ∅ ⟧
d >> 68-65-6C-6C-6F
Explain
You can explain rewriting rule by printing them in [LaTeX][latex] format:
$ phino explain --normalize
\begin{tabular}{rl}
\trrule{alpha}
{ [[ B_1, \tau_1 -> ?, B_2 ]] ( \tau_2 -> e ) }
{ [[ B_1, \tau_1 -> ?, B_2 ]] ( \tau_1 -> e ) }
{ if $ \indexof{ \tau_2 } = \vert B_1 \vert $ }
{ }
\trrule{dc}
{ T ( \tau -> e ) }
{ T }
{ }
{ }
...
\trrule{stop}
{ [[ B ]] . \tau }
{ T }
{ if $ \tau \notin B \;\text{and}\; @ \notin B \;\text{and}\; L \notin B $ }
{ }
\end{tabular}
For more details, use phino [COMMAND] --help option.
Rule structure
This is BNF-like yaml rule structure. Here types ended with
apostrophe, like Attribute' are built types from 𝜑-program AST
Rule:
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 extension
Condition:
= and: [Condition] # logical AND
| or: [Condition] # logical OR
| not: Condition # logical NOT
| alpha: Attribute' # check if given attribute is alpha
| eq: # compare two comparable objects
- Comparable
- Comparable
| in: # check if attributes exist in bindings
- Attribute'
- Binding'
| nf: Expression' # returns True if given expression in normal form
# which means that no more other normalization rules
# can be applied
| xi: Expression' # special condition for Rcopy normalization rule to
# avoid infinite recursion while the condition checking
# returns True if there's no ξ outside of the formation
# in given expression.
| 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'
Comparable: # comparable object that may be used in 'eq' condition
= Attribute'
| Number
| Expression'
Number: # comparable number
= Integer # just regular integer
| index: Attribute' # calculate index of alpha attribute
| length: BiMeta' # calculate length of bindings by given meta binding
Extension: # 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 function
ExtArgument
= Bytes' # !d
| Binding' # !B
| Expression' # !e
| Attribute' # !a
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 rulesscope- resolves the scope for given expression. Works only with meta expressions denotes as𝑒or!e. The scope is nearest outer formation, if it's present. In all other cases the default scope is used, which is anonymous formation⟦ ρ ↦ ∅ ⟧.random-tau- creates attribute with random unique name. Accepts bindings, and attributes. Ensures that created attribute is not present in list of provided attributes and does not exist as attribute in provided bindings.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 unixsedfunction. Accepts two arguments: target expression and pattern. Pattern must start withs/, consists of three parts separated by/, for example, this patterns/\\s+//greplaces all the spaces with empty string. To escape braces and slashes in pattern and replacement parts - use them with\\, e.g.s/\\(.+\\)//g.random-string- accepts dataizable expression or bytes as pattern. Replaces%xand%dformatters with random hex numbers and decimals accordingly. Uniqueness is guaranteed during one execution ofphino.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.
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
