From c5d8aafa4311825e5499a0bbb2b5864ff86a23c8 Mon Sep 17 00:00:00 2001 From: grammarware Date: Wed, 6 Aug 2008 14:24:22 +0000 Subject: [PATCH] LCI 1.6: * renamings all over the place * is gone, defined implicitly by s * detailed s ditched in favour of external wrappers * new tool for transformation * schema massaging * probably bugfixes git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@142 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- shared/xsd/lcf.xsd | 136 +++++++++++++--------------------- topics/convergence/lci/lci.py | 129 +++++++++++--------------------- topics/fl/lci/fl.lcf | 104 +++++++++----------------- 3 files changed, 131 insertions(+), 238 deletions(-) diff --git a/shared/xsd/lcf.xsd b/shared/xsd/lcf.xsd index 6fb90d8a..1e8398d9 100644 --- a/shared/xsd/lcf.xsd +++ b/shared/xsd/lcf.xsd @@ -22,101 +22,48 @@ - - - - - - An action in LCF is a transformation step. - Usually an action is defined as a reference to an XBGF file with a sequence of atomic grammar transformations - grouped by one theme. - Actions are combined in chains to get from sources and intermediate targets to one final target. - - - - - - - - - - - - - - - - An shortcut in LCF is just a simple macro. + A shortcut in LCF is just a simple macro. If binds a longer definition to a concise name. For example, a path with long directory names that is used multiple times in the LCF document is a good shortcut. - Shortcuts can be defined on basis of other shortcuts defined before them in the LCF file. - + - + + + Shortcuts can be defined on basis of other shortcuts defined before them in the LCF file. + + + + + - - - - An expand in LCF is a way to use macros. - The volatile expand references a user-defined shortcut. - The expand-action is substituted with a name of an action inside which it is used. - The expand-input is substituted with a name of the file that is the main input for the parser/evaluator. - The expand-output is substituted with a name of the file that is produced by the parser/evaluator. - The expand-context is substituted with a name of the file that contains a context for the evaluator. - The expand-yields is substituted with a value that the evaluator is expected to return. - - For more information on sample-related matters, consult LDF schema. - - - - - - - - - - - - - - - - - - - - - - A command in LCF is something that is possible to run with a given shell. - If one needs to redirect the output stream (stdout), use the @out attribute. - If one needs to redirect the error stream (stderr), use the @err attribute. + An expand in LCF is a way to use shortcuts. - - - + + + @@ -130,12 +77,14 @@ - + - + + + @@ -143,7 +92,9 @@ - + + + @@ -152,14 +103,14 @@ - + - + @@ -175,8 +126,8 @@ A target in LCF is the convergence point. A target must have a name by which it is referenced and displayed on a diagram. A target can have any number of branches. - Each branch defines an input that can be either source name or a target name. - Each branch also references a sequence of actions that are performed on that source or target to reach this target. + Each branch defines an input that can be either source name or a target name. + Each branch also references a sequence of actions that are performed on that source or target to reach this target. Once all branches are made, a diff tool is run to make sure all results converge. If there is one branch, no diffing takes place. If there are three or more branches, diffs occur pairwise. @@ -188,7 +139,19 @@ - + + + + Perform element in LCF executes a transformation step. + A performed action must reside in an external XBGF file + that contains a sequence of atomic grammar transformations + grouped by one theme. + + Performing a chain of actions is a way to get from sources + and intermediate targets to one final target. + + + @@ -200,25 +163,26 @@ A tool in LCF is an external script. At this point there are three tools which output is needed by LCI: - The validator makes sure that the BGFs are valid against their schema. - This includes extracted BGFs as well as all derived BGFs. - If the validator is not defined, LCI works fine without it. - The diff tool takes two parameters and returns zero if both BGFs are deemed equal. - If the diff tool is not defined, LCI can only work with one-branch targets. - The testset generates a test set in LDF, presumably by taking it from a bigger LDF document. + The validator makes sure that the BGFs are valid against their schema. + This includes extracted BGFs as well as all derived BGFs. + If the validator is not defined, LCI works fine without it. + The diff tool takes two parameters and returns zero if both BGFs are deemed equal. + If the diff tool is not defined, LCI can only work with one-branch targets. + The testset generates a test set in LDF, presumably by taking it from a bigger LDF document. - + - + - - + + + - + \ No newline at end of file diff --git a/topics/convergence/lci/lci.py b/topics/convergence/lci/lci.py index 28bfe329..134939cc 100755 --- a/topics/convergence/lci/lci.py +++ b/topics/convergence/lci/lci.py @@ -7,7 +7,7 @@ shutup = ' 1> /dev/null 2> /dev/null' sections = {'SHORTCUTS':1,'ACTIONS':2,'SOURCES':3,'TARGETS':4,'IMPLEMENTATIONS':5} shortcuts = {} -actions = {} +actions = [] sources = {} targets = {} implementations = {} @@ -25,52 +25,30 @@ def sysexit(n): def readxmlconfig (cfg): config = ElementTree.parse(cfg) - cx1=cx2=cx3=cx4=cx5=cx6=0 # shortcuts for outline in config.findall('//shortcut'): - cx1+=1 shortcuts[outline.findtext('name')]=expandxml(outline.findall('definition')[0],{}) # actions - for outline in config.findall('//action'): - for name in outline.findall('name'): - cmds = [] - for cmd in outline.findall('definition/command'): - cmds.append(expandxml(cmd,{'action':name.text})) - if cmd.attrib.has_key('out'): - cmds[-1]+=' 1> '+cmd.attrib['out'] - if cmd.attrib.has_key('err'): - cmds[-1]+=' 2> '+cmd.attrib['err'] - actions[name.text]=cmds - cx2+=1 + for outline in config.findall('//target/branch/perform'): + if outline.text not in actions: + actions.append(outline.text) # sources for outline in config.findall('//source'): - args = [expandxml(outline.findall('extractor/name')[0],{})] - for arg in outline.findall('extractor/arguments/argument'): + args = [expandxml(outline.findall('extraction/name')[0],{})] + for arg in outline.findall('extraction/arguments/argument'): args.append(expandxml(arg,{})) sources[outline.findtext('name')]=args - cx3+=1 - pcmds = [] - ecmds = [] - for cmd in outline.findall('parser/command'): - pcmds.append(expandxml(cmd,{})) - if cmd.attrib.has_key('out'): - pcmds[-1]+=' 1> '+cmd.attrib['out'] - if cmd.attrib.has_key('err'): - pcmds[-1]+=' 2> '+cmd.attrib['err'] - for cmd in outline.findall('evaluator/command'): - ecmds.append(expandxml(cmd,{})) - if cmd.attrib.has_key('out'): - ecmds[-1]+=' 1> '+cmd.attrib['out'] - if cmd.attrib.has_key('err'): - ecmds[-1]+=' 2> '+cmd.attrib['err'] - if pcmds and ecmds: - implementations[outline.findtext('name')]=[pcmds,ecmds] - cx5+=1 + pcmd = ecmd = '' + if outline.findall('parsing/command'): + pcmd = expandxml(outline.findall('parsing/command')[0],{}) + if outline.findall('evaluation/command'): + ecmd = expandxml(outline.findall('evaluation/command')[0],{}) + if pcmd and ecmd: + implementations[outline.findtext('name')]=[pcmd,ecmd] # targets for outline in config.findall('//target'): name = outline.findtext('name') targets[name]= [[],''] - cx4+=1 for br in outline.findall('branch'): branch = [br.findtext('input')] for p in br.findall('perform'): @@ -78,7 +56,6 @@ def readxmlconfig (cfg): targets[name][0].append(branch) # tools for outline in config.findall('//tool'): - cx6+=1 cmd = outline.findall('command')[0] line = expandxml(cmd,{}) if cmd.attrib.has_key('out'): @@ -87,7 +64,8 @@ def readxmlconfig (cfg): line += ' 2> '+cmd.attrib['err'] tools[outline.findtext('name')]=line - print 'Read',cx1,'shortcuts,',cx6,'tools,',cx2,'actions,',cx3,'sources','('+`cx5`,'implemented),',cx4,'targets.' + print 'Read',len(shortcuts),'shortcuts,',len(tools),'tools,',len(actions),'actions,', + print len(sources),'sources','('+`len(implementations)`,'implemented),',len(targets),'targets.' def expandone(tag,text,rep): if text: @@ -202,7 +180,7 @@ def extractall(): def validateall(): for bgf in sources.keys(): - run = tools['validator']+' '+bgf+'.bgf' + run = tools['validation']+' '+bgf+'.bgf' logwrite(run) if os.system(run+shutup): print 'Validation failed on',bgf @@ -210,18 +188,6 @@ def validateall(): sysexit(3) print 'Validation successful.' -def runforall(cmd,prc): - for bgf in sources.keys(): - for line in actions[cmd]: - run = expanduni(line,{'input':bgf,'type':sources[bgf][0],'arguments':expanduni(sources[bgf][1],{})}) - logwrite(run) - ret = os.system(run+shutup) - if ret!=0: - print prc,'failed on',bgf - print 'Command was:',run - sysexit(3) - print prc,'successful.' - def preparebgf(cut): # executes preparational actions (abstract, unerase, etc) before comparison if len(cut)==1: @@ -237,23 +203,18 @@ def preparebgf(cut): # files x.bgf, x.corrupt.bgf, x.corrupt.confuse.bgf and x.corrupt.confuse.destroy.bgf # the very last one will be diffed for a in cut[1:]: - if a not in actions.keys(): - print 'Action',a,'needed for',curname,'not found.' - sysexit(5) - for linetorun in actions[a]: - run = expanduni(linetorun,{'input':curname}) - logwrite(run) - ret = os.system(run+shutup) - if ret!=0: - print a,'failed on',curname - print 'Command was:',run - sysexit(4) + run = tools['transformation']+' '+curname+'.bgf xbgf/'+a+'.xbgf '+curname+'.'+a+'.bgf' + logwrite(run) + if os.system(run+shutup): + print a,'failed on',curname + print 'Command was:',run + sysexit(4) curname += '.'+a a=cut[:] a.reverse() name = ' '.join(a) - if tools.has_key('validator'): - a = tools['validator']+' '+curname+'.bgf' + if tools.has_key('validation'): + a = tools['validation']+' '+curname+'.bgf' logwrite(a) print 'Successfully performed',name,'- the result is', if os.system(a+shutup): @@ -288,7 +249,7 @@ def buildtargets(): def diffall(t,car,cdr): if len(cdr)==1: - run = tools['diff']+' '+car+'.bgf '+cdr[0]+'.bgf' + run = tools['comparison']+' '+car+'.bgf '+cdr[0]+'.bgf' logwrite(run) ret = os.system(run+shutup) if ret!=0: @@ -359,11 +320,9 @@ def runtestset(): # evaluate if context is given results = {} for program in implementations.keys(): - results[program]=0 - for cmd in implementations[program][1]: - run = expanduni(cmd,{'input':testcase[0],'context':testcase[1],'yields':testcase[2]}) - logwrite(run) - results[program]+=os.system(run) + run = expanduni(implementations[program][1]+' '+testcase[1]+' '+testcase[0]+' '+testcase[2],{}) + logwrite(run) + results[program]=os.system(run+shutup) print 'Test case',testcase[0], if results.values()==[0]*len(implementations): # all zeros @@ -377,11 +336,9 @@ def runtestset(): # parse otherwise results = {} for program in implementations.keys(): - results[program]=0 - for cmd in implementations[program][0]: - run = expanduni(cmd,{'input':testcase[0],'output':testcase[0]+'.parsed'}) - logwrite(run) - results[program]+=os.system(run) + run = expanduni(implementations[program][0]+' '+testcase[0]+' '+testcase[0]+'.parsed',{}) + logwrite(run) + results[program]=os.system(run+shutup) print 'Test case',testcase[0], if results.values()==[0]*len(implementations): # all zeros @@ -394,25 +351,29 @@ def runtestset(): def checkconsistency(): # some simple assertions + # all targets depend on existing targets or sources + for t in targets.keys(): + for i in targets[t][0]: + if not (targets.has_key(i[0]) or sources.has_key(i[0])): + print 'Target',t,'needs',i[0],'which is not defined' + sysexit(7) + # all actions can be found try: - # all targets depend on existing targets or sources - for t in targets.keys(): - for i in targets[t][0]: - if not (targets.has_key(i[0]) or sources.has_key(i[0])): - print 'Target',t,'needs',i[0],'which is not defined' - raise Exception - except: - sysexit(7) + for a in actions: + open('xbgf/'+a+'.xbgf','r').close() + except IOError, e: + print 'Undefined action used: need',e.filename + sysexit(8) if __name__ == "__main__": - print 'Language Covergence Infrastructure v1.5' + print 'Language Covergence Infrastructure v1.6' if len(sys.argv) == 3: log = open(sys.argv[1].split('.')[0]+'.log','w') readxmlconfig(sys.argv[1]) checkconsistency() makegraph(sys.argv[2]) extractall() - if tools.has_key('validator'): + if tools.has_key('validation'): validateall() buildtargets() print 'Grammar convergence ended successfully.' diff --git a/topics/fl/lci/fl.lcf b/topics/fl/lci/fl.lcf index 59bb8be5..97abc7cd 100644 --- a/topics/fl/lci/fl.lcf +++ b/topics/fl/lci/fl.lcf @@ -14,67 +14,35 @@ slps/shared/tools - - runjava1jar - - fl/java1/javafl.jar - - - - rundcgdir - - fl/prolog - - - - if validator is present, extracted bgfs and all bgfs produced by transformations will be validated with it - - - validator + + validation java -jar slps/download/msv/msv.jar slps/shared/xsd/bgf.xsd - diff + comparison tools/bdt testset - - xsltproc slps/shared/xsl/ldf2samples.xslt fl/ldf/fl.ldf + + tools/ldf2samples fl/ldf/fl.ldf - - - unerase - abstract1 - concrete2abstract - downcase - horizontal2vertical - preferDcg - reroot - trimJaxb - downcase - trimOm - preferJaxb - stripTerminals - layering - preferJava - massageXsd - - - tools/xbgf .bgf xbgf/.xbgf ..bgf - - - - + + transformation + + tools/xbgf + + + antlr - + tools/antlr2bgf @@ -86,21 +54,21 @@ antlr.bgf - - - - java -cp ${CLASSPATH}:runjava1jar -ea TestIO + + + + tools/runantlrparser - - - - java -cp ${CLASSPATH}:runjava1jar -ea TestEvaluator + + + + tools/runantlrevaluator - + dcg - + tools/dcg2bgf @@ -112,21 +80,21 @@ dcg.bgf - - + + - swipl -q -f rundcgdir/TestIO.pro -t "main('','')" + tools/runprologparser - - + + - swipl -q -f rundcgdir/TestEvaluator.pro -t "main('','',)" + tools/runprologevaluator - + om - + tools/java2bgf @@ -141,11 +109,11 @@ om.bgf - + xsd - + tools/xsd2bgf @@ -157,11 +125,11 @@ xsd.bgf - + jaxb - + tools/java2bgf @@ -176,7 +144,7 @@ jaxb.bgf - +