Skip to content

Commit

Permalink
Identify FIXME: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Jun 7, 2020
1 parent 2621bf7 commit 4a4cb85
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The match attempts to capture the list of elements involved, but all
predicates are stripped away. (The explorer can’t practically make use
of them, and removing them simplifies the display.)

Starting in version 0.1.6, comments containing the string “FIXME:” are also highlighted.

An interactive example of the explorer run on itself is online at
[[https://xslt.xmlexplorer.com/ouroboros/]].

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
xsltExplorerTitle=XSLT Explorer
xsltExplorerVersion=0.1.5
xsltExplorerVersion=0.1.6

saxonVersion=10.1
xspecVersion=1.6.0
Expand Down
15 changes: 15 additions & 0 deletions src/main/xslt/analyze.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
select="count(//a:template[parent::a:stylesheet])"/>
<xsl:attribute name="functions"
select="count(//a:function[parent::a:stylesheet])"/>
<xsl:attribute name="fixmes"
select="count(//a:comment)"/>
<xsl:apply-templates/>
</summary>
</xsl:template>
Expand All @@ -48,13 +50,15 @@
<xsl:variable name="params" select="a:variable[@class='param']"/>
<xsl:variable name="templates" select="a:template"/>
<xsl:variable name="functions" select="a:function"/>
<xsl:variable name="fixmes" select=".//a:comment except .//a:stylesheet//a:comment"/>

<xsl:attribute name="imports" select="count($imports)"/>
<xsl:attribute name="includes" select="count($includes)"/>
<xsl:attribute name="variables" select="count($vars)"/>
<xsl:attribute name="params" select="count($params)"/>
<xsl:attribute name="templates" select="count($templates)"/>
<xsl:attribute name="functions" select="count($functions)"/>
<xsl:attribute name="fixmes" select="count($fixmes)"/>

<xsl:variable name="vp-unused" as="element(a:variable)*"
select="a:variable[empty(key('xref', @id))]"/>
Expand Down Expand Up @@ -145,6 +149,8 @@
</xsl:for-each>
</templates>

<comments/>

<xsl:variable name="functions-shadow"
select="a:function[@name and f:function-shadows(., @name/string())]"/>

Expand Down Expand Up @@ -190,6 +196,7 @@
</functions>

<xsl:apply-templates select="a:variable|a:template|a:function|a:stylesheet"/>
<xsl:apply-templates select=".//a:comment except .//a:stylesheet//a:comment"/>
</stylesheet>
</xsl:template>

Expand Down Expand Up @@ -382,6 +389,14 @@
</template>
</xsl:template>

<xsl:template match="a:comment">
<comment id="{f:generate-id(.)}"
class="comment">
<xsl:copy-of select="@line-number,@column-number"/>
<xsl:sequence select="normalize-space(.)"/>
</comment>
</xsl:template>

<xsl:function name="f:variables-referenced" as="element(a:variable)*">
<xsl:param name="node" as="element()"/>
<xsl:sequence select="($node//a:variable-ref ! key('id', @xref))[parent::a:stylesheet] union ()"/>
Expand Down
25 changes: 20 additions & 5 deletions src/main/xslt/parse.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
exclude-result-prefixes="a f m p xs"
version="3.0">

<!-- FIXME: Implement XPath parsing as an extension function. -->
<?xsltexplorer-skip-import?>
<xsl:import href="xpath-31.xslt"/>

<xsl:param name="fixme" select="'FIXME:'"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
Expand All @@ -31,7 +34,7 @@
then $extra-attributes
else f:source-location(.)"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="*"/>
<xsl:apply-templates/>
</stylesheet>
</xsl:template>

Expand All @@ -40,7 +43,7 @@
select="preceding-sibling::node()[not(self::text())][1]"/>
<xsl:if test="not($pi/self::processing-instruction('xsltexplorer-skip-import'))">
<xsl:message select="'Importing', @href/string(), '…'"/>
<xsl:apply-templates select="doc(resolve-uri(@href, base-uri(.)))/*">
<xsl:apply-templates select="doc(resolve-uri(@href, base-uri(.)))/node()">
<xsl:with-param name="href" select="@href/string()"/>
<xsl:with-param name="extra-attributes" as="attribute()+">
<xsl:sequence select="f:source-location(.)"/>
Expand All @@ -56,7 +59,7 @@
<xsl:if test="not(preceding-sibling
::processing-instruction('xsltexplorer-skip-include'))">
<xsl:message select="'Including', @href/string(), '…'"/>
<xsl:apply-templates select="doc(resolve-uri(@href, base-uri(.)))/*">
<xsl:apply-templates select="doc(resolve-uri(@href, base-uri(.)))/node()">
<xsl:with-param name="href" select="@href/string()"/>
<xsl:with-param name="extra-attributes" as="attribute()+">
<xsl:sequence select="f:source-location(.)"/>
Expand Down Expand Up @@ -230,7 +233,16 @@
</xsl:if>
</xsl:template>

<xsl:template match="text()|comment()|processing-instruction()"/>
<xsl:template match="comment()">
<xsl:if test="contains(., $fixme)">
<comment id="{f:encode-for-id(f:unique-id(.))}">
<xsl:sequence select="f:source-location(.)"/>
<xsl:sequence select="string(.)"/>
</comment>
</xsl:if>
</xsl:template>

<xsl:template match="text()|processing-instruction()"/>

<!-- ============================================================ -->

Expand Down Expand Up @@ -325,7 +337,7 @@
<!-- ============================================================ -->

<xsl:function name="f:unique-id" as="xs:string">
<xsl:param name="ref" as="element()"/>
<xsl:param name="ref" as="node()"/>

<xsl:variable name="prefix"
select="if ($ref/self::xsl:stylesheet)
Expand All @@ -342,6 +354,9 @@
<xsl:when test="$ref/self::xsl:template">
<xsl:sequence select="$prefix || 't-' || (count($ref/preceding::xsl:template)+1)"/>
</xsl:when>
<xsl:when test="$ref/self::comment()">
<xsl:sequence select="$prefix || 'c-' || (count($ref/preceding::comment())+1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$prefix || generate-id($ref)"/>
</xsl:otherwise>
Expand Down
33 changes: 32 additions & 1 deletion src/main/xslt/summarize.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<xsl:sequence select="@functions ! f:summary-count(./string(), 'function')"/>
<xsl:sequence select="@variables ! f:summary-count(./string(), 'variable')"/>
<xsl:sequence select="@params ! f:summary-count(./string(), 'param')"/>
<xsl:sequence select="@fixmes ! f:summary-count(./string(), 'FIXME: comment')"/>
</xsl:variable>

<xsl:if test="$details">
Expand Down Expand Up @@ -193,6 +194,12 @@
<xsl:sequence select="f:summary-details(a:params)"/>
</span>
</xsl:if>
<xsl:if test="@fixmes ne '0'">
<span>
<xsl:sequence select="f:summary-count(@fixmes, 'FIXME: comment')"/>
<xsl:sequence select="f:summary-details(a:comments)"/>
</span>
</xsl:if>
</xsl:variable>

<xsl:if test="exists($summary)">
Expand All @@ -208,10 +215,20 @@
<div class="title closed">Instructions</div>
<div class="body">
<xsl:apply-templates select="a:* except (a:stylesheet|a:variables|a:functions
|a:templates|a:params)"/>
|a:templates|a:params
|a:comments|a:comment)"/>
</div>
</div>

