mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
dd5a9496a2
commit
2afbcea8c3
@ -437,26 +437,86 @@ module.BaseParser = {
|
|||||||
// 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...
|
// XXX ASYNC...
|
||||||
expand: async function*(page, ast, state={}){
|
_expand: function*(page, ast, state={}){
|
||||||
/*/
|
var that = this
|
||||||
expand: function*(page, ast, state={}){
|
|
||||||
//*/
|
|
||||||
try{
|
try{
|
||||||
ast = ast == null ?
|
ast = ast == null ?
|
||||||
// XXX ASYNC...
|
Promise.awaitOrRun(
|
||||||
this.group(page, await page.raw ?? '')
|
page.raw,
|
||||||
/*/
|
function(raw){
|
||||||
page.raw
|
return that.group(page, raw ?? '') })
|
||||||
.then(function(raw){
|
: typeof(ast) != 'object' ?
|
||||||
return this.group(page, raw ?? '') })
|
this.group(page, ast)
|
||||||
//*/
|
: ast instanceof types.Generator ?
|
||||||
|
ast
|
||||||
|
: ast.iter()
|
||||||
|
|
||||||
|
Promise.sync
|
||||||
|
.resolve(ast)
|
||||||
|
.then(function(ast){
|
||||||
|
})
|
||||||
|
|
||||||
|
// XXX SYNC need to optionally await for ast...
|
||||||
|
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 }
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
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, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
// quote argument syntax...
|
||||||
|
.replace(/["']/g, function(c){
|
||||||
|
return '%'+ c.charCodeAt().toString(16) })
|
||||||
|
.replace(/:/g, ':')
|
||||||
|
.replace(/=/g, '=')
|
||||||
|
+'")') } },
|
||||||
|
expand: async function*(page, ast, state={}){
|
||||||
|
try{
|
||||||
|
ast = ast == null ?
|
||||||
|
this.group(page, await 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){
|
||||||
@ -474,7 +534,6 @@ 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)
|
||||||
?? ''
|
?? ''
|
||||||
@ -485,17 +544,6 @@ 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){
|
||||||
|
|||||||
@ -40,9 +40,12 @@
|
|||||||
*
|
*
|
||||||
* XXX ASAP need to add error handling to .awaitOrRun(..)
|
* XXX ASAP need to add error handling to .awaitOrRun(..)
|
||||||
* ...might be even better to make it support the same interface as Promise...
|
* ...might be even better to make it support the same interface as Promise...
|
||||||
|
* XXX BUG: for some reason editing the root page ('/') hangs /tree...
|
||||||
|
* ...the problem is most likely is in that tree appends tree to
|
||||||
|
* each path in the list and '/' + '/tree' is ....
|
||||||
|
* ...why aren't we catching the recursion here???
|
||||||
* 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 .parse(..): should we handle pattern paths and lists of text???
|
* XXX .parse(..): should we handle pattern paths and lists of text???
|
||||||
* XXX parser: error handling: add line number + context... (???)
|
* XXX parser: error handling: add line number + context... (???)
|
||||||
* XXX BUG: parser:
|
* XXX BUG: parser:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user