Skip to content

Commit

Permalink
adding new tools and pimping old ones
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1166 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 28, 2012
1 parent a597e36 commit 9b33f7a
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 36 deletions.
23 changes: 23 additions & 0 deletions shared/tools/showrootprods
@@ -0,0 +1,23 @@
#!/bin/sh

LOCAL=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL}

if [ $# -eq 1 ]; then
OUTPUT=/dev/stdout
elif [ $# -ne 2 ]; then
echo "This tool pretty-prints production rules of the root nonterminals."
echo "Usage: showrootprods <input-bgf-document> [<output-text>]"
echo "When output file is not specified, stdout is used."
exit 1
elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
else
OUTPUT=$2
fi

xsltproc ${SLPS}/shared/xsl/rootprods.xslt $1> ${OUTPUT}
10 changes: 10 additions & 0 deletions shared/tools/tnb
@@ -0,0 +1,10 @@
#!/bin/sh

LOCAL=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL}

${SLPS}/topics/investigation/analysis/listtopsbottoms.py $@

70 changes: 34 additions & 36 deletions shared/xsl/bgf2dot.xslt
@@ -1,36 +1,34 @@
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:xhtml="http://www.w3.org/1999/xhtml">

<xsl:output
method="text"
encoding="UTF-8"
omit-xml-declaration="yes"
/>

<xsl:template match="/bgf:grammar">
<xsl:text>digraph generated{</xsl:text>
<xsl:for-each select="./bgf:production">
<xsl:call-template name="findDependencies">
<xsl:with-param name="start" select="./nonterminal"/>
<xsl:with-param name="traverse" select="./bgf:expression"/>
</xsl:call-template>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:template>

<xsl:template name="findDependencies">
<xsl:param name="start"/>
<xsl:param name="traverse"/>
<xsl:for-each select="$traverse//nonterminal">
<xsl:if test=".!=$start">
<xsl:value-of select="$start"/>
<xsl:text>-></xsl:text>
<xsl:value-of select="."/>
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="text" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="/bgf:grammar">
<xsl:text>digraph generated{</xsl:text>
<xsl:for-each select="./bgf:production">
<xsl:call-template name="findDependencies">
<xsl:with-param name="start" select="./nonterminal"/>
<xsl:with-param name="traverse" select="./bgf:expression"/>
</xsl:call-template>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template name="findDependencies">
<xsl:param name="start"/>
<xsl:param name="traverse"/>
<xsl:for-each select="$traverse//nonterminal">
<xsl:if test=".!=$start">
<xsl:value-of select="$start"/>
<xsl:text>-&gt;</xsl:text>
<xsl:value-of select="."/>
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="$traverse//value">
<xsl:if test=".!=$start">
<xsl:value-of select="$start"/>
<xsl:text>-&gt;</xsl:text>
<xsl:value-of select="."/>
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
7 changes: 7 additions & 0 deletions topics/export/rascal/bgf2rsc.xslt
Expand Up @@ -152,6 +152,13 @@ module </xsl:text>
<xsl:template name="no-parenthesis">
<xsl:param name="expr"/>
<xsl:choose>
<xsl:when test="$expr/selectable">
<xsl:value-of select="$expr/selectable/selector"/>
<xsl:text>: </xsl:text>
<xsl:call-template name="no-parenthesis">
<xsl:with-param name="expr" select="$expr/selectable/bgf:expression"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$expr/sequence">
<xsl:apply-templates select="$expr/sequence/bgf:expression[1]/*"/>
<xsl:for-each select="$expr/sequence/bgf:expression[position()&gt;1]">
Expand Down
11 changes: 11 additions & 0 deletions topics/mutation/expose-root/Makefile
@@ -0,0 +1,11 @@
test:
make clean
cp ../../convergence/fl/snapshot/*.bgf tests/
ls -1 tests/*.bgf | xargs -n1 ./testperform
rm *.xbgf

show:
ls -1 tests/*.ready.bgf | xargs -n1 ../../../shared/tools/showrootprods

clean:
rm -f *.xbgf tests/*.xbgf tests/*.ready.* tests/*.root.*
21 changes: 21 additions & 0 deletions topics/mutation/expose-root/generate.xslt
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:cbgf="http://planet-sl.org/cbgf" xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/bgf:grammar">
<xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf">
<xsl:for-each select="root">
<xsl:call-template name="expose-nonterminal">
<xsl:with-param name="nt" select="."/>
</xsl:call-template>
</xsl:for-each>
</xbgf:sequence>
</xsl:template>
<xsl:template name="expose-nonterminal">
<xsl:param name="nt"/>
<xsl:if test="count(/bgf:grammar/bgf:production[nonterminal=$nt]/bgf:expression//nonterminal)=1">
<xbgf:inline xmlns:xbgf="http://planet-sl.org/xbgf">
<xsl:value-of select="/bgf:grammar/bgf:production[nonterminal=$nt]/bgf:expression//nonterminal"/>
</xbgf:inline>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
7 changes: 7 additions & 0 deletions topics/mutation/expose-root/testperform
@@ -0,0 +1,7 @@
#!/bin/sh

../../../shared/generators/reroot2top $1 `basename $1 .bgf`.reroot.xbgf
cp $1 $1.root.bgf
../../../shared/tools/xbgf `basename $1 .bgf`.reroot.xbgf $1 $1.root.bgf
xsltproc generate.xslt $1.root.bgf > $1.expose.xbgf
../../../shared/tools/xbgf $1.expose.xbgf $1.root.bgf $1.ready.bgf

0 comments on commit 9b33f7a

Please sign in to comment.