Experimenting with parser further.

This commit is contained in:
Joshua Bemenderfer
2022-11-13 09:50:23 -05:00
parent f7a37681de
commit e07e3a837c
5 changed files with 151 additions and 23 deletions

View File

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

View File

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

View File

@@ -45,6 +45,10 @@ export function useDocument (reader: Reader, indent: string = ' '): Document {
return lineData.line?.slice(lineData.offsetTail)
},
level () {
return lineData.level
},
async content (contentLevel = -1, lines: string[] = []): Promise<string> {
if (contentLevel === -1) contentLevel = lineData.level + 1