Skip to content

Commit

Permalink
W3C XML to BGF working correctly
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@825 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Sep 10, 2010
1 parent 919eb2b commit 42263d2
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 11 deletions.
2 changes: 2 additions & 0 deletions shared/tools/spec2bgf
Expand Up @@ -14,6 +14,8 @@ elif [ $# -eq 2 ]; then
/usr/local/bin/xsltproc ${SLPS}/topics/extraction/w3c/spec2bgf.xslt $1 > $1.tmp
perl -pi -w -e 's/<unknown>\)\*<\/unknown>/<unknown>\)<\/unknown><postfix-star\/>/g;' $1.tmp
perl -pi -w -e 's/<unknown>\)\?<\/unknown>/<unknown>\)<\/unknown><postfix-optional\/>/g;' $1.tmp
perl -pi -w -e 's/<unknown>\?\)\?<\/unknown>/<postfix-optional\/><unknown>\)<\/unknown><postfix-optional\/>/g;' $1.tmp
perl -pi -w -e "s/<unknown>\(\'.\'<\/unknown>/<unknown>\(<\/unknown><terminal>.<\/terminal>/g;" $1.tmp
perl -pi -w -e 's/<unknown>\(<\/unknown>/<sequence><bgf:expression>/g;' $1.tmp
perl -pi -w -e 's/<unknown>\)<\/unknown>/<\/bgf:expression><\/sequence>/g;' $1.tmp
/usr/local/bin/xsltproc ${SLPS}/topics/extraction/w3c/postfix2confix.xslt $1.tmp > $2.tmp
Expand Down
9 changes: 9 additions & 0 deletions topics/documents/xpath/Makefile
@@ -1,3 +1,12 @@
bgf:
/usr/local/bin/xsltproc spec2bgf.xslt xpath-pp.xml > xpath1.bgf
perl -pi -w -e 's/<unknown>\)\*<\/unknown>/<unknown>\)<\/unknown><postfix-star\/>/g;' xpath1.bgf
perl -pi -w -e 's/<unknown>\)\?<\/unknown>/<unknown>\)<\/unknown><postfix-optional\/>/g;' xpath1.bgf
perl -pi -w -e 's/<unknown>\(<\/unknown>/<sequence><bgf:expression>/g;' xpath1.bgf
perl -pi -w -e 's/<unknown>\)<\/unknown>/<\/bgf:expression><\/sequence>/g;' xpath1.bgf
/usr/local/bin/xsltproc postfix2confix.xslt xpath1.bgf > xpath1a.bgf
/usr/local/bin/xsltproc ununknow.xslt xpath1a.bgf > xpath1b.bgf

build:
/usr/local/bin/xsltproc spec2ldf.xslt xpath-pp.xml > xpath1.ldf

Expand Down
44 changes: 43 additions & 1 deletion topics/extraction/w3c/cleanup.xslt
Expand Up @@ -46,7 +46,7 @@
</xsl:when>
<xsl:when test="count(*) &gt; 1 and unknown = '|'">
<choice>
<xsl:for-each select="*">
<xsl:for-each select="*[local-name(.)!='unknown']">
<bgf:expression>
<xsl:apply-templates select="."/>
</bgf:expression>
Expand All @@ -66,6 +66,48 @@
<xsl:template match="nonterminal|terminal">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="optional">
<optional>
<xsl:choose>
<xsl:when test="bgf:expression|sequence">
<xsl:apply-templates select="*"/>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<xsl:apply-templates select="*"/>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</optional>
</xsl:template>
<xsl:template match="plus">
<plus>
<xsl:choose>
<xsl:when test="bgf:expression|sequence">
<xsl:apply-templates select="*"/>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<xsl:apply-templates select="*"/>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</plus>
</xsl:template>
<xsl:template match="star">
<star>
<xsl:choose>
<xsl:when test="bgf:expression|sequence">
<xsl:apply-templates select="*"/>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<xsl:apply-templates select="*"/>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</star>
</xsl:template>
<xsl:template match="unknown">
<!-- <xsl:value-of select="."/> -->
<epsilon/>
Expand Down
15 changes: 10 additions & 5 deletions topics/extraction/w3c/postfix2confix.xslt
Expand Up @@ -25,12 +25,12 @@
<xsl:template match="bgf:expression">
<bgf:expression>
<xsl:choose>
<xsl:when test="choice">
<xsl:when test="choice and count(*) = 1">
<choice>
<xsl:apply-templates select="choice/*"/>
</choice>
</xsl:when>
<xsl:when test="sequence">
<xsl:when test="sequence and count(*) = 1">
<sequence>
<xsl:apply-templates select="sequence/*"/>
</sequence>
Expand All @@ -40,18 +40,18 @@
<xsl:choose>
<xsl:when test="local-name(following-sibling::*[1]) = 'postfix-optional'">
<optional>
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</optional>
</xsl:when>
<xsl:when test="local-name(following-sibling::*[1]) = 'postfix-star'">
<star>
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</star>
</xsl:when>
<xsl:when test="local-name(.) = 'postfix-optional'"/>
<xsl:when test="local-name(.) = 'postfix-star'"/>
<xsl:otherwise>
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Expand All @@ -65,4 +65,9 @@
<xsl:template match="nonterminal|terminal|unknown">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="sequence">
<sequence>
<xsl:apply-templates select="*"/>
</sequence>
</xsl:template>
</xsl:stylesheet>
7 changes: 7 additions & 0 deletions topics/extraction/w3c/spec2bgf.xslt
Expand Up @@ -5,6 +5,7 @@
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<xsl:for-each select="//scrap">
<xsl:comment>
<xsl:text>Scrap </xsl:text>
<xsl:value-of select="head"/>
</xsl:comment>
<xsl:for-each select=".//prod">
Expand Down Expand Up @@ -73,11 +74,17 @@
<xsl:template name="map-one-symbol">
<xsl:param name="node"/>
<xsl:choose>
<xsl:when test="$node = '?'">
<postfix-optional/>
</xsl:when>
<!-- terminal -->
<xsl:when test="substring($node,1,1) = &quot;'&quot;">
<terminal>
<xsl:value-of select="substring-before(substring($node,2),&quot;'&quot;)"/>
</terminal>
<xsl:call-template name="map-multiple-symbols">
<xsl:with-param name="list" select="substring-after(substring($node,2),&quot;'&quot;)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($node,1,1) = ' '">
<leading-space>
Expand Down
Expand Up @@ -140,11 +140,7 @@
<!-- TODO -->
<ldf:metainfo/>
<content>
<xsl:for-each select="*[local-name() != 'head']">
<text>
<xsl:apply-templates select="node()"/>
</text>
</xsl:for-each>
<xsl:apply-templates select="*[local-name() != 'head']"/>
</content>
</ldf:simple-section>
</content>
Expand Down Expand Up @@ -240,6 +236,15 @@
</xsl:for-each>
</list>
</xsl:template>
<xsl:template match="ulist">
<list>
<xsl:for-each select="item">
<item>
<xsl:apply-templates select="p/node()"/>
</item>
</xsl:for-each>
</list>
</xsl:template>
<!-- processing keywords -->
<xsl:template match="term">
<ldf:keyword>
Expand All @@ -263,4 +268,113 @@
<xsl:value-of select="//*[@id=$id]/head"/>
</xsl:template>

<!--
<scrap>
<head>Location Paths</head>
<prodgroup pcw5="1" pcw2="10" pcw4="18">
<prod id="NT-LocationPath">
<lhs>LocationPath</lhs>
<rhs><nt def="NT-RelativeLocationPath">RelativeLocationPath</nt></rhs>
<rhs>| <nt def="NT-AbsoluteLocationPath">AbsoluteLocationPath</nt></rhs>
</prod>
<prod id="NT-AbsoluteLocationPath">
<lhs>AbsoluteLocationPath</lhs>
<rhs>'/' <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt>?</rhs>
<rhs>| <nt def="NT-AbbreviatedAbsoluteLocationPath">AbbreviatedAbsoluteLocationPath</nt></rhs>
</prod>
<prod id="NT-RelativeLocationPath">
<lhs>RelativeLocationPath</lhs>
<rhs><nt def="NT-Step">Step</nt></rhs>
<rhs>| <nt def="NT-RelativeLocationPath">RelativeLocationPath</nt> '/' <nt def="NT-Step">Step</nt></rhs>
<rhs>| <nt def="NT-AbbreviatedRelativeLocationPath">AbbreviatedRelativeLocationPath</nt></rhs>
</prod>
</prodgroup>
</scrap>
-->
<xsl:template match="scrap">
<ldf:normative-role>syntax</ldf:normative-role>
<ldf:simple-section>
<role>abstract</role>
<!-- TODO -->
<ldf:metainfo>
<title>
<xsl:value-of select="head"/>
</title>
</ldf:metainfo>
<content>
<xsl:apply-templates select="prodgroup/prod"/>
</content>
</ldf:simple-section>
</xsl:template>
<xsl:template match="prod">
<!--
not needed anymore:
<ldf:anchor id="{@id}"/>
-->
<bgf:production>
<nonterminal>
<xsl:value-of select="lhs"/>
</nonterminal>
<xsl:choose>
<xsl:when test="count(rhs) = 1">
<xsl:apply-templates select="rhs"/>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<choice>
<xsl:apply-templates select="rhs"/>
</choice>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</bgf:production>
</xsl:template>
<xsl:template match="rhs">
<debug>
<xsl:for-each select="node()">
<x>
<xsl:value-of select="."/>
</x>
</xsl:for-each>
</debug>
<xsl:choose>
<xsl:when test="count(*) = 1 and text() = ''">
<one/>
<xsl:apply-templates select="node()"/>
</xsl:when>
<xsl:when test="count(*) = 1 and text() = '|'">
<two/>
<xsl:apply-templates select="node()[2]"/>
</xsl:when>
<xsl:when test="count(node()) > 2 and node()[1] = '|'">
<three/>
<bgf:expression>
<sequence>
<xsl:apply-templates select="node()[position()>1]"/>
</sequence>
</bgf:expression>
</xsl:when>
<xsl:otherwise>
<four/>
<bgf:expression>
<sequence>
<xsl:apply-templates select="node()"/>
</sequence>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="nt">
<nonterminal>
<xsl:value-of select="."/>
</nonterminal>
</xsl:template>
<!--
<rhs>
<nt def="NT-RelativeLocationPath">RelativeLocationPath</nt>
</rhs>
<rhs>
| <nt def="NT-AbsoluteLocationPath">AbsoluteLocationPath</nt>
</rhs>
-->
</xsl:stylesheet>
17 changes: 17 additions & 0 deletions topics/grammars/xpath/Makefile
@@ -1,6 +1,23 @@
test:
../../../shared/tools/spec2bgf xpath1.xml xpath.bgf
../../../shared/tools/checkxml bgf xpath.bgf
../../../shared/tools/xbgf xpath1.normalize.xbgf xpath.bgf xpath.fixed.bgf
../../../shared/tools/bgf2html xpath.fixed.bgf xpath.html

steps:
/usr/local/bin/xsltproc ../../extraction/w3c/spec2bgf.xslt xpath1.xml > xpath.v1.bgf
cp xpath.v1.bgf xpath.v2.bgf
perl -pi -w -e 's/<unknown>\)\*<\/unknown>/<unknown>\)<\/unknown><postfix-star\/>/g;' xpath.v2.bgf
perl -pi -w -e 's/<unknown>\)\?<\/unknown>/<unknown>\)<\/unknown><postfix-optional\/>/g;' xpath.v2.bgf
perl -pi -w -e 's/<unknown>\?\)\?<\/unknown>/<postfix-optional\/><unknown>\)<\/unknown><postfix-optional\/>/g;' xpath.v2.bgf
perl -pi -w -e "s/<unknown>\(\'.\'<\/unknown>/<unknown>\(<\/unknown><terminal>.<\/terminal>/g;" xpath.v2.bgf
perl -pi -w -e 's/<unknown>\(<\/unknown>/<sequence><bgf:expression>/g;' xpath.v2.bgf
perl -pi -w -e 's/<unknown>\)<\/unknown>/<\/bgf:expression><\/sequence>/g;' xpath.v2.bgf
/usr/local/bin/xsltproc ../../extraction/w3c/postfix2confix.xslt xpath.v2.bgf > xpath.v3.bgf
/usr/local/bin/xsltproc ../../extraction/w3c/cleanup.xslt xpath.v3.bgf > xpath.v4.bgf
../../../shared/tools/checkxml bgf xpath.v4.bgf
../../../shared/tools/xbgf xpath1.normalize.xbgf xpath.v4.bgf xpath.v5.bgf
../../../shared/tools/bgf2html xpath.v5.bgf xpath.html

get:
curl -k http://www.w3.org/TR/1999/REC-xpath-19991116.xml >xpath1.xml
Expand Down
52 changes: 52 additions & 0 deletions topics/grammars/xpath/xpath1.normalize.xbgf
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:undefine>
<nonterminal>Literal</nonterminal>
</xbgf:undefine>
<xbgf:redefine>
<bgf:production>
<label>NT-Digits</label>
<nonterminal>Digits</nonterminal>
<bgf:expression>
<plus>
<bgf:expression>
<choice>
<bgf:expression>
<terminal>0</terminal>
</bgf:expression>
<bgf:expression>
<terminal>1</terminal>
</bgf:expression>
<bgf:expression>
<terminal>2</terminal>
</bgf:expression>
<bgf:expression>
<terminal>3</terminal>
</bgf:expression>
<bgf:expression>
<terminal>4</terminal>
</bgf:expression>
<bgf:expression>
<terminal>5</terminal>
</bgf:expression>
<bgf:expression>
<terminal>6</terminal>
</bgf:expression>
<bgf:expression>
<terminal>7</terminal>
</bgf:expression>
<bgf:expression>
<terminal>8</terminal>
</bgf:expression>
<bgf:expression>
<terminal>9</terminal>
</bgf:expression>
</choice>
</bgf:expression>
</plus>
</bgf:expression>
</bgf:production>
</xbgf:redefine>
<xbgf:undefine>
<nonterminal>FunctionName</nonterminal>
</xbgf:undefine></xbgf:sequence>

0 comments on commit 42263d2

Please sign in to comment.