|
|
@ -1,6 +1,7 @@ |
|
|
|
"""Very simple LaTeX parser""" |
|
|
|
|
|
|
|
import logging |
|
|
|
from functools import lru_cache |
|
|
|
import ply.yacc as yacc |
|
|
|
|
|
|
|
from patacrep.latex import ast |
|
|
@ -211,15 +212,20 @@ def silent_yacc(*args, **kwargs): |
|
|
|
**kwargs |
|
|
|
) |
|
|
|
|
|
|
|
@lru_cache() |
|
|
|
def latex_yacc(filename=None): |
|
|
|
"""Call the yacc with the LaTeX parser. |
|
|
|
""" |
|
|
|
parser = silent_yacc(module=LatexParser(filename)) |
|
|
|
return parser |
|
|
|
|
|
|
|
def tex2plain(string): |
|
|
|
"""Parse string and return its plain text version.""" |
|
|
|
return detex( |
|
|
|
silent_yacc( |
|
|
|
module=LatexParser(), |
|
|
|
).parse( |
|
|
|
string, |
|
|
|
lexer=SimpleLexer().lexer, |
|
|
|
) |
|
|
|
latex_yacc().parse( |
|
|
|
string, |
|
|
|
lexer=SimpleLexer().lexer, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
def parse_song(content, filename=None): |
|
|
@ -231,7 +237,7 @@ def parse_song(content, filename=None): |
|
|
|
display error messages. |
|
|
|
""" |
|
|
|
return detex( |
|
|
|
silent_yacc(module=LatexParser(filename)).parse( |
|
|
|
latex_yacc(filename).parse( |
|
|
|
content, |
|
|
|
lexer=SongLexer().lexer, |
|
|
|
).metadata |
|
|
|