<xsl:if test=".//a:comment except .//a:stylesheet//a:comment">
<div class="instructions">
<div class="title closed">FIXME: comments</div>
<div class="body">
<xsl:apply-templates select=".//a:comment except .//a:stylesheet//a:comment"/>
</div>
</div>
</xsl:if>

<xsl:if test="string($source-listings) = ('1','true','yes')">
<div class="source-code">
<div class="title closed">Source code</div>
Expand Down Expand Up @@ -522,6 +539,20 @@
</div>
</xsl:template>

<xsl:template match="a:comment">
<div id="{@id}"
class="instruction {@class}">
<div class="title">
<xsl:sequence select="f:line-link(.)"/>
<xsl:text>Comment</xsl:text>
</div>

<div class="props">
<xsl:sequence select="string(.)"/>
</div>
</div>
</xsl:template>

<!-- ============================================================ -->

<xsl:template name="t:variables-referenced">
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/expected/first.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="1" params="1" templates="4" functions="2"><stylesheet id="S-39899" xml:base="..." imports="0" includes="0" variables="1" params="1" templates="4" functions="2"><variables><unused>S-39899-..shadowed</unused></variables><params></params><templates><unused>S-39899-example.com.first.foo</unused></templates><functions><unused>S-39899-example.com.first.f,1</unused><unused>S-39899-example.com.first.g,0</unused></functions><variable id="S-39899-..a" class="param" type="param" elsewhere="false" name="{}a" display-name="a" as="xs:string"><used-by class="template">S-39899-t-2</used-by><used-by-module>S-39899</used-by-module></variable><variable id="S-39899-..shadowed" class="variable unused" type="variable" elsewhere="false" name="{}shadowed" display-name="shadowed"></variable><template id="S-39899-example.com.first.foo" class="template" recursive="true" elsewhere="false" name="{http://example.com/first}foo" display-name="a:foo" match="a:foo"><used-by>S-39899-example.com.first.foo</used-by><used-by-module>S-39899</used-by-module></template><template id="S-39899-t-2" class="template" recursive="false" elsewhere="false" match="a:bar"><variable>S-39899-..a</variable><template>S-39899-example.com.second.foo</template></template><function id="S-39899-example.com.first.f,1" class="function unused" recursive="false" elsewhere="false" name="{http://example.com/first}f#1" display-name="a:f#1" as="xs:integer"><param name="num" as="xs:integer"></param><no-arity>S-39899-example.com.first.f,1</no-arity></function><function id="S-39899-example.com.first.g,0" class="function unused" recursive="false" elsewhere="false" name="{http://example.com/first}g#0" display-name="a:g#0" as="xs:integer"><no-arity>S-39899-example.com.first.g,0</no-arity><template>S-39899-example.com.third.third-template</template></function><template id="S-39899-example.com.second.foo" class="template" recursive="false" elsewhere="false" name="{http://example.com/second}foo" display-name="b:foo"><used-by>S-39899-t-2</used-by><used-by-module>S-39899</used-by-module></template><template id="S-39899-example.com.third.third-template" class="template" recursive="false" elsewhere="false" name="{http://example.com/third}third-template" display-name="t:third-template"><used-by>S-39899-example.com.first.g,0</used-by><used-by-module>S-39899</used-by-module></template></stylesheet></summary>
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="1" params="1" templates="4" functions="2" fixmes="0"><stylesheet id="S-39899" xml:base="..." imports="0" includes="0" variables="1" params="1" templates="4" functions="2" fixmes="0"><variables><unused>S-39899-..shadowed</unused></variables><params></params><templates><unused>S-39899-example.com.first.foo</unused></templates><comments></comments><functions><unused>S-39899-example.com.first.f,1</unused><unused>S-39899-example.com.first.g,0</unused></functions><variable id="S-39899-..a" class="param" type="param" elsewhere="false" name="{}a" display-name="a" as="xs:string"><used-by class="template">S-39899-t-2</used-by><used-by-module>S-39899</used-by-module></variable><variable id="S-39899-..shadowed" class="variable unused" type="variable" elsewhere="false" name="{}shadowed" display-name="shadowed"></variable><template id="S-39899-example.com.first.foo" class="template" recursive="true" elsewhere="false" name="{http://example.com/first}foo" display-name="a:foo" match="a:foo"><used-by>S-39899-example.com.first.foo</used-by><used-by-module>S-39899</used-by-module></template><template id="S-39899-t-2" class="template" recursive="false" elsewhere="false" match="a:bar"><variable>S-39899-..a</variable><template>S-39899-example.com.second.foo</template></template><function id="S-39899-example.com.first.f,1" class="function unused" recursive="false" elsewhere="false" name="{http://example.com/first}f#1" display-name="a:f#1" as="xs:integer"><param name="num" as="xs:integer"></param><no-arity>S-39899-example.com.first.f,1</no-arity></function><function id="S-39899-example.com.first.g,0" class="function unused" recursive="false" elsewhere="false" name="{http://example.com/first}g#0" display-name="a:g#0" as="xs:integer"><no-arity>S-39899-example.com.first.g,0</no-arity><template>S-39899-example.com.third.third-template</template></function><template id="S-39899-example.com.second.foo" class="template" recursive="false" elsewhere="false" name="{http://example.com/second}foo" display-name="b:foo"><used-by>S-39899-t-2</used-by><used-by-module>S-39899</used-by-module></template><template id="S-39899-example.com.third.third-template" class="template" recursive="false" elsewhere="false" name="{http://example.com/third}third-template" display-name="t:third-template"><used-by>S-39899-example.com.first.g,0</used-by><used-by-module>S-39899</used-by-module></template></stylesheet></summary>
1 change: 1 addition & 0 deletions src/test/resources/expected/fixme.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0" fixmes="2"><stylesheet id="S-22220" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0" fixmes="2"><variables></variables><params></params><templates></templates><comments></comments><functions></functions><template id="S-22220-t-1" class="template" recursive="false" elsewhere="false" match="element()"></template><template id="S-22220-t-2" class="template" recursive="false" elsewhere="false" match="attribute()|comment()|processing-instruction()|text()"></template><comment id="S-22220-c-1" class="comment">FIXME: this is a test of a fixme comment, don't really fix me!</comment><comment id="S-22220-c-2" class="comment">FIXME: Don't fix this either.</comment></stylesheet></summary>
2 changes: 1 addition & 1 deletion src/test/resources/expected/function.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="1" functions="3"><stylesheet id="S-3611" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="1" functions="3"><variables></variables><params></params><templates></templates><functions><unused>S-3611-example.org.ns.functions.ufunc,0</unused><unused>S-3611-example.org.ns.functions.rfunc,0</unused></functions><template id="S-3611-t-1" class="template" recursive="false" elsewhere="false" match="/"><function>S-3611-example.org.ns.functions.func,0</function></template><function id="S-3611-example.org.ns.functions.func,0" class="function" recursive="false" elsewhere="false" name="{http://example.org/ns/functions}func#0" display-name="f:func#0"><no-arity>S-3611-example.org.ns.functions.func,0</no-arity><used-by>S-3611-t-1</used-by><used-by-module>S-3611</used-by-module></function><function id="S-3611-example.org.ns.functions.ufunc,0" class="function unused" recursive="false" elsewhere="false" name="{http://example.org/ns/functions}ufunc#0" display-name="f:ufunc#0" as="xs:integer"><no-arity>S-3611-example.org.ns.functions.ufunc,0</no-arity></function><function id="S-3611-example.org.ns.functions.rfunc,0" class="function" recursive="true" elsewhere="false" name="{http://example.org/ns/functions}rfunc#0" display-name="f:rfunc#0"><no-arity>S-3611-example.org.ns.functions.rfunc,0</no-arity><used-by>S-3611-example.org.ns.functions.rfunc,0</used-by><used-by-module>S-3611</used-by-module></function></stylesheet></summary>
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="1" functions="3" fixmes="0"><stylesheet id="S-3611" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="1" functions="3" fixmes="0"><variables></variables><params></params><templates></templates><comments></comments><functions><unused>S-3611-example.org.ns.functions.ufunc,0</unused><unused>S-3611-example.org.ns.functions.rfunc,0</unused></functions><template id="S-3611-t-1" class="template" recursive="false" elsewhere="false" match="/"><function>S-3611-example.org.ns.functions.func,0</function></template><function id="S-3611-example.org.ns.functions.func,0" class="function" recursive="false" elsewhere="false" name="{http://example.org/ns/functions}func#0" display-name="f:func#0"><no-arity>S-3611-example.org.ns.functions.func,0</no-arity><used-by>S-3611-t-1</used-by><used-by-module>S-3611</used-by-module></function><function id="S-3611-example.org.ns.functions.ufunc,0" class="function unused" recursive="false" elsewhere="false" name="{http://example.org/ns/functions}ufunc#0" display-name="f:ufunc#0" as="xs:integer"><no-arity>S-3611-example.org.ns.functions.ufunc,0</no-arity></function><function id="S-3611-example.org.ns.functions.rfunc,0" class="function" recursive="true" elsewhere="false" name="{http://example.org/ns/functions}rfunc#0" display-name="f:rfunc#0"><no-arity>S-3611-example.org.ns.functions.rfunc,0</no-arity><used-by>S-3611-example.org.ns.functions.rfunc,0</used-by><used-by-module>S-3611</used-by-module></function></stylesheet></summary>
2 changes: 1 addition & 1 deletion src/test/resources/expected/identity.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0"><stylesheet id="S-54303" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0"><variables></variables><params></params><templates></templates><functions></functions><template id="S-54303-t-1" class="template" recursive="false" elsewhere="false" match="element()"></template><template id="S-54303-t-2" class="template" recursive="false" elsewhere="false" match="attribute()|comment()|processing-instruction()|text()"></template></stylesheet></summary>
<summary xmlns="http://nwalsh.com/ns/xslt/analysis" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0" fixmes="0"><stylesheet id="S-54303" xml:base="..." imports="0" includes="0" variables="0" params="0" templates="2" functions="0" fixmes="0"><variables></variables><params></params><templates></templates><comments></comments><functions></functions><template id="S-54303-t-1" class="template" recursive="false" elsewhere="false" match="element()"></template><template id="S-54303-t-2" class="template" recursive="false" elsewhere="false" match="attribute()|comment()|processing-instruction()|text()"></template></stylesheet></summary>
Loading

0 comments on commit 4a4cb85

Please sign in to comment.