mirror of
https://github.com/flynx/pWiki.git
synced 2026-07-14 04:20:58 +00:00
.parse(..) -> .exec(..) -- better semantics...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
79ad01b9aa
commit
f646b9939e
@ -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') },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -925,12 +925,12 @@ module.parser = {
|
|||||||
// | -<filter> <filter-spec>
|
// | -<filter> <filter-spec>
|
||||||
//
|
//
|
||||||
// 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 +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.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 +1048,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 +1119,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 +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.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 +1192,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 ??= {}
|
||||||
|
|
||||||
@ -1311,7 +1311,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)
|
||||||
|
|
||||||
@ -1485,7 +1485,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 +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.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 {
|
||||||
@ -448,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))
|
||||||
@ -458,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