From e28eb5198823d841deb39b0c8ff2005e8bdbf31e Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 27 Jun 2016 09:08:54 +0200 Subject: [PATCH 1/3] cache the latex yacc instance --- patacrep/latex/syntax.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/patacrep/latex/syntax.py b/patacrep/latex/syntax.py index edf9ceb1..7c76fbe2 100644 --- a/patacrep/latex/syntax.py +++ b/patacrep/latex/syntax.py @@ -2,6 +2,7 @@ import logging import ply.yacc as yacc +from functools import lru_cache from patacrep.latex import ast from patacrep.latex.detex import detex @@ -211,12 +212,17 @@ 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( + latex_yacc().parse( string, lexer=SimpleLexer().lexer, ) @@ -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 From b994f91d353b0444f9418eb8837e4f4b657a7021 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 27 Jun 2016 09:15:23 +0200 Subject: [PATCH 2/3] (pylint) fix --- patacrep/latex/syntax.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/patacrep/latex/syntax.py b/patacrep/latex/syntax.py index 7c76fbe2..b6daefd0 100644 --- a/patacrep/latex/syntax.py +++ b/patacrep/latex/syntax.py @@ -1,8 +1,8 @@ """Very simple LaTeX parser""" import logging -import ply.yacc as yacc from functools import lru_cache +import ply.yacc as yacc from patacrep.latex import ast from patacrep.latex.detex import detex @@ -223,9 +223,9 @@ def tex2plain(string): """Parse string and return its plain text version.""" return detex( latex_yacc().parse( - string, - lexer=SimpleLexer().lexer, - ) + string, + lexer=SimpleLexer().lexer, + ) ) def parse_song(content, filename=None): From 6da41a6c947d3902471f157f289d7001b9bfa0b0 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Mon, 27 Jun 2016 09:16:11 +0200 Subject: [PATCH 3/3] update news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f959491d..bbc8f7af 100644 --- a/NEWS.md +++ b/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