From 7b8766ac4c868f93e89f544a674abd9b6be17f8c Mon Sep 17 00:00:00 2001 From: Andrew Sales Date: Tue, 9 Jan 2024 13:40:47 +0000 Subject: [PATCH] [MOD] parse user-defined functions, re #21 - test failing and ignored prior to merge into main --- evaluate.xqm | 9 ++++--- test/test-evaluate.xqm | 60 +++++++++++++++++++++++++++++++++++++++++- utils.xqm | 19 +++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/evaluate.xqm b/evaluate.xqm index 600ee16..087bea7 100644 --- a/evaluate.xqm +++ b/evaluate.xqm @@ -11,14 +11,16 @@ import module namespace output = 'http://www.andrewsales.com/ns/xqs-output' at import module namespace utils = 'http://www.andrewsales.com/ns/xqs-utils' at 'utils.xqm'; +declare namespace xqy = 'http://www.w3.org/2012/xquery'; declare namespace sch = "http://purl.oclc.org/dsdl/schematron"; declare namespace svrl = "http://purl.oclc.org/dsdl/svrl"; -(:~ Evaluates the schema to produce SVRL output. +(:~ Evaluates the schema to produce SVRL output, applying the processing options + : specified. : @param instance the document instance : @param schema the Schematron schema : @param phase the active phase - : @param options map of options + : @param options map of processing options :) declare function eval:schema( $instance as node(), @@ -34,7 +36,8 @@ declare function eval:schema( {$schema/@schemaVersion} {output:namespace-decls-as-svrl($schema/sch:ns)} - {for $phase in ($schema/sch:phase/@id/data(), '') + {$schema/xqy:function ! utils:parse-function(., $options)[self::svrl:*]} + {for $phase in ($schema/sch:phase/@id, '') let $context as map(*) := context:get-context($instance, $schema, $phase, $options) return eval:phase($context)} diff --git a/test/test-evaluate.xqm b/test/test-evaluate.xqm index 00d4ef5..12e20fb 100644 --- a/test/test-evaluate.xqm +++ b/test/test-evaluate.xqm @@ -6,6 +6,7 @@ module namespace _ = 'http://www.andrewsales.com/ns/xqs-evaluation-tests'; declare namespace sch = "http://purl.oclc.org/dsdl/schematron"; declare namespace svrl = "http://purl.oclc.org/dsdl/svrl"; +declare namespace xqy = 'http://www.w3.org/2012/xquery'; import module namespace eval = 'http://www.andrewsales.com/ns/xqs-evaluate' at '../evaluate.xqm'; @@ -1513,9 +1514,66 @@ declare %unit:test function _:value-of-select-syntax-error() ) }; +declare %unit:test function _:phase-variable-scope-error() +{ + let $result := + eval:schema( + document{}, + + + + + + + + + + + + + + , + 'two', + map{'dry-run':'true'} + ) + return + ( + unit:assert-equals( + ($result/svrl:failed-assert)[1]/svrl:text, + Undeclared variable: $foo. @select='$foo' + ) + ) +}; + +(:TODO:) +declare %unit:ignore function _:function-syntax-error() +{ + let $result := + eval:schema( + document{}, + + + + + + + + , + '', + map{'dry-run':'true'} + ) + return + ( + unit:assert-equals( + ($result/svrl:failed-assert)[1]/svrl:text, + Calculation is incomplete. xqy:function='declare function local:foo(){{**}};' + ) + ) +}; + (:TODO pattern/@documents diagnostics properties -rule/let +functions :) \ No newline at end of file diff --git a/utils.xqm b/utils.xqm index 05b4db6..c82aa7a 100644 --- a/utils.xqm +++ b/utils.xqm @@ -6,6 +6,7 @@ declare namespace xqs = 'http://www.andrewsales.com/ns/xqs'; declare namespace sch = "http://purl.oclc.org/dsdl/schematron"; declare namespace svrl = "http://purl.oclc.org/dsdl/svrl"; declare namespace map = "http://www.w3.org/2005/xpath-functions/map"; +declare namespace xqy = 'http://www.w3.org/2012/xquery'; (:~ Builds the string of variable declarations in the prolog, for initial : evaluation. @@ -187,4 +188,22 @@ declare function utils:eval( {$err:description}{' @'||$node/name()}='{$node/data()}' }) else xquery:eval($query, $bindings, map{'pass':'true'}) +}; + +declare function utils:parse-function( + $node as element(xqy:function), + $options as map(*) +) +as element()+ +{ + , + try{ + xquery:parse($node || 0, map{'pass':'true'}) + } + catch * { + + {$err:description}{' '||$node/name()}='{$node/data()}' + + } }; \ No newline at end of file