refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-04-22 04:32:44 +03:00
parent dd4629c670
commit e4a1139be3
2 changed files with 122 additions and 129 deletions

View File

@ -338,7 +338,6 @@ module.UNDEFINED = ASIS(undefined)
var normalizeTabs = function(str){
str = str.split(/\n/g)
// get min number of leading tabs...
var i = str.length == 2 && /^\t/.test(str[1]) ?
str[1].split(/^(\t+)/)[1].length - 1
@ -352,7 +351,6 @@ var normalizeTabs = function(str){
return /^\t+/.test(l) ?
l.split(/^(\t+)/)[1].length
: 0}))
return (str[0] +'\n'
+ str
.slice(1)
@ -361,8 +359,7 @@ var normalizeTabs = function(str){
// replace tabs...
.replace(/\t/g, ' '))
// remove leading and trailing whitespace...
.trim()
}
.trim() }
var doWithRootAction =
@ -374,9 +371,7 @@ function(func){
|| MetaActions.getHandlerList)
.apply(this, args)
return func.apply(this, [handlers.pop()].concat(args))
}
}
return func.apply(this, [handlers.pop()].concat(args)) } }
//
@ -417,9 +412,16 @@ function(func){
// NOTE: identifiers are resolved as attributes of the context...
// XXX this is the same as ImageGrid's keyboard.parseActionCall(..), reuse
// in a logical manner...
// placeholders...
var __Atom
var __Argument
var parseStringAction =
module.parseStringAction =
function(txt){
Object.assign(
// parser...
function(txt){
// split off the doc...
var c = txt.split('--')
var doc = (c[1] || '').trim()
@ -481,29 +483,22 @@ function(txt){
code: txt,
}
}
parseStringAction.Identifier =
object.Constructor(
'Identifier',
{
},{
// atoms...
Atom: (__Atom = object.Constructor('Atom', {
__init__: function(value){
this.value = value
},
valueOf: function(){ return this.value },
})
parseStringAction.Argument =
object.Constructor(
'Argument',
{
__init__: function(value){
this.value = value
},
valueOf: function(){ return this.value },
})
parseStringAction.ALLARGS = new parseStringAction.Argument('...')
this.value = value },
valueOf: function(){
return this.value },
})),
Identifier: object.Constructor('Identifier',
Object.create(__Atom.prototype)),
Argument: (__Argument = object.Constructor('Argument',
Object.create(__Atom.prototype))),
ALLARGS: new __Argument('...'),
parseStringAction.resolveArgs = function(context, action_args, call_args){
// general API...
resolveArgs: function(context, action_args, call_args){
var that = this
var rest
var args = [].slice.call(action_args)
@ -522,12 +517,10 @@ parseStringAction.resolveArgs = function(context, action_args, call_args){
: arg })
rest != null
&& args.splice(rest, 1, ...call_args)
return args },
return args
}
// XXX should this break if action does not exist???
parseStringAction.callAction = function(context, action, ...args){
// XXX should this break if action does not exist???
callAction: function(context, action, ...args){
action = typeof(action) == typeof('str') ?
this(action)
: action
@ -536,25 +529,25 @@ parseStringAction.callAction = function(context, action, ...args){
context[action.action]
.apply(context, this.resolveArgs(context, action.arguments, args))
// action not found or is not callable... (XXX)
: undefined
}
parseStringAction.applyAction = function(context, action, args){
return this.callAction(context, action, ...args) }
: undefined },
applyAction: function(context, action, args){
return this.callAction(context, action, ...args) },
// XXX make this stricter...
var isStringAction =
module.isStringAction =
function(txt){
// XXX make this stricter...
isStringAction: function(txt){
try{
var parsed = typeof(txt) == typeof('str')
&& (this.parseStringAction || parseStringAction)(txt)
return parsed
&& /[a-zA-Z_][a-zA-Z0-9_]*/.test(parsed.action)
} catch(e){
return false
}
}
return false } },
})
// shorthand...
var isStringAction =
module.isStringAction =
parseStringAction.isStringAction

View File

@ -1,6 +1,6 @@
{
"name": "ig-actions",
"version": "3.24.3",
"version": "3.24.4",
"description": "",
"main": "actions.js",
"scripts": {