Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

View GitHub Profile
@conartist6
conartist6 / index.md
Last active September 7, 2024 20:19
Semver-0 proposal

0-based Semantic Versioning 0.0.0

Summary

0-based semver is a valid subset of Semver 2.0.0 where version numbers look like (for example) 0.24.1. 0-based semver also uses this specification to govern its own versions.

Given a triplet version number in the format X.Y.Z:

  1. X must always be 0
  2. The first initial development version of a package should be 0.0.1
@conartist6
conartist6 / index.js
Created August 22, 2024 15:53
Grammar no-compile example
import { i, re } from '@bablr/boot';
import { buildNumber } from '@bablr/agast-vm-helpers';
import * as Space from '@bablr/language-en-blank-space';
export const dependencies = { Space };
export function* eatMatchTrivia() {
if (yield i`match(/[ \t\r\n]/)`) {
return yield i`eat(<#*Space:Space>)`;
@conartist6
conartist6 / index.js
Last active August 13, 2024 20:54
JSON grammar with hoisting
import { readFileSync } from 'node:fs';
import { streamParse, Context, AgastContext } from 'bablr/enhanceable';
import { evaluateReturnAsync } from '@bablr/agast-helpers/tree';
import * as language from './z_2.json.grammar.fast.js';
import { buildFullyQualifiedSpamMatcher } from '@bablr/agast-vm-helpers';
const input = readFileSync(`${import.meta.dirname}/z_3_fixture.json`, 'utf-8');
const matcher = buildFullyQualifiedSpamMatcher({}, language.canonicalURL, 'Expression');
const ctx = Context.from(AgastContext.create(), language);
@conartist6
conartist6 / index.cstml
Last active August 5, 2024 15:48
CSTML JSON example: [1, true, "3"]
<!0:cstml bablr-language='https://github.com/bablr-lang/language-json'>
<>
<Array>
openToken:
<~*Punctuator '[' balanced=']' />
elements[]:
<Number span='Number'>
wholePart:
<Integer>
digits[]:
@conartist6
conartist6 / index.js
Last active July 23, 2024 03:02
BABLR for globbing mockup (public domain)
import { test as nonbacktrackingTest } from '@bablr/regex-vm';
import * as bablrLanguage from '@bablr/language-regex-vm-pattern';
import { buildTag } from 'bablr';
import { printCSTML } from '@bablr/agast-helpers/tree';
const re = buildTag(bablrLanguage, 'Pattern');
const weakMemo = (fn) => {
const cache = new WeakMap();
return (arg) => {
@conartist6
conartist6 / index.cstml
Last active October 25, 2024 12:16
Lithuanian CSTML for [1, 2, 3] courtesy of auris
<!0:cstml bablr-language='https://github.com/bablr-lang/language-json'>
<>
<Masyvas>
atidarymoŽymė:
<~*SkiriamasisŽenklas '[' atitinkantis=']' />
<#*Tarpas:Tarpas>
'\n '
</>
elementai[]: []
elementai[]:
@conartist6
conartist6 / 01.index.js
Last active May 20, 2024 02:51
Concurrent buffering
// Utils
const buildDeferred = () => {
const d = {};
d.promise = new Promise((resolve, reject) => {
d.resolve = resolve;
d.reject = reject;
});
return d;
}
@conartist6
conartist6 / index.js
Created May 11, 2024 15:23
StreamIterable
export const getStreamIterator = (obj) => {
return obj[Symbol.for('@@streamIterator')]?.() || obj[Symbol.iterator]?.();
};
export class SyncGenerator {
constructor(embeddedGenerator) {
if (!embeddedGenerator.next) throw new Error();
this.generator = embeddedGenerator;
@conartist6
conartist6 / index.js
Last active May 3, 2024 14:48
Recursive generator VM example
const arrayLast = arr => arr[arr.length - 1];
const { toString } = Object.prototype;
const isGenerator = val => toString.call(val) === '[object Generator]';
const cache = new Map();
function *fibonacci(n) {
let value;
if (cache.has(n)) return cache.get(n);
@conartist6
conartist6 / 01.formatted.log
Created April 14, 2024 13:22
CSTML input stream processing
conartist6@hq bablr-cli % echo '"eat()"' | node bin/index.js -l @bablr/language-bablr-vm-instruction -p Call -f
<!cstml 'https://github.com/bablr-lang/language-bablr-vm-instruction'>
<>
<Call>
callee:
<*Identifier>
'eat'
</>
arguments:
<Tuple>