Compare commits

..

No commits in common. "b9043887d32d4abb5ca35347d39708b7e3e6cda5" and "b1c1c4024f7057f0a70017766d066c6cc29ad574" have entirely different histories.

View File

@ -593,10 +593,14 @@ module.BaseParser = {
// - everything returns an ast
// - callbacks/events/handlers to trigger on specific macro
// resolution
//
// XXX Remove async/await... (???)
// - for trivial stuff they are nice
// - infectios -- force all subsequent levels to use async/await
// - provide no alternatives
// ...i.e. promises can be extended to indlude partial
// states and the like, async/await can't...
// XXX Q: do we need generators?
// XXX Handle errors...
// XXX BUG: awaiting on .wait* can deadlock...
expand: function(page, ast, state={}, nested_handlers={}){
var that = this
ast = typeof(ast) != 'object' ?
@ -647,43 +651,13 @@ module.BaseParser = {
&& (body = this.expand(page, body, state, nested_handlers))
// call macro...
// XXX since this can be async and if so it will be mixed
// into the next .wait*, we'll need to explicitly pass
// and then thread the current .wait* promises before
// overwriting, to avoid wait-for-self deadlocks...
// ...the question is how to thread it...
// one way to do this is to split state into:
// state - current state of eval, mutable for all
// context - the context of evaluation of the curent
// macro, unique per macro, this would
// also be good to store things like
// line numbers and the like...
// ways to organize this:
// - context.state - nesting
// - state, context - sepatrate args
// - state.__proto__ - protorype
/* XXX LOCAL_STATE
var res = that.callMacro( page, name, args, body, {
__proto__: state,
state,
waitAll: state.waitAll,
waitNested: state.waitNested,
})
/*/
var res = that.callMacro(page, name, args, body, state)
//*/
// async...
if(res instanceof Promise){
elem.resolving = res
let all, nested
// XXX if res is not started yet and it has not yet
// started waiting for .waitAll this can be a
// condition for a dead lock:
// res -> .waitAll -> res
all = state.waitAll =
Promise.all([state.waitAll, res])
elem.resolving = res
// XXX do we need to wait till the last .waitNested is
// resolved?
// ...should it's handlers complete??
@ -888,7 +862,7 @@ module.BaseParser = {
return res.join('') }) },
// XXX
execNested: function(page, ast, state={}, nested_handlers={}){
/* XXX LOCAL_STATE waitNested here deadlocks the parser -- not sure why...
/* XXX waitNested here deadlocks the parser -- not sure why...
//return this.exec(page, ast, state, nested_handlers, 'unresolved') },
return this.exec(page, ast, state, nested_handlers, 'waitNested') },
/*/
@ -989,13 +963,6 @@ module.parser = {
//
// XXX should we include the global filters (current) or exclude
// them by default???
// XXX BUG: async body breaks nested filters...
// '<filter upper/>aaa <filter -upper> moo @source(/async/page) </filter> bbb'
// -> 'AAA MOO PAGE BBB'
// XXX and this deadlocks with LOCAL_STATE
// while:
// '<filter upper/>aaa <filter -upper> moo @source(/page) </filter> bbb'
// -> 'AAA moo Page BBB'
filter: Macro(
[['clear']],
function(page, args, body, state){
@ -1109,12 +1076,6 @@ module.parser = {
if(!name){
return '' }
/* XXX LOCAL_STATE
var vars = state.state.vars ??= {}
/*/
var vars = state.vars ??= {}
//*/
return Promise.awaitOrRun(
this.execNested(page, name, state),
function(name){
@ -1131,6 +1092,7 @@ module.parser = {
: undefined)
?? args.shown
var vars = state.vars ??= {}
// XXX INC_DEC
if(args.parent && name in vars){
while(!vars.hasOwnProperty(name)
@ -1258,15 +1220,10 @@ module.parser = {
var that = this
var name = args.name
/* XXX LOCAL_STATE
var slots = state.state.slots ??= {}
/*/
var slots = state.slots ??= {}
//*/
return Promise.awaitOrRun(
this.execNested(page, name, state),
function(name){
var slots = state.slots ??= {}
//var hidden = name in slots
var hidden =
@ -1620,23 +1577,16 @@ module.parser = {
lazy(
function(page, args, body, state){
var that = this
/* XXX LOCAL_STATE
var macros = state.state.macros ??= {}
/*/
var macros = state.macros ??= {}
//*/
return Promise.awaitOrRun(
this.execNested(page, args.name, state),
function(name){
// set macro...
if(name && body){
macros[name] = body
;(state.macros ??= {})[name] = body
// get macro...
} else if(name){
body = macros[name] }
body = (state.macros ?? {})[name] }
// else...
if(args.src