Skip to content

Commit

Permalink
output dbg msgs only if 'debug_modules' param contains corresp. module
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Aug 5, 2019
1 parent 495ac1c commit 2b4e5e6
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 77 deletions.
6 changes: 2 additions & 4 deletions scripts/rnc_to_analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ xsltproc --stringparam out-name "$rng_simplified_arg" stylesheets/rnc_simplifica

echo "simplified rng -> analysis: '$rng_simplified' -> '$output_dir/{2_flattened.xml,3_serialized.txt}'"

debug_modules_options=
for mod in "${debug_modules[@]}"; do
debug_modules_options="$debug_modules_options debug_$mod=1"
done
debug_modules_options="debug_modules=${debug_modules[@]}"

# echo "debug_modules_options: $debug_modules_options"
$SCRIPT_DIR/local_stylesheet.sh \
--input-dir "$output_dir" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<value-of select="@name"/>
<text>):</text>
</element>
<value-of select="eoa:debug(concat('unique_expr_str: ', $unique_xpath_expr_str))"/>
<value-of select="eoa:debug(concat('xpath_condition_str: ', $xpath_condition_str))"/>
<value-of select="eoa:debug('define_to_schematron', concat('unique_expr_str: ', $unique_xpath_expr_str))"/>
<value-of select="eoa:debug('define_to_schematron', concat('xpath_condition_str: ', $xpath_condition_str))"/>
<element name="constraint" namespace="{$tei_namespace}">
<sch:rule context="{$unique_xpath_expr_str}">
<sch:assert test="{$xpath_condition_str}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

<!-- this should never happen: -->
<template mode="rng_to_xpath_cond_impl" as="xs:string" match="rng:attribute">
<value-of select="eoa:error(concat('rng_to_xpath_cond_impl: called with element: ', name(), '. value: ', .))"/>
<value-of select="eoa:error('xpath_cond_from_rng', concat('rng_to_xpath_cond_impl: called with element: ', name(), '. value: ', .))"/>
<text/>
</template>

Expand Down Expand Up @@ -277,7 +277,7 @@
</template>

<template mode="rng_to_xpath_cond_impl" as="xs:string" match="node() | @*" >
<value-of select="eoa:error(concat('rng_to_xpath_cond_impl. no implementation for ', name(), '. value: ', .))"/>
<value-of select="eoa:error('xpath_cond_from_rng', concat('rng_to_xpath_cond_impl. no implementation for ', name(), '. value: ', .))"/>
</template>

<!-- rng_to_xpath_cond_raw:
Expand Down Expand Up @@ -333,7 +333,7 @@
</template>

<template mode="rng_to_xpath_cond_raw" as="xs:string" match="node()|@*" >
<value-of select="eoa:error(concat('rng_to_xpath_cond_raw. no implementation for ', name(), '. value: ', .))"/>
<value-of select="eoa:error('xpath_cond_from_rng', concat('rng_to_xpath_cond_raw. no implementation for ', name(), '. value: ', .))"/>
</template>

<!-- context:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<text>xs:</text>
</when>
<otherwise>
<value-of select="eoa:warning(concat('no namespace prefix datatype library ', @datatypeLibrary))"/>
<value-of select="eoa:warning('xpath_cond_from_rng_attributes', concat('no namespace prefix datatype library ', @datatypeLibrary))"/>
<text/>
</otherwise>
</choose>
Expand Down Expand Up @@ -131,7 +131,7 @@

<template mode="attribute_condition" match="*" as="xs:string">
<param name="attr_name" as="xs:string"/>
<value-of select="eoa:warning(concat('no rule to check attribute ', $attr_name))"/>
<value-of select="eoa:warning('xpath_cond_from_rng_attributes', concat('no rule to check attribute ', $attr_name))"/>
<value-of select="concat( '@', $attr_name )"/>
</template>

Expand All @@ -150,15 +150,15 @@
<text>xml:</text>
</when>
<otherwise>
<value-of select="eoa:warning(concat('no namespace prefix for ', rng:name/@ns))"/>
<value-of select="eoa:warning('xpath_cond_from_rng_attributes', concat('no namespace prefix for ', rng:name/@ns))"/>
</otherwise>
</choose>
</variable>
<value-of select="concat($ns_prefix, rng:name)"/>
</template>

<template mode="attribute_name" match="*">
<value-of select="eoa:error( concat('attribute_name only valid for rng:attribute, but called from ', name()) )"/>
<value-of select="eoa:error( 'xpath_cond_from_rng_attributes', concat('attribute_name only valid for rng:attribute, but called from ', name()) )"/>
</template>

</stylesheet>
71 changes: 66 additions & 5 deletions stylesheets/rng_to_odd/common/print.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<!--
<import href="utils.xsl"/>
-->

