mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
more refining the query language + docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ec42cf7899
commit
23aeaffe5d
@ -787,6 +787,9 @@ var TagsPrototype = {
|
|||||||
// | (<query> .. )
|
// | (<query> .. )
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// NOTE: all lists are treated as sets in that any item can be present
|
||||||
|
// only once and all duplicates are discarded.
|
||||||
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Execution model:
|
// Execution model:
|
||||||
@ -822,6 +825,19 @@ var TagsPrototype = {
|
|||||||
// returns a list while quoting will place the value as-is
|
// returns a list while quoting will place the value as-is
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// Expansion:
|
||||||
|
// ^( .. )
|
||||||
|
// will expand the contents to the containing list
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// (a b ^(c d) c e)
|
||||||
|
// -> (a b c d e)
|
||||||
|
//
|
||||||
|
// NOTE: that the repeating value 'c' is discarded.
|
||||||
|
// NOTE: @( .. ) can be used to expand values at the pre-processor
|
||||||
|
// stage.
|
||||||
|
//
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// Pre-processor function:
|
// Pre-processor function:
|
||||||
// (search ..)
|
// (search ..)
|
||||||
@ -894,7 +910,8 @@ var TagsPrototype = {
|
|||||||
// avoid the parse stage...
|
// avoid the parse stage...
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// XXX do we need quoting???
|
// XXX would be nice to have access to the forming argument list to
|
||||||
|
// be able to expand list (a-la ...list in JS)
|
||||||
// XXX not sure about the .flat(1) calls...
|
// XXX not sure about the .flat(1) calls...
|
||||||
__query_ns_pre: {
|
__query_ns_pre: {
|
||||||
search: function(...args){
|
search: function(...args){
|
||||||
@ -917,7 +934,6 @@ var TagsPrototype = {
|
|||||||
t = t instanceof Array ? t : [t]
|
t = t instanceof Array ? t : [t]
|
||||||
return [...args
|
return [...args
|
||||||
.reduce(function(res, l){
|
.reduce(function(res, l){
|
||||||
//return res.intersect(l.flat(1)) },
|
|
||||||
return res
|
return res
|
||||||
.intersect(l instanceof Array ?
|
.intersect(l instanceof Array ?
|
||||||
l.flat(1)
|
l.flat(1)
|
||||||
@ -943,18 +959,30 @@ var TagsPrototype = {
|
|||||||
// .query(query, true)
|
// .query(query, true)
|
||||||
// -> values
|
// -> values
|
||||||
//
|
//
|
||||||
|
// XXX do we need expand(..) ???
|
||||||
query: function(query, raw){
|
query: function(query, raw){
|
||||||
var that = this
|
var that = this
|
||||||
var pre = this.__query_ns_pre
|
var pre = this.__query_ns_pre
|
||||||
var ns = this.__query_ns
|
var ns = this.__query_ns
|
||||||
var sns = this.__query_ns_special
|
var sns = this.__query_ns_special
|
||||||
|
|
||||||
|
var expand = function(prefix, list){
|
||||||
|
return prefix == null ?
|
||||||
|
list
|
||||||
|
: list
|
||||||
|
.reduce(function(res, e){
|
||||||
|
return res[res.length-1] == prefix ?
|
||||||
|
res.slice(0, -1).concat(e instanceof Array ? e : [e])
|
||||||
|
: res.concat([e]) }, [])
|
||||||
|
.filter(function(e){
|
||||||
|
return e != prefix }) }
|
||||||
|
|
||||||
// Query Language pre-processor...
|
// Query Language pre-processor...
|
||||||
var PreQL = function(args){
|
var PreQL = function(args){
|
||||||
return (
|
return (
|
||||||
// function -> query args and call...
|
// function -> query args and call...
|
||||||
args[0] in pre ?
|
args[0] in pre ?
|
||||||
pre[args[0]].call(that, ...PreQL(args.slice(1)))
|
pre[args[0]].call(that, ...expand('@', PreQL(args.slice(1))))
|
||||||
// list of tags -> query each arg...
|
// list of tags -> query each arg...
|
||||||
: args
|
: args
|
||||||
.map(function(arg){
|
.map(function(arg){
|
||||||
@ -970,17 +998,16 @@ var TagsPrototype = {
|
|||||||
return (
|
return (
|
||||||
// function -> query args and call...
|
// function -> query args and call...
|
||||||
args[0] in ns ?
|
args[0] in ns ?
|
||||||
ns[args[0]].call(that, ...QL(args.slice(1)))
|
ns[args[0]].call(that, ...expand('^', QL(args.slice(1))))
|
||||||
// special form -> pass args as-is...
|
// special form -> pass args as-is...
|
||||||
: args[0] in sns ?
|
: args[0] in sns ?
|
||||||
sns[args[0]].call(that, ...args.slice(1))
|
sns[args[0]].call(that, ...expand('^', args.slice(1)))
|
||||||
// list of tags -> query each arg...
|
// list of tags -> query each arg...
|
||||||
: args
|
: args
|
||||||
.map(function(arg){
|
.map(function(arg){
|
||||||
return arg instanceof Array ?
|
return arg instanceof Array ?
|
||||||
QL(arg)
|
QL(arg)
|
||||||
// quoting...
|
// quoting...
|
||||||
// XXX this should be a lexer directive (???)
|
|
||||||
: arg.startsWith('`') ?
|
: arg.startsWith('`') ?
|
||||||
arg.slice(1)
|
arg.slice(1)
|
||||||
: that.values(arg) }) ) }
|
: that.values(arg) }) ) }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user