Browse Source

Merge pull request #233 from patacrep/cache_yacc

Cache the latex yacc instance
pull/235/head
oliverpool 8 years ago
committed by GitHub
parent
commit
51595895c3
  1. 1
      NEWS.md
  2. 20
      patacrep/latex/syntax.py

1
NEWS.md

@ -15,6 +15,7 @@
* The `meta` directive is now supported: `{meta: COMMANDNAME:arg}` [#220](https://github.com/patacrep/patacrep/pull/220)
* LaTeX songs
* The `meta` directive is now supported: `\metacrep{COMMANDNAME}{arg}` [#220](https://github.com/patacrep/patacrep/pull/220)
* Faster index generation [#233](https://github.com/patacrep/patacrep/pull/233)
# patacrep 5.0.0

20
patacrep/latex/syntax.py

@ -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

Loading…
Cancel
Save