Skip to content

Commit

Permalink
fixing bugs; improving pretty-printing
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@668 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Jul 31, 2009
1 parent c6113de commit f19ca1b
Show file tree
Hide file tree
Showing 9 changed files with 722 additions and 322 deletions.
23 changes: 13 additions & 10 deletions download/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
all:

install: install-antlr install-fop install-msv install-et install-pp
install: install-antlr install-fop install-msv install-et install-pp install-generateDS

install-jastadd:
curl -k http://builds.jastadd.org/JastAdd/2009-06-10/jastadd2.jar > jastadd2.jar

install-antlr:
curl -k http://www.antlr.org/download/antlrworks-1.1.7.jar > antlrworks-1.1.7.jar
Expand All @@ -27,17 +30,17 @@ install-fop:
mv fop-0.94 fop
make clean-temps

install-msv:
curl -k https://msv.dev.java.net/files/documents/61/85936/msv.20080213.zip > msv.zip
unzip msv.zip
mkdir -p msv
mv msv-20080213/*.jar msv
make clean-temps
install-generateDS:
svn co http://codespeak.net/svn/lxml/trunk lxml
python setup.py build --static-deps
curl -k http://www.rexx.com/~dkuhlman/generateDS-1.17b.tar.gz > generateDS-1.17b.tar.gz
tar xzvf generateDS-1.17b.tar.gz
easy_install lxml
cd generateDS-1.17b ; python setup.py build
cd generateDS-1.17b ; python setup.py install

clean-temps:
rm -f fop.tar
rm -f msv.zip
rm -rf msv-*
rm -rf fop.tar msv.zip generateDS-1.17b.tar* msv-*
rm -fr elementtree-1.2.7-20070827-preview
rm -rf pyparsing-1.5.0

Expand Down
2 changes: 1 addition & 1 deletion shared/python/xldfCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def xldf_transform_grammar(localpath,cmd,tree):
ET.ElementTree(root).write('xldf-tmp.xbgf')
found = findnode(tree,cmd.findtext('target'))
if not found:
print '[----] xldf:transform failed: target id',cmd.findtext('where'),'not found'
print '[----] xldf:transform failed: target id',cmd.findtext('target'),'not found'
return
realprods = []
contextprods = []
Expand Down
3 changes: 3 additions & 0 deletions shared/python/xsd2ldf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def mapXSD2LDF(stree,dtree,grammar):
gotit.append(prod)
# Need to decide whether to put productions inside description subsections
#section.append(grammar[nt.attrib['name']])
if nt.attrib['name'] not in grammar.keys():
print '[----] The definition of',nt.attrib['name'],'not found in the grammar!'
return
for prod in grammar[nt.attrib['name']]:
if prod not in gotit:
el.append(prod)
Expand Down
21 changes: 18 additions & 3 deletions shared/xsd/ldf.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
targetNamespace="http://planet-sl.org/ldf">

<xsd:import namespace="http://planet-sl.org/bgf" schemaLocation="bgf.xsd"/>
<xsd:import namespace="http://www.w3.org/1998/Math/MathML" schemaLocation="fakemathml.xsd"/>

<!-- info -->
<xsd:annotation>
Expand Down Expand Up @@ -126,7 +127,7 @@
According to W3C Process Document, each viable specification goes through the stages
of Working Draft (WD), Candidate Recommendation (CR), Proposed Recommendation (PR),
W3C Recommendation (REC), with possible continuation to Proposed Edited Recommendation
and decline to Rescinded Recommendation. There has also been a ``Note'' status in the past
and decline to Rescinded Recommendation. There has also been a ``Note'fma' status in the past
for internal drafts.
</xsd:documentation>
<xsd:documentation>
Expand Down Expand Up @@ -337,11 +338,17 @@
<xsd:element name="figure" type="ldf:simpleFigure"/>
<xsd:element name="table" type="ldf:simpleTable"/>
<xsd:element name="list" type="ldf:simpleList"/>
<xsd:element name="formula" type="xsd:string"/>
<xsd:element name="formula">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:any namespace="http://www.w3.org/1998/Math/MathML"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="sample" type="xsd:string"/>
<xsd:element ref="bgf:production"/>
<!-- later redo with MathML -->
<!--<xsd:element ref="mml:math"/>-->
<!--<xsd:element ref="mml:math" />-->
</xsd:choice>
</xsd:group>

Expand Down Expand Up @@ -828,6 +835,14 @@
<!--<xsd:anyAttribute namespace="##other" processContents="lax"/>-->
</xsd:complexType>

<xsd:element name="formula">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:any namespace="http://www.w3.org/1998/Math/MathML"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="keyword" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Expand Down
191 changes: 191 additions & 0 deletions shared/xsl/bgf2xhtml.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<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="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:template match="/bgf:grammar">
<xsl:apply-templates select="./bgf:*"/>
</xsl:template>

<xsl:template match="bgf:production">
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="name">
<xsl:text>production-</xsl:text>
<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:text>production-</xsl:text>
<xsl:value-of select="./nonterminal"/>
<xsl:text>-label-</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:if>
<span xmlns="http://www.w3.org/1999/xhtml" class="nt">
<xsl:value-of select="./nonterminal"/>
</span>
<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:call-template name="no-parenthesis">
<xsl:with-param name="expr" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>
</xsl:text>
<xsl:call-template name="no-parenthesis">
<xsl:with-param name="expr" select="./bgf:expression"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

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

<xsl:template match="marked">
<span xmlns="http://www.w3.org/1999/xhtml" class="marked">
<xsl:text><![CDATA[<]]></xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text><![CDATA[>]]></xsl:text>
</span>
</xsl:template>

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

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

<xsl:template match="optional">
<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>STR</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>INT</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="epsilon">
<xsl:text>&#x03B5;</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:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">
<xsl:text>#production-</xsl:text>
<xsl:value-of select="."/>
</xsl:attribute>
<span class="nt">
<xsl:value-of select="."/>
</span>
</xsl:element>
</xsl:template>

<xsl:template match="selectable">
<span xmlns="http://www.w3.org/1999/xhtml" class="selector">
<xsl:value-of select="selector"/>
</span>
<xsl:text>::</xsl:text>
<xsl:choose>
<xsl:when test="local-name(bgf:expression/*) = 'star'
or local-name(bgf:expression/*) = 'optional'
or local-name(bgf:expression/*) = 'plus'">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="bgf:expression"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="bgf:expression"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="sequence">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="./bgf:expression[1]/*"/>
<xsl:for-each select="./bgf:expression[position()>1]">
<xsl:text> </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>

<!-- inner choices - BNF bar -->
<xsl:template match="choice">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="./bgf:expression[1]/*"/>
<xsl:for-each select="./bgf:expression[position()>1]">
<xsl:text> | </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>

<xsl:template name="no-parenthesis">
<xsl:param name="expr"/>
<xsl:choose>
<xsl:when test="$expr/sequence">
<xsl:apply-templates select="$expr/sequence/bgf:expression[1]/*"/>
<xsl:for-each select="$expr/sequence/bgf:expression[position()>1]">
<xsl:text> </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$expr"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
13 changes: 11 additions & 2 deletions shared/xsl/ldf2tex.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:ldf="http://planet-sl.org/ldf"
xmlns:ldx="http://planet-sl.org/ldx"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xhtml="http://www.w3.org/1999/xhtml">

<xsl:import href="bgf2bnf.xslt" />
<xsl:import href="mathml2tex.xslt" />

<xsl:output
method="text"
Expand Down Expand Up @@ -201,7 +203,8 @@
<xsl:if test="local-name($text) != 'cell'">
<xsl:text>$</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
<xsl:apply-templates select="mml:math/*"/>
<!--<xsl:value-of select="."/>-->
<xsl:text>$</xsl:text>
<xsl:if test="local-name($text) != 'cell'">
<xsl:text>$</xsl:text>
Expand Down Expand Up @@ -417,6 +420,12 @@
</xsl:text>
</xsl:template>

<xsl:template match="code">
<xsl:text>\texttt{</xsl:text>
<xsl:value-of select="."/>
<xsl:text>}</xsl:text>
</xsl:template>

<!--
\begin{figure}[t!]
\begin{center}
Expand Down Expand Up @@ -445,7 +454,7 @@
<xsl:value-of select="caption"/>
<xsl:text>}</xsl:text>
<xsl:if test="@id">
<xsl:text>\caption{</xsl:text>
<xsl:text>\label{</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>}</xsl:text>
</xsl:if>
Expand Down
Loading

0 comments on commit f19ca1b

Please sign in to comment.