Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Facilities for PDF and HTML generation from LDF are added
* LDF->BGF transformation added - simple yet extremely useful * A very sketchy version of FL in LDF is added, it does not yet produce a complete grammar git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@75 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
c1bede6
commit 1a8aa34
Showing
10 changed files
with
2,214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#! /bin/sh | ||
|
||
# Get our hands on the languedoc basedir | ||
LOCAL=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL} | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "This tool transforms Language Document Format to BNF-like Grammar Format" | ||
echo "Usage: ldf2bgf <input-language-document> <output-grammar>" | ||
exit 1 | ||
elif [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
else | ||
rm -f $2 | ||
xsltproc ${SLPS}/shared/xsl/ldf2bgf.xslt $1 > $2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
LOCAL=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL} | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "This tool transforms Language Document Format to HyperText Markup Language" | ||
echo "Usage: ldf2html <input-language-document> <output-hypertext>" | ||
exit 1 | ||
elif [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
else | ||
rm -f $2 | ||
xsltproc ${SLPS}/shared/xsl/ldf2xhtml.xslt $1 | python ${SLPS}/topics/extraction/ldf2pdf/closemeta.py > $2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
|
||
LOCAL=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL} | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "This tool transforms Language Document Format to Portable Document Format" | ||
echo "Usage: ldf2pdf <input-language-document> <output-pdf>" | ||
exit 1 | ||
elif [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
else | ||
rm -f $2 | ||
sh ${SLPS}/shared/tools/ldf2html $1 html.tmp | ||
xsltproc ${SLPS}/shared/xsl/xhtml2fo.xslt html.tmp > fo.tmp | ||
${SLPS}/download/fop/fop -q fo.tmp $2 | ||
rm -f html.tmp fo.tmp | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<xsl:stylesheet version = '1.0' | ||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' | ||
xmlns:bgf="http://planet-sl.org/bgf" | ||
xmlns:ldf="http://planet-sl.org/ldf"> | ||
<xsl:output method="xml" encoding="UTF-8"/> | ||
|
||
<xsl:template match="/ldf:document"> | ||
<bgf:grammar> | ||
<xsl:apply-templates select="content"/> | ||
</bgf:grammar> | ||
</xsl:template> | ||
|
||
<xsl:template match="grammar"> | ||
<xsl:copy-of select="@*|node()"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="text"/> | ||
<xsl:template match="title"/> | ||
<xsl:template match="sample"/> | ||
<xsl:template match="runnable"/> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
<xsl:stylesheet version = '1.0' | ||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' | ||
xmlns:bgf="http://planet-sl.org/bgf" | ||
xmlns:ldf="http://planet-sl.org/ldf" | ||
xmlns:ldx="http://planet-sl.org/ldx" | ||
xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
|
||
<xsl:output | ||
method="html" | ||
encoding="UTF-8" | ||
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" | ||
/> | ||
|
||
<xsl:strip-space elements="sample"/> | ||
<xsl:preserve-space elements="runnable"/> | ||
|
||
<xsl:template match="/ldf:document"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<title> | ||
<xsl:value-of select="/ldf:document/title"/> - generated by LGF2XHTML | ||
</title> | ||
<style type="text/css"> | ||
h1, h2 | ||
{ | ||
text-align: center; | ||
} | ||
.note | ||
{ | ||
text-align: right; | ||
font-weight: bold; | ||
margin: 0px; | ||
} | ||
.frame | ||
{ | ||
border: 1px solid black; | ||
border-spacing: 2px; | ||
border-collapse: collapse; | ||
background-color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1> | ||
<xsl:value-of select="/ldf:document/title"/> | ||
</h1> | ||
<h2> | ||
(c) | ||
<xsl:value-of select="/ldf:document/author"/> | ||
</h2> | ||
<h3>Abstract</h3> | ||
<p> | ||
<xsl:value-of select="/ldf:document/abstract"/> | ||
</p> | ||
|
||
<hr/> | ||
|
||
<xsl:apply-templates select="/ldf:document/content"/> | ||
</body> | ||
</html> | ||
</xsl:template> | ||
|
||
<!--xsl:value-of select="."/--> | ||
<xsl:template match="text"> | ||
<p xmlns="http://www.w3.org/1999/xhtml"> | ||
<xsl:for-each select="node()"> | ||
<xsl:choose> | ||
<xsl:when test="namespace-uri() = 'http://planet-sl.org/ldx'"> | ||
<xsl:apply-templates select="."/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:copy-of select="."/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:for-each> | ||
</p> | ||
|
||
</xsl:template> | ||
|
||
<xsl:template match="grammar"> | ||
<blockquote xmlns="http://www.w3.org/1999/xhtml" class="frame"> | ||
<p class="note"> | ||
<small> | ||
<a> | ||
<xsl:attribute name = "href"> | ||
<xsl:value-of select="./@language"/> | ||
</xsl:attribute> | ||
Grammar productions | ||
<xsl:if test="./@version"> | ||
(ver. <xsl:value-of select="./@version"/>) | ||
</xsl:if> | ||
</a> | ||
</small> | ||
</p> | ||
<xsl:apply-templates select="./bgf:*"/> | ||
</blockquote> | ||
</xsl:template> | ||
|
||
<xsl:template match="sample"> | ||
<xsl:call-template name="treatsamples"> | ||
<xsl:with-param name="s" select="."/> | ||
</xsl:call-template> | ||
</xsl:template> | ||
|
||
<xsl:template match="runnable"> | ||
<xsl:call-template name="treatrunnables"> | ||
<xsl:with-param name="e" select="."/> | ||
</xsl:call-template> | ||
</xsl:template> | ||
|
||
<xsl:template name="treatsamples"> | ||
<xsl:param name="s"/> | ||
<xsl:if test="$s/@id"> | ||
<a> | ||
<xsl:attribute name = "name"> | ||
<xsl:value-of select="$s/@id"/> | ||
</xsl:attribute> | ||
</a> | ||
</xsl:if> | ||
<blockquote xmlns="http://www.w3.org/1999/xhtml" class="frame"> | ||
<p class="note"> | ||
<small> | ||
<a> | ||
<xsl:attribute name = "href"> | ||
<xsl:value-of select="$s/@language"/> | ||
</xsl:attribute> | ||
Source code sample | ||
<xsl:if test="$s/@version"> | ||
(ver. <xsl:value-of select="$s/@version"/>) | ||
</xsl:if> | ||
</a> | ||
</small> | ||
</p> | ||
<br/> | ||
<pre> | ||
<xsl:value-of select="$s"/> | ||
</pre> | ||
</blockquote> | ||
</xsl:template> | ||
|
||
<xsl:template name="treatrunnables"> | ||
<xsl:param name="e"/> | ||
<blockquote xmlns="http://www.w3.org/1999/xhtml" class="frame"> | ||
<p class="note"> | ||
<small> | ||
<a> | ||
<xsl:attribute name = "href"> | ||
<xsl:value-of select="$e/@language"/> | ||
</xsl:attribute> | ||
Sample execution | ||
<xsl:if test="$e/@version"> | ||
(ver. <xsl:value-of select="$e/@version"/>) | ||
</xsl:if> | ||
</a> | ||
</small> | ||
</p> | ||
<br/> | ||
<code> | ||
<strong> | ||
<a> | ||
<xsl:attribute name = "href">#<xsl:value-of select="$e/context"/> | ||
</xsl:attribute> | ||
<xsl:value-of select="$e/main"/> | ||
</a> | ||
</strong> | ||
<xsl:apply-templates select="$e/argument"/> | ||
</code> | ||
<br/> | ||
<p class="note"> | ||
<small> | ||
(Should return <xsl:value-of select="$e/yields"/>) | ||
</small> | ||
</p> | ||
</blockquote> | ||
</xsl:template> | ||
|
||
<xsl:template match="argument" xml:space="preserve"> | ||
<strong xmlns="http://www.w3.org/1999/xhtml"> | ||
<xsl:value-of select="."/> | ||
</strong> | ||
</xsl:template> | ||
|
||
<xsl:template match="section"> | ||
<h3 xmlns="http://www.w3.org/1999/xhtml"> | ||
<xsl:value-of select="./title"/> | ||
</h3> | ||
<xsl:apply-templates select="./content"/> | ||
</xsl:template> | ||
|
||
<!-- END OF LDF, START OF BGF --> | ||
|
||
<xsl:template match="bgf:production"> | ||
<code xmlns="http://www.w3.org/1999/xhtml"> | ||
<a> | ||
<xsl:attribute name = "name"> | ||
<xsl:value-of select="./nonterminal"/> | ||
</xsl:attribute> | ||
</a> | ||
<strong> | ||
<xsl:value-of select="./nonterminal"/> | ||
</strong> | ||
::= | ||
<xsl:apply-templates select="./expression"/> | ||
<br/> | ||
</code> | ||
</xsl:template> | ||
|
||
<xsl:template match="plus"> | ||
<xsl:apply-templates select="./*"/><sup xmlns="http://www.w3.org/1999/xhtml">+</sup> | ||
</xsl:template> | ||
|
||
<xsl:template match="star"> | ||
<xsl:apply-templates select="./*"/><sup xmlns="http://www.w3.org/1999/xhtml">*</sup> | ||
</xsl:template> | ||
|
||
<xsl:template match="optional"> | ||
<xsl:apply-templates select="./*"/>? | ||
</xsl:template> | ||
|
||
<xsl:template match="terminal"> | ||
"<xsl:value-of select="."/>" | ||
</xsl:template> | ||
|
||
<xsl:template match="nonterminal"> | ||
<a xmlns="http://www.w3.org/1999/xhtml"> | ||
<xsl:attribute name = "href">#<xsl:value-of select="."/> | ||
</xsl:attribute> | ||
<xsl:value-of select="."/> | ||
</a> | ||
</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="./expression[1]"/> | ||
</xsl:call-template> | ||
<xsl:for-each select="./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:apply-templates select="$expr/*"/> | ||
</xsl:template> | ||
|
||
<xsl:template name="cdr"> | ||
<xsl:param name="expr"/> | ||
<br xmlns="http://www.w3.org/1999/xhtml"/> | ||
| <xsl:apply-templates select="$expr/*"/> | ||
</xsl:template> | ||
|
||
<!-- END OF BGF, START OF LDX --> | ||
|
||
<xsl:template match="ldx:reference"> | ||
<code xmlns="http://www.w3.org/1999/xhtml"> | ||
<a> | ||
<xsl:attribute name = "href"> | ||
#<xsl:value-of select="."/> | ||
</xsl:attribute> | ||
<xsl:value-of select="."/> | ||
</a> | ||
</code> | ||
</xsl:template> | ||
|
||
|
||
</xsl:stylesheet> |
Oops, something went wrong.