Ambiguous query selector (~) allows typeOf comparison

i.e: Instead of checking if the target is the SAME type, the query will use Titanium.typeOf to determine if the class extends the type
This commit is contained in:
hbomb79 2017-05-08 22:38:18 +12:00
parent 68eccdcb23
commit aee0c0f704
7 changed files with 13 additions and 7 deletions

View file

@ -142,4 +142,4 @@ function DynamicValue:refresh()
self.resolvedStacks, self.cachedValues = stacks, newCachedValues
if stacks then self:solve() end
end
end

View file

@ -8,7 +8,7 @@ local function splitXMLTheme( queue, tree )
if children then
for n = 1, #children do
local type = tree[ i ].type
queue[ #queue + 1 ] = { ( type == "Any" and "*" or type ) .. getTagDetails( tree[ i ] ), children[ n ], tree[ i ] }
queue[ #queue + 1 ] = { ( tree[ i ].arguments.typeOf and "~" or "" ) .. ( type == "Any" and "*" or type ) .. getTagDetails( tree[ i ] ), children[ n ], tree[ i ] }
end
end
end

View file

@ -19,6 +19,8 @@ function QueryLexer:tokenize()
if self.inCondition then
self:tokenizeCondition( stream )
elseif stream:find "^~" then
self:pushToken { type = "QUERY_TYPEOF", value = self:consumePattern "^~" }
elseif stream:find "^%b[]" then
self:pushToken { type = "QUERY_COND_OPEN" }
self:consume( 1 )

View file

@ -20,7 +20,7 @@ local function queryScope( scope, section, results )
node = scope[ i ]
if ( not section.id or node.id == section.id ) and
( not section.type or section.type == "*" or node.__type == section.type ) and
( not section.type or section.type == "*" or ( section.ambiguous and Titanium.typeOf( node, section.type ) or node.__type == section.type ) ) and
( not section.classes or node:hasClass( section.classes ) ) then
local condition, failed = section.condition
if condition then

View file

@ -41,7 +41,10 @@ function QueryParser:parse()
local token = self:stepForward()
while token do
if token.type == "QUERY_TYPE" then
if token.type == "QUERY_TYPEOF" then
if currentStep.ambiguous then self:throw "Attempted to set query section as 'ambiguous' using typeof operator (~). Already set as ambiguous (trailing ~)" end
currentStep.ambiguous = true
elseif token.type == "QUERY_TYPE" then
if currentStep.type then self:throw( "Attempted to set query type to '"..token.value.."' when already set as '"..currentStep.type.."'" ) end
currentStep.type = token.value

View file

@ -109,4 +109,4 @@ function MDynamic:refreshDynamicValue( property )
if dyn then
dyn:attach()
end
end
end

View file

@ -1,9 +1,10 @@
local function doesLevelMatch( target, criteria, noAttr )
if ( ( criteria.type and target.__type == criteria.type ) or criteria.type == "*" or not criteria.type ) and noAttr then
local doesTypeMatch = criteria.ambiguous and Titanium.typeOf( target, criteria.type ) or target.__type == criteria.type
if ( criteria.type == "*" or not criteria.type or doesTypeMatch ) and noAttr then
return true
end
if ( criteria.type and target.__type ~= criteria.type and criteria.type ~= "*" ) or ( criteria.id and target.id ~= criteria.id ) or ( criteria.classes and not target:hasClass( criteria.classes ) ) then
if ( criteria.type and not doesTypeMatch and criteria.type ~= "*" ) or ( criteria.id and target.id ~= criteria.id ) or ( criteria.classes and not target:hasClass( criteria.classes ) ) then
return false
end