def parse(self, fname): self.steps = [] self.xml = ET.parse(fname) for e in self.xml.findall(slpsns.cbgf_('*')): s = Step() s.parse(e) self.steps.append(s)
def parse(self,fname): self.steps = [] self.xml = ET.parse(fname) for e in self.xml.findall(slpsns.cbgf_('*')): s = Step() s.parse(e) self.steps.append(s)
return '"'+x+'"' def grammarNameOf(x): if x.find('/') < 0: return x.split('.')[0] else: return x.split('/')[-1].split('.')[0] if __name__ == "__main__": if len(sys.argv) != 6: print('Usage:') print(' xedd.py input.xedd input.edd output.edd coupled-grammar.cbgf coupled-grammarbase.cbgf') sys.exit(-1) slpsns.init(ET) readConfig(sys.argv[2]) cbgf = ET.Element(slpsns.cbgf_('relationship')) cbgfr = ET.Element(slpsns.cbgf_('relationship')) # renaming ALWAYS happens if the name of the notation is changed # if we do not call two different entities two different names, we cannot tell them apart edd1 = grammarNameOf(sys.argv[2]) edd2 = grammarNameOf(sys.argv[3]) for s in ('Grammar', 'Production', 'Definition', 'Symbol','Nonterminal','Terminal'): r = ET.SubElement(cbgf,slpsns.cbgf_('rename-rename')) n = ET.SubElement(r,'nonterminal') ET.SubElement(n,'from').text = edd1 + s ET.SubElement(n,'to').text = edd2 + s # processing commands for cmd in ET.parse(sys.argv[1]).findall('*'): if cmd.tag == slpsns.xedd_('rename'): ms = cmd.findtext('metasymbol') x = cmd.findtext('from')
def getXml(self): #print 'Getting the XML of production...' self.ex = ET.Element(slpsns.cbgf_(self.name)) for p in self.params: self.ex.append(p.getXml()) return self.ex
def getXml(self): self.ex = ET.Element(slpsns.cbgf_('relationship')) for e in self.steps: self.ex.append(e.getXml()) return self.ex