New implementation of v3, should be more foolproof with simpler schemas.

This commit is contained in:
Joshua Bemenderfer
2023-01-28 22:24:44 -05:00
parent 14cc34f32e
commit ef3c59fb74
5 changed files with 157 additions and 93 deletions

View File

@@ -1,2 +1 @@
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./parser.cjs");function a(l,u=" "){let r=s.createLineData(null,u);const t={ended:!1,clone(){return a(l.clone(),u)},async next(){if(r.line=await l.next(),r.line===null)return!0;s.parseLine(r)},current(){return t},line(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetHead)},head(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetHead,r.offsetTail)},tail(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetTail)},level(){return r.level},async content(e=-1,n=[]){var i;return e===-1&&(e=r.level+1),await t.next()||r.level<e?n.join(`
`):(n.push(((i=r.line)==null?void 0:i.slice(e))||""),t.content(e,n))},async seek(e,n=-1){return n===-1&&(n=r.level),await t.next()?!1:t.head()===e?t:r.level<n?!1:t.seek(e,n)}};return t}exports.useDocument=a;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./parser.cjs");function a(l,u=" "){let r=s.createLineData(null,u);const t={ended:!1,clone(){return a(l.clone(),u)},async next(){if(r.line=await l.next(),r.line===null)return!0;s.parseLine(r)},current(){return t},line(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetHead)},head(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetHead,r.offsetTail)},tail(){var e;return(e=r.line)==null?void 0:e.slice(r.offsetTail)},level(){return r.level},async content(e=-1,n=[]){var i;return e===-1&&(e=r.level+1),await t.next()||r.level<e?n:(n.push(((i=r.line)==null?void 0:i.slice(e))||""),t.content(e,n))},async seek(e,n=-1){return n===-1&&(n=r.level),await t.next()?!1:t.head()===e?t:r.level<n?!1:t.seek(e,n)}};return t}exports.useDocument=a;

View File

@@ -1,41 +1,40 @@
import { parseLine as f, createLineData as s } from "./parser.js";
function d(i, l = " ") {
let n = s(null, l);
function d(l, i = " ") {
let r = s(null, i);
const t = {
ended: !1,
clone() {
return d(i.clone(), l);
return d(l.clone(), i);
},
async next() {
if (n.line = await i.next(), n.line === null)
if (r.line = await l.next(), r.line === null)
return !0;
f(n);
f(r);
},
current() {
return t;
},
line() {
var e;
return (e = n.line) == null ? void 0 : e.slice(n.offsetHead);
return (e = r.line) == null ? void 0 : e.slice(r.offsetHead);
},
head() {
var e;
return (e = n.line) == null ? void 0 : e.slice(n.offsetHead, n.offsetTail);
return (e = r.line) == null ? void 0 : e.slice(r.offsetHead, r.offsetTail);
},
tail() {
var e;
return (e = n.line) == null ? void 0 : e.slice(n.offsetTail);
return (e = r.line) == null ? void 0 : e.slice(r.offsetTail);
},
level() {
return n.level;
return r.level;
},
async content(e = -1, r = []) {
async content(e = -1, n = []) {
var u;
return e === -1 && (e = n.level + 1), await t.next() || n.level < e ? r.join(`
`) : (r.push(((u = n.line) == null ? void 0 : u.slice(e)) || ""), t.content(e, r));
return e === -1 && (e = r.level + 1), await t.next() || r.level < e ? n : (n.push(((u = r.line) == null ? void 0 : u.slice(e)) || ""), t.content(e, n));
},
async seek(e, r = -1) {
return r === -1 && (r = n.level), await t.next() ? !1 : t.head() === e ? t : n.level < r ? !1 : t.seek(e, r);
async seek(e, n = -1) {
return n === -1 && (n = r.level), await t.next() ? !1 : t.head() === e ? t : r.level < n ? !1 : t.seek(e, n);
}
};
return t;

View File

@@ -49,13 +49,13 @@ export function useDocument (reader: Reader, indent: string = ' '): Document {
return lineData.level
},
async content (contentLevel = -1, lines: string[] = []): Promise<string> {
async content (contentLevel = -1, lines: string[] = []): Promise<Array<string>> {
if (contentLevel === -1) contentLevel = lineData.level + 1
const ended = await document.next()
if (ended) return lines.join('\n')
if (ended) return lines
if (lineData.level < contentLevel) return lines.join('\n')
if (lineData.level < contentLevel) return lines
lines.push(lineData.line?.slice(contentLevel) || '')
return document.content(contentLevel, lines)