Skip to content

Commit

Permalink
rsc2bgf delivers root(s); some tool progress; XEDD has become so good…
Browse files Browse the repository at this point in the history
… that I'm slowly releasing it

git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1136 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Dec 4, 2011
1 parent 1196f9f commit efbd9cc
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 13 deletions.
50 changes: 50 additions & 0 deletions shared/python/BGF3.py
Expand Up @@ -383,3 +383,53 @@ def getXml(self):
return self.ex
def __str__(self):
return str(self.data)+'+'

# sepliststar
class SepListStar:
def __init__(self):
self.item = None
self.sep = None
def parse(self,slelem):
exprs = slelem.findall(slpsns.bgf_('expression'))
self.item = Expression(None)
self.item.parse(exprs[0])
self.sep = Expression(None)
self.sep.parse(exprs[1])
def setItem(self,name):
self.item = name
def setSep(self,expr):
self.sep = expr
def getXml(self):
#print 'Getting the XML of selectable',self.sel,'...'
self.ex = ET.Element(slpsns.bgf_('expression'))
self.xml = ET.SubElement(self.ex,'sepliststar')
self.xml.append(self.item.getXml())
self.xml.append(self.sep.getXml())
return self.ex
def __str__(self):
return '{'+str(self.item)+' '+str(self.sep)+'}*'

# seplistplus
class SepListPlus:
def __init__(self):
self.item = None
self.sep = None
def parse(self,slelem):
exprs = slelem.findall(slpsns.bgf_('expression'))
self.item = Expression(None)
self.item.parse(exprs[0])
self.sep = Expression(None)
self.sep.parse(exprs[1])
def setItem(self,name):
self.item = name
def setSep(self,expr):
self.sep = expr
def getXml(self):
#print 'Getting the XML of selectable',self.sel,'...'
self.ex = ET.Element(slpsns.bgf_('expression'))
self.xml = ET.SubElement(self.ex,'seplistplus')
self.xml.append(self.item.getXml())
self.xml.append(self.sep.getXml())
return self.ex
def __str__(self):
return '{'+str(self.item)+' '+str(self.sep)+'}+'
36 changes: 24 additions & 12 deletions shared/python/slpsns.py
@@ -1,21 +1,27 @@
#!/usr/bin/python

lcfns = 'http://planet-sl.org/lcf'
ldfns = 'http://planet-sl.org/ldf'
lcfns = 'http://planet-sl.org/lcf'
ldfns = 'http://planet-sl.org/ldf'
xldfns = 'http://planet-sl.org/xldf'
bgfns = 'http://planet-sl.org/bgf'
xbgfns= 'http://planet-sl.org/xbgf'
xsdns = 'http://www.w3.org/2001/XMLSchema'
htmlns= 'http://www.w3.org/1999/xhtml'
bgfns = 'http://planet-sl.org/bgf'
xbgfns = 'http://planet-sl.org/xbgf'
cbgfns = 'http://planet-sl.org/cbgf'
eddns = 'http://planet-sl.org/edd'
xeddns = 'http://planet-sl.org/xedd'
xsdns = 'http://www.w3.org/2001/XMLSchema'
htmlns = 'http://www.w3.org/1999/xhtml'

def init(ET):
ET._namespace_map[lcfns] = 'lcf'
ET._namespace_map[ldfns] = 'ldf'
ET._namespace_map[lcfns] = 'lcf'
ET._namespace_map[ldfns] = 'ldf'
ET._namespace_map[xldfns] = 'xldf'
ET._namespace_map[bgfns] = 'bgf'
ET._namespace_map[xbgfns]='xbgf'
ET._namespace_map[xsdns] = 'xsd'
ET._namespace_map[htmlns]='html'
ET._namespace_map[bgfns] = 'bgf'
ET._namespace_map[xbgfns] = 'xbgf'
ET._namespace_map[cbgfns] = 'cbgf'
ET._namespace_map[eddns] = 'edd'
ET._namespace_map[xeddns] = 'xedd'
ET._namespace_map[xsdns] = 'xsd'
ET._namespace_map[htmlns] = 'html'

