Пример #1
0
def main(bgffile,xbgffile):
	seq = ET.Element(slpsns.xbgf_('sequence'))
	rr = ET.SubElement(seq,slpsns.xbgf_('reroot'))
	for r in ET.XML('<list>'+''.join(open(bgffile,'r').readlines()).strip()+'</list>').findall('*'):
		x = ET.SubElement(rr,'root')
		x.text = r.text
	ET.ElementTree(seq).write(xbgffile)
	return
Пример #2
0
def sliceFile(xbgfDir1,xbgfDir2,text):
 sliced = []
 xtree = ET.parse(xbgfDir1+text+'.xbgf')
 cx = 0
 for t in xtree.findall('*'):
  cx += 1
  seq = ET.Element(slpsns.xbgf_('sequence'))
  if t.tag==slpsns.xbgf_('atomic'):
   for sub in t.findall('*'):
    seq.append(sub)
  else:
   seq.append(t)
  ET.ElementTree(seq).write(xbgfDir2+text+'-'+`cx`+'.xbgf')
  sliced.append(text+'-'+`cx`)
 return sliced
Пример #3
0
 def parse(self, fname):
     self.steps = []
     self.xml = ET.parse(fname)
     for e in self.xml.findall(slpsns.xbgf_('*')):
         s = Step()
         s.parse(e)
         self.steps.append(s)
Пример #4
0
	def parse(self,fname):
		self.steps = []
		self.xml = ET.parse(fname)
		for e in self.xml.findall(slpsns.xbgf_('*')):
			s = Step()
			s.parse(e)
			self.steps.append(s)
Пример #5
0
def appendXbgf(tree,xbgfFile):
 if not tree:
  tree = ET.Element(slpsns.xbgf_('sequence'))
 xtree = ET.parse(xbgfFile)
 for t in xtree.findall('*'):
  tree.append(t)
 return tree
Пример #6
0
def noPartiallySafe(xbgf):
 return len(xbgf.findall('//'+slpsns.xbgf_('strip/selector')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('strip/allSelectors')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('strip/label')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('strip/allLabels')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('rename/nonterminal')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('rename/selector')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('rename/label')))
Пример #7
0
def xldf_transformGrammar(localpath,cmd,tree):
 root = ET.Element(slpsns.xbgf_('sequence'),{})
 cx0 = 0
 for rule in cmd.findall('*')[1:]:
  if rule.tag != 'context':
   root.append(rule)
   cx0 += 1
 ET.ElementTree(root).write('xldf-tmp.xbgf')
 found = findnode(tree,cmd.findtext('target'))
 if not found:
  print '[----] xldf:transform failed: target id',cmd.findtext('target'),'not found'
  return
 realprods = []
 contextprods = []
 for p in found.findall('*/*/'+slpsns.bgf_('production')):
  realprods.append(p)
 for p in found.findall('*/'+slpsns.bgf_('production')):
  realprods.append(p)
 for c in cmd.findall('context'):
  f = findnode(tree,c.text)
  if not f:
   print '[----] xldf:transform failed: context target id',c.text,'not found'
   return
  for p in f.findall('*/*/'+slpsns.bgf_('production')):
   contextprods.append(p)
 root = ET.Element(slpsns.bgf_('grammar'),{})
 for p in realprods:
  root.append(p)
 for p in contextprods:
  root.append(p)
 #print '[====]',len(realprods),'+',len(contextprods),'productions'
 ET.ElementTree(root).write('xldf-tmp.bgf')
 if os.system('xbgf xldf-tmp.xbgf xldf-tmp.bgf xldf-tmp-result.bgf | grep -v Loading | grep -v Saving'):
  print '[----] xldf:transform failed: error in XBGF'
  return
 try:
  gtree = ET.parse('xldf-tmp-result.bgf')
 except IOError,e:
  print '[----] xldf:transform failed: XBGF result file not found'
  sys.exit(3)
  return
Пример #8
0
def notr(xbgf):
 return len(xbgf.findall('/*')) - \
        len(xbgf.findall('/'+slpsns.xbgf_('atomic'))) + \
        len(xbgf.findall('/'+slpsns.xbgf_('atomic')+'/*'))
Пример #9
0
	def getXml(self):
		#print 'Getting the XML of production...'
		self.ex = ET.Element(slpsns.xbgf_(self.name))
		self.ex.text = self.data
		return self.ex
Пример #10
0
	def getXml(self):
		#print 'Getting the XML of production...'
		self.ex = ET.Element(slpsns.xbgf_(self.name))
		for p in self.params:
			self.ex.append(p.getXml())
		return self.ex
Пример #11
0
	def getXml(self):
		self.ex = ET.Element(slpsns.xbgf_('sequence'))
		for e in self.steps:
			self.ex.append(e.getXml())
		return self.ex
Пример #12
0
def noPartiallyUnsafe(xbgf):
 return len(xbgf.findall('//'+slpsns.xbgf_('strip/terminal')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('strip/allTerminals')))+\
        len(xbgf.findall('//'+slpsns.xbgf_('rename/terminal')))
Пример #13
0
 def getXml(self):
     self.ex = ET.Element(slpsns.xbgf_('sequence'))
     for e in self.steps:
         self.ex.append(e.getXml())
     return self.ex
