From 907194ec9b276b6e8e66cc442b21d9788019519e Mon Sep 17 00:00:00 2001 From: Andrew Sales Date: Sun, 6 Aug 2023 12:10:00 +0100 Subject: [PATCH] [MOD] pseudo-pattern for syntax checking; fired-rule for every check --- evaluate.xqm | 49 ++++++++++++++++++++++++++++++++++++------ test/test-evaluate.xqm | 2 +- utils.xqm | 6 +++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/evaluate.xqm b/evaluate.xqm index 10cea42..7e5a32b 100644 --- a/evaluate.xqm +++ b/evaluate.xqm @@ -33,6 +33,7 @@ declare function eval:schema( {output:schema-title($schema/sch:title)} {$schema/@schemaVersion} {output:namespace-decls-as-svrl($schema/sch:ns)} + {for $phase in ($schema/sch:phase/@id/data(), '') let $context as map(*) := context:get-context($instance, $schema, $phase, $options) return eval:phase($context)} @@ -95,23 +96,53 @@ declare function eval:pattern( (: let $_ := trace('PATTERN '||$pattern/@id||' prolog='||$prolog) :) (: let $_ := trace('PATTERN $bindings '||serialize($context?globals, map{'method':'adaptive'})) :) + let $rules := $pattern/sch:rule return ( if($context?dry-run eq 'true') - then $context?globals?*[svrl:*] + then + ($context?globals?*[self::svrl:*], eval:all-rules($rules, $context)) else ( {$pattern/(@id, @name, @role), if($pattern/@documents) then attribute{'documents'}{$context?instance ! base-uri(.)} else()} , - $context?instance ! eval:rules( - $pattern/sch:rule, - utils:make-query-prolog($context), - map:put($context, 'instance', .) - ) + eval:rules($rules, $context) ) ) }; +declare function eval:all-rules( + $rules as element(sch:rule)*, + $context as map(*) +) +as element()* +{ + $context?instance + ! + (for $rule in $rules + return + eval:rule( + $rule, + utils:make-query-prolog($context), + map:put($context, 'instance', .) + )) +}; + +declare function eval:rules( + $rules as element(sch:rule)*, + $context as map(*) +) +as element()* +{ + $context?instance + ! + eval:rules( + $rules, + utils:make-query-prolog($context), + map:put($context, 'instance', .) + ) +}; + (:~ Evaluate rules, stopping once one fires. : (Necessitated by ISO2020 6.5.) : @param rules the rules to evaluate @@ -162,7 +193,11 @@ as element()* ) return if($rule-context) - then( + then + if($context?dry-run eq 'true') + then $rule-context[self::svrl:*] + else + ( {$rule/(@id, @name, @context, @role, @flag), if($rule/../@documents) then attribute{'document'}{$context?instance/base-uri()} else ()} diff --git a/test/test-evaluate.xqm b/test/test-evaluate.xqm index e944aa3..c1c87e7 100644 --- a/test/test-evaluate.xqm +++ b/test/test-evaluate.xqm @@ -1320,7 +1320,7 @@ declare %unit:test function _:global-variable-syntax-error() ), unit:assert-equals( $result/svrl:failed-assert/svrl:text, - No specifier after lookup operator: ';'. + No specifier after lookup operator: ';'. @value='?' ) ) }; \ No newline at end of file diff --git a/utils.xqm b/utils.xqm index d87ccf6..16a7dc9 100644 --- a/utils.xqm +++ b/utils.xqm @@ -141,14 +141,14 @@ declare function utils:eval( { if($options?dry-run eq 'true') then + (, try{ xquery:parse($query, map{'pass':'true'}) } catch * { - , - {$err:description} - } + {$err:description} {' @'||$node/name()}='{$node/data()}' + }) else xquery:eval($query, $bindings, map{'pass':'true'}) }; \ No newline at end of file