Skip to content

Commit

Permalink
+reprettyprinter; hypertext rendering of LDF done
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@670 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 1, 2009
1 parent 33841b1 commit 679b2d8
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 68 deletions.
68 changes: 68 additions & 0 deletions shared/python/repp.py
@@ -0,0 +1,68 @@
#!/usr/bin/python
import os
import sys
import string
import slpsns
import elementtree.ElementTree as ET

def identify(e):
if 'id' in e.attrib:
return e.tag+'@'+e.get('id')
else:
return e.tag

def createCleanElementFrom(e):
#print 'Copying element',e.tag.replace(slpsns.htm_(''),'')
e2 = ET.Element(e.tag.replace(slpsns.htm_(''),''))
if e.text:
e2.text = e.text
if e.tail:
e2.tail = e.tail
for a in e.attrib:
e2.set(a,e.get(a))
#print 'Copying attribute',a
for se in e.findall('*'):
e2.append(createCleanElementFrom(se))
return e2


def repp(localpath,tree,prettyprinter):
ending = ''
for e in tree.findall('*'):
tree.remove(e)
tree.text = ''
inputfile = 'printed_for_xldf.tmp'
if os.system(localpath+prettyprinter+' '+localpath+tree.get('src')+' '+inputfile):
print '[----] Failed: can''t execute the pretty-printer!'
return
for e in ET.parse(inputfile).findall('/*/*'):
#for e in ET.XML('<t>'+''.join(open(inputfile,'r').readlines())+'</t>').findall('*'):
tree.append(createCleanElementFrom(e))
print '[++++] Re-pretty-printed.'
return


def main(inldffile,ppfile,outldffile):
tree = ET.parse(inldffile)
if inldffile.find('/')<0:
localpath = ''
else:
localpath = '/'.join(inldffile.split('/')[:-1])+'/'
cx = 0
for s in tree.findall('//sample'):
print '[????] Found',identify(s),'of',s.get('src')
repp(localpath,s,ppfile)
cx += 1
print 'Total',cx,'samples processed'
tree.write(outldffile)
return

if __name__ == "__main__":
if len(sys.argv) == 4:
apply(main,sys.argv[1:4])
else:
print '''Change the Pretty-Printer automation tool
Usage:'''
print ' ',sys.argv[0],'<input ldf file>','<new samples pretty-printer>','<output ldf file>'
sys.exit(1)
2 changes: 1 addition & 1 deletion shared/python/xsd2ldf.py
Expand Up @@ -92,7 +92,7 @@ def main(xsdfile,bgffile,ldffile):
el.text = 'unknown'
el = ET.SubElement(section,'date')
# generate!!!
el.text = '2008-02-21'
el.text = '2008-08-01'

section = ET.SubElement(dtree,'frontMatter')
el = ET.SubElement(section,'foreword')
Expand Down
1 change: 1 addition & 0 deletions shared/tools/ldf2html
Expand Up @@ -16,5 +16,6 @@ elif [ ! -r $1 ]; then
else
xsltproc ${SLPS}/shared/xsl/ldf2xhtml.xslt $1 | python ${SLPS}/shared/python/closemeta.py > $2
perl -pi -w -e 's/---/&#8212;/g;' $2
perl -pi -w -e 's/xmlns:ns0\=\"http:\/\/planet-sl.org\/ldf\" xmlns=\"\"//g;' $2
perl -pi -w -e 's/--/&#8211;/g;' $2
fi
22 changes: 22 additions & 0 deletions shared/tools/repp
@@ -0,0 +1,22 @@
#! /bin/sh

# Get our hands on basedir
LOCAL1=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL1}

