mirror of
https://github.com/flynx/pWiki.git
synced 2026-07-13 20:10:57 +00:00
refactoring parser -- still not 100%...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
7786ddaeb6
commit
67db497eab
12
v3/package-lock.json
generated
12
v3/package-lock.json
generated
@ -32,9 +32,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "5.0.6",
|
"version": "5.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz",
|
||||||
"integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==",
|
"integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"balanced-match": "^4.0.2"
|
"balanced-match": "^4.0.2"
|
||||||
@ -231,9 +231,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ig-types": {
|
"node_modules/ig-types": {
|
||||||
"version": "6.26.2",
|
"version": "6.26.3",
|
||||||
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-6.26.2.tgz",
|
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-6.26.3.tgz",
|
||||||
"integrity": "sha512-VGg8MVmpblVCmZK52bJcDtPG3uRFiEyPnlDEIJv3MymTm+aUNWR/Th20NU2wfGV/Ux3KlsbGlhe+0c9ZKTYPDw==",
|
"integrity": "sha512-WDGHnC2up/7x5agsS2HfQbegfY97mMGM4xNv1HII3OiidcoPFDjp7nLdOOsWfZOtXA7nGWdAriGeVCOOJxEhew==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ig-object": "^6.0.0",
|
"ig-object": "^6.0.0",
|
||||||
|
|||||||
@ -1300,19 +1300,6 @@ module.parser = {
|
|||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.parseNested(page, src, state),
|
this.parseNested(page, src, state),
|
||||||
function(src){
|
function(src){
|
||||||
// check for recursion...
|
|
||||||
// XXX will this work for @source(..)???
|
|
||||||
var stack = state.include_stack ??= []
|
|
||||||
if(stack.includes(src)){
|
|
||||||
if(!recursive){
|
|
||||||
throw new Error('Recursive macro: '+stack) }
|
|
||||||
return that.expand(page, recursive, state) }
|
|
||||||
stack.push(src)
|
|
||||||
|
|
||||||
var cache = state.cache ??= {}
|
|
||||||
if(cache[src]){
|
|
||||||
return cache[src] }
|
|
||||||
|
|
||||||
// XXX should this be a tree??
|
// XXX should this be a tree??
|
||||||
// ...need to at least split direct and
|
// ...need to at least split direct and
|
||||||
// indirect dependencies...
|
// indirect dependencies...
|
||||||
@ -1325,9 +1312,18 @@ module.parser = {
|
|||||||
|
|
||||||
// content handler...
|
// content handler...
|
||||||
handler ??=
|
handler ??=
|
||||||
function(page, src, text, state){
|
function(page, body, path, text, state){
|
||||||
page = page.get(src)
|
// check for recursion...
|
||||||
return args.isolated ?
|
var include_stack = state.include_stack ??= []
|
||||||
|
if(include_stack.includes(path)){
|
||||||
|
if(!recursive){
|
||||||
|
throw new Error('Recursive macro: '+include_stack) }
|
||||||
|
return that.expand(page, recursive, state) }
|
||||||
|
include_stack.push(path)
|
||||||
|
|
||||||
|
// XXX check cache???
|
||||||
|
|
||||||
|
var res = args.isolated ?
|
||||||
this.resolve(
|
this.resolve(
|
||||||
page,
|
page,
|
||||||
text,
|
text,
|
||||||
@ -1335,38 +1331,30 @@ module.parser = {
|
|||||||
args.isolated == 'partial' ?
|
args.isolated == 'partial' ?
|
||||||
serialize.partialDeepCopy(state)
|
serialize.partialDeepCopy(state)
|
||||||
: {},
|
: {},
|
||||||
{stack: state.stack ?? []}))
|
{include_stack}))
|
||||||
: this.expand(page, text, state) }
|
: this.expand(page, text, state)
|
||||||
|
|
||||||
var pageHandler =
|
// handle recursion...
|
||||||
function([path, text]){
|
return Promise.awaitOrRun(
|
||||||
var content_handled = false
|
res,
|
||||||
return body ?
|
function(){
|
||||||
// handle body / <content/>...
|
|
||||||
Promise.awaitOrRun(
|
|
||||||
that.expand(page.get(path), body, state,
|
|
||||||
{ content: function(){
|
|
||||||
content_handled = true
|
|
||||||
return text = handler.call(that, page, src, text, state) } }),
|
|
||||||
function(text){
|
|
||||||
// if no <content/> present we still
|
|
||||||
// need to handle the included page...
|
|
||||||
content_handled
|
|
||||||
|| handler.call(that, page, src, text, state)
|
|
||||||
return text })
|
|
||||||
// place as-is...
|
|
||||||
: handler.call(that, page, src, text, state) }
|
|
||||||
var resultHandler =
|
|
||||||
function(pages){
|
|
||||||
state.include_stack.at(-1) == src
|
state.include_stack.at(-1) == src
|
||||||
&& state.include_stack.pop()
|
&& state.include_stack.pop()
|
||||||
// cleanup...
|
// cleanup...
|
||||||
if(state.include_stack.length == 0){
|
if(state.include_stack.length == 0){
|
||||||
delete state.include_stack
|
delete state.include_stack
|
||||||
delete state.recursive }
|
delete state.recursive }
|
||||||
// cache the final result...
|
|
||||||
cache[src] = pages
|
return res }) }
|
||||||
return pages }
|
|
||||||
|
var pageHandler =
|
||||||
|
function([path, text]){
|
||||||
|
// handle nested promises...
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
text,
|
||||||
|
function(text){
|
||||||
|
return handler.call(that, page, body, path, text, state) }) }
|
||||||
|
|
||||||
|
|
||||||
// get and run things...
|
// get and run things...
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
@ -1374,23 +1362,32 @@ module.parser = {
|
|||||||
page.get(src).raw,
|
page.get(src).raw,
|
||||||
function(paths, texts){
|
function(paths, texts){
|
||||||
texts =
|
texts =
|
||||||
|
// XXX how do we handle paths returning non-strings???
|
||||||
// special case: list page...
|
// special case: list page...
|
||||||
paths.length == 1
|
paths.length == 1
|
||||||
&& texts instanceof Array ?
|
&& texts instanceof Array ?
|
||||||
[texts]
|
[texts]
|
||||||
: texts instanceof Array ?
|
: texts instanceof Array ?
|
||||||
texts
|
texts
|
||||||
: [texts]
|
: [texts ?? '']
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
// handle pages...
|
// handle pages...
|
||||||
Promise
|
Promise
|
||||||
.iter(
|
.iter(
|
||||||
|
that.joinBlocks(
|
||||||
|
page,
|
||||||
Array
|
Array
|
||||||
.zip(paths, texts)
|
.zip(paths, texts)
|
||||||
.map(pageHandler))
|
.map(pageHandler),
|
||||||
|
args.join,
|
||||||
|
state))
|
||||||
.flat()
|
.flat()
|
||||||
.sync(),
|
.sync(),
|
||||||
resultHandler ) }) }) })),
|
function(pages){
|
||||||
|
/* XXX cache the final result...
|
||||||
|
cache[src] = pages
|
||||||
|
//*/
|
||||||
|
return pages }) }) }) })),
|
||||||
|
|
||||||
// NOTE: the main difference between this and @include is that
|
// NOTE: the main difference between this and @include is that
|
||||||
// this renders the src in the context of current page while
|
// this renders the src in the context of current page while
|
||||||
@ -1559,7 +1556,38 @@ module.parser = {
|
|||||||
body = (state.macros ?? {})[name] }
|
body = (state.macros ?? {})[name] }
|
||||||
return args.src && body ?
|
return args.src && body ?
|
||||||
// run macro...
|
// run macro...
|
||||||
that.macros.include.call(that, page, args, body, state)
|
that.macros.include.call(that, page, args, body, state,
|
||||||
|
function(page, body, path, text, state){
|
||||||
|
var that = this
|
||||||
|
|
||||||
|
var handle = function(page, text, state){
|
||||||
|
return args.isolated ?
|
||||||
|
that.resolve(
|
||||||
|
page,
|
||||||
|
text,
|
||||||
|
Object.assign(
|
||||||
|
args.isolated == 'partial' ?
|
||||||
|
serialize.partialDeepCopy(state)
|
||||||
|
: {},
|
||||||
|
{include_stack: state.include_stack ?? []}))
|
||||||
|
: that.expand(page, text, state) }
|
||||||
|
|
||||||
|
//var content_handled = false
|
||||||
|
return body ?
|
||||||
|
// handle body / <content/>...
|
||||||
|
Promise.awaitOrRun(
|
||||||
|
that.expand(page.get(path), body, state,
|
||||||
|
{ content: function(){
|
||||||
|
content_handled = true
|
||||||
|
return text = handle(page, text, state) } }),
|
||||||
|
function(text){
|
||||||
|
// if no <content/> present we still
|
||||||
|
// need to handle the included page...
|
||||||
|
//content_handled
|
||||||
|
// || handle.call(that, page, text, state)
|
||||||
|
return text })
|
||||||
|
// place as-is...
|
||||||
|
: handle(page, text, state) })
|
||||||
: '' }) })),
|
: '' }) })),
|
||||||
|
|
||||||
// nesting rules...
|
// nesting rules...
|
||||||
|
|||||||
@ -92,7 +92,7 @@ module.exports.P = {
|
|||||||
.iter(res)
|
.iter(res)
|
||||||
.sync() },
|
.sync() },
|
||||||
/*/
|
/*/
|
||||||
res },
|
: res },
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
// XXX should this return an arrya for a multi-match???
|
// XXX should this return an arrya for a multi-match???
|
||||||
@ -284,13 +284,14 @@ test.Setups({
|
|||||||
],
|
],
|
||||||
} },
|
} },
|
||||||
//*/
|
//*/
|
||||||
// content...
|
/*/ XXX content...
|
||||||
include_content: function(assert, path='/page'){
|
include_content: function(assert, path='/page'){
|
||||||
return {
|
return {
|
||||||
page: P,
|
page: P,
|
||||||
code: [
|
code: [
|
||||||
'<include "'+ path +'">[[ <content/> ]]</include>',
|
'<include "'+ path +'">[[ <content/> ]]</include>',
|
||||||
'[[ '+ P.get(path).raw +' ]]', ], } },
|
'[[ '+ P.get(path).raw +' ]]', ], } },
|
||||||
|
//*/
|
||||||
// XXX
|
// XXX
|
||||||
|
|
||||||
// recursion...
|
// recursion...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user