From 3087a55219db5c039297996957fbf891bd0203ea Mon Sep 17 00:00:00 2001 From: grammarware Date: Sat, 8 Nov 2008 17:19:22 +0000 Subject: [PATCH] updated the extractor, added BGF analysis tool git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@408 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- shared/tools/checkbgf | 11 ++++ topics/extraction/html2bgf/html2bgf.py | 5 ++ topics/java/lci/Makefile | 2 +- topics/java/lci/java-lci.csproj | 3 +- topics/java/lci/xbgf/correct-app3.xbgf | 5 ++ topics/java/lci/xbgf/extend-doc12.xbgf | 19 +++---- topics/java/lci/xbgf/refactor-app3.xbgf | 37 +++++++++++-- .../java/lci/xbgf/refactorClasses-doc2.xbgf | 4 +- .../java/lci/xbgf/refactorClasses-doc3.xbgf | 31 ++++------- .../lci/xbgf/refactorInterfaces-doc3.xbgf | 42 +++++++++++++++ topics/presentation/analyses/bgf_check.py | 53 +++++++++++++++++++ 11 files changed, 174 insertions(+), 38 deletions(-) create mode 100755 shared/tools/checkbgf create mode 100755 topics/presentation/analyses/bgf_check.py diff --git a/shared/tools/checkbgf b/shared/tools/checkbgf new file mode 100755 index 00000000..9028ee40 --- /dev/null +++ b/shared/tools/checkbgf @@ -0,0 +1,11 @@ +#!/bin/sh + +# Get our hands on basedir +LOCAL1=${PWD} +cd `dirname $0` +cd ../.. +SLPS=${PWD} +cd ${LOCAL1} + +python ${SLPS}/topics/presentation/analyses/bgf_check.py $1 + diff --git a/topics/extraction/html2bgf/html2bgf.py b/topics/extraction/html2bgf/html2bgf.py index f257e2a7..a06aa752 100755 --- a/topics/extraction/html2bgf/html2bgf.py +++ b/topics/extraction/html2bgf/html2bgf.py @@ -286,6 +286,11 @@ def mapHTMLtoTokenStream(line): flags.append(True) line = line[14:] continue + if line.find('Opt')==0: + tokens.append('?????') + flags.append(True) + line = line[14:] + continue if line.find('opt')==0: tokens.append('?????') flags.append(True) diff --git a/topics/java/lci/Makefile b/topics/java/lci/Makefile index 3bf9c97c..2daf5967 100644 --- a/topics/java/lci/Makefile +++ b/topics/java/lci/Makefile @@ -4,7 +4,7 @@ build: diff: python ../../convergence/lci/lci.py java3.lcf architecture - gdts bgf/app3.correct.refactor.generalizeLabels.generalizeBlock.generalize.bgf bgf/doc3.correct.generalizeModifiers.generalizeNames.deyaccify.refactorTypes.refactorExpressions.inlineStatements.generalizeStatements.refactorStatements.editExpressions.refactorClasses.refactorInterfaces.refactorEnums.refactorDeclarations.edit.bgf + gdts bgf/wa.bgf bgf/wd.bgf test: python ../../convergence/lci/lci.py java.lcf architecture diff --git a/topics/java/lci/java-lci.csproj b/topics/java/lci/java-lci.csproj index 4020dfb0..d93f361b 100644 --- a/topics/java/lci/java-lci.csproj +++ b/topics/java/lci/java-lci.csproj @@ -97,7 +97,8 @@ - + + diff --git a/topics/java/lci/xbgf/correct-app3.xbgf b/topics/java/lci/xbgf/correct-app3.xbgf index 3edeb921..a2328d14 100644 --- a/topics/java/lci/xbgf/correct-app3.xbgf +++ b/topics/java/lci/xbgf/correct-app3.xbgf @@ -178,4 +178,9 @@ Annotation: ElementValues + + + + Identifier + \ No newline at end of file diff --git a/topics/java/lci/xbgf/extend-doc12.xbgf b/topics/java/lci/xbgf/extend-doc12.xbgf index f91c4261..22bee761 100644 --- a/topics/java/lci/xbgf/extend-doc12.xbgf +++ b/topics/java/lci/xbgf/extend-doc12.xbgf @@ -1506,10 +1506,11 @@ ? - WildcardBounds - - - Opt + + + WildcardBounds + + @@ -1609,11 +1610,11 @@ vs. - [], ,([n(TypeDeclSpecifier), ?(n(TypeArguments))]) --> - + InterfaceType - + ClassType - + InterfaceType @@ -1633,7 +1634,7 @@ - + ClassType @@ -2164,7 +2165,7 @@ - + diff --git a/topics/java/lci/xbgf/refactor-app3.xbgf b/topics/java/lci/xbgf/refactor-app3.xbgf index a8eec1fc..9956d0dd 100644 --- a/topics/java/lci/xbgf/refactor-app3.xbgf +++ b/topics/java/lci/xbgf/refactor-app3.xbgf @@ -12,9 +12,6 @@ Expression3 - - InterfaceMemberDecl - + --> @@ -108,7 +105,37 @@ - + Selector + + + + ModifiersOpt + + + + Modifier + + + + + + + + InterfaceMemberDecl + InterfaceMethodOrFieldDecl + InterfaceMethodOrFieldRest + InterfaceGenericMethodDecl + InterfaceMethodDeclaratorRest + VoidInterfaceMethodDeclaratorRest + ConstantDeclaratorsRest + + + InterfaceBodyDeclaration + + + + InterfaceBodyDeclaration + diff --git a/topics/java/lci/xbgf/refactorClasses-doc2.xbgf b/topics/java/lci/xbgf/refactorClasses-doc2.xbgf index 918b591a..14d95c90 100644 --- a/topics/java/lci/xbgf/refactorClasses-doc2.xbgf +++ b/topics/java/lci/xbgf/refactorClasses-doc2.xbgf @@ -94,7 +94,7 @@ Later with factor/distribute this should be done better! --> - + ClassOrInterfaceDeclaration @@ -405,7 +405,7 @@ - + diff --git a/topics/java/lci/xbgf/refactorClasses-doc3.xbgf b/topics/java/lci/xbgf/refactorClasses-doc3.xbgf index 8b68f92a..45149b3e 100644 --- a/topics/java/lci/xbgf/refactorClasses-doc3.xbgf +++ b/topics/java/lci/xbgf/refactorClasses-doc3.xbgf @@ -175,7 +175,7 @@ - + @@ -204,7 +204,7 @@ - + @@ -305,9 +305,9 @@ vs. - [], ;([n(FormalParameter), ,([n(FormalParameters), t((,)), n(FormalParameter)])]) --> - + FormalParameters - + FormalParameters @@ -330,7 +330,7 @@ - + FormalParameterDecls @@ -360,7 +360,7 @@ - + FormalParameterDeclsRest @@ -654,7 +654,7 @@ - + @@ -730,7 +730,7 @@ - + VoidMethodDeclaratorRest @@ -782,7 +782,7 @@ - + MethodOrFieldDecl @@ -801,7 +801,7 @@ - + MethodOrFieldRest @@ -1044,16 +1044,6 @@ - - ModifiersOpt - + + + + + + TypeParameters + + + + + + + TypeParameters + + + + + + + + + InterfaceBodyDeclaration + + + InterfaceBodyDeclaration + \ No newline at end of file diff --git a/topics/presentation/analyses/bgf_check.py b/topics/presentation/analyses/bgf_check.py new file mode 100755 index 00000000..358608cf --- /dev/null +++ b/topics/presentation/analyses/bgf_check.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +import os +import sys + +productions = "count(/*/*[local-name()='production'])" +nonterminals = "count(/*[local-name()='grammar']/*/nonterminal[not(text()=../preceding-sibling::*/nonterminal/text())])" +top = "count(/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())])" +listtop = "/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())]" +bottom = " | (echo '' ; xpath '//nonterminal[not(text()=/*/*/nonterminal/text())]' 2> /dev/null; echo '' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " +listbottom = "//nonterminal[not(text()=/*/*/nonterminal/text())]" +unique = " | (echo '' ; xpath '//nonterminal' 2> /dev/null; echo '' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " + +def runxpath(filename,xpathexpr): + os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') + tmp = open('TMP-res','r') + res = tmp.readline().strip() + tmp.close() + return res + +def runxpathlist(filename,xpathexpr): + os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') + tmp = open('TMP-res','r') + resa = tmp.readline().strip().split('') + resu = [] + for x in resa: + if x not in resu: + resu.append(x) + resu.sort() + return ''.join(resu).replace('',', ')[:-2] + tmp.close() + res = res.replace('','').replace('',', ') + return res[:-2] + +def runxpath2(filename,xpathexpr): + os.system('cat '+filename+xpathexpr+' 1>TMP-res 2>/dev/null') + tmp = open('TMP-res','r') + res = tmp.readline().strip() + tmp.close() + return res + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool generates an overview of a bunch of BGF sources and targets.' + print 'Usage:' + print ' checkbgf ' + sys.exit(1) + print 'Productions: ',runxpath(sys.argv[1],productions) + print 'Nonterminals defined:',runxpath(sys.argv[1],nonterminals) + print '%20s:' % 'unique',runxpath2(sys.argv[1],unique) + print '%20s:' % 'bottom',runxpath2(sys.argv[1],bottom),'(',runxpathlist(sys.argv[1],listbottom),')' + print '%20s:' % 'top',runxpath(sys.argv[1],top),'(',runxpathlist(sys.argv[1],listtop),')' + sys.exit(0) +