Skip to content

Commit

Permalink
[MOD] pseudo-pattern for syntax checking; fired-rule for every check
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Aug 6, 2023
1 parent d308eab commit 907194e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
49 changes: 42 additions & 7 deletions evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare function eval:schema(
{output:schema-title($schema/sch:title)}
{$schema/@schemaVersion}
{output:namespace-decls-as-svrl($schema/sch:ns)}
<svrl:active-pattern name='syntax checker' documents='{$schema/base-uri()}'/>
{for $phase in ($schema/sch:phase/@id/data(), '')
let $context as map(*) := context:get-context($instance, $schema, $phase, $options)
return eval:phase($context)}
Expand Down Expand Up @@ -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 (
<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', .)
)
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
Expand Down Expand Up @@ -162,7 +193,11 @@ as element()*
)
return
if($rule-context)
then(
then
if($context?dry-run eq 'true')
then $rule-context[self::svrl:*]
else
(
<svrl:fired-rule>
{$rule/(@id, @name, @context, @role, @flag),
if($rule/../@documents) then attribute{'document'}{$context?instance/base-uri()} else ()}
Expand Down
2 changes: 1 addition & 1 deletion test/test-evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ declare %unit:test function _:global-variable-syntax-error()
),
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>No specifier after lookup operator: ';'.</svrl:text>
<svrl:text>No specifier after lookup operator: ';'. @value='?'</svrl:text>
)
)
};
6 changes: 3 additions & 3 deletions utils.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ declare function utils:eval(
{
if($options?dry-run eq 'true')
then
(<svrl:fired-rule context='{$node/path()}'/>,
try{
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>
}
<svrl:text>{$err:description} {' @'||$node/name()}='{$node/data()}'</svrl:text></svrl:failed-assert>
})
else xquery:eval($query, $bindings, map{'pass':'true'})
};

0 comments on commit 907194e

Please sign in to comment.