<!-- overwrite this to enable module specific debug output -->
<param name="debug_modules" as="xs:string*" select="()"/>

<!-- verbosity: 0: only errors, 1: warnings, 2: info, 3: debug -->
<param name="verbosity" as="xs:integer" required="no" select="2"/>
Expand All @@ -25,27 +28,63 @@
<function name="eoa:error" as="xs:integer"><value-of select="3"/></function>

<function name="eoa:debug" as="element()?">
<param name="module" as="xs:string"/>
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:debug(), $module, $message)"/>
</function>

<function name="eoa:debug" as="element()?">
<!-- default param: <param name="module" as="xs:string"/> -->
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:debug(), $message)"/>
</function>

<function name="eoa:info" as="element()?">
<param name="module" as="xs:string"/>
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:info(), $module, $message)"/>
</function>

<function name="eoa:info" as="element()?">
<!-- default param: <param name="module" as="xs:string"/> -->
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:info(), $message)"/>
</function>

<function name="eoa:warning" as="element()?">
<param name="module" as="xs:string"/>
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:warning(), $module, $message)"/>
</function>

<function name="eoa:warning" as="element()?">
<!-- default param: <param name="module" as="xs:string"/> -->
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:warning(), $message)"/>
</function>

<function name="eoa:error" as="element()?">
<param name="module" as="xs:string"/>
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
<sequence select="eoa:message(eoa:error(), $module, $message)"/>
</function>

<function name="eoa:error" as="element()?">
<!-- default param: <param name="module" as="xs:string"/> -->
<param name="message" as="xs:string*"/>
<!-- TODO: This probably doesn't work if the message is
more than a single string -->
Expand All @@ -55,67 +94,89 @@
<!-- promise: this function never returns anything! -->
<function name="eoa:message" as="element()?">
<param name="level" as="xs:integer"/>
<!-- default param: <param name="module" as="xs:string"/> -->
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="$level"/>
<with-param name="message" select="$message"/>
</call-template>
</function>

<!-- promise: this function never returns anything! -->
<function name="eoa:message" as="element()?">
<param name="level" as="xs:integer"/>
<param name="module" as="xs:string"/>
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="$level"/>
<with-param name="module" select="$module"/>
<with-param name="message" select="$message"/>
</call-template>
</function>

<template name="eoa:debug" as="element()?">
<param name="module" as="xs:string" select="''"/>
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="eoa:debug()"/>
<with-param name="module" select="$module"/>
<with-param name="message" select="$message"/>
</call-template>
</template>

<template name="eoa:info" as="element()?">
<param name="module" as="xs:string" select="''"/>
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="eoa:info()"/>
<with-param name="module" select="$module"/>
<with-param name="message" select="$message"/>
</call-template>
</template>

<template name="eoa:warning" as="element()?">
<param name="module" as="xs:string" select="''"/>
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="eoa:warning()"/>
<with-param name="module" select="$module"/>
<with-param name="message" select="$message"/>
</call-template>
</template>

<template name="eoa:error" as="element()?">
<param name="module" as="xs:string" select="''"/>
<param name="message" as="xs:string*"/>
<call-template name="eoa:message">
<with-param name="level" select="eoa:error()"/>
<with-param name="module" select="$module"/>
<with-param name="message" select="$message"/>
</call-template>
</template>

<template name="eoa:message" as="element()?">
<param name="level" as="xs:integer"/>
<param name="module" as="xs:string" select="''"/>
<param name="message" as="xs:string*"/>
<choose>
<when test="$level = 0 and $verbosity >= 3">
<when test="$level = 0 and $verbosity >= 3 and ($module = '' or $module = $debug_modules)">
<for-each select="$message">
<message terminate="no">[DEBUG]: <value-of select="."/></message>
<message terminate="no">[DEBUG]: <value-of select="concat($module, ': ')"/><value-of select="."/></message>
</for-each>
</when>
<when test="$level = 1 and $verbosity >= 2">
<for-each select="$message">
<message terminate="no">[INFO]: <value-of select="."/></message>
<message terminate="no">[INFO]: <value-of select="concat($module, ': ')"/><value-of select="."/></message>
</for-each>
</when>
<when test="$level = 2 and $verbosity >= 1">
<for-each select="$message">
<message terminate="no">[WARNING]: <value-of select="."/></message>
<message terminate="no">[WARNING]: <value-of select="concat($module, ': ')"/><value-of select="."/></message>
</for-each>
</when>
<when test="$level = 3">
<for-each select="$message">
<message terminate="{position() = last()}">[ERROR]: <value-of select="."/>. Exiting.</message>
<message terminate="{position() = last()}">[ERROR]: <value-of select="concat($module, ': ')"/><value-of select="."/>. Exiting.</message>
</for-each>
</when>
</choose>
Expand Down
3 changes: 3 additions & 0 deletions stylesheets/rng_to_odd/rng_to_analysis.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ as officially documented here: https://relaxng.org/spec.html#simple-syntax
<!-- output intermediate steps into this directory...: -->
<param name="output" required="yes"/>
<!-- enable these to get debug messages for specific modules: -->
<param name="debug_modules" as="xs:string*" select="()"/>
<!--
<param name="debug_xpath_unique_expr_advanced" select="false()" as="xs:boolean"/>
<param name="debug_rng_to_dnf" select="false()" as="xs:boolean"/>
-->

