Skip to content

Commit

Permalink
[MOD] patterns will have global context, so report errors there
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Aug 5, 2023
1 parent 44fb3f8 commit d308eab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
38 changes: 21 additions & 17 deletions evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ declare function eval:schema(
{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
($context?globals?*[self::svrl:*[@err:*]],
eval:phase($context))}
return eval:phase($context)}
</svrl:schematron-output>
else
eval:schema($instance, $schema, $phase)
Expand Down Expand Up @@ -97,15 +95,19 @@ declare function eval:pattern(
(: let $_ := trace('PATTERN '||$pattern/@id||' prolog='||$prolog) :)
(: let $_ := trace('PATTERN $bindings '||serialize($context?globals, map{'method':'adaptive'})) :)

return (:TODO active-pattern/@name:)(
<svrl:active-pattern>
{$pattern/(@id, @name, @role),
if($pattern/@documents) then attribute{'documents'}{$context?instance ! base-uri(.)} else()}
</svrl:active-pattern>,
$context?instance ! eval:rules(
$pattern/sch:rule,
utils:make-query-prolog($context),
map:put($context, 'instance', .)
return (
if($context?dry-run eq 'true')
then $context?globals?*[svrl:*]
else (
<svrl:active-pattern>
{$pattern/(@id, @name, @role),
if($pattern/@documents) then attribute{'documents'}{$context?instance ! base-uri(.)} else()}
</svrl:active-pattern>,
$context?instance ! eval:rules(
$pattern/sch:rule,
utils:make-query-prolog($context),
map:put($context, 'instance', .)
)
)
)
};
Expand Down Expand Up @@ -155,7 +157,7 @@ as element()*
let $rule-context := utils:eval(
$query => utils:escape(),
map:merge((map{'':$context?instance}, $context?globals)),
map{'pass':'true', 'dry-run':$context?dry-run},
map{'dry-run':$context?dry-run},
$rule/@context
)
return
Expand Down Expand Up @@ -215,7 +217,7 @@ declare function eval:assertion(
let $result := utils:eval(
$prolog || $assertion/@test => utils:escape(),
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true', 'dry-run':$context?dry-run},
map{'dry-run':$context?dry-run},
$assertion/@test
)
return
Expand All @@ -238,16 +240,18 @@ declare function eval:phase($context as map(*))
let $phase := $context?phase
let $_ := utils:check-duplicate-variable-names($phase/sch:let)

let $dry-run as map(*) := map{'dry-run':$context?dry-run}

(:add phase variables to context:)
let $globals as map(*) := context:evaluate-root-context-variables(
$phase/sch:let,
$context?instance,
$context?ns-decls,
$phase/../sch:ns,
$context?globals,
map{'dry-run':$context?dry-run}
$dry-run
)
let $context := map:put($context, 'globals', $globals)

return $context?patterns ! eval:pattern(., $context)
return $context?patterns ! eval:pattern(., map:merge(($context, $dry-run)))
};
1 change: 1 addition & 0 deletions utils.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ declare function utils:eval(
xquery:parse($query, map{'pass':'true'})
}
catch * {
<svrl:fired-rule context='{$node/path()}'/>,
<svrl:failed-assert err:code='{$err:code}' location='{$node/path()}'
test='xquery:parse(.)'>
<svrl:text>{$err:description}</svrl:text></svrl:failed-assert>
Expand Down

0 comments on commit d308eab

Please sign in to comment.