Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

View GitHub Profile
@conartist6
conartist6 / agAST.js
Last active October 8, 2023 13:11
Annotated agAST builder example
// Node objects are immutable
// Also immutable are: properties, attributes, children, terminals, and any arrays
// Immutable trees can be cached as valid with regard to a particular grammar!
const freeze = (node) => Object.freeze(Object.seal(node));
// Helpers to make the following code less verbose
let t = {
token: (type, str, attributes) => t.node(type, [t.str([str])], {}, attributes),
node: (type, children, properties, attributes) =>
freeze({
@conartist6
conartist6 / index.jsonc
Last active October 5, 2023 15:54
@bablr/boot sample instruction AST
// eat(<| Token 'foo' |>
{
"tagName": {
"language": "Instruction",
"type": "Call"
},
"children": [
{
"type": "Reference",
"value": "verb"
@conartist6
conartist6 / cstml.cstml
Last active September 9, 2023 13:53
Proposal: tagType.parser
<!docype cstml>
<!parsers>
<CSTML "https://url/to/grammar"/>
<Regex "https://url/to/re/grammar"/>
</>
<CSTML:TokenTag [Tag]>
<| Punctuator "<|" balanced="|>" startSpan="Tag" |>
<Identifier path="tagName">
<| Identifier "ID" |>
</>
@conartist6
conartist6 / cstml.js
Last active September 18, 2023 00:39
CSTML BABLR grammar (will run with https://github.com/bablr-lang/bablr-vm)
/*
This file contains a formal grammar defined by yielding instructions to a state machine.
The grammar is extensible, because you can always wrap it in a higher-order grammar!
Formally the system is a VM exectuting an https://en.wikipedia.org/wiki/Earley_parser
The VM is not yet sufficiently finished to execute this grammar, but it soon will be.
Usage will be:
```js
import { parse } from 'cst-tokens';
@conartist6
conartist6 / bracket.txt
Created May 2, 2023 14:59
Battlebots Bracket 2023
(1) MINOTAUR RIPTIDE (2)
(32) FUSION SHATTER! (31)
MINOTAUR RIPTIDE
SWITCHBACK HYPERSHOCK
(16) SWITCHBACK LUCKY (15)
(17) MALICE HYPERSHOCK (18)
MINOTAUR RIPTIDE
COBALT TANTRUM
(8) SAWBLAZE END GAME (7)
(25) BLIP TANTRUM (26)
@conartist6
conartist6 / resume-ish.md
Last active April 2, 2023 15:38
A brief description of me

Who am I?

I am Conrad Buck (also known as conartist6): a software engineer, open source maintainer, and currently full time self-employed inventor.

I specialize in the creation of tools and platforms, with a particular attention to human factors both in the process of software develpment and in the way software affects the lives of the people who use it. I have an abiding love of all things playful, and see deep symmetry between the artistic, scientific, and engineering processes. I am a private pilot.

My history

Between the 2012 and 2020 I was a Frontend Engineer based in San Francisco, where I worked for MyVR, Spruce Media, Switchfly, VMWare, Facebook, and Plangrid (departed due to pandemic). I have most (-.5 credits) of a Bachelor of Arts in Computer Science degree from Bucknell University. A full accounting of this history is on [LinkedIn](https://www.linkedin.com/i

@conartist6
conartist6 / index.md
Last active March 16, 2023 15:55
cst-tokens internal data stucture
  A range is represented as a [Token, Token] tuple.

  A range can only be iterated backwards, which creates the need to store tokens in an array!

  Each node must have its own tokens array to enable efficient editing.

  A context object often abbreviated `ctx` holds WeakMaps, including `paths` and `previousTokens`.

  Tokens reference their preceding token using the `previousTokens` WeakMap.
@conartist6
conartist6 / index.js
Last active March 1, 2023 19:33
cst-tokens grammar snippet
import { prod, tok, sym, Grammar } from '@/helpers';
new Grammar({
productions: {
// This version of ImportSpecifier uses helpers to be concise:
*ImportSpecifier() {
yield eat(prod`Identifier:imported`);
yield eatMatch(tok`Keyword:as`, prod`Identifier:local`);
},
@conartist6
conartist6 / index.js
Last active January 28, 2023 00:00
ReadOnlyMap
const _ = Symbol('private');
class ReadOnlyMap {
constructor(map) {
this[_] = map;
}
static from(entries) {
return new ReadOnlyMap(new Map(entries));
}
@conartist6
conartist6 / ranges.js
Last active January 22, 2023 18:10
Tokenizer ranges
class Tokenizer {
constructor(source) {
this.source = source;
this.result = null; // result is a token, i.e. a stack of tokens
this.pathRangesByToken = new WeakMap();
this.prevTokensByToken = new WeakMap();
}
ownTokensFor(path) {
const { prevTokensByToken, pathRangesByToken } = this;