Skip to content

Instantly share code, notes, and snippets.

View conartist6's full-sized avatar

Conrad Buck conartist6

View GitHub Profile
@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>
@conartist6
conartist6 / 01.script.js
Last active April 9, 2024 15:53
Successful BABLR template tag embedding
import * as language from '@bablr/language-cstml';
import { buildTag } from 'bablr/enhanceable';
const cstml = buildTag(language, 'Expression');
const tree = cstml`<> ${cstml`<*Word>${cstml`'ok'`}</>`} </>`;
@conartist6
conartist6 / 01.input.cstml
Last active April 1, 2024 17:28
Successful BABLR VM run with language embedding
<> </>
Input: `<> </>`
@conartist6
conartist6 / 0.input.cstml
Last active March 14, 2024 03:56
BABLR two-VM parse log
<></>
@conartist6
conartist6 / index.md
Last active November 29, 2023 15:10
agAST

What is agAST?

agAST is a generalized AST format for javascript. It is the format created for and used by the BABLR VM. It is meant to specify basic aspects of how tools store programs, so that common tools can be used to work on programs written in any programming language.

agAST is meant to be the successor to the existing ESTree specification. Unlike ESTree, agAST has no language-specific opinions.

agAST trees are made up of nodes of the following shape:

let node = {
@conartist6
conartist6 / parse-trampoline.js
Created November 10, 2023 18:35
BABLR-VM minimal parse trampoline
import { buildExpression, effectsFor } from './utils/instruction.js';
import { getCooked } from './utils/token.js';
import { Match } from './match.js';
import { Context } from './context.js';
import { Source } from './source.js';
import { runSync } from './run.js';
import { dispatcher } from './dispatcher.js';
import { transformTokenMatcher } from './transforms.generated.js';
const defer = Symbol('defer');
@conartist6
conartist6 / isobench.js
Created November 3, 2023 16:24
Iterator benchmark
import { IsoBench } from 'iso-bench';
const range = max => ({
*[Symbol.iterator]() {
for (let i = 0; i < max; i++) yield i;
}
});
globalThis.i = 0;
@conartist6
conartist6 / index.js
Last active October 22, 2023 15:17
Private/readonly class properties with weak maps
// To keep the data truly private, just don't export these
const privateMaps = {
secret: new WeakMap(),
constant: new WeakMap(),
}
export class Test {
constructor(secret, constant) {
privateMaps.secret.set(this, secret);
privateMaps.constant.set(this, constant);
@conartist6
conartist6 / index.js
Last active October 13, 2023 16:01
Prettier agAST 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!
let freeze = (node) => Object.freeze(Object.seal(node));
// Helpers for constructing agAST trees
let t = {
// Tokens are really just nodes with non-ref children
token: (type, str, attributes = {}) => t.node(type, [t.str([str])], {}, attributes),
node: (type, children = [], properties = {}, attributes = {}) =>