From 8acb914237fc39400338890fc3e01085f3823916 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 14 Feb 2023 01:16:45 +0300 Subject: [PATCH] cleanup... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 154 ------------------------------------------------ pwiki/parser.js | 132 ----------------------------------------- 2 files changed, 286 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index acd1948..73e9eba 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -267,7 +267,6 @@ object.Constructor('BasePage', { return this.store.delete(pwpath.relative(this.path, path)) }, __energetic: undefined, - //* XXX EXPERIMENTAL get energetic(){ return this.__energetic === true || ((this.actions @@ -280,24 +279,12 @@ object.Constructor('BasePage', { this.store.isEnergetic(this.path), function(res){ return !!res })) }, - /*/ // XXX ASYNC - get energetic(){ return async function(){ - return this.__energetic === true - || ((this.actions - && this.actions[this.name] - && !!this[ - this.actions[this.name] === true ? - this.name - : this.actions[this.name] ].energetic) - || !!await this.store.isEnergetic(this.path)) }.call(this) }, - //*/ set energetic(value){ this.__energetic = value }, // page data... // strict: undefined, - //* XXX EXPERIMENTAL get data(){ var that = this // direct actions... @@ -351,51 +338,6 @@ object.Constructor('BasePage', { return typeof(res) == 'function' ? res.bind(that) : res }) }) }, - /*/ // XXX ASYNC - get data(){ return (async function(){ - // direct actions... - if(this.actions - && this.actions[this.name]){ - var name = - this.actions[this.name] === true ? - this.name - : this.actions[this.name] - var args = this.args - var page = this.get('..', {args}) - var res = (this.isPattern - && !this.__energetic - && !page[name].energetic) ? - await page - .map(function(page){ - var res = page[name] - return typeof(res) == 'function' ? - res.bind(page.get(name, {args})) - : function(){ - return res } }) - : await page[name] - return typeof(res) == 'function' ? - res.bind(this) - : res instanceof Array ? - res - : function(){ - return res } } - - var that = this - // NOTE: we need to make sure each page gets the chance to handle - // its context (i.e. bind action to page).... - if(this.isPattern - // XXX ENERGETIC... - && !await this.energetic){ - return this - .map(function(page){ - return page.data }) } - // single page... - // XXX ENERGETIC... - var res = await this.store.get(this.path, !!this.strict, !!await this.energetic) - return typeof(res) == 'function' ? - res.bind(this) - : res }).call(this) }, - //*/ set data(value){ if(this.actions && this.actions[this.name]){ @@ -1815,7 +1757,6 @@ object.Constructor('Page', BasePage, { // and debugging, set comment it out to disable... //__debug_last_render_state: undefined, // XXX should this handle pattern paths??? - //* XXX EXPERIMENTAL parse: function(text, state){ var that = this return Promise.awaitOrRun( @@ -1840,30 +1781,6 @@ object.Constructor('Page', BasePage, { }), text, state) }) }, - /*/ // XXX ASYNC - parse: async function(text, state){ - var that = this - text = await text - // .parser() - if(arguments.length == 1 - && text instanceof Object - && !(text instanceof Array)){ - state = text - text = null } - state = state ?? {} - state.renderer = state.renderer ?? this - // this is here for debugging and introspection... - '__debug_last_render_state' in this - && (this.__debug_last_render_state = state) - // parse... - return this.__parser__.parse( - this.get('.', { - renderer: state.renderer, - args: this.args, - }), - text, - state) }, - //*/ // raw page text... // @@ -1871,7 +1788,6 @@ object.Constructor('Page', BasePage, { // NOTE: when matching multiple pages this will return a list... // // XXX revise how we handle .strict mode... - // XXX EXPERIMENTAL get raw(){ var that = this return Promise.awaitOrRun( @@ -1909,38 +1825,6 @@ object.Constructor('Page', BasePage, { .flat()) : data.text ) }, null) }, - /*/ // XXX ASYNC - get raw(){ return (async function(){ - var data = await this.data - // no data... - // NOTE: if we hit this it means that nothing was resolved, - // not even the System/NotFound page, i.e. something - // went really wrong... - // NOTE: in .strict mode this will explicitly fail and not try - // to recover... - if(data == null){ - if(!this.strict - && this.NOT_FOUND_ERROR){ - var msg = this.get(this.NOT_FOUND_ERROR) - if(await msg.match()){ - return msg.raw } } - // last resort... - throw new Error('NOT FOUND ERROR: '+ this.path) } - // get the data... - return ( - // action... - typeof(data) == 'function' ? - data() - // multiple matches... - : data instanceof Array ? - Promise.all(data - .map(function(d){ - return typeof(d) == 'function'? - d() - : d.text }) - .flat()) - : data.text )}).call(this) }, - //*/ set raw(value){ this.data = {text: value} }, //this.onTextUpdate(value) }, @@ -2010,8 +1894,6 @@ object.Constructor('Page', BasePage, { // ...currently they are rendered in the context of the page and // not in their own context... // XXX revise how we handle strict mode... - // - // XXX EXPERIMENTAL // XXX would be nice to be able to chain .awaitOrRun(..) calls instead // of nesting them like here... get text(){ @@ -2054,42 +1936,6 @@ object.Constructor('Page', BasePage, { depends, renderer: that, }) }) }) }, - /*/ // XXX ASYNC - get text(){ return (async function(){ - // strict mode -- break on non-existing pages... - if(this.strict - && !await this.resolve(true)){ - throw new Error('NOT FOUND ERROR: '+ this.location) } - - var path = pwpath.split(this.path) - ;(path.at(-1) ?? '')[0] == '_' - || path.push(this.PAGE_TEMPLATE) - var tpl = pwpath.join(path) - var tpl_name = path.pop() - //var tpl_name = path.at(-1) - - // get the template relative to the top most pattern... - tpl = await this.get(tpl).find(true) - if(!tpl){ - console.warn('UNKNOWN RENDER TEMPLATE: '+ tpl_name) - return this.get(this.NOT_FOUND_TEMPLATE_ERROR).parse() } - - var depends = this.depends = new Set([tpl]) - // do the parse... - // NOTE: we render the template in context of page... - return this - // NOTE: this.path can both contain a template and not, this - // normalizes it to the path up to the template path... - .get(path, {args: this.args}) - .parse( - this.get( - '/'+tpl, - {args: this.args}).raw, - { - depends, - renderer: this, - }) }).call(this) }, - //*/ set text(value){ this.data = {text: value} }, //this.onTextUpdate(value) }, diff --git a/pwiki/parser.js b/pwiki/parser.js index fbf9ce6..80d427d 100755 --- a/pwiki/parser.js +++ b/pwiki/parser.js @@ -461,7 +461,6 @@ module.BaseParser = { // an await of something does not fix the issue, we need to await // for something significant -- await this.parse('') works, while // await vars[name] does not -- to the contrary of the above example... - // XXX EXPERIMENTAL -- this seems to be slower than the original version... expand: function(page, ast, state={}){ var that = this ast = ast == null ? @@ -519,67 +518,6 @@ module.BaseParser = { .replace(/=/g, '=') +'")')] }) .sync() }, - /*/ // XXX ASYNC - expand: async function*(page, ast, state={}){ - try{ - ast = ast == null ? - this.group(page, await page.raw ?? '') - : typeof(ast) != 'object' ? - this.group(page, ast) - : ast instanceof types.Generator ? - ast - : ast.iter() - - while(true){ - var {value, done} = ast.next() - if(done){ - return } - - // text block... - if(typeof(value) == 'string'){ - yield value - continue } - - // macro... - var {name, args, body} = value - // nested macro -- skip... - if(typeof(page.macros[name]) != 'function'){ - yield {...value, skip: true} - continue } - - var res = - await this.callMacro(page, name, args, body, state) - ?? '' - - // result... - if(res instanceof Array - || page.macros[name] instanceof types.Generator){ - yield* res - } else { - yield res } } - - // error... - }catch(err){ - console.error(err) - yield page.parse( - // XXX add line number and page path... - '@include("./ParseError' - +':path=' - // XXX use pwpath.encodeElem(..) ??? - + page.path - +':msg=' - + err.message - // quote html stuff... - .replace(/&/g, '&') - .replace(//g, '>') - // quote argument syntax... - .replace(/["']/g, function(c){ - return '%'+ c.charCodeAt().toString(16) }) - .replace(/:/g, ':') - .replace(/=/g, '=') - +'")') } }, - //*/ // recursively resolve and enumerate the ast... // @@ -596,7 +534,6 @@ module.BaseParser = { // NOTE: (..) is called in the context of page... // // XXX should this also resolve e.data??? - //* XXX EXPERIMENTAL... resolve: function(page, ast, state={}){ var that = this ast = ast @@ -635,37 +572,6 @@ module.BaseParser = { // keep the API consistently array-like... ast.iter() : ast }, - /*/ // XXX ASYNC - resolve: async function*(page, ast, state={}){ - ast = ast - ?? this.expand(page, null, state) - ast = typeof(ast) != 'object' ? - this.expand(page, ast, state) - : ast - - // NOTE: we need to await for ast here as we need stage 2 of - // parsing to happen AFTER everything else completes... - // XXX GENERATOR -- this breaks the parser... - // ...investigate the data flow... - //for await (var e of ast){ - for(var e of await ast){ - // expand delayed sections... - e = typeof(e) == 'function' ? - e.call(page, state) - : e - // expand arrays... - if(e instanceof Array - | e instanceof types.Generator){ - yield* this.resolve(page, e, state) - // data -- unwrap content... - } else if(e instanceof Object && 'data' in e){ - yield { data: await this.resolve(page, e.data, state) } - // skipped items... - } else if(e instanceof Object && e.skip){ - continue - } else { - yield e } } }, - //*/ // Fully parse a page... // @@ -687,7 +593,6 @@ module.BaseParser = { // a slot when loaded will replace the prior occurrences... // // XXX add a special filter to clear pending filters... (???) - //* XXX EXPERIMENTAL... parse: function(page, ast, state={}){ var that = this return this.resolve(page, ast, state) @@ -723,43 +628,6 @@ module.BaseParser = { : section ) }) .flat() .join('') }, - /*/ // XXX ASYNC - parse: async function(page, ast, state={}){ - var that = this - return await this.resolve(page, ast, state) - // filters... - .map(function(section){ - // normalize types... - section = - typeof(section) == 'number' ? - section + '' - : section == null ? - '' - : section - return ( - // expand section... - typeof(section) != 'string' ? - section.data - // global filters... - : state.filters ? - that.normalizeFilters(state.filters) - .reduce(function(res, filter){ - // unknown filter... - // NOTE: we try not to break on user errors - // if we can help it... - if(page.filters[filter] == null){ - console.warn( - '.parse(..): unsupported filter: '+ filter) - return res } - // NOTE: if a filter returns falsy then it - // will have no effect on the result... - return page.filters[filter].call(page, res) - ?? res }, section) - // no global filters... - : section ) }) - .flat() - .join('') }, - //*/ } var parser =