experimenting with path argument syntaxes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-21 12:31:04 +03:00
parent 561de44f54
commit b96174ed7f
3 changed files with 55 additions and 2 deletions

View File

@ -1507,7 +1507,7 @@ module.System = {
this.render_root
&& (this.render_root.location = to.path)
return this.render_root.path },
//
// syntax:
// /<path-from>/to:<path-to>/move
//
@ -1526,6 +1526,10 @@ module.System = {
&& (this.render_root.location = to)
return '' },
//
test_path: function(){
},
// XXX System/back
// XXX System/forward
// XXX System/sort

View File

@ -402,7 +402,7 @@ module.BaseParser = {
expand: async function*(page, ast, state={}){
ast = ast == null ?
//this.group(page)
this.group(page, await page.raw)
this.group(page, await page.raw ?? '')
: typeof(ast) == 'string' ?
this.group(page, ast)
: ast instanceof types.Generator ?

View File

@ -221,6 +221,55 @@ module = {
if(alt_pages){
for(var page of [...this.ALTERNATIVE_PAGES]){
yield* this.paths(path.concat(page), seen) }} },
// XXX EXPERIMENTAL...
//
// .splitSrgs(<path>)
// -> <spec>
//
// Format:
// {
// path: <path>
// args: {
// <name>:<value>,
// ...
// }
// action: <action>
// }
//
// Syntax:
// <path>/<name>:<value>/<name>:<value>/../action
//
// XXX the problem here is that we could legitimately create path
// items containing ":" -- it either needs to be a reserved char
// or this scheme will not work...
splitArgs: function(path){
path = this.normalize(path, 'array')
var res = {
path: '',
args: {},
actions: path.pop(),
}
var state = 'path'
var cur, value
for(var elem of path){
if(elem.includes(':')){
state = 'arg' }
if(state == 'path'){
res.path += '/'+ elem
} else if(state == 'arg'){
;[cur, value] = elem.split(':')
res[cur] = value
state = value
} else if(state == 'value'){
res[cur] += '/'+ value } }
return res },
}