if [ $# -ne 3 ]; then
echo "Usage: repp <LDF-input> <preprocessor> <LDF-output>"
exit 1
elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
elif [ ! -r $2 ]; then
echo "Oops: $2 not found or not readable."
exit 1
else
rm -f $3
python ${SLPS}/shared/python/repp.py $1 $2 $3
fi
41 changes: 30 additions & 11 deletions shared/xsd/ldf.xsd
Expand Up @@ -2,7 +2,7 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ldf="http://planet-sl.org/ldf"
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:xhtml="http://www.w3.org/1999/xhtml/datatypes/"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
targetNamespace="http://planet-sl.org/ldf">

<xsd:import namespace="http://planet-sl.org/bgf" schemaLocation="bgf.xsd"/>
Expand Down Expand Up @@ -178,10 +178,12 @@
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="unknown"/>
<xsd:enumeration value="draft"/> <!-- working draft, committee draft -->
<xsd:enumeration value="draft"/>
<!-- working draft, committee draft -->
<xsd:enumeration value="candidate"/>
<xsd:enumeration value="proposed"/>
<xsd:enumeration value="approved"/> <!-- recommendation, international standard -->
<xsd:enumeration value="approved"/>
<!-- recommendation, international standard -->
<xsd:enumeration value="revised"/>
<xsd:enumeration value="obsolete"/>
<xsd:enumeration value="withdrawn"/>
Expand Down Expand Up @@ -345,10 +347,19 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!--<xsd:element name="sample">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="src" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>-->
<xsd:element name="sample">
<xsd:complexType mixed="true">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:any />
<xsd:any namespace="http://www.w3.org/1999/xhtml" processContents="lax"/>
</xsd:sequence>
<xsd:attribute name="src" type="xsd:string"/>
</xsd:complexType>
Expand All @@ -375,7 +386,7 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="simpleList">
<xsd:complexType name="simpleList">
<xsd:sequence>
<xsd:element name="item" type="ldf:mixedType" maxOccurs="unbounded"/>
</xsd:sequence>
Expand Down Expand Up @@ -497,8 +508,8 @@
<xsd:element name="cell" maxOccurs="unbounded" type="ldf:simpleText"/>
</xsd:sequence>
</xsd:complexType>
<xsd:group name="structuredSectionElement">

<xsd:group name="structuredSectionElement">
<xsd:choice>
<xsd:element name="placeholder" type="ldf:generated">
<xsd:annotation>
Expand Down Expand Up @@ -597,7 +608,7 @@
</xsd:element>
</xsd:choice>
</xsd:group>

<!-- tokens -->

<xsd:group name="normative">
Expand Down Expand Up @@ -727,11 +738,11 @@
</xsd:annotation>
</xsd:element>
<!-- none of the above -->

</xsd:choice>
</xsd:group>

<!--xsd:complexType name="contentType">
<!--xsd:complexType name="contentType">
<xsd:annotation>
<xsd:documentation>
A sections content is a list of different kinds of portions.
Expand Down Expand Up @@ -843,6 +854,14 @@
</xsd:complexType>

<xsd:element name="formula">
<xsd:annotation>
<xsd:documentation>
Formulae can be used in language documentation in many ways.
The internal representation format is MathML which is W3C Recommendation,
but the external representation can vary, in our case there are two:
\TeX\ and HTML.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:any namespace="http://www.w3.org/1998/Math/MathML"/>
Expand Down Expand Up @@ -890,5 +909,5 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>

</xsd:schema>
130 changes: 81 additions & 49 deletions shared/xsl/bgf2xhtml.xslt
Expand Up @@ -15,29 +15,15 @@
</xsl:template>

<xsl:template match="bgf:production">
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="name">
<xsl:value-of select="./nonterminal"/>
</xsl:attribute>
</xsl:element>
<xsl:if test="./label">
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="name">
<xsl:value-of select="./nonterminal"/>
<xsl:text>-labelled-</xsl:text>
<xsl:value-of select="./label"/>
</xsl:attribute>
</xsl:element>
<xsl:text>[</xsl:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="label">
<xsl:value-of select="./label"/>
</span>
<xsl:text>] </xsl:text>
<xsl:call-template name="displaylabel">
<xsl:with-param name="l" select="label"/>
</xsl:call-template>
</xsl:if>
<span xmlns="http://www.w3.org/1999/xhtml" class="nt">
<xsl:value-of select="./nonterminal"/>
</span>
<xsl:text>:</xsl:text>
<xsl:call-template name="displaynt">
<xsl:with-param name="nt" select="nonterminal"/>
</xsl:call-template>
<xsl:text>:</xsl:text>
<xsl:choose>
<xsl:when test="./bgf:expression/choice">
<xsl:for-each select="./bgf:expression/choice/bgf:expression">
Expand All @@ -63,7 +49,7 @@
</xsl:template>

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

<xsl:template match="marked">
Expand All @@ -90,50 +76,47 @@
</xsl:template>

<xsl:template match="terminal">
<span xmlns="http://www.w3.org/1999/xhtml" class="t">
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</span>
<xsl:call-template name="displayt">
<xsl:with-param name="t" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template match="value">
<xsl:choose>
<xsl:when test=". = 'string'">
<xsl:text>STR</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>INT</xsl:text>
</xsl:otherwise>
</xsl:choose>
<span xmlns="http://www.w3.org/1999/xhtml" class="meta">
<xsl:choose>
<xsl:when test=". = 'string'">
<xsl:text>str</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>int</xsl:text>
</xsl:otherwise>
</xsl:choose>
</span>
</xsl:template>

<xsl:template match="epsilon">
<xsl:text>&#x03B5;</xsl:text>
</xsl:template>

<xsl:template match="empty">
<xsl:text>EMPTY</xsl:text>
<span xmlns="http://www.w3.org/1999/xhtml" class="meta">
<xsl:text>empty</xsl:text>
</span>
</xsl:template>

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

<span xmlns="http://www.w3.org/1999/xhtml" class="meta">
<xsl:text>any</xsl:text>
</span> </xsl:template>

<xsl:template match="nonterminal">
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="."/>
</xsl:attribute>
<span class="nt">
<xsl:value-of select="."/>
</span>
</xsl:element>
<xsl:call-template name="linknt">
<xsl:with-param name="nt" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template match="selectable">
<span xmlns="http://www.w3.org/1999/xhtml" class="selector">
<span xmlns="http://www.w3.org/1999/xhtml" class="sel">
<xsl:value-of select="selector"/>
</span>
<xsl:text>::</xsl:text>
Expand Down Expand Up @@ -188,4 +171,53 @@
</xsl:choose>
</xsl:template>

<xsl:template name="linknt">
<xsl:param name="nt"/>
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="$nt"/>
</xsl:attribute>
<span class="nt">
<xsl:value-of select="$nt"/>
</span>
</xsl:element>
</xsl:template>

<xsl:template name="displaynt">
<xsl:param name="nt"/>
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="name">
<xsl:value-of select="$nt"/>
</xsl:attribute>
<span class="nt">
<xsl:value-of select="$nt"/>
</span>
</xsl:element>
</xsl:template>

<xsl:template name="displayt">
<xsl:param name="t"/>
<span xmlns="http://www.w3.org/1999/xhtml" class="t">
<xsl:text>"</xsl:text>
<xsl:value-of select="$t"/>
<xsl:text>"</xsl:text>
</span>
</xsl:template>

<xsl:template name="displaylabel">
<xsl:param name="l"/>
<xsl:text>[</xsl:text>
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="class">
<xsl:text>label</xsl:text>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="$l"/>
</xsl:attribute>
<xsl:value-of select="$l" />
</xsl:element>
<xsl:text>] </xsl:text>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 679b2d8

Please sign in to comment.