if __name__ == "__main__": if len(sys.argv) != 5: print('This mutation enforces the naming convention in a given BGF grammar.') print('Usage:\n '+sys.argv[0]+' <from> <to> <bgf-input> <xbgf-output>') print(' where <from> and <to> can be any of the following:') print(' U = upper case - = dash-separated') print(' l = lower case _ = underscore-separated') print(' m = mixed case . = dot-separated') print(' C = camel case s = space-separated') print(' ! = nonseparated') sys.exit(1) nc1 = sys.argv[1] nc2 = sys.argv[2] bgf = BGF3.Grammar() xbgf = XBGF3.Sequence() bgf.parse(sys.argv[3]) for nt in metrics3.var(bgf): if not check(nc1[0],nt): print(nt,'does not satisfy convention',sys.argv[1]) else: print(nt,'-->',convert(nc1,nc2,nt)) s = XBGF3.Step('rename') n = XBGF3.Wrapping('nonterminal') n.addChild(XBGF3.Leaf('from',nt)) n.addChild(XBGF3.Leaf('to',convert(nc1,nc2,nt))) s.addParam(n) xbgf.addStep(s) ET.ElementTree(xbgf.getXml()).write(sys.argv[4]) sys.exit(0)
# -*- coding: utf-8 -*- import os, sys sys.path.append(os.getcwd().split('slps')[0] + 'slps/shared/python') import BGF3 import metrics3 if __name__ == "__main__": if len(sys.argv) != 3: print( 'This generator proposes to remove all chain productions and inline all once-used nonterminal symbols.' ) print('Usage:') print(' ' + sys.argv[0] + ' <bgf-input> <xbgf-output>') sys.exit(1) bgf = BGF3.Grammar() bgf.parse(sys.argv[1]) xbgf = open(sys.argv[2], 'w') xbgf.write( '<?xml version="1.0" encoding="UTF-8"?><xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:bgf="http://planet-sl.org/bgf">\n' ) inline = [] nts = metrics3.var(bgf) for n in nts: ps = bgf.getProdsOfN(n) if len(ps) == 1 and ps[0].expr.wrapped.who() == 'Nonterminal': print('Nonterminal', n, 'is advised to be inlined.') xbgf.write('<xbgf:inline>' + n + '</xbgf:inline>\n') xbgf.write('</xbgf:sequence>') xbgf.close() sys.exit(0)
print( 'This mutation enforces the naming convention in a given BGF grammar.' ) print('Usage:\n ' + sys.argv[0] + ' <from> <to> <bgf-input> <xbgf-output>') print(' where <from> and <to> can be any of the following:') print(' U = upper case - = dash-separated') print(' l = lower case _ = underscore-separated') print(' m = mixed case . = dot-separated') print(' C = camel case s = space-separated') print(' ! = nonseparated') sys.exit(1) nc1 = sys.argv[1] nc2 = sys.argv[2] bgf = BGF3.Grammar() xbgf = XBGF3.Sequence() bgf.parse(sys.argv[3]) for nt in metrics3.var(bgf): if not check(nc1[0], nt): print(nt, 'does not satisfy convention', sys.argv[1]) else: print(nt, '-->', convert(nc1, nc2, nt)) s = XBGF3.Step('rename') n = XBGF3.Wrapping('nonterminal') n.addChild(XBGF3.Leaf('from', nt)) n.addChild(XBGF3.Leaf('to', convert(nc1, nc2, nt))) s.addParam(n) xbgf.addStep(s) ET.ElementTree(xbgf.getXml()).write(sys.argv[4]) sys.exit(0)
#!/Library/Frameworks/Python.framework/Versions/3.1/bin/python3 # -*- coding: utf-8 -*- import os,sys sys.path.append(os.getcwd().split('slps')[0]+'slps/shared/python') import BGF3 import metrics3 if __name__ == "__main__": if len(sys.argv) != 3: print('This generator proposes to remove all chain productions and inline all once-used nonterminal symbols.') print('Usage:') print(' '+sys.argv[0]+' <bgf-input> <xbgf-output>') sys.exit(1) bgf = BGF3.Grammar() bgf.parse(sys.argv[1]) xbgf = open(sys.argv[2],'w') xbgf.write('<?xml version="1.0" encoding="UTF-8"?><xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:bgf="http://planet-sl.org/bgf">\n') inline = [] nts = metrics3.var(bgf) for n in nts: ps = bgf.getProdsOfN(n) if len(ps) == 1 and ps[0].expr.wrapped.who() == 'Nonterminal': print('Nonterminal',n,'is advised to be inlined.') xbgf.write('<xbgf:inline>'+n+'</xbgf:inline>\n') xbgf.write('</xbgf:sequence>') xbgf.close() sys.exit(0)