brute-force-fixed the issue, not yet happy with the code...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2026-07-05 21:11:44 +03:00
parent a59ddf61a9
commit c7be62a48f

View File

@ -730,7 +730,17 @@ module.BaseParser = {
// resolve stage II macros and merge results... // resolve stage II macros and merge results...
// //
// XXX DNF // <ast> ::= [ <item>, ... ]
// <item> ::=
// <basic-value>
// | <elem>
//
// <elem> is returned if its value is not resolved yet.
//
//
// NOTE: to fully resolve the ast this may need to be called several
// times...
//
// //
// XXX these yeild different results: // XXX these yeild different results:
// r = parser.resolve( // r = parser.resolve(
@ -769,9 +779,9 @@ module.BaseParser = {
// exec stage II macros... // exec stage II macros...
if(typeof(elem.value) == 'function'){ if(typeof(elem.value) == 'function'){
let e = elem let e = elem
// NOTE: if not everything is resolved, delay the stage II
// callbacks till .wait is done...
Promise.awaitOrRun( Promise.awaitOrRun(
// if not everything is resolved, delay the stage II
// callbacks till .wait is done...
state.wait, state.wait,
function(){ function(){
return elem = e.value = return elem = e.value =
@ -791,25 +801,23 @@ module.BaseParser = {
continue } continue }
// expand ast... // expand ast...
if(elem instanceof Array){ if(elem instanceof Array){
// XXX this can be or containe promises...
elems.push(...that.resolve(page, elem, state)) elems.push(...that.resolve(page, elem, state))
continue } continue }
// expand .body attribute...
/* XXX is this needed here???
if(elem.body instanceof Array){
console.warn('!!! RESOLVE_BODY')
// XXX this can be or containe promises...
elem.body = that.resolve(page, elem.body, state) }
//*/
// nested macro with no value set -- skip... // nested macro with no value set -- skip...
if(that.macros[elem.name] instanceof Array){ if(that.macros[elem.name] instanceof Array){
continue } continue }
// unresolved... //* XXX unresolved...
;(state.unresolved ??= [])
.push(elem.resolving instanceof Promise ?
elem.resolving
: elem)
//*/
// NOTE: we do not need to expand .body attributes as these
// are the responsibility of the respective macros...
elems.push(elem) } elems.push(elem) }
return elems }, return elems },
// XXX render api... // XXX render api...
// XXX how should this play with filters??? // XXX how should this play with filters???
// ...should filters be client-side only?? // ...should filters be client-side only??
@ -817,18 +825,37 @@ module.BaseParser = {
// XXX // XXX
}, },
// XXX
parse: function(page, ast, state={}, nested_handlers={}, wait='wait'){ parse: function(page, ast, state={}, nested_handlers={}, wait='wait'){
var that = this var that = this
var reresolve = !!state.wait // XXX might be a good idea to limit recursion depth here...
var merge = function(ast){
return Promise.awaitOrRun(
...state.unresolved,
function(){
delete state.unresolved
// re-resolve...
ast = that.resolve(page, ast, state, nested_handlers)
return state.unresolved ?
merge(ast)
: (ast ?? '').join('') }) }
return Promise.awaitOrRun( return Promise.awaitOrRun(
this.resolve(page, ast, state, nested_handlers), this.resolve(page, ast, state, nested_handlers),
state[wait], state[wait],
function(ast, reresolve){ function(ast){
ast = reresolve ? // NOTE: since we are waiting for state[wait], state.unresolved
that.resolve(page, ast, state, nested_handlers) // might get cleaned out by this point so we need to check
: ast // manually...
return (ast ?? '').join('') }) }, for(var e of ast){
if(typeof(e) == 'object'){
state.unresolved = []
break } }
return state.unresolved ?
merge(ast)
: (ast ?? '').join('') }) },
// XXX how should this play with filters??? // XXX how should this play with filters???
// ...should filters be client-side only?? // ...should filters be client-side only??
parseNested: function(page, ast, state={}, nested_handlers={}){ parseNested: function(page, ast, state={}, nested_handlers={}){
@ -1335,19 +1362,21 @@ module.parser = {
// XXX check cache??? // XXX check cache???
var nested
var res = args.isolated ? var res = args.isolated ?
this.resolve( this.resolve(
page, page,
text, text,
args.isolated == 'partial' ? nested = args.isolated == 'partial' ?
serialize.partialDeepCopy(state) serialize.partialDeepCopy(state)
: {}) : {})
: this.expand(page, text, state) : this.expand(page, text, state)
// handle recursion...
Promise.awaitOrRun( Promise.awaitOrRun(
(nested ?? {}).waitAll,
state.waitAll, state.waitAll,
function(){ function(){
// handle recursion...
state.include_stack.at(-1) == src state.include_stack.at(-1) == src
&& state.include_stack.pop() && state.include_stack.pop()
// cleanup... // cleanup...