Make sty file parser fit for mdsymbol.sty

Now it is able to generate a lib/symbols section from mdsymbol.sty.
This commit is contained in:
Georg Baum 2013-12-11 21:07:59 +01:00
parent ee08aefeac
commit bbdff9996f

View File

@ -25,6 +25,7 @@ def process(file):
package, ext = os.path.splitext(os.path.basename(file)) package, ext = os.path.splitext(os.path.basename(file))
if ext != ".sty": if ext != ".sty":
package = '' package = ''
mdsymbolcode = 0
n = len(lines) n = len(lines)
for i in xrange(n): for i in xrange(n):
@ -44,19 +45,33 @@ def process(file):
if mo != None: if mo != None:
font_names[mo.group(1)] = mo.group(3) font_names[mo.group(1)] = mo.group(3)
mo = re.match(r'.*\\DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line) mo = re.match(r'^\s*\\mdsy\@DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
if mo != None:
font_names[mo.group(1)] = mo.group(3)
# \mdsy@setslot resets the counter for \mdsy@DeclareSymbol
mo = re.match(r'^\s*\\mdsy\@setslot\s*\{(.*?)\}.*', line)
if mo != None:
mdsymbolcode = int(mo.group(1))
# \mdsy@nextslot increments the counter for \mdsy@DeclareSymbol
mo = re.match(r'^\s*\\mdsy\@nextslot.*', line)
if mo != None:
mdsymbolcode = mdsymbolcode + 1
mo = re.match(r'.*\\(\\mdsy\@)?DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
code = -1 code = -1
try: try:
if mo != None: if mo != None:
symbol = mo.group(2) symbol = mo.group(3)
type = mo.group(3) type = mo.group(4)
font = mo.group(4) font = mo.group(5)
if mo.group(5) == '': if mo.group(6) == '':
code = int(mo.group(6)) code = int(mo.group(7))
elif mo.group(5) == '"': elif mo.group(6) == '"':
code = int(mo.group(6), 16) code = int(mo.group(7), 16)
else: else:
code = int(mo.group(6), 8) code = int(mo.group(7), 8)
else: else:
mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line) mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
if mo != None: if mo != None:
@ -67,6 +82,23 @@ def process(file):
except ValueError: except ValueError:
code = -1 code = -1
if mo == None:
mo = re.match(r'^\s*\\mdsy\@DeclareSymbol\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
if mo != None:
symbol = mo.group(1)
type = mo.group(3)
font = mo.group(2)
code = mdsymbolcode
mdsymbolcode = mdsymbolcode + 1
if mo == None:
mo = re.match(r'^\s*\\mdsy\@DeclareAlias\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
if mo != None:
symbol = mo.group(1)
type = mo.group(3)
font = mo.group(2)
code = mdsymbolcode - 1
if mo != None and symbol not in ignore_list: if mo != None and symbol not in ignore_list:
mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line) mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
if mo2 != None and symbol == mo2.group(1)+"op": if mo2 != None and symbol == mo2.group(1)+"op":