Compare commits

..

5 Commits

Author SHA1 Message Date
fa720d40fd notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-07-07 18:17:00 +03:00
75c86f66e1 notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-07-07 13:53:07 +03:00
f646b9939e .parse(..) -> .exec(..) -- better semantics...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-07-07 13:48:00 +03:00
79ad01b9aa tests...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-07-07 13:21:29 +03:00
b37925d28e more testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-07-07 12:13:45 +03:00
2 changed files with 80 additions and 31 deletions

View File

@ -33,7 +33,7 @@ var pwpath = require('./path')
// "aaa \"bbb \\"ccc\\" bbb\" aaa"
// XXX RENAME...
// ...this handles the syntax and lexing...
// ...this handles the syntax and execution...
var BaseParser =
module.BaseParser = {
// patterns...
@ -743,7 +743,7 @@ module.BaseParser = {
//
//
// 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...
resolve: function(page, ast, state={}, nested_handlers={}){
var that = this
@ -814,7 +814,7 @@ module.BaseParser = {
// XXX
},
parse: function(page, ast, state={}, nested_handlers={}, wait='wait'){
exec: function(page, ast, state={}, nested_handlers={}, wait='wait'){
var that = this
// XXX might be a good idea to limit recursion depth here...
var merge = function(ast){
@ -837,7 +837,7 @@ module.BaseParser = {
state[wait],
function(ast){
// 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...
return (state.unresolved
|| !that.isResolved(ast)) ?
@ -847,8 +847,8 @@ module.BaseParser = {
// XXX how should this play with filters???
// ...should filters be client-side only??
parseNested: function(page, ast, state={}, nested_handlers={}){
return this.parse(page, ast, state, nested_handlers, 'waitNestedi') },
execNested: function(page, ast, state={}, nested_handlers={}){
return this.exec(page, ast, state, nested_handlers, 'waitNestedi') },
}
@ -898,6 +898,8 @@ var parser =
module.parser = {
__proto__: BaseParser,
INCLUDE_NEST_LIMIT: 20,
//
// <macro>(<args>, <body>, <state>){ .. }
// -> undefined
@ -924,13 +926,20 @@ module.parser = {
// <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:
// pwiki.parse('<filter test>moo test</filter>')
// pwiki.exec('<filter test>moo test</filter>')
// -> ''
// while these do:
// pwiki.parse('<filter test/>moo test')
// pwiki.exec('<filter 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'
// for more info see:
// 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!
return Promise.awaitOrRun(
// XXX how do we resolve the await loop?
parser.parseNested(this, ast, {
parser.execNested(this, ast, {
...state,
filters: local.includes(this.ISOLATED_FILTERS) ?
local
@ -1048,7 +1057,7 @@ module.parser = {
return '' }
return Promise.awaitOrRun(
this.parseNested(page, name, state),
this.execNested(page, name, state),
function(name){
// XXX INC_DEC
var inc = args.inc
@ -1119,7 +1128,7 @@ module.parser = {
if(text){
return Promise.awaitOrRun(
//state.waitNested,
that.parseNested(page, text, state),
that.execNested(page, text, state),
function(value){
text = vars[name] = value
return show ?? false ?
@ -1133,8 +1142,8 @@ module.parser = {
var lst = []
for(var [name, value] of Object.entries(args)){
lst.push(
this.parseNested(page, name, state),
this.parseNested(page, value, state)) }
this.execNested(page, name, state),
this.execNested(page, value, state)) }
var vars = state.vars ??= {}
return Promise.awaitOrRun(
state.waitNested,
@ -1192,7 +1201,7 @@ module.parser = {
var name = args.name
return Promise.awaitOrRun(
this.parseNested(page, name, state),
this.execNested(page, name, state),
function(name){
var slots = state.slots ??= {}
@ -1285,7 +1294,6 @@ module.parser = {
// XXX need a way to make encode option transparent...
// XXX do we want to load a specific slot/block???
// XXX REVISE...
INCLUDE_LIMIT: 20,
include: Macro(
['src', 'recursive', 'join',
['s', 'strict', 'isolated']],
@ -1311,7 +1319,7 @@ module.parser = {
var base = page.basepath
return Promise.awaitOrRun(
this.parseNested(page, args.src, state),
this.execNested(page, args.src, state),
function(src){
//src = page.resolvePathVars(src)
@ -1331,7 +1339,7 @@ module.parser = {
// re-include limit...
// XXX HACK???
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
// breaks returning [object Object] overriding
// the actual return value
@ -1485,7 +1493,7 @@ module.parser = {
var that = this
return Promise.awaitOrRun(
args.src
&& this.parseNested(page, args.src, state),
&& this.execNested(page, args.src, state),
function(src){
//src = page.resolvePathVars(src)
var text =
@ -1560,7 +1568,7 @@ module.parser = {
function(page, args, body, state){
var that = this
return Promise.awaitOrRun(
this.parseNested(page, args.name, state),
this.execNested(page, args.name, state),
function(name){
// set macro...
if(name && body){

View File

@ -112,7 +112,7 @@ module.exports.P = {
// XXX should this return an arrya for a multi-match???
get text(){
return this.__parser__.parse(this, this.raw, {}) },
return this.__parser__.exec(this, this.raw, {}) },
get: function(p){
return {
@ -278,17 +278,13 @@ test.Setups({
page: P,
code:[
'@include("/isolated") @slot(slot overloaded)',
'overloaded ',
],
} },
'overloaded ', ], } },
include_isolated: function(assert){
return {
page: P,
code:[
'@include(isolated /isolated) @slot(slot overloaded)',
'original overloaded',
],
} },
'original overloaded', ], } },
include_partial_isolated: function(assert){
return {
page: P,
@ -317,8 +313,26 @@ test.Setups({
'<< << recursion found >> >>', ], } },
// quote...
// for inline quoting see: test.Modifiers.quote
// XXX
// NOTE: for inline quoting see: test.Modifiers.quote
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 &lt;/quote>') },
// macro...
macro: function(assert, path='/page', res){
@ -335,6 +349,33 @@ test.Setups({
code: [
'<macro src="/not_found">[[ @source(./path) ]]<else>ERR</else></macro>',
'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
@ -407,7 +448,7 @@ test.Tests({
var p = serialize.partialDeepCopy(page)
var s = serialize.partialDeepCopy(st)
assert(
(res = await parser.parse(
(res = await parser.exec(
p,
input,
s))
@ -417,7 +458,7 @@ test.Tests({
'\n\t out: "'+ res +'"',
'\n\texpected: "'+ expect +'"') } } },
//asyncParse: async function(assert, state){
// return await this.parse(assert, state) },
// return await this.exec(assert, state) },
})