diff --git a/evaluate.xqm b/evaluate.xqm index c21913d..600ee16 100644 --- a/evaluate.xqm +++ b/evaluate.xqm @@ -185,6 +185,13 @@ declare function eval:rule( as element()* { let $_ := utils:check-duplicate-variable-names($rule/sch:let) + let $variable-errors := utils:evaluate-rule-variables( + $rule/sch:let, + $prolog, + map:merge((map{'':$context?instance}, $context?globals)), + $context, + () + ) let $query := string-join( ($prolog, utils:local-variable-decls($rule/sch:let), if($rule/sch:let) then 'return ' else '', $rule/@context), @@ -203,6 +210,7 @@ as element()* if($context?dry-run eq 'true') then ( + $variable-errors[self::svrl:*], $rule-context[self::svrl:*], eval:assertions($rule, $prolog, <_/>, $context) (:pass dummy context node:) ) diff --git a/test/test-evaluate.xqm b/test/test-evaluate.xqm index cf6796d..00d4ef5 100644 --- a/test/test-evaluate.xqm +++ b/test/test-evaluate.xqm @@ -1399,7 +1399,7 @@ declare %unit:test function _:dry-run-all-rules-processed() ) }; -declare %unit:ignore function _:rule-variable-syntax-error() +declare %unit:test function _:rule-variable-syntax-error() { let $result := eval:schema( @@ -1408,6 +1408,7 @@ declare %unit:ignore function _:rule-variable-syntax-error() + @@ -1418,13 +1419,12 @@ declare %unit:ignore function _:rule-variable-syntax-error() return ( unit:assert-equals( - count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/@context')]), + count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/Q{http://purl.oclc.org/dsdl/schematron}let[1]/@value')]), 1 ), unit:assert-equals( - $result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/@context')] - /svrl:text, - TODO + $result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/Q{http://purl.oclc.org/dsdl/schematron}let[1]/@value')]/svrl:text, + Incomplete FLWOR expression, expecting 'return'. @value='' ) ) }; @@ -1511,4 +1511,11 @@ declare %unit:test function _:value-of-select-syntax-error() Unexpected end of query: '.'. @select='...' ) ) -}; \ No newline at end of file +}; + +(:TODO +pattern/@documents +diagnostics +properties +rule/let +:) \ No newline at end of file diff --git a/utils.xqm b/utils.xqm index 45815e1..05b4db6 100644 --- a/utils.xqm +++ b/utils.xqm @@ -125,6 +125,42 @@ declare function utils:check-duplicate-variable-names($decls as element(sch:let) ) else() }; +(:~ In dry-run mode only, evaluate rule variables. + : Provides more localized information if syntax errors are present in rule + : variable declarations. + :) +declare function utils:evaluate-rule-variables( + $variables as element(sch:let)*, + $prolog as xs:string?, + $bindings as map(*), + $context as map(*), + $errors as element()* +) +as element()* +{ + if($context?dry-run eq 'true') + then + if(exists($variables)) + then + let $var := head($variables) + let $prolog := $prolog || utils:local-variable-decls($var) + let $errs := utils:eval( + $prolog || ' return $' || $var/@name => utils:escape(), + $bindings, + map{'dry-run':$context?dry-run}, + $var/@value + ) + return utils:evaluate-rule-variables( + tail($variables), + $prolog, + $bindings, + $context, + ($errors,$errs) + ) + else $errors + else () +}; + (:~ Wrapper around xquery:eval(). In "dry-run" mode, the query passed in is : parsed only, and any errors caught reported as svrl:failed-assert. : @param $query string of the query to evaluate