Пример #14
0
  for y in x:
   results[y] = {}
   for z in targets.keys():
    results[y][z] = 0
 for x in targets.keys():
  results['LOC'][x] = 0
  results['NOI'][x] = 0
  results['NOX'][x] = 0
  for y in targets[x]:
   results['LOC'][x] += slpsXPath.loc(path+y+'.xbgf')
   results['NOI'][x] += slpsXPath.noi(path+y+'.xbgf')
   xbgf = ET.parse(path+y+'.xbgf')
   results['NOX'][x] += len(xbgf.findall('/*'))
   for z in names:
    for q in z:
     results[q][x] += len(xbgf.findall(q.replace('xbgf:',slpsns.xbgf_(''))))
 for x in names:
  for y in x:
   used = False
   for z in targets.keys():
    if results[y][z]:
     used = True
   if not used:
    print '%%',y,'not used in any XBGF script'
 sorted = targets.keys()[:]
 sorted.sort()
 print '\\begin{tabular}{l|'+('c|'*len(targets))+'|c}'
 for x in sorted:
  print '&\\textbf{'+x+'}',
 print '&\\textbf{Total}\\\\\\hline'
 for x in names:
Пример #15
0
 def getXml(self):
     #print 'Getting the XML of production...'
     self.ex = ET.Element(slpsns.xbgf_(self.name))
     for p in self.params:
         self.ex.append(p.getXml())
     return self.ex
Пример #16
0
   results['NI^'][x] += slpsXPath.nosi(xbgfFile,'PERMISSIVENESS')
   results['COR'][x] += slpsXPath.nosi(xbgfFile,'EXTRACTERROR')
   results['SGO'][x] += slpsXPath.countSemanticPreserving(xbgf,xbgfFile)
   results['SID'][x] += slpsXPath.countSemanticIncDec(xbgf,xbgfFile)
   results['SRE'][x] += slpsXPath.countSemanticRevising(xbgf,xbgfFile)
   results['NOX'][x] += slpsXPath.notr(xbgf)
   results['EKB'][x] += slpsXPath.nosi(xbgfFile,'KNOWNBUG')
   results['EPX'][x] += slpsXPath.nosi(xbgfFile,'POSTEXTR')
   results['EIC'][x] += slpsXPath.nosi(xbgfFile,'INITCORR')
   results['EAR'][x] += slpsXPath.nosi(xbgfFile,'KNOWNBUG')+slpsXPath.nosi(xbgfFile,'POSTEXTR')+slpsXPath.nosi(xbgfFile,'INITCORR')
   results['FEX'][x] += slpsXPath.nosi(xbgfFile,'EXTENSION')
   results['FRE'][x] += slpsXPath.nosi(xbgfFile,'RELAXATION')
   results['FCO'][x] += slpsXPath.nosi(xbgfFile,'CORRECTION')
   results['FIN'][x] += slpsXPath.nosi(xbgfFile,'EXTENSION')+slpsXPath.nosi(xbgfFile,'RELAXATION')+slpsXPath.nosi(xbgfFile,'CORRECTION')
   for z in names:
    results[z][x] += len(xbgf.findall('/'+slpsns.xbgf_(z)))
 for x in names[:]:
  used = False
  for y in targets.keys():
   if results[x][y]:
    used = True
  if not used:
   names.remove(x)
 sorted = targets.keys()[:]
 sorted.sort()
 if sorted == ['read12','read123','jls1','jls12','jls123','jls2','jls3']:
  sorted = ['jls1','jls2','jls3','jls12','jls123','read12','read123']
 elif sorted == ['abstract','concrete','java','limit','model','topdown']:
  sorted = ['topdown','concrete','model','java','abstract','limit']
 print '\\begin{tabular}{l|'+('c|'*len(targets))+'|c}'
 for x in sorted:
Пример #17
0
 def getXml(self):
     #print 'Getting the XML of production...'
     self.ex = ET.Element(slpsns.xbgf_(self.name))
     self.ex.text = self.data
     return self.ex
Пример #18
0
         results[y] = {}
         for z in targets.keys():
             results[y][z] = 0
 for x in targets.keys():
     results['LOC'][x] = 0
     results['NOI'][x] = 0
     results['NOX'][x] = 0
     for y in targets[x]:
         results['LOC'][x] += slpsXPath.loc(path + y + '.xbgf')
         results['NOI'][x] += slpsXPath.noi(path + y + '.xbgf')
         xbgf = ET.parse(path + y + '.xbgf')
         results['NOX'][x] += len(xbgf.findall('/*'))
         for z in names:
             for q in z:
                 results[q][x] += len(
                     xbgf.findall(q.replace('xbgf:', slpsns.xbgf_(''))))
 for x in names:
     for y in x:
         used = False
         for z in targets.keys():
             if results[y][z]:
                 used = True
         if not used:
             print '%%', y, 'not used in any XBGF script'
 sorted = targets.keys()[:]
 sorted.sort()
 print '\\begin{tabular}{l|' + ('c|' * len(targets)) + '|c}'
 for x in sorted:
     print '&\\textbf{' + x + '}',
 print '&\\textbf{Total}\\\\\\hline'
 for x in names:
Пример #19
0
def noni(xbgf,arrayxbgf):
 cx = 0
 for c in arrayxbgf:
  cx += len(xbgf.findall('//'+slpsns.xbgf_(c)))# + len(xbgf.findall('//'+slpsns.xbgf_('atomic')+'/'+slpsns.xbgf_(c)))
 return cx