Permalink
Browse files

inlining and extracting groups (inner choices, possibly sequences) fo…

…r enhancing the TXL extractor and exporter

git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@838 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information...
grammarware committed Oct 1, 2010
1 parent 5061ece commit 0060ce536680d1b372c6058c27d4b5794496dace
View
@@ -20,4 +20,7 @@ else
OUTPUT=$2
fi
xsltproc ${SLPS}/topics/export/txl/bgf2txl.xslt $1> ${OUTPUT}
xsltproc ${SLPS}/topics/transformation/normalization/subdefs/extract.xslt $1> tmp.xbgf
${SLPS}/shared/tools/xbgf tmp.xbgf $1 tmp.bgf
xsltproc ${SLPS}/topics/export/txl/bgf2txl.xslt tmp.bgf > ${OUTPUT}
rm -f tmp.bgf tmp.xbgf
View
@@ -10,19 +10,18 @@ if [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
elif [ $# -eq 2 ]; then
rm -f $2
txl $1 ${SLPS}/topics/extraction/txl/TXLGrammar/Txl/txl.txl -xml > grammar.xml
`dirname $0`/../internals/fixtxlxml grammar.xml grammar2.xml
xsltproc ${SLPS}/topics/extraction/txl/txl2bgf.xslt grammar2.xml > $2
echo 'rm -f grammar.xml grammar2.xml'
OUTPUT=$2
elif [ $# -eq 1 ]; then
txl $1 ${SLPS}/topics/extraction/txl/TXLGrammar/Txl/txl.txl -xml > grammar.xml
`dirname $0`/../internals/fixtxlxml grammar.xml grammar2.xml
xsltproc ${SLPS}/topics/extraction/txl/txl2bgf.xslt grammar2.xml > ${LOCAL}/`basename $1 .txl`.bgf
rm -f grammar.xml grammar2.xml
OUTPUT=${LOCAL}/`basename $1 .txl`.bgf
else
echo "This tool extracts a BGF grammar from a TXL grammar"
echo "Usage: txl2bgf <txl-grammar> [<output-grammar>]"
exit 2
fi
txl $1 ${SLPS}/topics/extraction/txl/TXLGrammar/Txl/txl.txl -xml > grammar.xml
`dirname $0`/../internals/fixtxlxml grammar.xml grammar2.xml
xsltproc ${SLPS}/topics/extraction/txl/txl2bgf.xslt grammar2.xml > tmp.bgf
xsltproc ${SLPS}/topics/transformation/normalization/subdefs/inline.xslt tmp.bgf > tmp.xbgf
${SLPS}/shared/tools/xbgf tmp.xbgf tmp.bgf ${OUTPUT}
rm -f tmp.bgf tmp.xbgf grammar.xml grammar2.xml
@@ -105,7 +105,7 @@ function main match [</xsl:text>
<xsl:text>EMPTY</xsl:text>
</xsl:template>
<xsl:template match="any">
<xsl:text>ANY</xsl:text>
<xsl:text>[any]</xsl:text>
</xsl:template>
<xsl:template match="nonterminal">
<xsl:if test="local-name(../..) != 'plus' and local-name(../..) != 'star'">
@@ -108,6 +108,11 @@
<epsilon/>
</bgf:expression>
</xsl:when>
<xsl:when test="type/typeSpec/typeid/id = 'any'">
<bgf:expression>
<any/>
</bgf:expression>
</xsl:when>
<!-- fallback -->
<xsl:otherwise>
<bgf:expression>
@@ -0,0 +1,8 @@
bgfdir = ../../../storage/bgf/tests.small
tooldir = ../../../../shared/tools
test:
ls -1 ${bgfdir} | xargs -n1 ./runtestcase ${tooldir} ${bgfdir}
clean:
rm -f *~ tmp.*.bgf tmp.xbgf
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/bgf:grammar">
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xsl:for-each select="bgf:production">
<xsl:if test="bgf:expression/sequence//choice">
<xsl:call-template name="extract">
<xsl:with-param name="name" select="nonterminal"/>
<xsl:with-param name="choices" select="bgf:expression/sequence//choice"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xbgf:sequence>
</xsl:template>
<xsl:template name="extract">
<xsl:param name="name"/>
<xsl:param name="choices"/>
<xsl:for-each select="$choices">
<xbgf:extract xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<bgf:production>
<nonterminal>
<xsl:value-of select="$name"/>
<xsl:text>-grp-</xsl:text>
<xsl:value-of select="position()"/>
</nonterminal>
<bgf:expression>
<xsl:copy-of select="."/>
</bgf:expression>
</bgf:production>
<in>
<nonterminal><xsl:value-of select="$name"/></nonterminal>
</in>
</xbgf:extract>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/bgf:grammar">
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xsl:for-each select="bgf:production">
<xsl:if test="contains(nonterminal,'-grp-')">
<xbgf:inline>
<xsl:value-of select="nonterminal"/>
</xbgf:inline>
</xsl:if>
</xsl:for-each>
</xbgf:sequence>
</xsl:template>
</xsl:stylesheet>
@@ -0,0 +1,27 @@
#!/bin/sh
xsltproc extract.xslt $2/$3 > tmp.xbgf
if [ $? -ne 0 ]
then
exit 255
fi
$1/xbgf tmp.xbgf $2/$3 tmp.1.bgf
if [ $? -ne 0 ]
then
exit 255
fi
xsltproc inline.xslt tmp.1.bgf > tmp.xbgf
if [ $? -ne 0 ]
then
exit 255
fi
$1/xbgf tmp.xbgf tmp.1.bgf tmp.2.bgf
if [ $? -ne 0 ]
then
exit 255
fi
$1/gdt tmp.2.bgf $2/$3
if [ $? -ne 0 ]
then
exit 255
fi

0 comments on commit 0060ce5

Please sign in to comment.