mirror of
https://github.com/flynx/pWiki.git
synced 2026-10-03 04:41:39 +00:00
Compare commits
No commits in common. "fa720d40fdff84237d967fd7b6028412afe10f8c" and "d8f8d5cc1e7d1d2573ee1c611a84e61d41e0c754" have entirely different histories.
fa720d40fd
...
d8f8d5cc1e
@ -33,7 +33,7 @@ var pwpath = require('./path')
|
|||||||
// "aaa \"bbb \\"ccc\\" bbb\" aaa"
|
// "aaa \"bbb \\"ccc\\" bbb\" aaa"
|
||||||
|
|
||||||
// XXX RENAME...
|
// XXX RENAME...
|
||||||
// ...this handles the syntax and execution...
|
// ...this handles the syntax and lexing...
|
||||||
var BaseParser =
|
var BaseParser =
|
||||||
module.BaseParser = {
|
module.BaseParser = {
|
||||||
// patterns...
|
// patterns...
|
||||||
@ -743,7 +743,7 @@ module.BaseParser = {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// XXX can we prevent reaces over state.unresolved???
|
// XXX can we prevent reaces over state.unresolved???
|
||||||
// it can be deleted when calling .exec(..) / .execNested(..)
|
// it can be deleted when calling .parse(..) / .parseNested(..)
|
||||||
// while parsing, for example from within a macro...
|
// while parsing, for example from within a macro...
|
||||||
resolve: function(page, ast, state={}, nested_handlers={}){
|
resolve: function(page, ast, state={}, nested_handlers={}){
|
||||||
var that = this
|
var that = this
|
||||||
@ -814,7 +814,7 @@ module.BaseParser = {
|
|||||||
// XXX
|
// XXX
|
||||||
},
|
},
|
||||||
|
|
||||||
exec: function(page, ast, state={}, nested_handlers={}, wait='wait'){
|
parse: function(page, ast, state={}, nested_handlers={}, wait='wait'){
|
||||||
var that = this
|
var that = this
|
||||||
// XXX might be a good idea to limit recursion depth here...
|
// XXX might be a good idea to limit recursion depth here...
|
||||||
var merge = function(ast){
|
var merge = function(ast){
|
||||||
@ -837,7 +837,7 @@ module.BaseParser = {
|
|||||||
state[wait],
|
state[wait],
|
||||||
function(ast){
|
function(ast){
|
||||||
// NOTE: in an async world where any promised macro can
|
// NOTE: in an async world where any promised macro can
|
||||||
// call .exec(..) / .execNested(..) we can't trust
|
// call .parse(..) / .parseNested(..) we can't trust
|
||||||
// the lack of .unresolved in state...
|
// the lack of .unresolved in state...
|
||||||
return (state.unresolved
|
return (state.unresolved
|
||||||
|| !that.isResolved(ast)) ?
|
|| !that.isResolved(ast)) ?
|
||||||
@ -847,8 +847,8 @@ module.BaseParser = {
|
|||||||
|
|
||||||
// XXX how should this play with filters???
|
// XXX how should this play with filters???
|
||||||
// ...should filters be client-side only??
|
// ...should filters be client-side only??
|
||||||
execNested: function(page, ast, state={}, nested_handlers={}){
|
parseNested: function(page, ast, state={}, nested_handlers={}){
|
||||||
return this.exec(page, ast, state, nested_handlers, 'waitNestedi') },
|
return this.parse(page, ast, state, nested_handlers, 'waitNestedi') },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -898,8 +898,6 @@ var parser =
|
|||||||
module.parser = {
|
module.parser = {
|
||||||
__proto__: BaseParser,
|
__proto__: BaseParser,
|
||||||
|
|
||||||
INCLUDE_NEST_LIMIT: 20,
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// <macro>(<args>, <body>, <state>){ .. }
|
// <macro>(<args>, <body>, <state>){ .. }
|
||||||
// -> undefined
|
// -> undefined
|
||||||
@ -926,20 +924,13 @@ module.parser = {
|
|||||||
// <filter> <filter-spec>
|
// <filter> <filter-spec>
|
||||||
// | -<filter> <filter-spec>
|
// | -<filter> <filter-spec>
|
||||||
//
|
//
|
||||||
// XXX the rewrite:
|
|
||||||
// - these need to be called after everything is done
|
|
||||||
// - globally in .exec(..) ???
|
|
||||||
// - localy after the item content is ready
|
|
||||||
// -> should we have and .onDone(..) event somwhere in the tree???
|
|
||||||
// ...this would be usefull for the callback renderer too...
|
|
||||||
//
|
|
||||||
// XXX BUG: this does not show any results:
|
// XXX BUG: this does not show any results:
|
||||||
// pwiki.exec('<filter test>moo test</filter>')
|
// pwiki.parse('<filter test>moo test</filter>')
|
||||||
// -> ''
|
// -> ''
|
||||||
// while these do:
|
// while these do:
|
||||||
// pwiki.exec('<filter test/>moo test')
|
// pwiki.parse('<filter test/>moo test')
|
||||||
// -> 'moo TEST'
|
// -> 'moo TEST'
|
||||||
// await pwiki.exec('<filter test>moo test</filter>@var()')
|
// await pwiki.parse('<filter test>moo test</filter>@var()')
|
||||||
// -> 'moo TEST'
|
// -> 'moo TEST'
|
||||||
// for more info see:
|
// for more info see:
|
||||||
// file:///L:/work/pWiki/pwiki2.html#/Editors/Results
|
// file:///L:/work/pWiki/pwiki2.html#/Editors/Results
|
||||||
@ -983,7 +974,7 @@ module.parser = {
|
|||||||
// ...at this stage it should more or less be static -- check!
|
// ...at this stage it should more or less be static -- check!
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
// XXX how do we resolve the await loop?
|
// XXX how do we resolve the await loop?
|
||||||
parser.execNested(this, ast, {
|
parser.parseNested(this, ast, {
|
||||||
...state,
|
...state,
|
||||||
filters: local.includes(this.ISOLATED_FILTERS) ?
|
filters: local.includes(this.ISOLATED_FILTERS) ?
|
||||||
local
|
local
|
||||||
@ -1057,7 +1048,7 @@ module.parser = {
|
|||||||
return '' }
|
return '' }
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.execNested(page, name, state),
|
this.parseNested(page, name, state),
|
||||||
function(name){
|
function(name){
|
||||||
// XXX INC_DEC
|
// XXX INC_DEC
|
||||||
var inc = args.inc
|
var inc = args.inc
|
||||||
@ -1128,7 +1119,7 @@ module.parser = {
|
|||||||
if(text){
|
if(text){
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
//state.waitNested,
|
//state.waitNested,
|
||||||
that.execNested(page, text, state),
|
that.parseNested(page, text, state),
|
||||||
function(value){
|
function(value){
|
||||||
text = vars[name] = value
|
text = vars[name] = value
|
||||||
return show ?? false ?
|
return show ?? false ?
|
||||||
@ -1142,8 +1133,8 @@ module.parser = {
|
|||||||
var lst = []
|
var lst = []
|
||||||
for(var [name, value] of Object.entries(args)){
|
for(var [name, value] of Object.entries(args)){
|
||||||
lst.push(
|
lst.push(
|
||||||
this.execNested(page, name, state),
|
this.parseNested(page, name, state),
|
||||||
this.execNested(page, value, state)) }
|
this.parseNested(page, value, state)) }
|
||||||
var vars = state.vars ??= {}
|
var vars = state.vars ??= {}
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
state.waitNested,
|
state.waitNested,
|
||||||
@ -1201,7 +1192,7 @@ module.parser = {
|
|||||||
var name = args.name
|
var name = args.name
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.execNested(page, name, state),
|
this.parseNested(page, name, state),
|
||||||
function(name){
|
function(name){
|
||||||
var slots = state.slots ??= {}
|
var slots = state.slots ??= {}
|
||||||
|
|
||||||
@ -1294,6 +1285,7 @@ module.parser = {
|
|||||||
// XXX need a way to make encode option transparent...
|
// XXX need a way to make encode option transparent...
|
||||||
// XXX do we want to load a specific slot/block???
|
// XXX do we want to load a specific slot/block???
|
||||||
// XXX REVISE...
|
// XXX REVISE...
|
||||||
|
INCLUDE_LIMIT: 20,
|
||||||
include: Macro(
|
include: Macro(
|
||||||
['src', 'recursive', 'join',
|
['src', 'recursive', 'join',
|
||||||
['s', 'strict', 'isolated']],
|
['s', 'strict', 'isolated']],
|
||||||
@ -1319,7 +1311,7 @@ module.parser = {
|
|||||||
|
|
||||||
var base = page.basepath
|
var base = page.basepath
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.execNested(page, args.src, state),
|
this.parseNested(page, args.src, state),
|
||||||
function(src){
|
function(src){
|
||||||
//src = page.resolvePathVars(src)
|
//src = page.resolvePathVars(src)
|
||||||
|
|
||||||
@ -1339,7 +1331,7 @@ module.parser = {
|
|||||||
// re-include limit...
|
// re-include limit...
|
||||||
// XXX HACK???
|
// XXX HACK???
|
||||||
if( ++(state.included ??= {[path]: 0})[path]
|
if( ++(state.included ??= {[path]: 0})[path]
|
||||||
> this.INCLUDE_NEST_LIMIT ?? 20){
|
> this.macros.INCLUDE_LIMIT ?? 20){
|
||||||
// XXX BUG: for some reason for async recursion this
|
// XXX BUG: for some reason for async recursion this
|
||||||
// breaks returning [object Object] overriding
|
// breaks returning [object Object] overriding
|
||||||
// the actual return value
|
// the actual return value
|
||||||
@ -1493,7 +1485,7 @@ module.parser = {
|
|||||||
var that = this
|
var that = this
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
args.src
|
args.src
|
||||||
&& this.execNested(page, args.src, state),
|
&& this.parseNested(page, args.src, state),
|
||||||
function(src){
|
function(src){
|
||||||
//src = page.resolvePathVars(src)
|
//src = page.resolvePathVars(src)
|
||||||
var text =
|
var text =
|
||||||
@ -1568,7 +1560,7 @@ module.parser = {
|
|||||||
function(page, args, body, state){
|
function(page, args, body, state){
|
||||||
var that = this
|
var that = this
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.execNested(page, args.name, state),
|
this.parseNested(page, args.name, state),
|
||||||
function(name){
|
function(name){
|
||||||
// set macro...
|
// set macro...
|
||||||
if(name && body){
|
if(name && body){
|
||||||
|
|||||||
@ -112,7 +112,7 @@ module.exports.P = {
|
|||||||
|
|
||||||
// XXX should this return an arrya for a multi-match???
|
// XXX should this return an arrya for a multi-match???
|
||||||
get text(){
|
get text(){
|
||||||
return this.__parser__.exec(this, this.raw, {}) },
|
return this.__parser__.parse(this, this.raw, {}) },
|
||||||
|
|
||||||
get: function(p){
|
get: function(p){
|
||||||
return {
|
return {
|
||||||
@ -278,13 +278,17 @@ test.Setups({
|
|||||||
page: P,
|
page: P,
|
||||||
code:[
|
code:[
|
||||||
'@include("/isolated") @slot(slot overloaded)',
|
'@include("/isolated") @slot(slot overloaded)',
|
||||||
'overloaded ', ], } },
|
'overloaded ',
|
||||||
|
],
|
||||||
|
} },
|
||||||
include_isolated: function(assert){
|
include_isolated: function(assert){
|
||||||
return {
|
return {
|
||||||
page: P,
|
page: P,
|
||||||
code:[
|
code:[
|
||||||
'@include(isolated /isolated) @slot(slot overloaded)',
|
'@include(isolated /isolated) @slot(slot overloaded)',
|
||||||
'original overloaded', ], } },
|
'original overloaded',
|
||||||
|
],
|
||||||
|
} },
|
||||||
include_partial_isolated: function(assert){
|
include_partial_isolated: function(assert){
|
||||||
return {
|
return {
|
||||||
page: P,
|
page: P,
|
||||||
@ -313,26 +317,8 @@ test.Setups({
|
|||||||
'<< << recursion found >> >>', ], } },
|
'<< << recursion found >> >>', ], } },
|
||||||
|
|
||||||
// quote...
|
// quote...
|
||||||
// NOTE: for inline quoting see: test.Modifiers.quote
|
// for inline quoting see: test.Modifiers.quote
|
||||||
quote_a: function(assert, quoted='@include(/page)'){
|
// XXX
|
||||||
return {code: [
|
|
||||||
'@quote(text="'+ quoted +'")',
|
|
||||||
quoted ], } },
|
|
||||||
quote_b: function(assert, quoted='@include(/page)'){
|
|
||||||
return {code: [
|
|
||||||
'<quote>'+ quoted +'</quote>',
|
|
||||||
quoted ], } },
|
|
||||||
/* XXX this is broken...
|
|
||||||
quote_quote_a_a: function(assert){
|
|
||||||
return this.quote_a(assert, '@qoote(text=\\"text\\")') },
|
|
||||||
//*/
|
|
||||||
quote_quote_a_b: function(assert){
|
|
||||||
return this.quote_b(assert, '@qoote(text="text")') },
|
|
||||||
quote_quote_b_a: function(assert){
|
|
||||||
return this.quote_a(assert, '<qoote> text </quote>') },
|
|
||||||
// XXX do we need a non-html way to quote things??
|
|
||||||
quote_quote_b_b: function(assert){
|
|
||||||
return this.quote_b(assert, '<qoote> text </quote>') },
|
|
||||||
|
|
||||||
// macro...
|
// macro...
|
||||||
macro: function(assert, path='/page', res){
|
macro: function(assert, path='/page', res){
|
||||||
@ -349,33 +335,6 @@ test.Setups({
|
|||||||
code: [
|
code: [
|
||||||
'<macro src="/not_found">[[ @source(./path) ]]<else>ERR</else></macro>',
|
'<macro src="/not_found">[[ @source(./path) ]]<else>ERR</else></macro>',
|
||||||
'ERR', ], } },
|
'ERR', ], } },
|
||||||
macro_define: function(assert){
|
|
||||||
return {
|
|
||||||
page: P,
|
|
||||||
code: [
|
|
||||||
'<macro name=show_path>[[ @source(./path) ]]<else>ERR</else></macro>',
|
|
||||||
'', ], } },
|
|
||||||
macro_use: function(assert){
|
|
||||||
var res = this.macro_define(assert)
|
|
||||||
return {
|
|
||||||
page: P,
|
|
||||||
code: [
|
|
||||||
res.code[0] + '<macro name=show_path src="/page"/>',
|
|
||||||
'[[ /page ]]' ]} },
|
|
||||||
macro_use_404: function(assert){
|
|
||||||
var res = this.macro_define(assert)
|
|
||||||
return {
|
|
||||||
page: P,
|
|
||||||
code: [
|
|
||||||
res.code[0] + '<macro name=show_path src="/mooo"/>',
|
|
||||||
'ERR' ]} },
|
|
||||||
macro_use_multi: function(assert){
|
|
||||||
var res = this.macro_define(assert)
|
|
||||||
return {
|
|
||||||
page: P,
|
|
||||||
code: [
|
|
||||||
res.code[0] + '<macro name=show_path src="/*/page"/>',
|
|
||||||
'[[ /async/page ]][[ /multi/page ]][[ /async/multi/page ]]' ]} },
|
|
||||||
|
|
||||||
// XXX var...
|
// XXX var...
|
||||||
// XXX
|
// XXX
|
||||||
@ -448,7 +407,7 @@ test.Tests({
|
|||||||
var p = serialize.partialDeepCopy(page)
|
var p = serialize.partialDeepCopy(page)
|
||||||
var s = serialize.partialDeepCopy(st)
|
var s = serialize.partialDeepCopy(st)
|
||||||
assert(
|
assert(
|
||||||
(res = await parser.exec(
|
(res = await parser.parse(
|
||||||
p,
|
p,
|
||||||
input,
|
input,
|
||||||
s))
|
s))
|
||||||
@ -458,7 +417,7 @@ test.Tests({
|
|||||||
'\n\t out: "'+ res +'"',
|
'\n\t out: "'+ res +'"',
|
||||||
'\n\texpected: "'+ expect +'"') } } },
|
'\n\texpected: "'+ expect +'"') } } },
|
||||||
//asyncParse: async function(assert, state){
|
//asyncParse: async function(assert, state){
|
||||||
// return await this.exec(assert, state) },
|
// return await this.parse(assert, state) },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user