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... // Parser/Runner...
// XXX TODO: // XXX TODO:
// - callbacks on elements resolving... // - 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 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 = {
@ -209,24 +216,11 @@ 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')
@ -247,20 +241,7 @@ 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){
@ -795,9 +776,7 @@ module.BaseMacros = {
// merge resolved elements into the last item of elems... // merge resolved elements into the last item of elems...
var elems = [] var elems = []
var queue = [...ast] for(var elem of 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...
@ -828,7 +807,7 @@ module.BaseMacros = {
continue } continue }
// expand ast... // expand ast...
if(elem instanceof Array){ if(elem instanceof Array){
queue.unshift(...elem) elems.push(...that.resolve(page, elem, state))
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){
@ -1044,9 +1023,8 @@ module.macros = {
// <filter> <filter-spec> // <filter> <filter-spec>
// | -<filter> <filter-spec> // | -<filter> <filter-spec>
// //
// // XXX should we include the global filters (current) or exclude
// XXX should local filter include the global filters (current) // them by default???
// or exclude them by default???
filter: Macro( filter: Macro(
[['clear']], [['clear']],
function(page, args, body, state){ function(page, args, body, state){