File: mode_lint.xsl

package info (click to toggle)
jedit 5.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 14,720 kB
  • sloc: java: 103,377; xml: 96,521; makefile: 43; sh: 42; cpp: 6; python: 6
file content (106 lines) | stat: -rw-r--r-- 3,676 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?xml version="1.0" ?>
<!-- :mode=xsl:tabSize=2:indentSize=2:folding=none: -->
<!-- apply to modes/catalog to look for unused rules in mode files

   Copyright © 2012 - Eric Le Lay <kerik-sf@users.sf.net>
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or any later version.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">

    <!-- output simple one line messages for now -->
	<xsl:output method="text" encoding="UTF-8"/>
    
    <!-- main template: grab rulesets and references in all mode files
         and compute errors
      -->
	<xsl:template match="/">
    
    <!-- use the other templates to grab -->
		<xsl:variable name="refs" as="node()*">
			<xsl:apply-templates/>
		</xsl:variable>
    
    <!-- analyze the relations -->
		<xsl:for-each select="$refs/rules">
    	
    	<!-- named RULES section not referenced anywhere -->
			<xsl:if test="not($refs//ref[@name = current()/@set])
			 and not(ends-with(current()/@set, '::MAIN'))">
				<xsl:text> mode </xsl:text>
				<xsl:value-of select="parent::mode/@file"/>
				<xsl:text> ruleset </xsl:text>
				<xsl:value-of select="@set"/>
				<xsl:text> not referenced anywhere &#10;</xsl:text>
			</xsl:if>
	
			<xsl:for-each select="ref">
	    	<!-- reference to RULES that can't be found -->
				<xsl:if test="not($refs//rules[@set = current()/@name])">
					<xsl:text> mode </xsl:text>
					<xsl:value-of select="ancestor::mode/@file"/>
					<xsl:text> undefined ref </xsl:text>
					<xsl:value-of select="@name"/>
					<xsl:text>&#10;</xsl:text>
				</xsl:if>
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="MODE[@FILE]">
		<mode file="{@FILE}" name="{@NAME}">
			<xsl:apply-templates select="document(@FILE,.)/MODE">
				<xsl:with-param name="mode-name" tunnel="yes" select="@NAME" as="xs:string"/>
			</xsl:apply-templates>
		</mode>
	</xsl:template>
	
	<xsl:template match="RULES[@SET]">
		<xsl:param name="mode-name" tunnel="yes" as="xs:string"/>
		<rules set="{$mode-name}::{@SET}">
			<xsl:apply-templates/>
		</rules>
	</xsl:template>
	
	<!-- name default RULES mode::MAIN  -->
	<xsl:template match="RULES">
		<xsl:param name="mode-name" tunnel="yes" as="xs:string"/>
		<rules set="{$mode-name}::MAIN">
			<xsl:apply-templates/>
		</rules>
	</xsl:template>
	
	<!-- the default template doesn't apply templates to attributes -->
	<xsl:template match="*">
		<xsl:apply-templates select="@*"/>
		<xsl:apply-templates select="*"/>
	</xsl:template>
	
	<!-- in general, ignore attributes and text to avoid noise in the output -->
	<xsl:template match="@*"/>
	<xsl:template match="text()"/>
	
	<!-- SPAN, IMPORT -->
	<xsl:template match="@DELEGATE">
		<xsl:param name="mode-name" tunnel="yes" as="xs:string"/>
		<xsl:choose>
			<xsl:when test="contains(.,':')">
				<ref name="{.}"/>
			</xsl:when>
			<xsl:otherwise>
				<!-- always output qualified references -->
				<ref name="{$mode-name}::{.}"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>