<!-- output formats : -->
<output
Expand Down
20 changes: 10 additions & 10 deletions stylesheets/rng_to_odd/rng_to_analysis/rnc_analyse_structure.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@
</template>

<template mode="structure_advanced" match="eoa:element">
<value-of select="eoa:info(concat('structure_advanced: calculating element ', @name))"/>
<value-of select="eoa:info('structure_advanced', concat('calculating element ', @name))"/>
<copy>
<apply-templates mode="structure_advanced" select="@* | *[not( self::eoa:definitions )]"/>
<element name="definitions" namespace="{$eoa_namespace}">
<value-of select="eoa:debug( concat('calculating unique xpath expressions for all definitions of element ', @name,':'))"/>
<value-of select="eoa:debug('structure_advanced', concat('calculating unique xpath expressions for all definitions of element ', @name,':'))"/>
<variable name="xpath_unique_expr_advanced">
<call-template name="xpath_unique_expr_advanced">
<with-param name="define_ids" as="xs:string*" select=".//rng:define/@name"/>
Expand All @@ -110,13 +110,13 @@
-->
<variable name="problems" as="element(eoa:problems)?" select="$xpath_unique_expr_advanced/eoa:problems"/>
<if test="$problems">
<value-of select="eoa:warning('structure_advanced: there are problems with this element:')"/>
<value-of select="eoa:warning('structure_advanced', 'there are problems with this element:')"/>
<for-each select="$problems/eoa:problem">
<value-of select="eoa:warning(concat(eoa:object, ': ', eoa:message))"/>
<value-of select="eoa:warning('structure_advanced', concat(eoa:object, ': ', eoa:message))"/>
</for-each>
</if>
<for-each select="eoa:definitions/eoa:define">
<value-of select="eoa:info(concat('structure_advanced: calculating definition ', @name))"/>
<value-of select="eoa:info('structure_advanced', concat('calculating definition ', @name))"/>
<!-- convert "eoa:values -> eoa:path": -->
<variable name="unique_xpath_expressions_values" as="element()*">
<for-each select="$xpath_unique_expr_advanced/eoa:result/eoa:entry[eoa:key = current()/rng:define/@name]/eoa:value">
Expand Down Expand Up @@ -156,15 +156,15 @@
<apply-templates mode="is_rng_supported" select="rng:define"/>
</variable>
<if test="$is_rng_supported">
<value-of select="eoa:warning( concat('problem in the rng for element ', rng:define/@name, '. reason: ', $is_rng_supported) )"/>
<value-of select="eoa:warning( 'structure_advanced', concat('problem in the rng for element ', rng:define/@name, '. reason: ', $is_rng_supported) )"/>
</if>

<value-of select="eoa:debug( 'calculating rng_no_attributes:')"/>
<value-of select="eoa:debug( 'structure_advanced', 'calculating rng_no_attributes:')"/>
<variable name="no_attributes" as="element(rng:define)">
<apply-templates mode="no_attributes" select="rng:define"/>
</variable>

<value-of select="eoa:debug( 'calculating rng_only_attributes:')"/>
<value-of select="eoa:debug( 'structure_advanced', 'calculating rng_only_attributes:')"/>
<variable name="only_attributes" as="element(rng:define)">
<apply-templates mode="only_attributes" select="rng:define"/>
</variable>
Expand Down Expand Up @@ -270,7 +270,7 @@
<!-- filter out anything concerning attributes: -->

<template mode="no_attributes" match="rng:attribute">
<value-of select="eoa:error( 'no_attributes called with rng:attribute')"/>
<value-of select="eoa:error( 'structure_advanced', 'no_attributes called with rng:attribute')"/>
<!--
<element name="empty" namespace="{$rng_namespace}"/>
-->
Expand Down Expand Up @@ -331,7 +331,7 @@
<!-- clean a definition keeping only the parts concerning attributes: -->

<template mode="only_attributes" match="rng:ref">
<value-of select="eoa:error( 'only_attributes called with rng:ref')"/>
<value-of select="eoa:error( 'structure_advanced', 'only_attributes called with rng:ref')"/>
</template>

<template mode="only_attributes"
Expand Down
Loading

0 comments on commit 2b4e5e6

Please sign in to comment.