Skip to content

Commit

Permalink
Adding another topic: presentation.
Browse files Browse the repository at this point in the history
Now "extraction" topic is dedicated strictly to derivation of BGFs from various sources.
The "presentation" topic is for getting various info out of BGFs.
The "transformation" topic is still for BGF to BGF transformations.
The "convergence" topic is for using BGF to BGF transformations for grammar convergence.


git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@314 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Sep 25, 2008
1 parent 05fc543 commit 392f8fb
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 1 deletion.
39 changes: 39 additions & 0 deletions shared/tools/bgf2bnf
@@ -0,0 +1,39 @@
#!/bin/sh

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

if [ $# -eq 1 ]; then
OUTPUT=`basename $1 .bgf`.bnf
elif [ $# -ne 2 ]; then
echo "This tool transforms XML BNF-like Grammar Format documents to EBNF dialect used in JLS."
echo "Usage: bgf2bnf <input-bgf-document> [<output-text>]"
exit 1
elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
else
OUTPUT=$2
fi

${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/strips.xbgf $1 $1.noselectors > /dev/null
if [ ! -r $1.noselectors ]; then
${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/stripl.xbgf $1 $1.nolabels > /dev/null
if [ -r $1.nolabels ]; then
mv $1.nolabels $1.stripped
else
cp $1 $1.stripped
fi
else
${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/stripl.xbgf $1.noselectors $1.nolabels > /dev/null
if [ -r $1.nolabels ]; then
mv $1.nolabels $1.stripped
else
mv $1.noselectors $1.stripped
fi
fi
xsltproc ${SLPS}/shared/xsl/bgf2bnf.xslt $1.stripped > ${OUTPUT}
rm -f $1.stripped $1.noselectors $1.nolabels
2 changes: 1 addition & 1 deletion shared/tools/ldf2html
Expand Up @@ -14,5 +14,5 @@ elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
else
xsltproc ${SLPS}/shared/xsl/ldf2xhtml.xslt $1 | python ${SLPS}/topics/extraction/ldf2pdf/closemeta.py > $2
xsltproc ${SLPS}/shared/xsl/ldf2xhtml.xslt $1 | python ${SLPS}/topics/presentation/ldf2pdf/closemeta.py > $2
fi
129 changes: 129 additions & 0 deletions shared/xsl/bgf2bnf.xslt
@@ -0,0 +1,129 @@
<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:apply-templates select="./bgf:*"/>
</xsl:template>

<xsl:template match="bgf:production">
<xsl:value-of select="./nonterminal"/>
<xsl:text>:</xsl:text>
<xsl:choose>
<xsl:when test="./bgf:expression/choice">
<xsl:for-each select="./bgf:expression/choice/bgf:expression">
<xsl:text>
</xsl:text>
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="./bgf:expression"/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="bgf:expression">
<xsl:apply-templates select="./*"/>
</xsl:template>

<xsl:template match="plus">
<xsl:apply-templates select="./*"/>
<xsl:text>{ </xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>} </xsl:text>
</xsl:template>

<xsl:template match="star">
<xsl:text>{ </xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>} </xsl:text>
</xsl:template>

<xsl:template match="optional">
<xsl:text>[ </xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>] </xsl:text>
</xsl:template>

<xsl:template match="terminal">
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>" </xsl:text>
</xsl:template>

<xsl:template match="value">
<xsl:choose>
<xsl:when test=". = 'string'">
<xsl:text>STRING </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>INT </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="epsilon">
<xsl:text>EPSILON </xsl:text>
</xsl:template>

<xsl:template match="empty">
<xsl:text>EMPTY </xsl:text>
</xsl:template>

<xsl:template match="any">
<xsl:text>ANY </xsl:text>
</xsl:template>

<xsl:template match="nonterminal">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="sequence">
<xsl:apply-templates select="./*"/>
</xsl:template>

<xsl:template match="choice">
<xsl:call-template name="car">
<xsl:with-param name="expr" select="./bgf:expression[1]"/>
</xsl:call-template>
<xsl:for-each select="./bgf:expression[position()>1]">
<xsl:call-template name="cdr">
<xsl:with-param name="expr" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="car">
<xsl:param name="expr"/>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="$expr/*"/>
<xsl:text>
</xsl:text>
</xsl:template>

<xsl:template name="cdr">
<xsl:param name="expr"/>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="$expr/*"/>
<xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>
12 changes: 12 additions & 0 deletions topics/presentation/bgf2bnf/Makefile
@@ -0,0 +1,12 @@
all:
make clean
make test

build:

test:
find ../../fl/lci/snapshot/ -name "*.bgf" | xargs -n1 ../../../shared/tools/bgf2bnf
find ../../java/lci/snapshot/ -name "*.bgf" | xargs -n1 ../../../shared/tools/bgf2bnf

clean:
rm -f *.bnf
6 changes: 6 additions & 0 deletions topics/presentation/bgf2bnf/stripl.xbgf
@@ -0,0 +1,6 @@
<xbgf:sequence
xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:strip>
<allLabels/>
</xbgf:strip>
</xbgf:sequence>
6 changes: 6 additions & 0 deletions topics/presentation/bgf2bnf/strips.xbgf
@@ -0,0 +1,6 @@
<xbgf:sequence
xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:strip>
<allSelectors/>
</xbgf:strip>
</xbgf:sequence>
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 392f8fb

Please sign in to comment.