Compare commits

...

4 Commits

Author SHA1 Message Date
d5a9dd3277 cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-08-07 00:17:56 +03:00
2f5e752044 macros now more transparent + added macro wrapper support, mostly for debugging...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-08-06 20:03:21 +03:00
5061eeb851 Merge branch 'master' of github.com:flynx/pWiki 2026-08-05 00:56:27 +03:00
cdbe2440c5 notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-08-05 00:56:22 +03:00

View File

@ -15,26 +15,19 @@ var pwpath = require('./path')
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Parser/Runner... // Parser/Runner...
// XXX TODO: // XXX TODO:
// - callbacks on elements resolving... // - callbacks on elements resolving...
// - option/way to wrap macro output -- callback?? // - a real parset -- compare performance and select an implementation...
// - naming:
// parser -> macro
// //
// //
// XXX ASAP move the macros here...
// XXX BUG?: <macro src=/moo/> is not parsed correctly... // XXX BUG?: <macro src=/moo/> is not parsed correctly...
// XXX need to correctly handle nested and escaped quotes... // XXX need to correctly handle nested and escaped quotes...
// i.e. // i.e.
// "aaa \"bbb \\"ccc\\" bbb\" aaa" // "aaa \"bbb \\"ccc\\" bbb\" aaa"
// XXX RENAME...
// ...this handles the syntax and execution...
var BaseMacros = var BaseMacros =
module.BaseMacros = { module.BaseMacros = {
@ -216,11 +209,24 @@ module.BaseMacros = {
(res[e] = true) (res[e] = true)
: (res[order.shift()] = e) }) : (res[order.shift()] = e) })
return res }, return res },
/* XXX MACRO_WRAPPER...
// XXX for this to be simple need to handle macro return values:
// - value
// - primise
// - function
// ...but do we actually need to care?
// returningn an array should be transparent -> TEST!!! (XXX)
// XXX do we need this or should the user simply overload .callMacro(..)???
// ...returning an array should be transparent... (XXX ???)
__macro_result__: function(res, page, macro, args, body, state, ...rest){
return ['', res, ''] },
//*/
// NOTE: this unifies the body, body argument and text argument (in // NOTE: this unifies the body, body argument and text argument (in
// order of priority) and passes the value in the body macro // order of priority) and passes the value in the body macro
// handler argument. // handler argument.
// XXX should a macro be run in the context of the page or the parser??? // XXX should a macro be run in the context of the page or the parser???
callMacro: function(page, macro, args, body, state, ...rest){ callMacro: function(page, macro, args, body, state, ...rest){
var that = this
do { do {
macro = this.macros[macro] macro = this.macros[macro]
} while(typeof(macro) == 'string') } while(typeof(macro) == 'string')
@ -241,7 +247,20 @@ module.BaseMacros = {
body body
?? args.body ?? args.body
?? args.text } ?? args.text }
return macro.call(this, page, args, body, state, ...rest) }, //return macro.call(this, page, args, body, state, ...rest) },
var res = macro.call(this, page, args, body, state, ...rest)
return typeof(this.__macro_result__) == 'function' ?
//this.__macro_result__(res, page, args, body, state, ...rest)
Promise.awaitOrRun(
res,
function(res){
return typeof(res) == 'function' ?
function(...args){
return that.__macro_result__(
res.call(this, ...args),
page, args, body, state, ...rest) }
: that.__macro_result__(res, page, args, body, state, ...rest) })
: res },
// place join block between block elements... // place join block between block elements...
joinBlocks: function(page, blocks, join, state){ joinBlocks: function(page, blocks, join, state){
@ -776,7 +795,9 @@ module.BaseMacros = {
// 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){ var queue = [...ast]
while(queue.length > 0){
var elem = queue.shift()
// nesting... // nesting...
while(elem && elem.value){ while(elem && elem.value){
// exec stage II macros... // exec stage II macros...
@ -807,7 +828,7 @@ module.BaseMacros = {
continue } continue }
// expand ast... // expand ast...
if(elem instanceof Array){ if(elem instanceof Array){
elems.push(...that.resolve(page, elem, state)) queue.unshift(...elem)
continue } continue }
// 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){
@ -1023,8 +1044,9 @@ module.macros = {
// <filter> <filter-spec> // <filter> <filter-spec>
// | -<filter> <filter-spec> // | -<filter> <filter-spec>
// //
// XXX should we include the global filters (current) or exclude //
// them by default??? // XXX should local filter include the global filters (current)
// or exclude them by default???
filter: Macro( filter: Macro(
[['clear']], [['clear']],
function(page, args, body, state){ function(page, args, body, state){