Push current progress so I can work on my laptop.

This commit is contained in:
Joshua Bemenderfer 2023-02-05 07:44:11 -05:00
parent 94767772b4
commit 657c95a4c1
28 changed files with 2372 additions and 3468 deletions

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "@terrace/repo",
"private": true,
"type": "module",
"scripts": {
"build:repo": "node ./repo/build.js",
"build": "turbo run build --cache-dir=.turbo",
"dev": "turbo run dev --no-cache --force",
"test": "turbo run test --no-cache --force"
},
"devDependencies": {
"@terrace/core": "workspace:*",
"turbo": "^1.7.3",
"jest": "^29.4.1"
}
}

View File

@ -1,5 +1,7 @@
#ifndef TERRACE_PARSER_H
#define TERRACE_PARSER_H
struct terrace_linedata_s {
char type;
unsigned int level;
unsigned int offsetHead;
unsigned int offsetTail;
@ -8,30 +10,19 @@ struct terrace_linedata_s {
typedef struct terrace_linedata_s terrace_linedata_t;
void terrace_parse_line(char* line, terrace_linedata_t *lineData) {
char type = 0;
unsigned int level = 0;
unsigned int offsetTail = 0;
if (line[0] == '\n') {
if (lineData->type == 1) level++;
if (lineData->type == 0) level = lineData->level;
lineData->type = type;
lineData->level = level;
// Reuse lineData->level from previous line.
lineData->offsetHead = 0;
lineData->offsetTail = 0;
} else {
type = 1;
unsigned int level = 0;
while (line[level] == ' ' && level <= lineData->level + 1) ++level;
lineData->type = type;
lineData->level = level;
lineData->offsetHead = level;
lineData->offsetTail = level;
while (line[lineData->offsetTail] != '\0' && line[lineData->offsetTail] != ' ') ++lineData->offsetTail;
}
lineData->type = type;
lineData->level = level;
lineData->offsetHead = level;
}
#endif

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 Joshua Michael Bemenderfer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,34 +0,0 @@
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
export default function (config) {
return async function ({ lineData, ended, next }) {
if (ended) return ''
const blockLevel = lineData.level
let md = ''
function finalize() {
return unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.process(md)
}
async function markdownContents({ line, lineData, ended }) {
if (ended || lineData.level <= blockLevel) {
const final = String(await finalize())
return final
}
md += line.slice(blockLevel + 1) + '\n'
return markdownContents(await next())
}
return markdownContents(await next())
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
{
"name": "@terrace/block-markdown",
"type": "module",
"version": "0.0.1",
"main": "./index.js",
"scripts": {
"test": "vitest"
},
"devDependencies": {
"vitest": "^0.24.5"
},
"dependencies": {
"rehype-stringify": "^9.0.3",
"remark-parse": "^10.0.1",
"remark-rehype": "^10.1.0",
"unified": "^10.1.2"
}
}

View File

@ -1 +1 @@
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./parser.cjs");function f(r,c=" "){const e=i.createLineData("",c);let n=!1;async function o(t=-1){if(n)n=!1;else{const a=await r.next();if(a===null)return!1;e.line=a,i.parseLine(e)}return l()<=t?(n=!0,!1):!0}const l=()=>e.level,u=(t=e.offsetHead)=>e.line.slice(t),s=()=>e.line.slice(e.offsetHead,e.offsetTail);return{next:o,level:l,line:u,head:s,tail:()=>e.line.slice(e.offsetTail),match:t=>t===s()}}exports.useDocument=f;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./parser.cjs");function f(r,c=" "){const e=i.createLineData("",c);let n=!1;async function o(t=-1){if(n)n=!1;else{const a=await r();if(a==null)return!1;e.line=a,i.parseLine(e)}return l()<=t?(n=!0,!1):!0}const l=()=>e.level,u=(t=e.offsetHead)=>e.line.slice(t),s=()=>e.line.slice(e.offsetHead,e.offsetTail);return{next:o,level:l,line:u,head:s,tail:()=>e.line.slice(e.offsetTail),match:t=>t===s()}}exports.useDocument=f;

View File

@ -6,8 +6,8 @@ function h(s, f = " ") {
if (n)
n = !1;
else {
const i = await s.next();
if (i === null)
const i = await s();
if (i == null)
return !1;
e.line = i, r(e);
}

View File

@ -1 +1 @@
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function t(e="",r=" "){return{line:e,indent:r,level:0,offsetHead:0,offsetTail:0}}function f(e){if(typeof e!="object"||!e||typeof e.level!="number")throw new Error("'lineData' must be an object with 'line' string, and 'type' and 'level' integer properties");if(typeof e.indent!="string"||e.indent.length===0||e.indent.length>1)throw new Error("'lineData.indent' must be a single-character string");if(typeof e.line!="string")throw new Error("'lineData.line' must be a string");let r=0;if(!e.line.length)e.level=e.level,e.offsetHead=0,e.offsetTail=0;else{for(;e.line[r]===e.indent&&r<=e.level+1;)++r;for(e.level=r,e.offsetHead=r,e.offsetTail=r;e.line[e.offsetTail]&&e.line[e.offsetTail]!==" ";)++e.offsetTail}return e}exports.createLineData=t;exports.parseLine=f;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function t(e="",r=" "){return{line:e,indent:r,level:0,offsetHead:0,offsetTail:0}}function f(e){if(typeof e!="object"||!e||typeof e.level!="number")throw new Error("'lineData' must be an object with string line and numeric level properties");if(typeof e.indent!="string"||e.indent.length===0||e.indent.length>1)throw new Error("'lineData.indent' must be a single-character string");if(typeof e.line!="string")throw new Error("'lineData.line' must be a string");let r=0;if(!e.line.length)e.level=e.level,e.offsetHead=0,e.offsetTail=0;else{for(;e.line[r]===e.indent&&r<=e.level+1;)++r;for(e.level=r,e.offsetHead=r,e.offsetTail=r;e.line[e.offsetTail]&&e.line[e.offsetTail]!==" ";)++e.offsetTail}return e}exports.createLineData=t;exports.parseLine=f;

View File

@ -1,9 +1,9 @@
function f(e = "", r = " ") {
return { line: e, indent: r, level: 0, offsetHead: 0, offsetTail: 0 };
}
function t(e) {
function o(e) {
if (typeof e != "object" || !e || typeof e.level != "number")
throw new Error("'lineData' must be an object with 'line' string, and 'type' and 'level' integer properties");
throw new Error("'lineData' must be an object with string line and numeric level properties");
if (typeof e.indent != "string" || e.indent.length === 0 || e.indent.length > 1)
throw new Error("'lineData.indent' must be a single-character string");
if (typeof e.line != "string")
@ -21,5 +21,5 @@ function t(e) {
}
export {
f as createLineData,
t as parseLine
o as parseLine
};

View File

@ -1,2 +1,2 @@
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function i(r,n=0){const t=Array.isArray(r)?r:r.split(`
`),e={index:n-1,next:()=>(e.index++,e.index>=t.length?null:t[e.index]),clone:l=>i(r,l==null?n:e.index)};return e}exports.createStringReader=i;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function n(r,e=0){const t=Array.isArray(r)?r:r.split(`
`);return e--,()=>(e++,e>=t.length?null:t[e])}exports.createStringReader=n;

View File

@ -1,12 +1,8 @@
function l(e, r = 0) {
const t = Array.isArray(e) ? e : e.split(`
`), n = {
index: r - 1,
next: () => (n.index++, n.index >= t.length ? null : t[n.index]),
clone: (i) => l(e, i == null ? r : n.index)
};
return n;
function e(t, r = 0) {
const n = Array.isArray(t) ? t : t.split(`
`);
return r--, () => (r++, r >= n.length ? null : n[r]);
}
export {
l as createStringReader
e as createStringReader
};

View File

@ -1 +1 @@
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={};function r(t){const a=e.createInterface({input:e.createReadStream(t,"utf-8")})[Symbol.asyncIterator]();return async()=>(await a.next()).value}exports.createReadlineReader=r;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("node:fs"),n=require("node:readline/promises"),t=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},o=t(r),u=t(n);function d(e){const a=u.default.createInterface({input:o.default.createReadStream(e,"utf-8")})[Symbol.asyncIterator]();return async()=>(await a.next()).value}exports.createReadlineReader=d;

View File

@ -1,10 +1,11 @@
const e = {};
function n(t) {
const a = e.createInterface({
input: e.createReadStream(t, "utf-8")
import r from "node:fs";
import a from "node:readline/promises";
function c(e) {
const t = a.createInterface({
input: r.createReadStream(e, "utf-8")
})[Symbol.asyncIterator]();
return async () => (await a.next()).value;
return async () => (await t.next()).value;
}
export {
n as createReadlineReader
c as createReadlineReader
};

View File

@ -20,9 +20,9 @@ export function useDocument (reader: Reader, indent: string = ' '): Document {
if (repeat) repeat = false
// Otherwise parse the line normally.
else {
const line = await reader.next()
const line = await reader()
// If there are no more lines, bail out.
if (line === null) return false
if (line == null) return false
lineData.line = line
parseLine(lineData)

View File

@ -3,15 +3,11 @@ import type { Reader } from './reader'
export function createStringReader(doc: string|string[], index = 0): Reader {
const lines = Array.isArray(doc) ? doc : doc.split('\n')
const reader = {
index: index - 1,
next: () => {
reader.index++
if (reader.index >= lines.length) return null
return lines[reader.index]
},
clone: (startIndex?: number) => createStringReader(doc, startIndex == null ? index : reader.index)
}
index--;
return reader
return () => {
index++
if (index >= lines.length) return null
return lines[index]
}
}

View File

@ -1,7 +1,8 @@
import fs from 'node:fs'
import readline from 'node:readline/promises'
import type { Reader } from './reader'
export function createReadlineReader(path: string): () => Promise<string|null> {
export function createReadlineReader(path: string): Reader {
const it = readline.createInterface({
input: fs.createReadStream(path, 'utf-8'),
})[Symbol.asyncIterator]()

View File

@ -1,5 +1 @@
export type Reader = {
index: number,
next: () => string|null|Promise<string|null>,
clone: (startIndex?: number) => Reader
}
export type Reader = () => string|null|Promise<string|null>

View File

@ -12,6 +12,12 @@ export default defineConfig({
'readers/js-string': 'src/readers/js-string.ts',
'readers/node-readline': 'src/readers/node-readline.ts',
}
},
rollupOptions: {
external: [
`node:fs`,
`node:readline/promises`
]
}
}
})

2662
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
packages:
- "./test"
- "./packages/js/*"
- "./experiments/*"

69
repo/build.js Normal file
View File

@ -0,0 +1,69 @@
import fs from 'node:fs/promises'
import { useDocument } from '@terrace/core'
import { createReadlineReader } from '@terrace/core/readers/node-readline'
function useHelpers({ next, level, head, tail }) {
async function kvObject(handleValue) {
const object = {}
const rootLevel = level()
while (await next(rootLevel)) {
if (!head()) continue
object[head()] = handleValue ? await handleValue(level()) : tail().trim()
}
return object
}
return { kvObject }
}
async function buildPackage() {
const { next, level, head, tail, match } = useDocument(createReadlineReader('./repo/package.tce'))
const { kvObject } = useHelpers({ next, level, head, tail })
const pkg = {}
while (await next()) {
if (match('name')) pkg.name = tail().trim()
if (match('version')) pkg.version = tail().trim()
if (match('license')) pkg.license = tail().trim()
if (match('type')) pkg.type = tail().trim()
if (match('private')) pkg.private = tail().trim() === 'true'
if (match('scripts')) pkg.scripts = await kvObject()
if (match('devDependencies')) pkg.devDependencies = await kvObject()
}
await fs.writeFile('./package.json', JSON.stringify(pkg, null, ' '))
}
async function buildTurbo() {
const { next, level, head, tail, match } = useDocument(createReadlineReader('./repo/turbo.tce'))
const { kvObject } = useHelpers({ next, level, head, tail })
const turbo = {}
while (await next()) {
if (match('#schema')) turbo['$schema'] = tail().trim()
if (match('pipeline')) turbo.pipeline = await (async () => {
const pipeline = {}
const rootLevel = level()
while (await next(rootLevel)) {
if (!head()) continue
const entry = pipeline[head()] = {}
const pipelineLevel = level()
while(await next(pipelineLevel)) {
if (match('dependsOn')) entry.dependsOn = tail().trim().split(' ')
if (match('outputs')) entry.outputs = tail().trim().split(' ')
}
}
return pipeline
})()
}
await fs.writeFile('./turbo.json', JSON.stringify(turbo, null, ' '))
}
buildPackage()
buildTurbo()

16
repo/package.tce Normal file
View File

@ -0,0 +1,16 @@
#schema package
name @terrace/repo
private true
type module
scripts
build:repo node ./repo/build.js
build turbo run build --cache-dir=.turbo
dev turbo run dev --no-cache --force
test turbo run test --no-cache --force
devDependencies
@terrace/core workspace:*
turbo ^1.7.3
jest ^29.4.1

12
repo/turbo.tce Normal file
View File

@ -0,0 +1,12 @@
#schema https://turbo.build/schema.json
pipeline
compile
dev
build
dependsOn ^build compile
outputs dist/**
test
dependsOn build

7
test/basic.test.tce Normal file
View File

@ -0,0 +1,7 @@
#schema test
input
key value
output
level: 0 | head: key | tail: value | line: key value

10
test/package.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "@terrace/test",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
},
"dependencies": {
"@terrace/core": "workspace:*"
}
}

36
test/test-runner.test.js Normal file
View File

@ -0,0 +1,36 @@
import { expect } from 'chai'
import fs from 'node:fs/promises'
import { useDocument } from '@terrace/core'
import { createReadlineReader } from '@terrace/core/readers/node-readline'
async function loadTest(path) {
const { next, level, head, tail, line, match } = useDocument(createReadlineReader(path))
const test = { input: [], output: [] }
while (await next()) {
if (match('input')) {
const rootLevel = level()
while (await next(rootLevel)) {
test.input.push(line(rootLevel))
}
}
if (match('output')) {
const rootLevel = level()
while (await next(rootLevel)) {
test.input.push(line(rootLevel))
}
}
}
return { input: test.input.join('\n'), output: test.output.join('\n') }
}
it('Runs a basic test', async () => {
const { input, output } = await loadTest('./basic.test.tce', 'utf-8')
console.log(input)
expect(1).to.equal(1)
})

21
turbo.json Normal file
View File

@ -0,0 +1,21 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"compile": {},
"dev": {},
"build": {
"dependsOn": [
"^build",
"compile"
],
"outputs": [
"dist/**"
]
},
"test": {
"dependsOn": [
"build"
]
}
}
}