""",
}
def htmlify(src, dest):
def highlight_words(val):
breaks = "[](). \n&/#"
sep = '\0'
for b in breaks:
val = val.replace(b, sep+b+sep)
val = val.split(sep)
r = ''
for v in val:
if not v:
continue
if v in ('CMENE', 'BRIVLA'):
v = '{1}'.format(v.lower(), v)
elif v.replace('h', 'H') == v.upper() and set(v).issubset(set(string.ascii_letters)):
#Is a selma'o
v = '{0}'.format(v)
elif v in list_order:
#Is a grammar thingie
v = '{0}'.format(v)
r += v
return r
grammar = {}
dess = {}
list_order = []
defs = []
key = None
header = ''
descr = ''
for line in open(src):
if line[0] == ';':
line = line[1:]
if line and line[0] == ';':
continue #Double ;; == ignore
if key == None:
if header:
descr += line
else:
header = line
else:
dess[key] += line
continue
if line[0] == ' ':
if ';' in line:
line, com = line.split(';', 1)
if com and com[0] != ';':
dess[key] += cgi.escape(com)
line = cgi.escape(line)
defs[-1] += line
grammar[key] += line
elif '=' in line:
line = cgi.escape(line)
defs.append(line)
key, des = line.split('=')
key = key.strip()
des = des.strip()
if des and des[0] == ';':
des = des[1:]
grammar[key] = ''
dess[key] = des
list_order.append(key)
len_order = list(list_order)
len_order.sort(key=lambda i: -len(i))
out = open(dest, 'w')
out.write("""
Lojban EBNF
""")
if header:
out.write("
%s
"%header)
if descr:
out.write("
%s
"%descr)
if menu:
out.write("""
\n""")
for name in menu_order:
out.write("""
{0}
{1}
""".format(name, menu[name]))
out.write("""
\n""")
for key in list_order:
val = grammar[key]
pairs = [("[", "]"), ('(', ')')]
val = highlight_words(val)
for A, B in pairs:
#val = val.replace()
val = val.replace(A, ''+A)
val = val.replace(B, B+'')
val = val.replace(' ', '')
if dess[key]:
desc = '