mirror of
https://github.com/flynx/pWiki.git
synced 2026-08-24 08:16:43 +00:00
notes... still planning...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
deb2502f28
commit
1411a2cf6d
@ -664,12 +664,18 @@ module.BaseParser = {
|
|||||||
// - state.__proto__ - protorype
|
// - state.__proto__ - protorype
|
||||||
// ...technically need a way to call .exec(..) and wait
|
// ...technically need a way to call .exec(..) and wait
|
||||||
// for the correct promise from inside a macro...
|
// for the correct promise from inside a macro...
|
||||||
/* XXX LOCAL_STATE
|
//* XXX LOCAL_STATE
|
||||||
// XXX think this is the best way to go, but needs the rest
|
// XXX think this is the best way to go, but needs the rest
|
||||||
// of the code refactored + still need to experiment...
|
// of the code refactored + still need to experiment...
|
||||||
|
// XXX part of the problem is that this mechanism is not used
|
||||||
|
// later (.resolve(..) and .finalize(..)) which creates
|
||||||
|
// the same sync problems there too -- need to unify
|
||||||
|
// both mechanisms...
|
||||||
var res = that.callMacro( page, name, args, body, {
|
var res = that.callMacro( page, name, args, body, {
|
||||||
|
// global state...
|
||||||
__proto__: state,
|
__proto__: state,
|
||||||
state,
|
state,
|
||||||
|
// local state...
|
||||||
waitAll: state.waitAll,
|
waitAll: state.waitAll,
|
||||||
waitNested: state.waitNested,
|
waitNested: state.waitNested,
|
||||||
})
|
})
|
||||||
@ -769,6 +775,9 @@ module.BaseParser = {
|
|||||||
ast
|
ast
|
||||||
: ast.iter()
|
: ast.iter()
|
||||||
|
|
||||||
|
// XXX LOCAL_STATE
|
||||||
|
//state.unresolved = []
|
||||||
|
|
||||||
// merge resolved elements into the last item of elems...
|
// merge resolved elements into the last item of elems...
|
||||||
var elems = []
|
var elems = []
|
||||||
for(var elem of ast){
|
for(var elem of ast){
|
||||||
@ -805,7 +814,7 @@ module.BaseParser = {
|
|||||||
// 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 }
|
||||||
;(state.unresolved ??= [])
|
state.unresolved
|
||||||
.push(elem.resolving instanceof Promise ?
|
.push(elem.resolving instanceof Promise ?
|
||||||
elem.resolving
|
elem.resolving
|
||||||
: elem)
|
: elem)
|
||||||
@ -865,12 +874,16 @@ module.BaseParser = {
|
|||||||
ast = this.resolve(page, ast, state, nested_handlers)
|
ast = this.resolve(page, ast, state, nested_handlers)
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
|
// XXX do we actually need to wait here???
|
||||||
|
// ...each macro should already be waiting...
|
||||||
...[state[wait]].flat(),
|
...[state[wait]].flat(),
|
||||||
function(){
|
function(){
|
||||||
// NOTE: in an async world where any promised macro can
|
// NOTE: in an async world where any promised macro can
|
||||||
// call .exec(..) / .execNested(..) we can't trust
|
// call .exec(..) / .execNested(..) we can't trust
|
||||||
// the lack of .unresolved in state...
|
// the lack of .unresolved in state...
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
|
// XXX LOCAL_STATE if we are nested we should not wait
|
||||||
|
// for anything after the caller...
|
||||||
(state.unresolved
|
(state.unresolved
|
||||||
|| !that.isResolved(ast)) ?
|
|| !that.isResolved(ast)) ?
|
||||||
resolve(ast)
|
resolve(ast)
|
||||||
@ -890,6 +903,8 @@ module.BaseParser = {
|
|||||||
this.finalize(...arguments),
|
this.finalize(...arguments),
|
||||||
function(res){
|
function(res){
|
||||||
return res.join('') }) },
|
return res.join('') }) },
|
||||||
|
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
execNested: function(page, ast, state={}, nested_handlers={}){
|
execNested: function(page, ast, state={}, nested_handlers={}){
|
||||||
/* XXX LOCAL_STATE waitNested here deadlocks the parser -- not sure why...
|
/* XXX LOCAL_STATE waitNested here deadlocks the parser -- not sure why...
|
||||||
@ -978,6 +993,28 @@ module.parser = {
|
|||||||
//
|
//
|
||||||
macros: {
|
macros: {
|
||||||
|
|
||||||
|
// XXX DEBUG this is not needed for production (???) move to tests...
|
||||||
|
echo: function(page, args, body, state){
|
||||||
|
console.log(['----', ...Object.keys(args), body ?? ''].join(' ').gray)
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
// XXX this works and sequences correctly...
|
||||||
|
//state.waitNested,
|
||||||
|
// XXX this deadlocks...
|
||||||
|
// calling .execNested(..) from any macro (@include(..)
|
||||||
|
// in the example code) will deadlock the execution
|
||||||
|
// if .execNested(..) is waiting for .waitNested...
|
||||||
|
// to reproduce:
|
||||||
|
// - uncomment the LOCAL_STATE track
|
||||||
|
// - run:
|
||||||
|
// @echo(A)@source(/async/echo)@echo(B)@include(/async/echo)@echo(C)
|
||||||
|
// -> need a way to call .exex(..) while evaluating...
|
||||||
|
this.execNested(page, '', state),
|
||||||
|
// XXX this also does not work...
|
||||||
|
//this.resolve(page, '', state),
|
||||||
|
function(){
|
||||||
|
console.log(' --', ...Object.keys(args), body ?? '') }) },
|
||||||
|
//*/
|
||||||
|
|
||||||
// Filter...
|
// Filter...
|
||||||
//
|
//
|
||||||
// @filter(<filter-spec>)
|
// @filter(<filter-spec>)
|
||||||
|
|||||||
@ -21,6 +21,7 @@ module.exports.PAGES = {
|
|||||||
'/blank': '',
|
'/blank': '',
|
||||||
'/page': 'Page',
|
'/page': 'Page',
|
||||||
'/async/page': Promise.resolve('Page'),
|
'/async/page': Promise.resolve('Page'),
|
||||||
|
'/async/echo': Promise.resolve('@echo(Page)'),
|
||||||
'/includePage': '@include(/page)',
|
'/includePage': '@include(/page)',
|
||||||
'/includePagePage': '@include(/page) @include(/page)',
|
'/includePagePage': '@include(/page) @include(/page)',
|
||||||
'/isolated': '@slot(slot original)',
|
'/isolated': '@slot(slot original)',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user