I'm currently working on a code project in Python that transliterates LaTeX mathematical markup into standard Python commands \frac{a}{b} to a/b.
I went about this in a way that I felt would be the most friendly towards nested equations: recursion. Every equation is broken up into objects and operators, and objects, such as parenthetical statements and LaTeX terms, are evaluated again, until maximum depth is attained.
However, I've hit somewhat of a roadblock with regex when it comes to dismantling certain LaTeX terms with multiple nested parameters, like the one I mentioned above. After fiddling around and googling for an eternity, I ended up with this:
Only problem is, I encounter this error when trying to evaluate the exact same term in Python:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\re.py", line 206, in findall
return _compile(pattern, flags).findall(string)
File "C:\Python34\lib\re.py", line 288, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python34\lib\sre_compile.py", line 465, in compile
p = sre_parse.parse(p, flags)
File "C:\Python34\lib\sre_parse.py", line 746, in parse
p = _parse_sub(source, pattern, 0)
File "C:\Python34\lib\sre_parse.py", line 358, in _parse_sub
itemsappend(_parse(source, state))
File "C:\Python34\lib\sre_parse.py", line 694, in _parse
p = _parse_sub(source, state)
File "C:\Python34\lib\sre_parse.py", line 358, in _parse_sub
itemsappend(_parse(source, state))
File "C:\Python34\lib\sre_parse.py", line 694, in _parse
p = _parse_sub(source, state)
File "C:\Python34\lib\sre_parse.py", line 358, in _parse_sub
itemsappend(_parse(source, state))
File "C:\Python34\lib\sre_parse.py", line 681, in _parse
raise error("unexpected end of pattern")
sre_constants.error: unexpected end of pattern
I'm not quite sure what the problem is in my regex, and have been changing little things for a while trying to get it to work, to no avail...