aboutsummaryrefslogtreecommitdiff
path: root/tssl
diff options
context:
space:
mode:
Diffstat (limited to 'tssl')
-rw-r--r--tssl/tssl-models.xslt47
-rw-r--r--tssl/tssl-validate.xslt40
-rw-r--r--tssl/tssl.rnc75
-rw-r--r--tssl/tssl.xslt220
4 files changed, 382 insertions, 0 deletions
diff --git a/tssl/tssl-models.xslt b/tssl/tssl-models.xslt
new file mode 100644
index 0000000..6a983b4
--- /dev/null
+++ b/tssl/tssl-models.xslt
@@ -0,0 +1,47 @@
+<!-- Generate Java code to be inserted into HTMLModels.java. -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// TagSoup is licensed under the Apache License,
+// Version 2.0. You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 . You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+ version="1.0">
+
+ <xsl:output method="text"/>
+
+ <xsl:strip-space elements="*"/>
+
+ <!-- The main template. We are going to generate Java constant
+ definitions for the groups in the file. -->
+ <xsl:template match="tssl:schema">
+ <xsl:apply-templates select="tssl:group">
+ <xsl:sort select="@id"/>
+ </xsl:apply-templates>
+ </xsl:template>
+
+ <!-- Generate a declaration for a single group. -->
+ <xsl:template match="tssl:group" name="tssl:group">
+ <xsl:param name="id" select="@id"/>
+ <xsl:param name="number" select="position()"/>
+ <xsl:text>&#x9;public static final int </xsl:text>
+ <xsl:value-of select="$id"/>
+ <xsl:text> = 1 &lt;&lt; </xsl:text>
+ <xsl:value-of select="$number"/>
+ <xsl:text>;&#xA;</xsl:text>
+ </xsl:template>
+
+</xsl:transform>
diff --git a/tssl/tssl-validate.xslt b/tssl/tssl-validate.xslt
new file mode 100644
index 0000000..81faab5
--- /dev/null
+++ b/tssl/tssl-validate.xslt
@@ -0,0 +1,40 @@
+<!-- Generate complaints if the schema is invalid in some way. -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// TagSoup is licensed under the Apache License,
+// Version 2.0. You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 . You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+ version="1.0">
+
+ <xsl:output method="text"/>
+
+ <xsl:strip-space elements="*"/>
+
+ <!-- Generates a report if an element does not belong to at least
+ one of the groups that its parent element contains. -->
+ <xsl:template match="tssl:element/tssl:element">
+ <xsl:if test="not(tssl:memberOfAny) and not(tssl:memberOf/@group = ../tssl:contains/@group)">
+ <xsl:value-of select="@name"/>
+ <xsl:text> is not in the content model of </xsl:text>
+ <xsl:value-of select="../@name"/>
+ <xsl:text>&#xA;</xsl:text>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </xsl:template>
+
+
+
+</xsl:transform>
diff --git a/tssl/tssl.rnc b/tssl/tssl.rnc
new file mode 100644
index 0000000..4443073
--- /dev/null
+++ b/tssl/tssl.rnc
@@ -0,0 +1,75 @@
+# This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+#
+# TagSoup is licensed under the Apache License,
+# Version 2.0. You may obtain a copy of this license at
+# http://www.apache.org/licenses/LICENSE-2.0 . You may also have
+# additional legal rights not granted by this license.
+#
+# TagSoup is distributed in the hope that it will be useful, but
+# unless required by applicable law or agreed to in writing, TagSoup
+# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+# OF ANY KIND, either express or implied; not even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+default namespace = "http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+
+start = schema
+
+## A TSSL schema has a namespace, which is applied to the elements by default,
+## and a name, which is used solely for documentation. It contains entity
+## definitions, a root element, and attributes to be applied to all elements.
+schema = element schema {
+ attribute ns {xsd:anyURI},
+ attribute prefix {xsd:NCName},
+ attribute name {xsd:NCName},
+ attribute version {"1.0"},
+ entity*,
+ group+,
+ \element,
+ \attribute*
+ }
+
+## An entity has a name and a Unicode codepoint in hex.
+entity = element entity {
+ attribute name {xsd:NCName},
+ attribute codepoint {xsd:string}
+ }
+
+## A group is a named group of elements. Every element belongs to one
+## or more groups and has a content model consisting of one or more groups.
+group = element group {
+ attribute id {xsd:ID}
+ }
+
+## An element has a name and a namespace (currently ignored).
+## It can have any of several types of content and can be restartable
+## or not. The element is also a member of one or more model groups
+## (with arbitrary names), and can contain as children zero or more
+## model groups. Elements also have attributes and "natural" children.
+\element = element element {
+ attribute ns {xsd:anyURI}?,
+ attribute name {xsd:NCName},
+ attribute type {type},
+ attribute closeMode { "unclosable" | "restartable" }?,
+ attribute text-parent { "true" | "false" }?,
+ (element memberOf { attribute group {xsd:IDREF}}+ |
+ element isRoot { empty} |
+ element memberOfAny { empty }),
+ element contains { attribute group {xsd:IDREF}}*,
+ \attribute*,
+ \element*
+ }
+
+## Here are the attribute types:
+
+type = "element" | "any" | "empty" | "mixed" | "string" | "cdata"
+
+## An attribute has a name and a namespace (currently not supported).
+## It also has an optional type and an optional default value.
+\attribute = element attribute {
+ attribute ns {xsd:anyURI}?,
+ attribute name {xsd:NCName},
+ attribute type {"ID" | "IDREF" | "IDREFS" | "NMTOKEN" | "BOOLEAN"}?,
+ attribute default {xsd:string}?
+ }
+
diff --git a/tssl/tssl.xslt b/tssl/tssl.xslt
new file mode 100644
index 0000000..a25be10
--- /dev/null
+++ b/tssl/tssl.xslt
@@ -0,0 +1,220 @@
+<!-- Generate Java code to be inserted into HTMLSchema.java. -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// TagSoup is licensed under the Apache License,
+// Version 2.0. You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 . You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+ version="1.0">
+
+ <xsl:output method="text"/>
+
+ <xsl:strip-space elements="*"/>
+
+ <!-- The main template. This generates calls on the Schema routines
+ setURI(), setPrefix(), elementType(), parent(), attribute(),
+ and entity() in that order. Several special cases are
+ handled by template calls. -->
+ <xsl:template match="tssl:schema">
+ <!-- setURI() -->
+ <xsl:text>&#x9;&#x9;setURI("</xsl:text>
+ <xsl:value-of select="@ns"/>
+ <xsl:text>");&#xA;</xsl:text>
+ <!-- setPrefix() -->
+ <xsl:text>&#x9;&#x9;setPrefix("</xsl:text>
+ <xsl:value-of select="@prefix"/>
+ <xsl:text>");&#xA;</xsl:text>
+ <!-- elementType() special cases -->
+ <xsl:text>&#x9;&#x9;elementType("&lt;pcdata>", M_EMPTY, M_PCDATA, 0);&#xA;</xsl:text>
+ <xsl:text>&#x9;&#x9;elementType("&lt;root>", </xsl:text>
+ <xsl:apply-templates select="tssl:element/tssl:isRoot"/>
+ <xsl:text>, M_EMPTY, 0);&#xA;</xsl:text>
+ <!-- elementType() main loop -->
+ <xsl:apply-templates select="//tssl:element">
+ <xsl:sort select="@name"/>
+ </xsl:apply-templates>
+ <!-- parent() special cases -->
+ <xsl:call-template name="parent">
+ <xsl:with-param name="elem" select="'&lt;pcdata>'"/>
+ <xsl:with-param name="parent" select="//tssl:element[@text-parent='true']/@name"/>
+ </xsl:call-template>
+ <xsl:call-template name="parent">
+ <xsl:with-param name="elem" select="tssl:element/@name"/>
+ <xsl:with-param name="parent" select="'&lt;root>'"/>
+ </xsl:call-template>
+ <!-- parent() main loop -->
+ <xsl:apply-templates select="//tssl:element/tssl:element" mode="parent">
+ <xsl:sort select="@name"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="//tssl:element/tssl:attribute">
+ <xsl:sort select="../@name"/>
+ <xsl:sort select="@name"/>
+ </xsl:apply-templates>
+ <!-- attribute() main loop -->
+ <xsl:apply-templates select="tssl:attribute">
+ <xsl:sort select="@name"/>
+ </xsl:apply-templates>
+ <!-- entity() main loop -->
+ <xsl:apply-templates select="tssl:entity">
+ <xsl:sort select="@name"/>
+ </xsl:apply-templates>
+ </xsl:template>
+
+ <!-- Generates a single call to elementType(). -->
+ <xsl:template match="tssl:element">
+ <xsl:text>&#x9;&#x9;elementType("</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>", </xsl:text>
+ <xsl:choose>
+ <xsl:when test="@type = 'element'">
+ <xsl:apply-templates select="tssl:contains"/>
+ </xsl:when>
+ <xsl:when test="@type = 'string'">
+ <xsl:text>M_PCDATA</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type = 'mixed'">
+ <xsl:text>M_PCDATA|</xsl:text>
+ <xsl:apply-templates select="tssl:contains"/>
+ </xsl:when>
+ <xsl:when test="@type = 'empty'">
+ <xsl:text>M_EMPTY</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type = 'any'">
+ <xsl:text>M_ANY</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type = 'cdata'">
+ <xsl:text>M_PCDATA</xsl:text>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>, </xsl:text>
+ <xsl:apply-templates select="tssl:memberOf"/>
+ <xsl:apply-templates select="tssl:memberOfAny"/>
+ <xsl:apply-templates select="tssl:isRoot"/>
+ <xsl:text>, </xsl:text>
+ <xsl:choose>
+ <xsl:when test="@type = 'cdata'">
+ <xsl:text>F_CDATA</xsl:text>
+ </xsl:when>
+ <xsl:when test="@closeMode = 'restartable'">
+ <xsl:text>F_RESTART</xsl:text>
+ </xsl:when>
+ <xsl:when test="@closeMode = 'unclosable'">
+ <xsl:text>F_NOFORCE</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>0</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>);&#xA;</xsl:text>
+ </xsl:template>
+
+ <!-- Applied from tssl:element to generate the contains argument. -->
+ <xsl:template match="tssl:contains">
+ <xsl:value-of select="@group"/>
+ <xsl:if test="position() != last()">
+ <xsl:text>|</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <!-- Applied from tssl:element to generate the memberOf argument. -->
+ <xsl:template match="tssl:memberOf">
+ <xsl:value-of select="@group"/>
+ <xsl:if test="position() != last()">
+ <xsl:text>|</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <!-- Applied from tssl:element to handle memberOfAny. -->
+ <xsl:template match="tssl:memberOfAny">
+ <xsl:text>M_ANY &amp; ~M_ROOT</xsl:text>
+ </xsl:template>
+
+ <!-- Applied from tssl:element to handle isRoot. -->
+ <xsl:template match="tssl:isRoot">
+ <xsl:text>M_ROOT</xsl:text>
+ </xsl:template>
+
+ <!-- Generates a single call to parent(). The mode is used to prevent XSLT
+ from getting confused and generating elementType calls instead. -->
+ <xsl:template match="tssl:element/tssl:element" name="parent" mode="parent">
+ <xsl:param name="elem" select="@name"/>
+ <xsl:param name="parent" select="../@name"/>
+ <xsl:text>&#x9;&#x9;parent("</xsl:text>
+ <xsl:value-of select="$elem"/>
+ <xsl:text>", "</xsl:text>
+ <xsl:value-of select="$parent"/>
+ <xsl:text>");&#xA;</xsl:text>
+ </xsl:template>
+
+ <!-- Generates a single call to attribute(). -->
+ <xsl:template match="tssl:element/tssl:attribute" name="tssl:attribute">
+ <xsl:param name="elem" select="../@name"/>
+ <xsl:param name="attr" select="@name"/>
+ <xsl:param name="type" select="@type"/>
+ <xsl:param name="default" select="@default"/>
+ <xsl:text>&#x9;&#x9;attribute("</xsl:text>
+ <xsl:value-of select="$elem"/>
+ <xsl:text>", "</xsl:text>
+ <xsl:value-of select="$attr"/>
+ <xsl:text>", "</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$type">
+ <xsl:value-of select="$type"/>
+ </xsl:when>
+ <xsl:when test="not($type)">
+ <xsl:text>CDATA</xsl:text>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>", </xsl:text>
+ <xsl:choose>
+ <xsl:when test="$default">
+ <xsl:text>"</xsl:text>
+ <xsl:value-of select="$default"/>
+ <xsl:text>"</xsl:text>
+ </xsl:when>
+ <xsl:when test="not($default)">
+ <xsl:text>null</xsl:text>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>);&#xA;</xsl:text>
+ </xsl:template>
+
+ <!-- Generates calls to attribute() (using the above template)
+ based on the global attribute definitions. -->
+ <xsl:template match="tssl:schema/tssl:attribute">
+ <xsl:variable name="attr" select="@name"/>
+ <xsl:variable name="type" select="@type"/>
+ <xsl:variable name="default" select="@default"/>
+ <xsl:for-each select="//tssl:element">
+ <xsl:sort select="@name"/>
+ <xsl:call-template name="tssl:attribute">
+ <xsl:with-param name="elem" select="@name"/>
+ <xsl:with-param name="attr" select="$attr"/>
+ <xsl:with-param name="type" select="$type"/>
+ <xsl:with-param name="default" select="$default"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:template>
+
+ <!-- Generates a single call to entity(). -->
+ <xsl:template match="tssl:entity">
+ <xsl:text>&#x9;&#x9;entity("</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>", 0x</xsl:text>
+ <xsl:value-of select="@codepoint"/>
+ <xsl:text>);&#xA;</xsl:text>
+ </xsl:template>
+
+</xsl:transform>