Skip to content

Commit

Permalink
Languedoc stuff
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@629 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed May 13, 2009
1 parent f524f12 commit bcf3481
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 33 deletions.
6 changes: 5 additions & 1 deletion shared/python/pp_pp.py
Expand Up @@ -3,6 +3,10 @@

# post-processor for pretty-printer

if len(sys.argv) > 1:
maxLen = int(sys.argv[1])
else:
maxLen = 70
mode = 0
for line in sys.stdin:
if mode == 1:
Expand All @@ -13,7 +17,7 @@
tokens = line.split(' ')
lline = tokens[0]
for token in tokens[1:]:
if len(lline + ' ' + token)>70:
if len(lline + ' ' + token)>maxLen:
print lline
lline = ' '*16 + token
else:
Expand Down
20 changes: 12 additions & 8 deletions shared/python/xldf.py
Expand Up @@ -9,36 +9,40 @@
#acceptedtags = ('{'+xsdns+'}complexType','{'+xsdns+'}element','{'+xsdns+'}simpleType','{'+xsdns+'}group')

# Unified interface
def xldf_perform_command(cmd,ltree):
def xldf_perform_command(localpath,cmd,ltree):
commandName = cmd.tag.replace(slpsns.xldf_(''),'')
if commandName == 'transform-document':
xldf_transform_document(cmd,ltree)
xldf_transform_document(localpath,cmd,ltree)
return
try:
eval('xldfCommands.xldf_'+commandName.replace('-','_'))(cmd,ltree)
eval('xldfCommands.xldf_'+commandName.replace('-','_'))(localpath,cmd,ltree)
except NameError,e:
print '[----] Unknown XLDF command:',commandName
print e
sys.exit(1)

def xldf_transform_document(cmd,tree):
def xldf_transform_document(localpath,cmd,tree):
print '[XLDF] transform(...,',cmd.findtext('file').split('/')[-1],') starts'
try:
xtree = ET.parse(cmd.findtext('file'))
xtree = ET.parse(localpath+cmd.findtext('file'))
except IOError,e:
print '[----] xldf:transform failed: file',cmd.findtext('file'),'not found'
print '[----] xldf:transform failed: file',localpath+cmd.findtext('file'),'not found'
return
for incmd in xtree.findall('*'):
xldf_perform_command(incmd,tree)
xldf_perform_command(localpath,incmd,tree)
print '[XLDF] transform(...,',cmd.findtext('file').split('/')[-1],') is done'
return

def main(xldffile,inldffile,outldffile):
grammar={}
if xldffile.find('/')<0:
localpath = ''
else:
localpath = '/'.join(xldffile.split('/')[:-1])+'/'
xtree = ET.parse(xldffile)
ltree = ET.parse(inldffile)
for cmd in xtree.findall('*'):
xldf_perform_command(cmd,ltree)
xldf_perform_command(localpath,cmd,ltree)
ltree.write(outldffile)
return

Expand Down
38 changes: 19 additions & 19 deletions shared/python/xldfCommands.py
Expand Up @@ -6,9 +6,9 @@
import elementtree.ElementTree as ET

# Commands
def xldf_insert(cmd,tree):
def xldf_insert(localpath,cmd,tree):
if cmd.findall('*')[0].findall('*')[0].tag != 'text':
xldf_insert_symbolic(cmd,tree)
xldf_insert_symbolic(localpath,cmd,tree)
return
welookfor = preparetext(cmd.findtext('*/*'))
for cnt in tree.findall('.//content'):
Expand Down Expand Up @@ -54,7 +54,7 @@ def xldf_insert(cmd,tree):
print '[----] xldf:insert failed, cannot find the designated target!'
return

def xldf_insert_symbolic(cmd,tree):
def xldf_insert_symbolic(localpath,cmd,tree):
welookfor = cmd.findall('*')[0].findall('*')[0]
for cnt in tree.findall('.//content'):
passed = False
Expand Down Expand Up @@ -99,7 +99,7 @@ def xldf_insert_symbolic(cmd,tree):
print '[----] xldf:insertS failed, cannot find the designated target!'
return

def xldf_append(cmd,tree):
def xldf_append(localpath,cmd,tree):
found = findnode(tree,cmd.findtext('where'))
if not found:
print '[----] xldf:append failed: target id',cmd.findtext('where'),'not found'
Expand Down Expand Up @@ -135,7 +135,7 @@ def xldf_append(cmd,tree):
print ')'
return

def xldf_place(cmd,tree):
def xldf_place(localpath,cmd,tree):
#found = tree.findall('//core[id="'+cmd.findtext('./section')+'"]')
found = findnode(tree,cmd.findtext('section'))
if not found:
Expand Down Expand Up @@ -164,7 +164,7 @@ def xldf_place(cmd,tree):
print '[----] xldf:place failed: don''t know how to place subsections in',found2.tag
return

def xldf_drop(cmd,tree):
def xldf_drop(localpath,cmd,tree):
found = findnode(tree,cmd.findtext('section'))
if not found:
print '[----] xldf:drop failed: node',cmd.findtext('section'),'not found!'
Expand All @@ -173,7 +173,7 @@ def xldf_drop(cmd,tree):
print '[XLDF] drop('+cmd.findtext('section')+')'
return

def xldf_combine(cmd,tree):
def xldf_combine(localpath,cmd,tree):
found = findnode(tree,cmd.findtext('section'))
if not found:
print '[----] xldf:combine failed: source node not found!'
Expand All @@ -191,7 +191,7 @@ def xldf_combine(cmd,tree):
# print '[----] xldf:combine failed: don''t know how to place subsections in',found2.tag
return

