mirror of
https://github.com/flynx/pWiki.git
synced 2026-10-03 12:51:40 +00:00
Compare commits
5 Commits
d8f8d5cc1e
...
fa720d40fd
| Author | SHA1 | Date | |
|---|---|---|---|
| fa720d40fd | |||
| 75c86f66e1 | |||
| f646b9939e | |||
| 79ad01b9aa | |||
| b37925d28e |
@ -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 lexing...
|
// ...this handles the syntax and execution...
|
||||||
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 .parse(..) / .parseNested(..)
|
// it can be deleted when calling .exec(..) / .execNested(..)
|
||||||
// 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
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function(page, ast, state={}, nested_handlers={}, wait='wait'){
|
exec: 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 .parse(..) / .parseNested(..) we can't trust
|
// call .exec(..) / .execNested(..) 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??
|
||||||
parseNested: function(page, ast, state={}, nested_handlers={}){
|
execNested: function(page, ast, state={}, nested_handlers={}){
|
||||||
return this.parse(page, ast, state, nested_handlers, 'waitNestedi') },
|
return this.exec(page, ast, state, nested_handlers, 'waitNestedi') },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -898,6 +898,8 @@ var parser =
|
|||||||
module.parser = {
|
module.parser = {
|
||||||
__proto__: BaseParser,
|
__proto__: BaseParser,
|
||||||
|
|
||||||
|
INCLUDE_NEST_LIMIT: 20,
|
||||||
|
|
||||||
//
|
//
|
||||||
// <macro>(<args>, <body>, <state>){ .. }
|
// <macro>(<args>, <body>, <state>){ .. }
|
||||||
// -> undefined
|
// -> undefined
|
||||||
@ -924,13 +926,20 @@ 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.parse('<filter test>moo test</filter>')
|
// pwiki.exec('<filter test>moo test</filter>')
|
||||||
// -> ''
|
// -> ''
|
||||||
// while these do:
|
// while these do:
|
||||||
// pwiki.parse('<filter test/>moo test')
|
// pwiki.exec('<filter test/>moo test')
|
||||||
// -> 'moo TEST'
|
// -> 'moo TEST'
|
||||||
// await pwiki.parse('<filter test>moo test</filter>@var()')
|
// await pwiki.exec('<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
|
||||||
@ -974,7 +983,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.parseNested(this, ast, {
|
parser.execNested(this, ast, {
|
||||||
...state,
|
...state,
|
||||||
filters: local.includes(this.ISOLATED_FILTERS) ?
|
filters: local.includes(this.ISOLATED_FILTERS) ?
|
||||||
local
|
local
|
||||||
@ -1048,7 +1057,7 @@ module.parser = {
|
|||||||
return '' }
|
return '' }
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.parseNested(page, name, state),
|
this.execNested(page, name, state),
|
||||||
function(name){
|
function(name){
|
||||||
// XXX INC_DEC
|
// XXX INC_DEC
|
||||||
var inc = args.inc
|
var inc = args.inc
|
||||||
@ -1119,7 +1128,7 @@ module.parser = {
|
|||||||
if(text){
|
if(text){
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
//state.waitNested,
|
//state.waitNested,
|
||||||
that.parseNested(page, text, state),
|
that.execNested(page, text, state),
|
||||||
function(value){
|
function(value){
|
||||||
text = vars[name] = value
|
text = vars[name] = value
|
||||||
return show ?? false ?
|
return show ?? false ?
|
||||||
@ -1133,8 +1142,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.parseNested(page, name, state),
|
this.execNested(page, name, state),
|
||||||
this.parseNested(page, value, state)) }
|
this.execNested(page, value, state)) }
|
||||||
var vars = state.vars ??= {}
|
var vars = state.vars ??= {}
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
state.waitNested,
|
state.waitNested,
|
||||||
@ -1192,7 +1201,7 @@ module.parser = {
|
|||||||
var name = args.name
|
var name = args.name
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.parseNested(page, name, state),
|
this.execNested(page, name, state),
|
||||||
function(name){
|
function(name){
|
||||||
var slots = state.slots ??= {}
|
var slots = state.slots ??= {}
|
||||||
|
|
||||||
@ -1285,7 +1294,6 @@ 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']],
|
||||||
@ -1311,7 +1319,7 @@ module.parser = {
|
|||||||
|
|
||||||
var base = page.basepath
|
var base = page.basepath
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
this.parseNested(page, args.src, state),
|
this.execNested(page, args.src, state),
|
||||||
function(src){
|
function(src){
|
||||||
//src = page.resolvePathVars(src)
|
//src = page.resolvePathVars(src)
|
||||||
|
|
||||||
@ -1331,7 +1339,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.macros.INCLUDE_LIMIT ?? 20){
|
> this.INCLUDE_NEST_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
|
||||||
@ -1485,7 +1493,7 @@ module.parser = {
|
|||||||
var that = this
|
var that = this
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
args.src
|
args.src
|
||||||
&& this.parseNested(page, args.src, state),
|
&& this.execNested(page, args.src, state),
|
||||||
function(src){
|
function(src){
|
||||||
//src = page.resolvePathVars(src)
|
//src = page.resolvePathVars(src)
|
||||||
var text =
|
var text =
|
||||||
@ -1560,7 +1568,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.parseNested(page, args.name, state),
|
this.execNested(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__.parse(this, this.raw, {}) },
|
return this.__parser__.exec(this, this.raw, {}) },
|
||||||
|
|
||||||
get: function(p){
|
get: function(p){
|
||||||
return {
|
return {
|
||||||
@ -278,17 +278,13 @@ 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,
|
||||||
@ -317,8 +313,26 @@ test.Setups({
|
|||||||
'<< << recursion found >> >>', ], } },
|
'<< << recursion found >> >>', ], } },
|
||||||
|
|
||||||
// quote...
|
// quote...
|
||||||
// for inline quoting see: test.Modifiers.quote
|
// NOTE: for inline quoting see: test.Modifiers.quote
|
||||||
// XXX
|
quote_a: function(assert, quoted='@include(/page)'){
|
||||||
|
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){
|
||||||
@ -335,6 +349,33 @@ 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
|
||||||
@ -407,7 +448,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.parse(
|
(res = await parser.exec(
|
||||||
p,
|
p,
|
||||||
input,
|
input,
|
||||||
s))
|
s))
|
||||||
@ -417,7 +458,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.parse(assert, state) },
|
// return await this.exec(assert, state) },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user