def lcf_(x):
return '{'+lcfns+'}'+x
Expand All @@ -27,7 +33,13 @@ def bgf_(x):
return '{'+bgfns+'}'+x
def xbgf_(x):
return '{'+xbgfns+'}'+x
def cbgf_(x):
return '{'+cbgfns+'}'+x
def xsd_(x):
return '{'+xsdns+'}'+x
def edd_(x):
return '{'+eddns+'}'+x
def xedd_(x):
return '{'+xeddns+'}'+x
def htm_(x):
return '{'+htmlns+'}'+x
46 changes: 46 additions & 0 deletions shared/xsd/xedd.xsd
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:edd="http://planet-sl.org/edd" xmlns:xedd="http://planet-sl.org/xedd" targetNamespace="http://planet-sl.org/xedd">
<xsd:annotation>
<xsd:documentation>
EBNF Dialect Definition Transformation operator suite
(Notation Specification Transformation)
</xsd:documentation>
</xsd:annotation>
<!--
TODO: edd.xsd is legacy for now; needs major update, and I mean MAJOR
<xsd:import namespace="http://planet-sl.org/edd" schemaLocation="edd.xsd"/>
-->
<xsd:element name="evolution">
<xsd:annotation>
<xsd:documentation>
Sequential composition of multiple transformations.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:group ref="xedd:step" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:group name="step">
<xsd:choice>
<xsd:element ref="xedd:rename"/>
</xsd:choice>
</xsd:group>
<xsd:element name="rename">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="metasymbol" type="xedd:metasymbols"/>
<xsd:element name="from" type="xsd:string"/>
<xsd:element name="to" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="metasymbols">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="terminator"/>
<xsd:enumeration value="defining"/>
<xsd:enumeration value="definition-separator"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
10 changes: 10 additions & 0 deletions topics/comparison/ndd.py
Expand Up @@ -109,6 +109,16 @@ def isEqualE(e1,e2):
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Star'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Star'>":
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Plus'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Plus'>":
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Nonterminal'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Nonterminal'>":
#print("--isEqualE--> NO (type mismatch)")
Expand Down
10 changes: 10 additions & 0 deletions topics/comparison/nid.py
Expand Up @@ -116,6 +116,16 @@ def isEqualE(e1,e2):
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Star'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Star'>":
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Plus'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Plus'>":
#print("--isEqualE--> NO (type mismatch)")
return False
return isEqualE(e1.wrapped.data,e2.wrapped.data)
if str(e1.wrapped.__class__) == "<class 'BGF3.Nonterminal'>":
if str(e2.wrapped.__class__) != "<class 'BGF3.Nonterminal'>":
#print("--isEqualE--> NO (type mismatch)")
Expand Down
4 changes: 3 additions & 1 deletion topics/extraction/rascal/extract.py
Expand Up @@ -88,7 +88,8 @@ def parseGroup(g):
# do something with imports?
continue
if tokens[0] == 'start':
start.append(tokens[-1])
print 'Assumed',tokens[2],'to be a root.'
start.append(tokens[2])
tokens = tokens[1:]
# fall through
if tokens[0] in ('syntax','layout','lexical'):
Expand Down Expand Up @@ -156,6 +157,7 @@ def parseGroup(g):
#for s in grammar['Command']:
# print ' ',s
bgf = BGF.Grammar()
bgf.roots = start
prevline = []
curly = 0
# going through the sorted list of nonterminals
Expand Down
55 changes: 55 additions & 0 deletions topics/transformation/xedd/Makefile
@@ -0,0 +1,55 @@
all:

try:
../../recovery/hunter/hunter.py lll1t.doc.lll1t lll1t.edd lll1n.doc.bgf
../../../shared/tools/cbgf2xbgf lll1.spec2doc.cbgf /dev/null lll1.reverse.xbgf
../../../shared/tools/xbgf lll1.reverse.xbgf lll1n.doc.bgf lll1n.spec.bgf
#../../../shared/tools/cbgf lll1t.coupled.cbgf
gdt lll1.spec.bgf lll1t.spec.bgf

specprop:
# This scenario propagates changes from the notation to its parser, to its grammar, to its beautified grammar and to its definition "in itself"
./xedd.py lll1.try.xedd lll1.edd lll1t.edd lll1t.coupled.cbgf
# need to learn to run Rascal from command line
cp backup/lll1t.rsc .
../../../shared/tools/rsc2bgf lll1t.rsc lll1t.raw.bgf
../../../shared/tools/normbgf lll1t.raw.bgf lll1t.spec.bgf
../../../shared/tools/cbgf lll1t.coupled.cbgf lll1.spec.bgf lll1t.spec.bgf
../../../shared/tools/cbgf2xbgf lll1.spec2doc.cbgf lll1.forward.xbgf /dev/null
../../../shared/tools/xbgf lll1.forward.xbgf lll1t.spec.bgf lll1t.doc.bgf
../../../shared/tools/reformat lll1t.doc.bgf lll1t.edd lll1t.doc.lll1t

edd:
cp ../../../shared/edd/lll1.edd lll1.edd
cp ../../../shared/edd/lll2.edd lll2.edd

rsc: edd
# need to learn to run Rascal from command line
cp ../../../../personal/work/gnf/src/bgf2rsc/GeneratedLLL.rsc .
cp backup/lll?.rsc .

bgfspec: rsc
../../../shared/tools/rsc2bgf lll1.rsc lll1.raw.bgf
../../../shared/tools/normbgf lll1.raw.bgf lll1.spec.bgf
../../../shared/tools/rsc2bgf lll2.rsc lll2.raw.bgf
../../../shared/tools/normbgf lll2.raw.bgf lll2.spec.bgf

bgfdoc:
cp ../../grammars/metasyntax/lll-ldta/grammar.bgf lll1.doc.bgf
../../../shared/tools/reformat lll1.doc.bgf lll1.edd lll1.doc.lll1
cp ../../grammars/metasyntax/lll-kort/grammar.bgf lll2.doc.bgf
../../../shared/tools/reformat lll2.doc.bgf lll2.edd lll2.doc.lll2

bgfspecndoc: bgfspec bgfdoc
../../../shared/tools/cbgf lll1.spec2doc.cbgf lll1.spec.bgf lll1.doc.bgf

get:
cp ../../grammars/metasyntax/lll-kort/src.manually.fixed.txt lll-gdkref.lll
cp ../../grammars/metasyntax/lll-ldta/src.ldta.2002.txt lll-ldta.lll
cd ../../grammars/metasyntax/lll1-edd && make extract
cd ../../grammars/metasyntax/lll2-edd && make extract
../../../shared/tools/reformat ../../grammars/metasyntax/lll1-edd/grammar.bgf lll1.edd lll1.lll
../../../shared/tools/reformat ../../grammars/metasyntax/lll2-edd/grammar.bgf lll2.edd lll2.lll

clean:
rm -f lll?.edd GeneratedLLL.rsc lll?.rsc lll?.raw.bgf lll?.spec.bgf lll?.doc.bgf *.xbgf *.lll?? *.res

0 comments on commit efbd9cc

Please sign in to comment.