Skip to content

Instantly share code, notes, and snippets.

@DeluxeOwl
DeluxeOwl / parsing-operators.md
Created June 23, 2025 05:27
An algorithm for parsing with user-defined mixfix operators, precedences, and contexts

original: https://www.reddit.com/r/ProgrammingLanguages/comments/1lgcbhe/an_algorithm_for_parsing_with_userdefined_mixfix/?share_id=sScCkD2vAveIZeCurtMw1

This post is meant as a long-overdue reply to u/PitifulTheme411's question on this topic. The length is unfortunate, but I wanted to be sure that I was explaining the algorithm in detail so that it could be reproduced.

An ad-hoc parser for user-defined mixfix operators in contexts

This algorithm supports defining mixfix operators with different parsing behavior based on context: possible contexts include expressions, patterns, types, and top-level declarations. A total order of precedence is assumed, but is not required. This algorithm also does not correspond to any formalism that I am aware of, so it's going to be the only thing that can parse your files if you use it.

Declarations of syntax within the file being parsed are not supported: they're relatively easy to analyze and provide IDE support for (both the file with the definitions and the file b

import {
Canvas,
DataSourceParam,
dist,
ImageShader,
rect,
RoundedRect,
rrect,
Shader,
Skia,
@DeluxeOwl
DeluxeOwl / grid.tsx
Created January 27, 2024 08:58
react native fancy grid, by @rohiddev
import React, { ReactNode, useMemo, useState } from "react";
import { View, useWindowDimensions } from "react-native";
export default function FancyGrid<T>({
data,
renderItem,
keyExtractor,
spacing = 8,
minWidth = 110,
maxWidth = 180,
@DeluxeOwl
DeluxeOwl / States-v3.md
Created March 28, 2023 12:38 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,