mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-20 18:11:41 +00:00
experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ab0d3c5390
commit
4d3a35014f
@ -436,60 +436,44 @@ 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...
|
// XXX ASYNC this does not yet work as a replacement for .expand(..), not sure why...
|
||||||
_expand: function*(page, ast, state={}){
|
_expand: function(page, ast, state={}){
|
||||||
var that = this
|
var that = this
|
||||||
try{
|
ast = ast == null ?
|
||||||
ast = ast == null ?
|
Promise.awaitOrRun(
|
||||||
Promise.awaitOrRun(
|
page.raw,
|
||||||
page.raw,
|
function(raw){
|
||||||
function(raw){
|
return that.group(page, raw ?? '') })
|
||||||
return that.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()
|
|
||||||
|
|
||||||
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 }
|
|
||||||
|
|
||||||
|
return Promise.iter(ast,
|
||||||
|
function(value){
|
||||||
// text block...
|
// text block...
|
||||||
if(typeof(value) == 'string'){
|
if(typeof(value) == 'string'){
|
||||||
yield value
|
return value }
|
||||||
continue }
|
|
||||||
|
|
||||||
// macro...
|
// macro...
|
||||||
var {name, args, body} = value
|
var {name, args, body} = value
|
||||||
// nested macro -- skip...
|
// nested macro -- skip...
|
||||||
if(typeof(page.macros[name]) != 'function'){
|
if(typeof(page.macros[name]) != 'function'){
|
||||||
yield {...value, skip: true}
|
return {...value, skip: true} }
|
||||||
continue }
|
// macro call...
|
||||||
|
return Promise.awaitOrRun(
|
||||||
// XXX
|
that.callMacro(page, name, args, body, state),
|
||||||
var res =
|
function(res){
|
||||||
await this.callMacro(page, name, args, body, state)
|
res = res ?? ''
|
||||||
?? ''
|
// result...
|
||||||
|
if(res instanceof Array
|
||||||
// result...
|
|| page.macros[name] instanceof types.Generator){
|
||||||
if(res instanceof Array
|
return res
|
||||||
|| page.macros[name] instanceof types.Generator){
|
} else {
|
||||||
yield* res
|
return [res] } }) },
|
||||||
} else {
|
function(err){
|
||||||
yield res } }
|
|
||||||
|
|
||||||
// error...
|
|
||||||
}catch(err){
|
|
||||||
console.error(err)
|
console.error(err)
|
||||||
yield page.parse(
|
return page.parse(
|
||||||
// XXX add line number and page path...
|
// XXX add line number and page path...
|
||||||
'@include("./ParseError'
|
'@include("./ParseError'
|
||||||
+':path='
|
+':path='
|
||||||
@ -506,7 +490,9 @@ module.BaseParser = {
|
|||||||
return '%'+ c.charCodeAt().toString(16) })
|
return '%'+ c.charCodeAt().toString(16) })
|
||||||
.replace(/:/g, ':')
|
.replace(/:/g, ':')
|
||||||
.replace(/=/g, '=')
|
.replace(/=/g, '=')
|
||||||
+'")') } },
|
+'")') })
|
||||||
|
.sync() },
|
||||||
|
//*/
|
||||||
expand: async function*(page, ast, state={}){
|
expand: async function*(page, ast, state={}){
|
||||||
try{
|
try{
|
||||||
ast = ast == null ?
|
ast = ast == null ?
|
||||||
@ -566,6 +552,7 @@ module.BaseParser = {
|
|||||||
.replace(/:/g, ':')
|
.replace(/:/g, ':')
|
||||||
.replace(/=/g, '=')
|
.replace(/=/g, '=')
|
||||||
+'")') } },
|
+'")') } },
|
||||||
|
//*/
|
||||||
|
|
||||||
// recursively resolve and enumerate the ast...
|
// recursively resolve and enumerate the ast...
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user