experimenting + notes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-12-03 02:52:27 +03:00
parent b575aaf784
commit dd5a9496a2
2 changed files with 25 additions and 1 deletions

View File

@ -436,17 +436,27 @@ module.BaseParser = {
// XXX macros: we are mixing up ast state and parse state... // XXX macros: we are mixing up ast state and parse state...
// one should only be used for parsing and be forgotten after // one should only be used for parsing and be forgotten after
// the ast is constructed the other should be part of the ast... // the ast is constructed the other should be part of the ast...
// XXX ASYNC...
expand: async function*(page, ast, state={}){ expand: async function*(page, ast, state={}){
/*/
expand: function*(page, ast, state={}){
//*/
try{ try{
ast = ast == null ? ast = ast == null ?
//this.group(page) // XXX ASYNC...
this.group(page, await page.raw ?? '') this.group(page, await page.raw ?? '')
/*/
page.raw
.then(function(raw){
return this.group(page, raw ?? '') })
//*/
: typeof(ast) != 'object' ? : typeof(ast) != 'object' ?
this.group(page, ast) this.group(page, ast)
: ast instanceof types.Generator ? : ast instanceof types.Generator ?
ast ast
: ast.iter() : ast.iter()
//XXX ASYNC need to .awaitOrRun(ast, ...)...
while(true){ while(true){
var {value, done} = ast.next() var {value, done} = ast.next()
if(done){ if(done){
@ -464,6 +474,7 @@ module.BaseParser = {
yield {...value, skip: true} yield {...value, skip: true}
continue } continue }
// XXX ASYNC...
var res = var res =
await this.callMacro(page, name, args, body, state) await this.callMacro(page, name, args, body, state)
?? '' ?? ''
@ -474,6 +485,17 @@ module.BaseParser = {
yield* res yield* res
} else { } else {
yield res } } yield res } }
/*/
yield* Promise.awaitOrRun(
this.callMacro(page, name, args, body, state),
function*(res){
res = res ?? ''
if(res instanceof Array
|| page.macros[name] instanceof types.Generator){
yield* res
} else {
yield res } })
//*/
// error... // error...
}catch(err){ }catch(err){

View File

@ -38,6 +38,8 @@
* *
* *
* *
* XXX ASAP need to add error handling to .awaitOrRun(..)
* ...might be even better to make it support the same interface as Promise...
* XXX BUG: seems that page caching stopped working... * XXX BUG: seems that page caching stopped working...
* ...are we over-refreshing??? * ...are we over-refreshing???
* XXX BUG: for some reason editing the root page ('/') hangs /tree... * XXX BUG: for some reason editing the root page ('/') hangs /tree...