Compare commits

..

No commits in common. "d5a9dd32778dd5feb8b18fe353497a96c13d5128" and "64c7a63930b537c2c19a1ed17c78b8d954816415" have entirely different histories.

View File

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