Skip to content

Commit

Permalink
trying to make ANTLR extractor somewhat more general
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@548 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Apr 7, 2009
1 parent 4b9fcbf commit 0a41414
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions topics/extraction/antlr2bgf/antlrstrip.py
Expand Up @@ -2,22 +2,31 @@
import sys
import re

p0 = re.compile('options [{][^}]*[}]')
p5 = re.compile('\'}\'')
p4 = re.compile('tokens [{][^}]*[}]')
p1 = re.compile('[{][^}]*[}]')
p2 = re.compile('[@][a-z]*')
p3 = re.compile('returns [\[][^\]]*[\]]')
p6 = re.compile('/[*]([^*]|[*][^/])*[*]/')
p4 = re.compile('tokens [{][^}]*[}]')

def main():
if (len(sys.argv)!=3):
print "Usage: antlrstrap.py Grammar.g Grammar_pure.g"
print "Usage: antlrstrip.py Grammar.g Grammar_pure.g"
return
inf = open(sys.argv[1],"r")
out = open(sys.argv[2],'w')
# reading the grammar
lines = ' '.join(inf.readlines())
# regexp-powered cleaning
lines = p1.sub('',lines)
lines = p2.sub('',lines)
lines = p3.sub('',lines)
lines = p6.sub('',lines) # kill comments
lines = p5.sub('',lines) # kill '}'s
lines = p1.sub('',lines) # kill semantic actions
lines = p2.sub('',lines) # kill modifiers
lines = p3.sub('',lines) # kill returns
lines = p0.sub('',lines) # kill options
lines = p4.sub('',lines) # kill tokens
# whitespace shrinking
lines = ' '.join(lines.split())
# removing terminal symbols, pretty-printing the rest
Expand Down

0 comments on commit 0a41414

Please sign in to comment.