Innes Anderson-Morrison
Thoughts and ideas (some better than others) from a software engineer and photographer with ADHD.
Based in the UK working as a staff engineer for Apollo GraphQL
(he/him)
Posts
So, I made a thing: https://github.com/sminez/structex
Structural regular expressions for Rust inspired by @robpike@hachyderm.io's 1987 paper that I was talking about a few weeks ago, but as a generic engine that you can
a) back by the regex engine of your choice
b) define what actions to apply to each match in your own code, rather than hard coding things in the engine
https://crates.io/crates/structex
As an example of how you can use this I put together a couple of hacky demos of what grep and sed look like with this setup:
https://github.com/sminez/structex/tree/main/examples/sgrep
https://github.com/sminez/structex/tree/main/examples/ssed
I've also just updated ad to replace its engine with the one from this crate 😄
I'm planning on writing a blog post about this over the next week or so when I have time so if this all seems completely bonkers / opaque then hopefully it'll make a little more sense there(!)
@jbert@hachyderm.io OK, still very much a work in progress but I've pushed it up to crates.io in order to nab the "structex" name while I finish things off.
https://github.com/sminez/structex
This example shows how to use it alongside something like handlebars in order to get string templated printing working as an action 😄
https://github.com/sminez/structex/blob/main/examples/fancy_impl_blocks.rs
It's only had minimal testing so far and I suspect there's a bunch of things that don't work quite right but I think as a proof of concept it gets the idea across?
The idea is to split the problem into two parts in order to avoid a bunch of issues with how actions interleave with the regex search:
- Apply the structural regular expression terms to an input in order to locate sub-strings. Each match may then be assigned a tag with optional content that will be emitted along with matches when they are found.
- Consume that stream of tagged matches and handle the actions as needed.
I have some more ideas on making the construction of a structex more robust (setting allowed tags etc) which I'll add once I've sorted out the testing and docs.
(@oac@fosstodon.org you might find this fun as well!)
I've spent the last few days overhauling my structural regular expression engine that is inspired by @robpike@hachyderm.io 's 1987 paper (available here: http://doc.cat-v.org/bell_labs/structural_regexps/) and Sam/Acme editors.
This time round I'm correctly handling the parallel execution side of things which is fun, but I'm also thinking about how to add a few extensions to the original system to address some of the issues called out in the paper.
I know about the "Vis" editor, but other than that and my own "ad" does anyone know of implementations outside of plan9's Sam and Acme? I'm still surprised that this concept didn't catch on more as it's incredibly useful.
Quick update on where I'm at with https://github.com/sminez/penrosx
The new backend is significantly tidied up compared to what I had back in April and running from the new trait merged into the main Penrose crate a few weeks ago. The ffi layer has been torn apart and rewritten and I've got scratchpads working now after wiring in the ability to query properties from windows.
There's still a bunch of things that need sorting out but I think it's now at a point where folks interested in taking it for a spin can see what they think! 😄