mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-30 18:40:08 +00:00
changed macro arg format, still need to update macros...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cf737725c5
commit
d40b9a96b1
46
pwiki2.js
46
pwiki2.js
@ -948,25 +948,52 @@ module.BaseParser = {
|
|||||||
return filter[0] != '-' })
|
return filter[0] != '-' })
|
||||||
.filter(function(filter){
|
.filter(function(filter){
|
||||||
return !skip.has(filter) })},
|
return !skip.has(filter) })},
|
||||||
|
/*/ XXX is this still used???
|
||||||
posArgs: function(args){
|
posArgs: function(args){
|
||||||
return Object.entries(args)
|
return Object.entries(args)
|
||||||
.reduce(function(res, [key, value]){
|
.reduce(function(res, [key, value]){
|
||||||
/^[0-9]+$/.test(key)
|
/^[0-9]+$/.test(key)
|
||||||
&& (res[key*1] = value)
|
&& (res[key*1] = value)
|
||||||
return res }, []) },
|
return res }, []) },
|
||||||
|
//*/
|
||||||
//
|
//
|
||||||
// Spec format:
|
// Spec format:
|
||||||
// [<orderd>, ... [<keyword>, ...]]
|
// [<orderd>, ... [<keyword>, ...]]
|
||||||
//
|
//
|
||||||
|
// NOTE: the input to this is formatted by .lex(..)
|
||||||
|
// NOTE: arg pre-parsing is dome by .lex(..) but at that stage we do not
|
||||||
|
// yet touch the actual macros (we need them to get the .arg_spec)
|
||||||
|
// so the actual parsing is done in .expand(..)
|
||||||
parseArgs: function(spec, args){
|
parseArgs: function(spec, args){
|
||||||
var ordered = spec.slice()
|
// spec...
|
||||||
var bool = new Set(
|
var order = spec.slice()
|
||||||
ordered[ordered.length-1] instanceof Array ?
|
var bools = new Set(
|
||||||
ordered.pop()
|
order[order.length-1] instanceof Array ?
|
||||||
|
order.pop()
|
||||||
: [])
|
: [])
|
||||||
|
order = order
|
||||||
|
.filter(function(k){
|
||||||
|
return !(k in args) })
|
||||||
|
|
||||||
|
var res = {}
|
||||||
},
|
var pos = Object.entries(args)
|
||||||
|
// stage 1: populate res with explicit data and place the rest in pos...
|
||||||
|
.reduce(function(pos, [key, value]){
|
||||||
|
/^[0-9]+$/.test(key) ?
|
||||||
|
(bools.has(value) ?
|
||||||
|
// bool...
|
||||||
|
(res[value] = true)
|
||||||
|
// positional...
|
||||||
|
: (pos[key*1] = value))
|
||||||
|
// keyword...
|
||||||
|
: (res[key] = value)
|
||||||
|
return pos }, [])
|
||||||
|
// stage 2: populate implicit values from pos...
|
||||||
|
.forEach(function(e, i){
|
||||||
|
order.length == 0 ?
|
||||||
|
(res[e] = true)
|
||||||
|
: (res[order.shift()] = e) })
|
||||||
|
return res },
|
||||||
|
|
||||||
// Strip comments...
|
// Strip comments...
|
||||||
//
|
//
|
||||||
@ -1198,9 +1225,16 @@ module.BaseParser = {
|
|||||||
// nested macro -- skip...
|
// nested macro -- skip...
|
||||||
if(!(page.macros[name] instanceof Function)){
|
if(!(page.macros[name] instanceof Function)){
|
||||||
continue }
|
continue }
|
||||||
|
// args...
|
||||||
|
args = this.parseArgs.call(page,
|
||||||
|
page.macros[name].arg_spec
|
||||||
|
?? [],
|
||||||
|
args)
|
||||||
|
// call...
|
||||||
var res =
|
var res =
|
||||||
page.macros[name].call(page, args, body, state, value)
|
page.macros[name].call(page, args, body, state, value)
|
||||||
?? ''
|
?? ''
|
||||||
|
// result...
|
||||||
if(res instanceof Array
|
if(res instanceof Array
|
||||||
|| page.macros[name] instanceof types.Generator){
|
|| page.macros[name] instanceof types.Generator){
|
||||||
yield* res
|
yield* res
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user