def xldf_retitle(cmd,tree):
def xldf_retitle(localpath,cmd,tree):
if cmd.findall('from/title'):
byid = False
welookfor = cmd.findtext('from/title')
Expand All @@ -217,7 +217,7 @@ def xldf_retitle(cmd,tree):
print '[XLDF] rename('+welookfor,',',cmd.findtext('to')+')'
return

def xldf_add_section(cmd,tree):
def xldf_add_section(localpath,cmd,tree):
success = False
s = cmd.findall('*')[0]
if s.tag in ('definitions','abbreviations','languageOverview'):
Expand Down Expand Up @@ -247,7 +247,7 @@ def xldf_add_section(cmd,tree):
print '[----] xldf:add-section failed, double check or try add-subsection instead'
return

def xldf_remove_section(cmd,tree):
def xldf_remove_section(localpath,cmd,tree):
found = findnode(tree,cmd.findtext('id'))
if found:
if cmd.findall('from'):
Expand All @@ -259,7 +259,7 @@ def xldf_remove_section(cmd,tree):
else:
print '[----] xldf:remove-section couldn''t find id',cmd.findtext('id')

def xldf_add_subsection(cmd,tree):
def xldf_add_subsection(localpath,cmd,tree):
success = False
s = cmd.findall('*')[0]
if s.tag in ('foreword','designGoals','scope','conformance','compliance','compatibility','notation','normativeReferences','documentStructure','whatsnew'):
Expand All @@ -279,7 +279,7 @@ def xldf_add_subsection(cmd,tree):
print '[----] xldf:add-subsection failed, double check or try add-section instead'
return

def xldf_extract_subsection(cmd,tree):
def xldf_extract_subsection(localpath,cmd,tree):
where = findnode(tree,cmd.findtext('from'))
if not where:
print '[----] xldf:extract-subsection failed, can''t find id',cmd.findtext('to')
Expand All @@ -302,7 +302,7 @@ def xldf_extract_subsection(cmd,tree):
print ')'
return

def xldf_add_figure(cmd,tree):
def xldf_add_figure(localpath,cmd,tree):
success = False
s = cmd.findall('*')[0]
found = findnode(tree,cmd.findtext('to'))
Expand All @@ -318,7 +318,7 @@ def xldf_add_figure(cmd,tree):
print '[----] add-figure failed, double check or try add-section instead'
return

def xldf_transform_grammar(cmd,tree):
def xldf_transform_grammar(localpath,cmd,tree):
root = ET.Element(slpsns.xbgf_('sequence'),{})
cx0 = 0
for rule in cmd.findall('*')[1:]:
Expand Down Expand Up @@ -389,11 +389,11 @@ def xldf_transform_grammar(cmd,tree):
print '[----] xldf:transform failed: no productions found in XBGF output'
return

def xldf_import_grammar(cmd,tree):
def xldf_import_grammar(localpath,cmd,tree):
try:
gtree = ET.parse(cmd.findtext('file'))
gtree = ET.parse(localpath+cmd.findtext('file'))
except IOError,e:
print '[----] xldf:import failed: file',cmd.findtext('file'),'not found'
print '[----] xldf:import failed: file',localpath+cmd.findtext('file'),'not found'
return
found = findnode(tree,cmd.findtext('target'))
if not found:
Expand All @@ -412,11 +412,11 @@ def xldf_import_grammar(cmd,tree):
print '[----] xldf:import failed: no productions found in',cmd.findtext('file')
return

def xldf_import_sample(cmd,tree):
def xldf_import_sample(localpath,cmd,tree):
ending = ''
if cmd.findall('prettyprinter'):
inputfile = 'printed_for_xldf.tmp'
if os.system(cmd.findtext('prettyprinter')+' '+cmd.findtext('file')+' '+inputfile):
if os.system(localpath+cmd.findtext('prettyprinter')+' '+localpath+cmd.findtext('file')+' '+inputfile):
print '[----] xldf:import failed: can''t execute the pretty-printer!'
return
ending = '- pretty-printed successfully'
Expand Down
2 changes: 1 addition & 1 deletion shared/tools/ldf2tex
Expand Up @@ -14,5 +14,5 @@ elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
else
xsltproc ${SLPS}/shared/xsl/ldf2tex.xslt $1 | python ${SLPS}/shared/python/pp_pp.py > $2
xsltproc ${SLPS}/shared/xsl/ldf2tex.xslt $1 | python ${SLPS}/shared/python/pp_pp.py 60 > $2
fi
24 changes: 24 additions & 0 deletions shared/tools/ldinc
@@ -0,0 +1,24 @@
#!/bin/sh

# Get our hands on basedir
LOCAL1=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL1}

if [ $# -ne 2 ]; then
echo "Languedoc Include tool: extracts LDFs from XSDs, transforms them and presents includable TeX documents."
echo "Usage: ldinc <format> <start-marker>"
echo "Where start-marker is either START_CONTENT or START_CORE"
exit 1
elif [ ! -d ${SLPS}/topics/languedoc/$1 ]; then
echo "Oops: directory $1 not found."
exit 1
else
${SLPS}/shared/tools/xsd2ldf ${SLPS}/shared/xsd/$1.xsd $1.ldf
${SLPS}/shared/tools/xldf ${SLPS}/topics/languedoc/$1/$1.xldf $1.ldf $1.ready.ldf
xsltproc ${SLPS}/shared/xsl/ldf2tex.xslt $1.ready.ldf | python ${SLPS}/shared/python/pp_pp.py 70 > $1.not.tex
cat $1.not.tex | grep -v 'END_CONTENT' | grep -A 10000 $2 > $1.tex
rm -f $1.not.tex $1.ready.ldf $1.ldf xldf-tmp* printed_for_xldf.tmp
fi

0 comments on commit bcf3481

Please sign in to comment.