Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BNF output for JLS->BGF extractor
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@248 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Sep 10, 2008
1 parent 3f2da27 commit e755608
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions shared/tools/html2bgf
Expand Up @@ -7,13 +7,13 @@ cd ../..
SLPS=${PWD}
cd ${LOCAL1}

if [ $# -ne 2 ]; then
if [ $# -lt 2 ]; then
echo "This tool extracts a BGF from Java Language Standard"
echo "Usage: $0 <input-hypertext-document> <output-bgf>"
echo "Usage: $0 <input-hypertext-document> <output-bgf> [options]"
exit 1
elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
else
python ${SLPS}/topics/extraction/html2bgf/html2bgf.py $1 $2
python ${SLPS}/topics/extraction/html2bgf/html2bgf.py $@
fi
25 changes: 21 additions & 4 deletions topics/extraction/html2bgf/html2bgf.py
Expand Up @@ -225,11 +225,17 @@ def readGrammar(fn):
choices.append([a,b])
src.close()

def printGrammarText(fn):
ext = open(fn,'w')
for nt in prods.keys():
ext.write(serialiseT(nt,prods[nt]))
ext.close()

def printGrammar(fn):
ext = open(fn,'w')
ext.write('<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">')
for nt in prods.keys():
ext.write(serialise(nt,prods[nt]))
ext.write(serialiseX(nt,prods[nt]))
ext.write('</bgf:grammar>')
ext.close()

Expand Down Expand Up @@ -283,6 +289,11 @@ def automatedImprove():
bs[i]='"("'
bs[i+2]='")"'
print 'Bracketing heuristic fix in',nt,'(singleton group)'
if i+4<len(bs) and bs[i+4]==')' and ((bs[i+1]=='[' and bs[i+3]==']') or (bs[i+1]=='{' and bs[i+3]=='}')):
# ([x]) or ({x}) is not BNF bracketing either
bs[i]='"("'
bs[i+4]='")"'
print 'Bracketing heuristic fix in',nt,'(singleton complex group)'
newprods.append(fixBrackets(nt,' '.join(bs).split()))
prods[nt]=newprods
pass
Expand Down Expand Up @@ -336,15 +347,21 @@ def fixBracketPair(nt,arr,left,right):

if __name__ == "__main__":
print 'HTML to Grammar automated extractor'
if len(sys.argv) == 3:
if len(sys.argv)==3 or len(sys.argv)==4:
print 'Reading the HTML document...'
readGrammar(sys.argv[1])
print 'Massaging the grammar...'
automatedImprove()
print 'Writing the extracted grammar...'
printGrammar(sys.argv[2])
if sys.argv[-1]=='-bnf':
printGrammarText(sys.argv[2])
else:
printGrammar(sys.argv[2])
else:
print 'Usage:'
print ' ',sys.argv[0],'<input>','<output>'
print ' ',sys.argv[0],'''<input> <output> [<options>]
Possible options:
-bnf Outputs in EBNF rather then in BGF'''
sys.exit(1)

5 changes: 4 additions & 1 deletion topics/java/lci/Makefile
Expand Up @@ -2,6 +2,9 @@ validator = ../../../shared/tools/checkxml

build:

diff: test
gdt bgf/jls2.prefer3.mkSignature.addFeatures2to3.bgf bgf/jls3.fixErrors3.mkSignature.make3converge.bgf

test:
python ../../convergence/lci/lci.py java.lcf architecture
@rm -f architecture*.dot
Expand All @@ -17,5 +20,5 @@ clean:
rm -rf bin obj
rm -f *.user *.suo
rm -f architecture*
rm -f fl.log
rm -f java.log

0 comments on commit e755608

Please sign in to comment.